88
99from onlykey import OnlyKey , Message
1010
11- print 'Generating a new NIST P-256 key pair...'
11+ print ( 'Generating a new NIST P-256 key pair...' )
1212
1313# Asymmetric encryption
1414alice = pyelliptic .ECC (curve = 'prime256v1' )
1919bob_public_key = bob .get_pubkey ()
2020alice_private_key = alice .get_privkey ()
2121
22- print "Bob's private key: " , hexlify (bob_private_key )
23- print "Bob's public key: " , hexlify (bob_public_key )
22+ print ( "Bob's private key: " , hexlify (bob_private_key ) )
23+ print ( "Bob's public key: " , hexlify (bob_public_key ) )
2424
25- print
26- print "Alices's private key: " , hexlify (alice_private_key )
27- print "Alices's public key: " , hexlify (alice_public_key )
28- print
25+ print ()
26+ print ( "Alices's private key: " , hexlify (alice_private_key ) )
27+ print ( "Alices's public key: " , hexlify (alice_public_key ) )
28+ print ()
2929
30- print
31- print 'Initialize OnlyKey client...'
30+ print ()
31+ print ( 'Initialize OnlyKey client...' )
3232ok = OnlyKey ()
33- print 'Done'
34- print
33+ print ( 'Done' )
34+ print ()
3535
3636time .sleep (2 )
3737
4040while not empty :
4141 empty = ok .read_string (timeout_ms = 100 )
4242
43- print 'You should see your OnlyKey blink 3 times'
44- print
43+ print ( 'You should see your OnlyKey blink 3 times' )
44+ print ()
4545
46- print 'Setting ECC private...'
46+ print ( 'Setting ECC private...' )
4747ok .set_ecc_key (101 , (2 + 32 ), bob_private_key )
4848# Slot 101 - 132 for ECC
4949# Type 1 = Ed25519, Type 2 = p256r1, Type 3 = p256k1
5454# if authentication key = type + 16
5555# For this example it will be a decryption key
5656time .sleep (1.5 )
57- print ok .read_string ()
57+ print ( ok .read_string () )
5858
5959time .sleep (2 )
60- print 'You should see your OnlyKey blink 3 times'
61- print
60+ print ( 'You should see your OnlyKey blink 3 times' )
61+ print ()
6262
6363
6464payload = alice_public_key
9393#
9494
9595
96- print 'Payload containing ephemeral public key' , repr (payload )
97- print
96+ print ( 'Payload containing ephemeral public key' , repr (payload ) )
97+ print ()
9898
9999# Compute the challenge pin
100100h = hashlib .sha256 ()
@@ -111,7 +111,7 @@ def get_button(byte):
111111
112112b1 , b2 , b3 = get_button (d [0 ]), get_button (d [15 ]), get_button (d [31 ])
113113
114- print 'Sending the payload to the OnlyKey...'
114+ print ( 'Sending the payload to the OnlyKey...' )
115115ok .send_large_message2 (msg = Message .OKDECRYPT , payload = payload , slot_id = 101 )
116116
117117# Tim - The OnlyKey can send the code to enter but it would be better if the app generates
@@ -141,30 +141,30 @@ def get_button(byte):
141141
142142# This method prevents some malware on a users system from sending fake requests to be signed
143143# at the same time as real requests and tricking the user into signing the wrong data
144- print 'Please enter the 3 digit challenge code on OnlyKey (and press ENTER if necessary)'
145- print '{} {} {}' .format (b1 , b2 , b3 )
144+ print ( 'Please enter the 3 digit challenge code on OnlyKey (and press ENTER if necessary)' )
145+ print ( '{} {} {}' .format (b1 , b2 , b3 ) )
146146raw_input ()
147147shared_secret1 = alice .get_ecdh_key (bob .get_pubkey ())
148148shared_secret2 = bob .get_ecdh_key (alice .get_pubkey ())
149- print 'Trying to read the shared secret from OnlyKey...'
149+ print ( 'Trying to read the shared secret from OnlyKey...' )
150150ok_shared_secret = ''
151151while ok_shared_secret == '' :
152152 time .sleep (0.5 )
153153 ok_shared_secret = ok .read_bytes (len (shared_secret1 ), to_str = True )
154154
155- print 'OnlyKey Shared Secret =' , hexlify (ok_shared_secret )
155+ print ( 'OnlyKey Shared Secret =' , hexlify (ok_shared_secret ) )
156156
157- print 'Local Shared Secret1 =' , hexlify (shared_secret1 )
158- print
157+ print ( 'Local Shared Secret1 =' , hexlify (shared_secret1 ) )
158+ print ()
159159
160- print 'Local Shared Secret2 =' , hexlify (shared_secret2 )
161- print
160+ print ( 'Local Shared Secret2 =' , hexlify (shared_secret2 ) )
161+ print ()
162162
163- print 'Assert that both shared secrets match'
164- print (hexlify (alice .get_ecdh_key (bob .get_pubkey ())))
163+ print ( 'Assert that both shared secrets match' )
164+ print (( hexlify (alice .get_ecdh_key (bob .get_pubkey () ))))
165165assert repr (shared_secret1 ) == repr (ok_shared_secret )
166- print 'Ok, secrets match'
167- print
166+ print ( 'Ok, secrets match' )
167+ print ()
168168
169169
170- print 'Done'
170+ print ( 'Done' )
0 commit comments