est_obj = grasp.objective("SRV.est") est_obj.synch = True est_obj.discoverable = False #override default est_obj.value = "EST-TLS" #for RFC7030 # est_obj.loop_count not set, the API forces it to 1 for link-local use #################################### # Create an asa_locator for IKEv2 # communication with peers #################################### acp_address = grasp._unspec_address # This is the unspecified address, # which signals link-local address to API acp_ttl = 120000 #milliseconds to live of the announcement acp_locator = grasp.asa_locator(acp_address, 0, False) acp_locator.is_ipaddress = True acp_locator.protocol = socket.IPPROTO_UDP #################################### # Create an asa_locator for EST-TLS # communication with peers #################################### est_address = grasp._unspec_address # This is the unspecified address, # which signals link-local address to API est_ttl = 120000 #milliseconds to live of the announcement est_locator = grasp.asa_locator(est_address, 0, False) est_locator.is_ipaddress = True est_locator.protocol = socket.IPPROTO_TCP
#################################### # Create a TCP port for BRSKI-TCP #################################### # For this demo, we just make up some numbers: tcp_port = 80 tcp_proto = socket.IPPROTO_TCP tcp_address = grasp._my_address # current address determined by GRASP kernel #################################### # Construct a correponding GRASP ASA locator #################################### tcp_locator = grasp.asa_locator(tcp_address, None, False) tcp_locator.protocol = tcp_proto tcp_locator.port = tcp_port tcp_locator.is_ipaddress = True #################################### # Create a UDP port for BRSKI-UDP #################################### # For this demo, we just make up some numbers: udp_port = 880 udp_proto = socket.IPPROTO_UDP udp_address = grasp._my_address # current address determined by GRASP kernel ####################################
#################################### # For this demo, we just make up some numbers: t_port = 11800 + grasp._prng.randint(0, 5) #slightly random for demo u_port = 11900 + grasp._prng.randint(0, 5) #slightly random for demo proxy_address = grasp._unspec_address # This is the unspecified address, # which signals link-local address to API proxy_ttl = 180000 #milliseconds to live of the announcement #################################### # Construct a correponding asa_locator #################################### proxy_locator = grasp.asa_locator(proxy_address, 0, False) proxy_locator.is_ipaddress = True #################################### # Construct the GRASP objective to announce the proxy #################################### proxy_obj = grasp.objective("AN_proxy") proxy_obj.synch = True proxy_obj.value = "" # proxy_obj.loop_count not set, the API forces it to 1 for link-local use #################################### # Register the GRASP objective ####################################
def main(args): ################################### # Main thread starts here ################################### grasp.tprint("==========================") grasp.tprint("Registrar initializing") grasp.tprint("==========================") grasp.test_mode = False # set if you want detailed diagnostics #time.sleep(1) # time to read the text #################################### # Register this ASA #################################### # The ASA name is arbitrary - it just needs to be # unique in the GRASP instance. If you wanted to # run two registrars in one GRASP instance, they # would need different names. For example the name # could include a timestamp. grasp.skip_dialogue(False, False, True) _err, asa_nonce = grasp.register_asa("Reggie") #grasp.tprint("TYPE: ", type(asa_nonce)) #.skip_dialogue(False,False,True) if not _err: grasp.tprint("ASA Registrar registered OK") else: grasp.tprint("ASA Registrar failure:", grasp.etext[_err]) exit() # demo code doesn't handle registration errors #grasp.skip_dialogue(False,False,True) #################################### # Create a TCP port for BRSKI-TCP #################################### # For this demo, we just make up some numbers: tcp_port = 80 tcp_proto = socket.IPPROTO_TCP tcp_address = grasp._my_address # current address determined by GRASP kernel #################################### # Construct a correponding GRASP ASA locator #################################### tcp_locator = grasp.asa_locator(tcp_address, None, False) tcp_locator.protocol = tcp_proto tcp_locator.port = tcp_port tcp_locator.is_ipaddress = True #################################### # Create a IPv4 port for BRSKI-IPv4 #################################### # For this demo, we just make up some numbers: ipv4_port = 80 ipv4_proto = socket.IPPROTO_TCP #ipv4_address = '172.2.13.0' #grasp._my_address # current address determined by GRASP kernel ipv4_address = findOwnIPv4() # current address determined by GRASP kernel #################################### # Construct a correponding GRASP ASA locator #################################### ipv4_locator = grasp.asa_locator(ipv4_address, None, False) ipv4_locator.protocol = ipv4_proto ipv4_locator.port = ipv4_port #ipv4_locator.is_ipaddress = True ipv4_locator.is_fqdn = True #################################### # Construct the GRASP objective #################################### radius = 255 # Limit the radius of flooding reg_obj = grasp.objective("AN_join_registrar") reg_obj.loop_count = radius reg_obj.synch = True # needed for flooding reg_obj.value = None #################################### # Register the GRASP objective #################################### _err = grasp.register_obj(asa_nonce, reg_obj) if not _err: grasp.tprint("Objective", reg_obj.name, "registered OK") else: grasp.tprint("Objective registration failure:", grasp.etext[_err]) exit() # demo code doesn't handle registration errors #################################### # Start pretty printing #################################### #grasp.init_bubble_text("BRSKI Join Registrar (flooding method)") grasp.tprint("==========================") grasp.tprint("Registrar starting now") grasp.tprint("==========================") #################################### # Start flooding thread #################################### f = flooder(reg_obj, ipv4_locator, asa_nonce) f.start() #flooder().start() grasp.tprint("Flooding", reg_obj.name, "for ever") ################################### # Listen for requests ################################### # Here, launch a thread to do the real work of the registrar # via the various ports But for the demo, we just pretend... #grasp.tprint("Pretending to listen to ports", tcp_port,",", udp_port, # "and for IP-in-IP") ################################### # Do whatever needs to be done in the main thread ################################### # At a minimum, the main thread should keep an eye # on the other threads and restart them if needed. # For the demo, we just dump some diagnostic data... try: while True: time.sleep(5) #grasp.tprint("Registrar main loop diagnostic dump:") #dump_some() except KeyboardInterrupt: print('interrupted!') grasp.tprint("EXITTING") f.stop() exit()