Skip to content

Commit bdc8d97

Browse files
committed
key slot lables
1 parent 3ae6903 commit bdc8d97

2 files changed

Lines changed: 24 additions & 10 deletions

File tree

onlykey/cli.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -151,17 +151,17 @@ def prompt_pin():
151151
tmp[slot.name] = slot
152152
slots = iter(['1a', '1b', '2a', '2b', '3a', '3b', '4a', '4b', '5a', '5b', '6a', '6b'])
153153
for slot_name in slots:
154-
print(tmp[slot_name].to_str())
155-
print(tmp[next(slots)].to_str())
154+
print(tmp[slot_name].to_str().replace('ÿ'," "))
155+
print(tmp[next(slots)].to_str().replace('ÿ'," "))
156156
print()
157157

158158
elif sys.argv[1] == 'getkeylabels':
159159
tmp = {}
160160
for slot in only_key.getkeylabels():
161161
tmp[slot.name] = slot
162-
slots = iter(['RSA Key 1', 'RSA Key 2', 'RSA Key 3', 'RSA Key 4', 'ECC Key 1', 'ECC Key 2', 'ECC Key 3', 'ECC Key 4', 'ECC Key 5', 'ECC Key 6', 'ECC Key 7', 'ECC Key 8', 'ECC Key 9', 'ECC Key 10', 'ECC Key 11', 'ECC Key 12', 'ECC Key 13', 'ECC Key 14', 'ECC Key 15', 'ECC Key 16', 'ECC Key 17', 'ECC Key 18', 'ECC Key 19', 'ECC Key 20', 'ECC Key 21', 'ECC Key 22', 'ECC Key 23', 'ECC Key 24', 'ECC Key 25', 'ECC Key 26', 'ECC Key 27', 'ECC Key 28', 'ECC Key 29'])
162+
slots = iter(['RSA Key 1', 'RSA Key 2', 'RSA Key 3', 'RSA Key 4', 'ECC Key 1', 'ECC Key 2', 'ECC Key 3', 'ECC Key 4', 'ECC Key 5', 'ECC Key 6', 'ECC Key 7', 'ECC Key 8', 'ECC Key 9', 'ECC Key 10', 'ECC Key 11', 'ECC Key 12', 'ECC Key 13', 'ECC Key 14', 'ECC Key 15', 'ECC Key 16'])
163163
for slot_name in slots:
164-
print(tmp[slot_name].to_str())
164+
print(tmp[slot_name].to_str().replace('ÿ'," "))
165165

166166
elif sys.argv[1] == 'setslot':
167167
try:
@@ -379,17 +379,17 @@ def mprompt():
379379
tmp[slot.name] = slot
380380
slots = iter(['1a', '1b', '2a', '2b', '3a', '3b', '4a', '4b', '5a', '5b', '6a', '6b'])
381381
for slot_name in slots:
382-
print(tmp[slot_name].to_str())
383-
print(tmp[next(slots)].to_str())
382+
print(tmp[slot_name].to_str().replace('ÿ'," "))
383+
print(tmp[next(slots)].to_str().replace('ÿ'," "))
384384
print()
385385

386386
if data[0] == 'getkeylabels':
387387
tmp = {}
388388
for slot in only_key.getkeylabels():
389389
tmp[slot.name] = slot
390-
slots = iter(['RSA Key 1', 'RSA Key 2', 'RSA Key 3', 'RSA Key 4', 'ECC Key 1', 'ECC Key 2', 'ECC Key 3', 'ECC Key 4', 'ECC Key 5', 'ECC Key 6', 'ECC Key 7', 'ECC Key 8', 'ECC Key 9', 'ECC Key 10', 'ECC Key 11', 'ECC Key 12', 'ECC Key 13', 'ECC Key 14', 'ECC Key 19', 'ECC Key 20', 'ECC Key 21', 'ECC Key 22', 'ECC Key 23', 'ECC Key 24', 'ECC Key 25', 'ECC Key 26', 'ECC Key 27', 'ECC Key 28', 'ECC Key 29'])
390+
slots = iter(['RSA Key 1', 'RSA Key 2', 'RSA Key 3', 'RSA Key 4', 'ECC Key 1', 'ECC Key 2', 'ECC Key 3', 'ECC Key 4', 'ECC Key 5', 'ECC Key 6', 'ECC Key 7', 'ECC Key 8', 'ECC Key 9', 'ECC Key 10', 'ECC Key 11', 'ECC Key 12', 'ECC Key 13', 'ECC Key 14', 'ECC Key 15', 'ECC Key 16'])
391391
for slot_name in slots:
392-
print(tmp[slot_name].to_str())
392+
print(tmp[slot_name].to_str().replace('ÿ'," "))
393393

394394
elif data[0] == 'setslot':
395395
try:

onlykey/client.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,20 @@ def read_bytes(self, n=64, to_str=False, timeout_ms=100):
352352
raise RuntimeError('Error OnlyKey must be configured first')
353353
elif outstr.decode(errors="ignore").find("Timeout occured while waiting for confirmation on OnlyKey") != -1:
354354
raise RuntimeError('Timeout occured while waiting for confirmation on OnlyKey')
355+
elif outstr.decode(errors="ignore").find("Error key not set as signature key") != -1:
356+
raise RuntimeError('Error key not set as signature key')
357+
elif outstr.decode(errors="ignore").find("Error key not set as decryption key") != -1:
358+
raise RuntimeError('Error key not set as decryption key')
359+
elif outstr.decode(errors="ignore").find("Error with RSA data to sign invalid size") != -1:
360+
raise RuntimeError('Error with RSA data to sign invalid size')
361+
elif outstr.decode(errors="ignore").find("Error with RSA signing") != -1:
362+
raise RuntimeError('Error with RSA signing')
363+
elif outstr.decode(errors="ignore").find("Error with RSA data to decrypt invalid size") != -1:
364+
raise RuntimeError('Error with RSA data to decrypt invalid size')
365+
elif outstr.decode(errors="ignore").find("Error with RSA decryption") != -1:
366+
raise RuntimeError('Error with RSA decryption')
367+
elif outstr.decode(errors="ignore").find("Error no key set in this slot") != -1:
368+
raise RuntimeError('Error no key set in this slot')
355369

356370
if to_str:
357371
# Returns the bytes a string if requested
@@ -393,10 +407,10 @@ def getkeylabels(self):
393407
self.send_message(msg=Message.OKGETLABELS, slot_id=107)
394408
time.sleep(0)
395409
slots = []
396-
for _ in range(33):
410+
for _ in range(20):
397411
data = self.read_string().split('|')
398412
slot_number = ord(data[0])
399-
if 25 <= slot_number <= 57:
413+
if 25 <= slot_number <= 44:
400414
slots.append(Slot(slot_number, label=data[1]))
401415

402416
return slots

0 commit comments

Comments
 (0)