forked from KeystoneHQ/KeystoneQRVerifier
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkeystonQRVerify.py
executable file
·56 lines (49 loc) · 1.91 KB
/
keystonQRVerify.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/python3
# Decode the values that a Keystone device displays to the Keystone Hardware Wallet app in order
# to verify that only xpub and other non-secure information is allowed to leak from
# a Keystone device.
import sys
sys.path.insert(0, './py_protocol')
import argparse
import gzip
from py_protocol import base_pb2
from ur.ur_decoder import URDecoder
from ur.cbor_lite import CBORDecoder
# Unzipped payload is in serialized proto3, convert it to human readable estring
def getMessageFromPayload(payload):
message = base_pb2.Base()
message.ParseFromString(payload)
return message
def getContentFromUR(content):
decoder = URDecoder()
while True:
for part in content:
each_part = part.lower().strip()
decoder.receive_part(each_part)
if decoder.is_complete():
break
if decoder.is_complete():
break
if decoder.is_success():
return decoder.result_message()
else:
return None
parser = argparse.ArgumentParser(description='Decode a keystone sync message.')
parser.add_argument("--filename", type=str, default="sample_qr_codes.txt",
help="Name of the file containing the keystone sync data")
args = parser.parse_args()
with open(args.filename) as f:
content = f.readlines()
ur = getContentFromUR(content)
(payload, _) = CBORDecoder(ur.cbor).decodeBytes()
unzippedPayload = gzip.decompress(bytearray(payload))
message = getMessageFromPayload(unzippedPayload)
print("*************************************************************")
print("Following is entire message sent via QRCode from vault to app")
print("*************************************************************")
print(message)
print("*************************************************************")
print("")
print("At this point one should verify each of the XPUBs shown above, and")
print("the UUID shown below (also at the top of the above output). See the")
print("README.md for how to do that.")