Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
TDDE21 DRIP 2022
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
Hampus Rosenquist
TDDE21 DRIP 2022
Commits
81456593
Commit
81456593
authored
2 years ago
by
Abdullah Bin Zubair
Browse files
Options
Downloads
Patches
Plain Diff
Moved to iroha-drip-general-master/drippy folder.
parent
09a4db62
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
iroha-drip-general-master/bluetooth/host_identity_1.py
+0
-161
0 additions, 161 deletions
iroha-drip-general-master/bluetooth/host_identity_1.py
with
0 additions
and
161 deletions
iroha-drip-general-master/bluetooth/host_identity_1.py
deleted
100644 → 0
+
0
−
161
View file @
09a4db62
import
sys
from
binascii
import
hexlify
,
unhexlify
from
bs4
import
BeautifulSoup
from
nacl.signing
import
SigningKey
from
.util
import
*
from
.cSHAKE
import
cSHAKE128
CONTEXT_ID
=
"
F0EFF02FBFF43D0FE7930C3C6E6174EA
"
CURVE_ID
=
"
0001
"
class
HostIdentity
:
def
__init__
(
self
,
hhit
,
hid
,
priv_key
,
pub_key
):
self
.
_hhit
=
hhit
self
.
_hid
=
hid
self
.
_priv_key
=
priv_key
self
.
_pub_key
=
pub_key
if
not
self
.
verify_hhit
():
print
(
"
The public key does not produce the same hash in hhit.
"
)
else
:
print
(
"
hhit verified
"
)
@staticmethod
def
from_file
(
file_name
):
bs
=
None
try
:
with
open
(
file_name
,
'
r
'
)
as
f
:
bs
=
BeautifulSoup
(
f
.
read
(),
'
lxml
'
)
except
PermissionError
as
e
:
print
(
e
)
sys
.
exit
(
1
)
host_id
=
bs
.
find
(
"
host_identity
"
)
# use first host id
priv_key
=
''
.
join
(
host_id
.
find
(
"
priv
"
).
string
.
split
(
'
:
'
))
pub_key
=
''
.
join
(
host_id
.
find
(
"
pub
"
).
string
.
split
(
'
:
'
))
hid
=
host_id
.
find
(
"
hid
"
).
string
hhit
=
''
.
join
([
"
{:>04}
"
.
format
(
byte_group
)
for
byte_group
in
host_id
.
find
(
"
hit
"
).
string
.
split
(
'
:
'
)])
return
HostIdentity
(
hhit
,
hid
,
priv_key
,
pub_key
)
def
get_hhit
(
self
):
return
self
.
_hhit
def
get_hid
(
self
):
return
self
.
_hid
def
get_pub_key
(
self
):
return
self
.
_pub_key
def
get_priv_key
(
self
):
return
self
.
_priv_key
def
verify_hhit
(
self
):
chash
=
cSHAKE128
(
unhexlify
(
CONTEXT_ID
+
CURVE_ID
+
self
.
_pub_key
),
64
,
""
,
unhexlify
(
CONTEXT_ID
))
return
chash
.
decode
(
"
utf-8
"
)
==
self
.
_hhit
[
16
:]
def
generate_self_attestation
(
self
,
expiration
):
if
expiration
<=
astm_time
():
print
(
"
expiration timestamp has already expired.
"
)
return
None
message
=
self
.
_hhit
+
self
.
_pub_key
+
"
{:>08x}
"
.
format
(
convert_be_to_le
(
expiration
))
sign_key
=
SigningKey
(
unhexlify
(
self
.
_priv_key
))
return
hexlify
(
sign_key
.
sign
(
unhexlify
(
message
)))
##############################
## Function for DRIP_Wrapper
##############################
def
generate_self_attestation_Wrapper
(
self
,
payload
,
expiration
):
if
expiration
<=
astm_time
():
print
(
"
expiration timestamp has already expired.
"
)
return
None
#hash of SAM Type for Wrapper, which is 0x02
DET
=
self
.
_hhit
hash_SAM
=
cSHAKE128
(
'
0x02
'
.
encode
(
'
utf-8
'
),
1
,
""
,
""
)
# 1 byte at the start as SAM type
DET_hash
=
cSHAKE128
(
DET
.
encode
(
'
utf-8
'
),
16
,
""
,
""
)
# Draft auth17 requirement of 16 bytes of DET
NBT_hash
=
cSHAKE128
(
"
{:>08x}
"
.
format
(
convert_be_to_le
(
int
(
astm_time
()))).
encode
(
'
utf-8
'
),
4
,
""
,
""
)
#Not before timestamp 4bytes
NAT_hash
=
cSHAKE128
(
"
{:>08x}
"
.
format
(
convert_be_to_le
(
expiration
)).
encode
(
'
utf-8
'
),
4
,
""
,
""
)
#Not after timestamp 4bytes
message
=
hash_SAM
+
DET_hash
+
payload
+
NBT_hash
+
NAT_hash
sign_key
=
SigningKey
(
unhexlify
(
self
.
_priv_key
))
return
hexlify
(
sign_key
.
sign
(
unhexlify
(
message
)))
#######################################################
## Function for DRIP_Manifests according to auth17 draft
#######################################################
def
generate_self_attestation_Manifests
(
self
,
prev_hashed_loc
,
hashed_loc
,
expiration
):
#hashed_loc is hashes of location for now its single, but it can be upto 11(Each 8 byte)
if
expiration
<=
astm_time
():
print
(
"
expiration timestamp has already expired.
"
)
return
None
DET
=
self
.
_hhit
#hash of SAM Type for Manifests, which is 0x03
hash_SAM
=
cSHAKE128
(
'
0x03
'
.
encode
(
'
utf-8
'
),
1
,
""
,
""
)
DET_hash
=
cSHAKE128
(
DET
.
encode
(
'
utf-8
'
),
16
,
""
,
""
)
# Draft auth17 requirement of 16 bytes of DET
NBT_hash
=
cSHAKE128
(
"
{:>08x}
"
.
format
(
convert_be_to_le
(
int
(
astm_time
()))).
encode
(
'
utf-8
'
),
4
,
""
,
""
)
#Not before timestamp 4bytes
NAT_hash
=
cSHAKE128
(
"
{:>08x}
"
.
format
(
convert_be_to_le
(
expiration
)).
encode
(
'
utf-8
'
),
4
,
""
,
""
)
#Not after timestamp 4bytes
message
=
hash_SAM
+
DET_hash
+
prev_hashed_loc
+
hashed_loc
+
NBT_hash
+
NAT_hash
sign_key
=
SigningKey
(
unhexlify
(
self
.
_priv_key
))
return
hexlify
(
sign_key
.
sign
(
unhexlify
(
message
)))
###################################################################
## Function for DRIP_Endorsement_Broadcast according to auth17 draft
###################################################################
def
generate_attestation_Endorsement_Broadcast
(
self
,
Drone_DET
,
Drone_hid
,
expiration
):
if
expiration
<=
astm_time
():
print
(
"
expiration timestamp has already expired.
"
)
return
None
DET_DIME
=
self
.
_hhit
DET_DIME_hash
=
cSHAKE128
(
DET_DIME
.
encode
(
'
utf-8
'
),
16
,
""
,
""
)
# Draft auth17 requirement of 16 bytes of DET
DET_DRONE_hash
=
cSHAKE128
(
Drone_DET
.
encode
(
'
utf-8
'
),
16
,
""
,
""
)
# Draft auth17 requirement of 16 bytes of DET
HID_DRONE_hash
=
cSHAKE128
(
Drone_hid
.
encode
(
'
utf-8
'
),
32
,
""
,
""
)
# Draft auth17 requirement of 32 bytes of DET
NBT_hash
=
cSHAKE128
(
"
{:>08x}
"
.
format
(
convert_be_to_le
(
int
(
astm_time
()))).
encode
(
'
utf-8
'
),
4
,
""
,
""
)
#Not before timestamp 4bytes
NAT_hash
=
cSHAKE128
(
"
{:>08x}
"
.
format
(
convert_be_to_le
(
expiration
)).
encode
(
'
utf-8
'
),
4
,
""
,
""
)
#Not after timestamp 4bytes
message
=
DET_DIME_hash
+
DET_DRONE_hash
+
HID_DRONE_hash
+
NBT_hash
+
NAT_hash
sign_key
=
SigningKey
(
unhexlify
(
self
.
_priv_key
))
return
sign_key
.
sign
(
unhexlify
(
message
))
#This function was being used for draft auth01 version but no more being used
def
generate_certificate
(
self
,
other
,
expiration
):
signing_ts
=
astm_time
()
if
expiration
<=
signing_ts
:
print
(
"
expiration timestamp has already expired.
"
)
return
None
ass_x
=
self
.
generate_self_attestation
(
expiration
).
decode
(
"
utf-8
"
)
ass_y
=
other
.
generate_self_attestation
(
expiration
).
decode
(
"
utf-8
"
)
len_ass_x
=
hex
(
struct
.
unpack
(
"
!2H
"
,
struct
.
pack
(
"
!i
"
,
len
(
ass_x
)))[
1
])[
2
:]
while
len
(
len_ass_x
)
<
4
:
len_ass_x
=
'
0
'
+
len_ass_x
len_ass_y
=
hex
(
struct
.
unpack
(
"
!2H
"
,
struct
.
pack
(
"
!i
"
,
len
(
ass_y
)))[
1
])[
2
:]
while
len
(
len_ass_y
)
<
4
:
len_ass_y
=
'
0
'
+
len_ass_y
message
=
len_ass_x
+
len_ass_y
\
+
ass_x
+
ass_y
\
+
hexlify
(
int
(
signing_ts
).
to_bytes
(
4
,
'
little
'
)).
decode
(
"
utf-8
"
)
\
+
hexlify
(
int
(
expiration
).
to_bytes
(
4
,
'
little
'
)).
decode
(
"
utf-8
"
)
sign_key
=
SigningKey
(
unhexlify
(
self
.
_priv_key
))
return
hexlify
(
sign_key
.
sign
(
unhexlify
(
message
)))
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