Skip to content

Commit df654ca

Browse files
committed
Ported Tests
1 parent 0da506f commit df654ca

11 files changed

Lines changed: 451 additions & 451 deletions

tests/PGP_message.py

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -93,25 +93,25 @@ def makekey():
9393
# ciphers=[SymmetricKeyAlgorithm.AES256, SymmetricKeyAlgorithm.AES192, SymmetricKeyAlgorithm.AES128],
9494
# compression=[CompressionAlgorithm.ZLIB, CompressionAlgorithm.BZ2, CompressionAlgorithm.ZIP, CompressionAlgorithm.Uncompressed])
9595

96-
print
97-
print 'Do you want to sign or decrypt a message?'
98-
print 's = sign, d = decrypt'
99-
print
96+
print()
97+
print('Do you want to sign or decrypt a message?')
98+
print('s = sign, d = decrypt')
99+
print()
100100

101101
action = raw_input()
102102

103-
print
104-
print 'Enter RSA key slot number to use (1 - 4) or enter 0 to list key labels'
105-
print
103+
print()
104+
print('Enter RSA key slot number to use (1 - 4) or enter 0 to list key labels')
105+
print()
106106

107107
slot = int(raw_input())
108108
ok.slot(slot)
109109

110110
while slot== 0:
111111
ok.displaykeylabels()
112-
print
113-
print 'Enter slot number to use (1 - 4) or enter 0 to list key labels'
114-
print
112+
print()
113+
print('Enter slot number to use (1 - 4) or enter 0 to list key labels')
114+
print()
115115
slot = int(raw_input())
116116
ok.slot(slot)
117117

@@ -128,60 +128,60 @@ def makekey():
128128
compression=[CompressionAlgorithm.ZLIB, CompressionAlgorithm.BZ2, CompressionAlgorithm.ZIP, CompressionAlgorithm.Uncompressed],
129129
key_expires=timedelta(days=365))
130130

131-
print
132-
print 'Do you want to sign a text message or add signature to a PGP Message?'
133-
print 't = text message, p = PGP Message'
134-
print
131+
print()
132+
print('Do you want to sign a text message or add signature to a PGP Message?')
133+
print('t = text message, p = PGP Message')
134+
print()
135135
action2 = raw_input()
136136
if action2 == 't':
137-
print
138-
print 'Type or paste the text message, press return to go to new line, and then press Ctrl+D or Ctrl+Z (Windows only)'
139-
print
137+
print()
138+
print('Type or paste the text message, press return to go to new line, and then press Ctrl+D or Ctrl+Z (Windows only)')
139+
print()
140140
msg_blob = sys.stdin.read()
141141
message_from_blob = priv_key.sign2(msg_blob)
142-
print 'Encoded Signed Message ='
143-
print '-----BEGIN PGP SIGNED MESSAGE-----'
144-
print 'Hash: SHA256'
145-
print
142+
print('Encoded Signed Message =')
143+
print('-----BEGIN PGP SIGNED MESSAGE-----')
144+
print('Hash: SHA256')
145+
print()
146146
if action2 == 'p':
147-
print
148-
print 'Paste OpenPGP Message, press return to go to new line, and then press Ctrl+D or Ctrl+Z (Windows only)'
149-
print
147+
print()
148+
print('Paste OpenPGP Message, press return to go to new line, and then press Ctrl+D or Ctrl+Z (Windows only)')
149+
print()
150150
msg_blob = sys.stdin.read()
151151
message_from_blob = pgpy.PGPMessage.from_blob(msg_blob)
152-
print
153-
print 'Message=', repr(message_from_blob)
152+
print()
153+
print('Message=', repr(message_from_blob))
154154
message_from_blob |= priv_key.sign2(message_from_blob)
155-
print 'Encoded Signed Message ='
155+
print('Encoded Signed Message =')
156156
#print
157157
#sign_bytes = message_from_blob.__bytes__()
158158
#print 'Message Bytes=', repr(sign_bytes)
159159
#print
160160
sign_text = str(message_from_blob)
161-
print msg_blob, sign_text
162-
print
161+
print(msg_blob, sign_text)
162+
print()
163163
#print 'Decoded Signed Message =', str(sign_bytes)
164164
if action == 'd':
165165
#pub_key = makepub()
166-
print
167-
print 'Paste OpenPGP Message, press return to go to new line, and then press Ctrl+D or Ctrl+Z (Windows only)'
168-
print
166+
print()
167+
print('Paste OpenPGP Message, press return to go to new line, and then press Ctrl+D or Ctrl+Z (Windows only)')
168+
print()
169169
msg_blob = sys.stdin.read()
170170
message_from_blob = pgpy.PGPMessage.from_blob(msg_blob)
171-
print
172-
print 'Message=', repr(message_from_blob)
171+
print()
172+
print('Message=', repr(message_from_blob))
173173
#with priv_key.unlock("test"):
174174
decrypted_message = priv_key.decrypt(message_from_blob)
175175
#decrypted_message2 = priv_key.parse(decrypted_message)
176176
#decrypted_message3 = priv_key.bytes_to_text(message_from_blob)
177-
print
177+
print()
178178
dec_bytes = decrypted_message.__bytes__()
179-
print 'Decoded Decrypted Message =', str(dec_bytes)
180-
print
179+
print('Decoded Decrypted Message =', str(dec_bytes))
180+
print()
181181
dec_text = str(decrypted_message)
182-
print 'Encoded Decrypted Message ='
183-
print dec_text
182+
print('Encoded Decrypted Message =')
183+
print(dec_text)
184184

185185

186186

187-
print 'Done'
187+
print('Done')

tests/ecdh_curve25519.py

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
from onlykey import OnlyKey, Message
1111

12-
print 'Generating a new curve25519 key pair...'
12+
print('Generating a new curve25519 key pair...')
1313
randm32 = os.urandom(32)
1414
randm64 = os.urandom(64)
1515

@@ -21,19 +21,19 @@
2121

2222
alice_private_key = curve.generatePrivateKey(randm32)
2323
alice_public_key = curve.generatePublicKey(alice_private_key)
24-
print
24+
print()
2525

26-
print 'bob privkey=', repr(bob_private_key)
27-
print 'bob pubkey=', repr(bob_public_key)
28-
print 'alice privkey=', repr(alice_private_key)
29-
print 'alice pubkey=', repr(alice_public_key)
30-
print
26+
print('bob privkey=', repr(bob_private_key))
27+
print('bob pubkey=', repr(bob_public_key))
28+
print('alice privkey=', repr(alice_private_key))
29+
print('alice pubkey=', repr(alice_public_key))
30+
print()
3131

32-
print
33-
print 'Initialize OnlyKey client...'
32+
print()
33+
print('Initialize OnlyKey client...')
3434
ok = OnlyKey()
35-
print 'Done'
36-
print
35+
print('Done')
36+
print()
3737

3838
time.sleep(2)
3939

@@ -42,10 +42,10 @@
4242
while not empty:
4343
empty = ok.read_string(timeout_ms=100)
4444

45-
print 'You should see your OnlyKey blink 3 times'
46-
print
45+
print('You should see your OnlyKey blink 3 times')
46+
print()
4747

48-
print 'Setting ECC private...'
48+
print('Setting ECC private...')
4949
ok.set_ecc_key(101, (1+32), bob_private_key)
5050
# Slot 101 - 132 for ECC
5151
# Type 1 = Ed25519, Type 2 = p256r1, Type 3 = p256k1
@@ -56,11 +56,11 @@
5656
# if authentication key = type + 16
5757
# For this example it will be a decryption key
5858
time.sleep(1.5)
59-
print ok.read_string()
59+
print(ok.read_string())
6060

6161
time.sleep(2)
62-
print 'You should see your OnlyKey blink 3 times'
63-
print
62+
print('You should see your OnlyKey blink 3 times')
63+
print()
6464

6565

6666
message = 'Secret Message'
@@ -106,7 +106,7 @@
106106

107107

108108
print 'Payload containing ephemeral public key', repr(payload)
109-
print
109+
print()
110110

111111
# Compute the challenge pin
112112
h = hashlib.sha256()
@@ -123,7 +123,7 @@ def get_button(byte):
123123

124124
b1, b2, b3 = get_button(d[0]), get_button(d[15]), get_button(d[31])
125125

126-
print 'Sending the payload to the OnlyKey...'
126+
print('Sending the payload to the OnlyKey...')
127127
ok.send_large_message2(msg=Message.OKDECRYPT, payload=payload, slot_id=101)
128128

129129
# Tim - The OnlyKey can send the code to enter but it would be better if the app generates
@@ -153,23 +153,23 @@ def get_button(byte):
153153

154154
# This method prevents some malware on a users system from sending fake requests to be signed
155155
# at the same time as real requests and tricking the user into signing the wrong data
156-
print 'Please enter the 3 digit challenge code on OnlyKey (and press ENTER if necessary)'
157-
print '{} {} {}'.format(b1, b2, b3)
156+
print('Please enter the 3 digit challenge code on OnlyKey (and press ENTER if necessary)')
157+
print('{} {} {}'.format(b1, b2, b3))
158158
raw_input()
159-
print 'Trying to read the shared secret from OnlyKey...'
159+
print('Trying to read the shared secret from OnlyKey...')
160160
ok_shared_secret = ''
161161
while ok_shared_secret == '':
162162
time.sleep(0.5)
163163
ok_shared_secret = ok.read_bytes(len(shared_secret), to_str=True)
164164

165-
print 'OnlyKey Shared Secret =', repr(ok_shared_secret)
165+
print('OnlyKey Shared Secret =', repr(ok_shared_secret))
166166

167-
print 'Local Shared Secret =', repr(ok_shared_secret)
168-
print
169-
print 'Assert that both shared secrets match'
167+
print('Local Shared Secret =', repr(ok_shared_secret))
168+
print()
169+
print('Assert that both shared secrets match')
170170
assert repr(shared_secret) == repr(ok_shared_secret)
171-
print 'Ok, secrets match'
172-
print
171+
print('Ok, secrets match')
172+
print()
173173

174174
#print 'Trying to read the KEK from OnlyKey...'
175175
#ok_KEK = ''
@@ -179,11 +179,11 @@ def get_button(byte):
179179

180180
#print 'OnlyKey KEK =', repr(ok_KEK)
181181

182-
print 'Local KEK =', repr(KEK)
183-
print
182+
print('Local KEK =', repr(KEK))
183+
print()
184184
#print 'Assert that both KEKs match'
185185
#assert repr(KEK) == repr(ok_KEK)
186186
#print 'Ok, KEKs match'
187187
#print
188188

189-
print 'Done'
189+
print('Done')

tests/ecdh_p256.py

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
from 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
1414
alice = pyelliptic.ECC(curve='prime256v1')
@@ -19,19 +19,19 @@
1919
bob_public_key = bob.get_pubkey()
2020
alice_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...')
3232
ok = OnlyKey()
33-
print 'Done'
34-
print
33+
print('Done')
34+
print()
3535

3636
time.sleep(2)
3737

@@ -40,10 +40,10 @@
4040
while 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...')
4747
ok.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
@@ -54,11 +54,11 @@
5454
# if authentication key = type + 16
5555
# For this example it will be a decryption key
5656
time.sleep(1.5)
57-
print ok.read_string()
57+
print(ok.read_string())
5858

5959
time.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

6464
payload = alice_public_key
@@ -93,8 +93,8 @@
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
100100
h = hashlib.sha256()
@@ -111,7 +111,7 @@ def get_button(byte):
111111

112112
b1, 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...')
115115
ok.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))
146146
raw_input()
147147
shared_secret1 = alice.get_ecdh_key(bob.get_pubkey())
148148
shared_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...')
150150
ok_shared_secret = ''
151151
while 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()))))
165165
assert 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

Comments
 (0)