Skip to content
Snippets Groups Projects
Commit d4fb1b29 authored by Abdullah Bin Zubair's avatar Abdullah Bin Zubair
Browse files

Update beacon for draft auth17 Structure

parent 1b32fe82
No related branches found
No related tags found
No related merge requests found
......@@ -32,7 +32,7 @@ FLIGHT_ID_FILE = os.path.join(FILE_DIR, "default_flight_id.txt")
load_dotenv()
payload = ""
hash_location = "" #hash of location info such lat & long, it is saved to send later in manifests
def separate_bytes(hex_str, delim=' '):
return re.sub(r'.{2}', r'\g<0>{}'.format(delim), hex_str).strip()
......@@ -80,7 +80,7 @@ def get_auth_pages(signature: bytes, auth_type=0x10):
return auth_pages
# Placing a single location message For Now
def Drip_Wrapper(gpsd: GpsPoller, iroha: DripIrohaAccount, flight_id):
def Drip_Wrapper(gpsd: GpsPoller, iroha: DripIrohaAccount, flight_id, HostID: HostIdentity, exp_date):
# ASTM F3-411 Location message 0x1
print("location_update")
global executor
......@@ -98,20 +98,22 @@ def Drip_Wrapper(gpsd: GpsPoller, iroha: DripIrohaAccount, flight_id):
lat = separate_bytes(astm_float_to_int_hex(g_lat))
lon = separate_bytes(astm_float_to_int_hex(g_lon))
payload = "10 00 00 00 {lat} {lon} 00 00 00 00 00 00 00 00 {ts} 00 00".format(
location_info = "10 00 00 00 {lat} {lon} 00 00 00 00 00 00 00 00 {ts} 00 00".format(
lat=lat, lon=lon, ts="00 00")
if(location_info):
hash_location = cSHAKE128( location_info,25,"", flight_id) # hash of location_info, 25 bytes
if iroha: # if iroha private supplied, send location transactions on separate thread.
# location will be flight id concatenated with the bluetooth payload
# In order to save space we can b64encode the bytes of the payload,
# instead of sending a hexstring which would result in location message
# taking up double the bytes (2 characters per byte).
iroha_msg = b64encode(
unhexlify(flight_id + ''.join(payload.split(' ')))).decode("utf-8")
unhexlify(flight_id + ''.join(location_info.split(' ')))).decode("utf-8")
executor.submit(
iroha.set_account_details, "location", iroha_msg
)
payload = HostID.generate_self_attestation_Wrapper(hash_location, get_timestamp(exp_date))
# Set (Extended) Advertising command
if is_bt5:
"""
......@@ -124,7 +126,7 @@ def Drip_Wrapper(gpsd: GpsPoller, iroha: DripIrohaAccount, flight_id):
Advertising_Data: 1e 16 fa ff 0d 00 10 + payload
"""
subprocess.run(
"hcitool -i hci0 cmd 0x08 0x0037 0x00 0x03 0x01 0x1f 0x1e 0x16 0xfa 0xff 0x0d 0x00 0x10 {payload}".format(payload=payload), shell=True)
"hcitool -i hci0 cmd 0x08 0x0037 0x00 0x03 0x01 0x1f 0x1e 0x16 0xfa 0xff 0x0d 0x00 0x10 {hash_location}{payload}".format(hash_location=hash_location,payload=payload), shell=True)
else:
"""
OGF: 0x08 (LE controller commands)
......@@ -133,30 +135,17 @@ def Drip_Wrapper(gpsd: GpsPoller, iroha: DripIrohaAccount, flight_id):
Advertising_Data: 1e 16 fa ff 0d 00 10 + payload
"""
subprocess.run(
"hcitool -i hci0 cmd 0x08 0x0008 1f 1e 16 fa ff 0d 00 10 {payload}".format(payload=payload), shell=True)
"hcitool -i hci0 cmd 0x08 0x0008 1f 1e 16 fa ff 0d 00 10 {hash_location}{payload}".format(hash_location=hash_location, payload=payload), shell=True)
def manifest_broadcast(payload, flight_id): ## Manifest broadcast can contain max 11 hashes (at 8-bytes each). For now we are sending one message.
def manifest_broadcast(HostID: HostIdentity, flight_id, prev_hash_loc, exp_date): ## Manifest broadcast can contain max 11 hashes (at 8-bytes each). For now we are sending one message.
# ASTM F3-411 Location message 0x1
print("manifest_broadcast")
hash_payload = " "
# If gpsd is active, check that it has received values
if payload == None:
print("payload is empty, cannot generate hash_payload")
if(payload):
hash_payload = cSHAKE128(
payload,
8,
"",
flight_id
)
print(hash_payload + "aaaaaaaaaa")
if hash_location == None:
print("payload is empty, cannot generate hash_payload for gps information")
payload = HostID.generate_self_attestation_Manifests(cSHAKE128(prev_hash_loc,8, "",flight_id),cSHAKE128(hash_location,8,"",flight_id), get_timestamp(exp_date))
# Set (Extended) Advertising command
if is_bt5:
"""
......@@ -169,7 +158,7 @@ def manifest_broadcast(payload, flight_id): ## Manifest broadcast can contain ma
Advertising_Data: 1e 16 fa ff 0d 00 10 + payload
"""
subprocess.run(
"hcitool -i hci0 cmd 0x08 0x0037 0x00 0x03 0x01 0x1f 0x1e 0x16 0xfa 0xff 0x0d 0x00 0x10 {payload}".format(payload=hash_payload), shell=True) #0x03
"hcitool -i hci0 cmd 0x08 0x0037 0x00 0x03 0x01 0x1f 0x1e 0x16 0xfa 0xff 0x0d 0x00 0x10 {payload}".format(payload=payload), shell=True) #0x03
else:
"""
OGF: 0x08 (LE controller commands)
......@@ -178,7 +167,7 @@ def manifest_broadcast(payload, flight_id): ## Manifest broadcast can contain ma
Advertising_Data: 1e 16 fa ff 0d 00 10 + payload
"""
subprocess.run(
"hcitool -i hci0 cmd 0x08 0x0008 1f 1e 16 fa ff 0d 00 10 {payload}".format(payload=hash_payload), shell=True)
"hcitool -i hci0 cmd 0x08 0x0008 1f 1e 16 fa ff 0d 00 10 {payload}".format(payload=payload), shell=True)
......@@ -281,9 +270,6 @@ def main():
type=str,
help="Specify the registry identity xml file."
)
parser.add_argument(
"-i", "--iroha",
dest="iroha_priv_key_file",
......@@ -344,6 +330,7 @@ def main():
print("The specified file is not an xml file")
sys.exit(-1)
#HostIdentity object containing Drone DRIP credentials
hi = HostIdentity.from_file(hi_file)
# registry host identity
......@@ -371,13 +358,10 @@ def main():
hhit = separate_bytes(hi.get_hhit())
hid = separate_bytes(hi.get_hid())
# hhit and signature of the registry
r_hhit = separate_bytes(r_hi.get_hhit())
r_signature = HostIdentity.generate_self_attestation(HostIdentity,astm_time()) # this signature should be generated by the registry,
# but just for now, we are generating the r_signature using the same function used for drone signature generate function
attest = hi.generate_self_concise_attestation(r_hhit,r_signature,get_timestamp(exp_date))
# this endorsement should be generated by the registry,
# but just for now, we are generating it according draft-ietf-drip-auth-17
attest = r_hi.generate_attestation_Endorsement_Broadcast(hhit,hid,get_timestamp(exp_date))
if attest is None:
print("Expiration date has expired.")
sys.exit(-1)
......@@ -469,10 +453,13 @@ def main():
elif i % 3 == 2:
auth_update(auth_pages[2:], 2)
# saving the hash_location information such as lon & lat, to use as previous location_hash later in Manifests
prev_hash_location = hash_location
# Location updates at least once every second.
Drip_Wrapper(gpsd, iroha, flight_id)
Drip_Wrapper(gpsd, iroha, flight_id, hi, exp_date)
# Manifest broadcast
manifest_broadcast(payload, flight_id)
manifest_broadcast(hi, flight_id, prev_hash_location, exp_date)
if args.run_scenario:
g_lat += random.uniform(0.0001, 0.001) * \
random.choice([-1, 0, 1])
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment