Skip to content
Snippets Groups Projects
Commit 693cb6f5 authored by Mawio's avatar Mawio
Browse files

Basic ID type 1 progress

parent 6ec77d55
No related branches found
No related tags found
No related merge requests found
......@@ -79,13 +79,13 @@ def get_auth_pages(signature: bytes, auth_type=0x10):
return auth_pages
# Placing a single location message For Now
# Placing a single location message For Now
def Drip_Wrapper(gpsd: GpsPoller, iroha: DripIrohaAccount, flight_id, HostID: HostIdentity, exp_date):
# ASTM F3-411 Location message 0x1
print("location_update")
global executor
# If gpsd is active, check that it has received values
if gpsd and gpsd.get_current_value() == None:
......@@ -113,9 +113,9 @@ def Drip_Wrapper(gpsd: GpsPoller, iroha: DripIrohaAccount, flight_id, HostID: Ho
executor.submit(
iroha.set_account_details, "location", iroha_msg
)
payload = HostID.generate_self_attestation_Wrapper(hash_location, get_timestamp(exp_date))
if is_wifi:
beacon_wifi("{hash_location}{payload}".format(hash_location=hash_location,payload=payload))
else:
......@@ -127,8 +127,8 @@ def Drip_Wrapper(gpsd: GpsPoller, iroha: DripIrohaAccount, flight_id, HostID: Ho
Advertising handle: 0x00 (Advertising set number)
Operation: 0x03 (Complete extended advertising data)
Fragment_Preference: 0x01 (The Controller should not fragment or should minimize fragmentation of Host advertising data)
Advertising_Data_Length: 0x1f
Advertising_Data: 1e 16 fa ff 0d 00 10 + payload
Advertising_Data_Length: 0x1f
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 {hash_location}{payload}".format(hash_location=hash_location,payload=payload), shell=True)
......@@ -136,7 +136,7 @@ def Drip_Wrapper(gpsd: GpsPoller, iroha: DripIrohaAccount, flight_id, HostID: Ho
"""
OGF: 0x08 (LE controller commands)
OCF: 0x0008 (LE Set Advertising Data command)
Advertising_Data_Length: 0x1f
Advertising_Data_Length: 0x1f
Advertising_Data: 1e 16 fa ff 0d 00 10 + payload
"""
subprocess.run(
......@@ -159,8 +159,8 @@ def manifest_broadcast(HostID: HostIdentity, flight_id, exp_date, prev_loc = ""
Advertising handle: 0x00 (Advertising set number)
Operation: 0x03 (Complete extended advertising data)
Fragment_Preference: 0x01 (The Controller should not fragment or should minimize fragmentation of Host advertising data)
Advertising_Data_Length: 0x1f
Advertising_Data: 1e 16 fa ff 0d 00 10 + payload
Advertising_Data_Length: 0x1f
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) #0x03
......@@ -168,7 +168,7 @@ def manifest_broadcast(HostID: HostIdentity, flight_id, exp_date, prev_loc = ""
"""
OGF: 0x08 (LE controller commands)
OCF: 0x0008 (LE Set Advertising Data command)
Advertising_Data_Length: 0x1f
Advertising_Data_Length: 0x1f
Advertising_Data: 1e 16 fa ff 0d 00 10 + payload
"""
subprocess.run(
......@@ -179,7 +179,7 @@ def manifest_broadcast(HostID: HostIdentity, flight_id, exp_date, prev_loc = ""
# Updated to draft-ietf-drip-auth-37
def broadcast_basic_id_1(hhit):
print("basic_id_1")
print(f"basic_id_1 with hhit: {hhit}")
"""
Serial Number = MFR Code | Length Code | MFR SN
......@@ -188,12 +188,29 @@ def broadcast_basic_id_1(hhit):
MFR SN = HHIT Suite ID | ORCHID hash left-padded with 3 bits of zeros and encoded into 15 characters
"""
MFR_code = "8653"
hhit_bytes = hhit.split(' ')
hhit_suite_id = hhit_bytes[-9]
ORCHID_hash = "".join(hhit_bytes[-8:])
MFR_SN = bin(int(hhit_suite_id + ORCHID_hash, 16))[2:].zfill(75)
# Encoding of MFR_SN according to RFC9374
encoding_dictionary = [
"0", "1", "2", "3", "4", "5", "6", "7",
"8", "9", "A", "B", "C", "D", "E", "F",
"G", "H", "J", "K", "L", "M", "N", "P",
"Q", "R", "T", "U", "V", "W", "X", "Y"
]
MFR_SN_encoded = ""
hhit_suite_id = '0' * 3 + unhexlify(hhit)[-72:-65]
ORCHID_hash = unhexlify(hhit)[-64:]
MFR_SN = encode(hhit_suite_id + ORCHID_hash)
for i in range(0, len(MFR_SN), 5):
bit_sequence = MFR_SN[i: i + 5]
MFR_SN_encoded += encoding_dictionary[int(bit_sequence, 2)]
serial_number = f"{MFR_code} 0xF {MFR_SN}"
serial_number = f"{MFR_code}F{MFR_SN_encoded}"
# Set (Extended) Advertising Command
if is_wifi:
......@@ -218,7 +235,7 @@ def broadcast_basic_id_1(hhit):
"""
OGF: 0x08 (LE controller commands)
OCF: 0x0008 (LE Set Advertising Data command)
Advertising_Data_Length: 0x1f
Advertising_Data_Length: 0x1f
Advertising_Data: 1e 16 fa ff 0d 00 00 42 + hhit
"""
subprocess.run(
......@@ -242,8 +259,8 @@ def basic_id_update(hhit):
Advertising handle: 0x00 (Advertising set number)
Operation: 0x03 (Complete extended advertising data)
Fragment_Preference: 0x01 (The Controller should not fragment or should minimize fragmentation of Host advertising data)
Advertising_Data_Length: 0x1f
Advertising_Data: 1e 16 fa ff 0d 00 10 + hhit
Advertising_Data_Length: 0x1f
Advertising_Data: 1e 16 fa ff 0d 00 10 + hhit
"""
subprocess.run(
"hcitool -i hci0 cmd 0x08 0x0037 0x00 0x03 0x01 0x1f 0x1e 0x16 0xfa 0xff 0x0d 0x00 0x00 0x42 {} 0x00 0x00 0x00 0x00 0x00 0x00 0x00".format('0x01', hhit), shell=True)
......@@ -251,7 +268,7 @@ def basic_id_update(hhit):
"""
OGF: 0x08 (LE controller commands)
OCF: 0x0008 (LE Set Advertising Data command)
Advertising_Data_Length: 0x1f
Advertising_Data_Length: 0x1f
Advertising_Data: 1e 16 fa ff 0d 00 00 42 + hhit
"""
subprocess.run(
......@@ -274,7 +291,7 @@ def auth_update(auth_pages, msg_number):
Advertising handle: 0x00 (Advertising set number)
Operation: 0x01 / 0x02 (First and last part of advertising data)
Fragment_Preference: 0x01 (The Controller should not fragment or should minimize fragmentation of Host advertising data)
Advertising_Data_Length: 0x1f
Advertising_Data_Length: 0x1f
Advertising_Data: 1e 16 fa ff 0d 00 20 + msg
"""
if msg_number == 1:
......@@ -287,7 +304,7 @@ def auth_update(auth_pages, msg_number):
"""
OGF: 0x08 (LE controller commands)
OCF: 0x0008 (LE Set Advertising Data command)
Advertising_Data_Length: 0x1f
Advertising_Data_Length: 0x1f
Advertising_Data: 1e 16 fa ff 0d 00 20 + msg
"""
subprocess.run(
......@@ -323,8 +340,8 @@ def main():
type=str,
help="Specify the host identity xml file."
)
parser.add_argument(
parser.add_argument(
"-r", "--registry_file", # this is for registry_identity_file
dest="registry_identity_file",
default="/usr/local/etc/hip/my_host_identities.xml",
......@@ -376,7 +393,7 @@ def main():
help="Specify expiration date for the attestation in the format YYYY-mm-ddTHH:MM"
)
#
#
args = parser.parse_args(sys.argv[1:])
# hi_file is read from identities/drone
......@@ -399,10 +416,10 @@ def main():
#HostIdentity object containing Drone DRIP credentials
hi = HostIdentity.from_file(hi_file)
# registry host identity
# registry host identity
r_hi = HostIdentity.from_file(r_hi_file)
iroha = None
......@@ -425,7 +442,7 @@ def main():
hhit = separate_bytes(hi.get_hhit())
hid = separate_bytes(hi.get_hid())
# this endorsement should be generated by the registry,
# 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))
#attest = r_hi.generate_self_attestation(get_timestamp(exp_date))
......@@ -506,6 +523,8 @@ def main():
i = 0
try:
broadcast_basic_id_1(hhit)
"""
while True:
os.system('clear')
print("The flight_id is {}".format(flight_id))
......@@ -513,8 +532,8 @@ def main():
# Send basic_id and auth at least once every 3 seconds.
# Send basic_id first second
if i % 3 == 0:
basic_id_update(hhit)
broadcast_basic_id_1(hhit)
# Send first half of auth pages second second
elif i % 3 == 1:
auth_update(auth_pages[:2], 1)
......@@ -523,10 +542,10 @@ def main():
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_location_info = location_info
prev_location_info = location_info
# Location updates at least once every second.
Drip_Wrapper(gpsd, iroha, flight_id, hi, exp_date)
# Manifest broadcast
# Manifest broadcast
manifest_broadcast(hi, flight_id, exp_date, prev_location_info)
if args.run_scenario:
......@@ -534,11 +553,12 @@ def main():
random.choice([-1, 0, 1])
g_lon += random.uniform(0.0001, 0.001) * \
random.choice([-1, 0, 1])
print(g_lat, g_lon)
i += 1
time.sleep(1 - time.monotonic() % 1)
"""
except KeyboardInterrupt:
# Reset bt
subprocess.run("hcitool -i hci0 cmd 0x03 0x0003", shell=True)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment