Skip to content

Commit

Permalink
Align with the lastest SeaCat CA progress.
Browse files Browse the repository at this point in the history
* tenant added
* windows compatibility
* static tenant removed
* proper default tenant
  • Loading branch information
martinkubajda authored and ateska committed Feb 24, 2019
1 parent 22dd002 commit 2ea3fcf
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
15 changes: 7 additions & 8 deletions itss.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,16 @@ class ITSS(object):
fname = './ts_102941_v111.asn'
asn1 = asn1tools.compile_files(fname, 'der')


def __init__(self, directory, ea_url, aa_url, hsm):
def __init__(self, tenant, directory, ea_url, aa_url, hsm):
self.EC = None # Enrollment credentials
self.AT = None # Authorization ticket

if not os.path.isdir(directory):
os.mkdir(directory)
self.Directory = directory

self.AA_url = aa_url
self.EA_url = ea_url
self.AA_url = aa_url + '/' + tenant
self.EA_url = ea_url + '/' + tenant

self.Certs = {}

Expand Down Expand Up @@ -346,10 +345,11 @@ def main():
parser.add_argument('-i', '--enrollment-id', help='Specify a custom enrollment ID')
parser.add_argument('-H', '--hsm', default="emulated", choices=['cicada', 'yubikey', 'emulated'], help='Use the HSM to store a private key.')
parser.add_argument('--g5-sim', default="224.1.1.1 5007 32 auto", help='Configuration of G5 simulator')
parser.add_argument('-t', '--tenant', default="c-its", help='Client tenant')

args = parser.parse_args()

itss_obj = ITSS(args.DIR, args.ea_url, args.aa_url, args.hsm)
itss_obj = ITSS(args.tenant, args.DIR, args.ea_url, args.aa_url, args.hsm)
ok = itss_obj.load()
store = False
if not ok:
Expand Down Expand Up @@ -391,16 +391,15 @@ def datagram_received(self, data, addr):
traceback.print_exc()

g5sim = MyG5Simulator(loop, args.g5_sim)


# Send out some payload periodically
async def periodic_sender():
while True:
smb = itss.CITS103097v121SecureMessageBuilder()
msg = smb.finish(itss_obj.AT, itss_obj.HSM, "payload from '{}'".format(platform.node()))

g5sim.send(msg)
await asyncio.sleep(1)
await asyncio.sleep(1)

asyncio.ensure_future(periodic_sender(), loop=loop)


Expand Down
13 changes: 9 additions & 4 deletions itss/g5sim.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import asyncio
import socket
import os


class G5Simulator(object):

def __init__(self, loop, config=""):
confp = config.split(' ')
if len(confp) == 0:
confp.append('224.1.1.1') # Default multicast group
confp.append('239.1.1.1') # Default multicast group
if len(confp) == 1:
confp.append('5007') # Default multicast port
if len(confp) == 2:
Expand All @@ -27,17 +28,21 @@ def __init__(self, loop, config=""):

self.ReceivingSocket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
self.ReceivingSocket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
self.ReceivingSocket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)

self.ReceivingSocket.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, 32)
self.ReceivingSocket.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_LOOP, 0)
self.ReceivingSocket.bind((self.mcast_grp, self.mcast_port))
if os.name != 'nt':
self.ReceivingSocket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)

self.ReceivingSocket.bind(('0.0.0.0', self.mcast_port))
self.ReceivingSocket.setsockopt(socket.SOL_IP, socket.IP_MULTICAST_IF, socket.inet_aton(self.mcast_if))
self.ReceivingSocket.setsockopt(socket.SOL_IP, socket.IP_ADD_MEMBERSHIP, socket.inet_aton(self.mcast_grp) + socket.inet_aton(self.mcast_if))

self.SendingSocket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
self.SendingSocket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
self.SendingSocket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)
self.SendingSocket.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, 32)
if os.name != 'nt':
self.SendingSocket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)

asyncio.ensure_future(self._run(loop), loop=loop)

Expand Down

0 comments on commit 2ea3fcf

Please sign in to comment.