Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
TDDE21 DRIP 2023
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Viktor Norgren
TDDE21 DRIP 2023
Commits
693cb6f5
Commit
693cb6f5
authored
1 year ago
by
Mawio
Browse files
Options
Downloads
Patches
Plain Diff
Basic ID type 1 progress
parent
6ec77d55
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
drip-general-master/bluetooth/beacon_2.py
+54
-34
54 additions, 34 deletions
drip-general-master/bluetooth/beacon_2.py
with
54 additions
and
34 deletions
drip-general-master/bluetooth/beacon_2.py
+
54
−
34
View file @
693cb6f5
...
...
@@ -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
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment