Skip to content

Commit ce36d3f

Browse files
onlykeyonlykey
authored andcommitted
add support for key labels, setting led brightness, and new preferences
1 parent 56cadbb commit ce36d3f

3 files changed

Lines changed: 65 additions & 15 deletions

File tree

onlykey/cli.py

Lines changed: 56 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -155,11 +155,9 @@ def prompt_pin():
155155
tmp = {}
156156
for slot in only_key.getkeylabels():
157157
tmp[slot.name] = slot
158-
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', 'ECC Key 30', 'ECC Key 31', 'ECC Key 32'])
158+
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'])
159159
for slot_name in slots:
160160
print(tmp[slot_name].to_str())
161-
print(tmp[next(slots)].to_str())
162-
print()
163161

164162
elif sys.argv[1] == 'setslot':
165163
try:
@@ -187,13 +185,19 @@ def prompt_pin():
187185
slot_id = 11
188186
elif sys.argv[2] == '6b':
189187
slot_id = 12
188+
elif sys.argv[2] >= int('25'):
189+
slot_id = int(sys.argv[2])
190190
except:
191191
print("setslot <id> <type> [value]")
192192
print("<id> must be slot number 1a - 6b")
193193
return
194194

195195
if sys.argv[3] == 'label':
196196
only_key.setslot(slot_id, MessageField.LABEL, sys.argv[4])
197+
elif sys.argv[3] == 'ecc_key_label':
198+
only_key.setslot(slot_id+28, MessageField.LABEL, sys.argv[4])
199+
elif sys.argv[3] == 'rsa_key_label':
200+
only_key.setslot(slot_id+24, MessageField.LABEL, sys.argv[4])
197201
elif sys.argv[3] == 'url':
198202
only_key.setslot(slot_id, MessageField.URL, sys.argv[4])
199203
elif sys.argv[3] == 'add_char2':
@@ -232,7 +236,7 @@ def prompt_pin():
232236
only_key.setslot(slot_id, MessageField.NEXTKEY5, sys.argv[4])
233237
else:
234238
print("setslot <id> <type> [value]")
235-
print("<type> must be ['label', 'url', 'add_char1', 'delay1', 'username', 'add_char2', 'delay2', 'password', 'add_char3', 'delay3', '2fa', 'totpkey', 'add_char4', 'add_char5']")
239+
print("<type> must be ['label', 'ecc_key_label', 'rsa_key_label', 'url', 'add_char1', 'delay1', 'username', 'add_char2', 'delay2', 'password', 'add_char3', 'delay3', '2fa', 'totpkey', 'add_char4', 'add_char5']")
236240
return
237241

238242
elif sys.argv[1] == 'wipeslot':
@@ -261,6 +265,8 @@ def prompt_pin():
261265
slot_id = 11
262266
elif sys.argv[2] == '6b':
263267
slot_id = 12
268+
elif sys.argv[2] >= int('25'):
269+
slot_id = int(sys.argv[2])
264270
except:
265271
print("wipeslot <id>")
266272
print("<id> must be slot number 1a - 6b")
@@ -277,6 +283,16 @@ def prompt_pin():
277283
only_key.setslot(1, MessageField.WIPEMODE, int(sys.argv[2]))
278284
elif sys.argv[1] == 'keytypespeed':
279285
only_key.setslot(1, MessageField.KEYTYPESPEED, int(sys.argv[2]))
286+
elif sys.argv[1] == 'led_brightness':
287+
only_key.setslot(1, MessageField.LEDBRIGHTNESS, int(sys.argv[2]))
288+
elif sys.argv[1] == '2nd_profile_mode':
289+
only_key.setslot(1, MessageField.SECPROFILEMODE, int(sys.argv[2]))
290+
elif sys.argv[1] == 'pgp_challenge_mode':
291+
only_key.setslot(1, MessageField.PGPCHALENGEMODE, int(sys.argv[2]))
292+
elif sys.argv[1] == 'ssh_challenge_mode':
293+
only_key.setslot(1, MessageField.SSHCHALENGEMODE, int(sys.argv[2]))
294+
elif sys.argv[1] == 'backup_key_mode':
295+
only_key.setslot(1, MessageField.BACKUPMODE, int(sys.argv[2]))
280296
elif sys.argv[1] == 'keylayout':
281297
only_key.setslot(1, MessageField.KEYLAYOUT, int(sys.argv[2]))
282298

@@ -287,7 +303,7 @@ def prompt_pin():
287303
else:
288304

289305
# Print help.
290-
print('OnlyKey CLI v0.5')
306+
print('OnlyKey CLI v0.6')
291307
print('Control-D to exit.')
292308
print()
293309

@@ -367,10 +383,9 @@ def mprompt():
367383
tmp = {}
368384
for slot in only_key.getkeylabels():
369385
tmp[slot.name] = slot
370-
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', 'ECC Key 30', 'ECC Key 31', 'ECC Key 32'])
386+
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'])
371387
for slot_name in slots:
372388
print(tmp[slot_name].to_str())
373-
print(tmp[next(slots)].to_str())
374389

375390
elif data[0] == 'setslot':
376391
try:
@@ -398,13 +413,19 @@ def mprompt():
398413
slot_id = 11
399414
elif data[1] == '6b':
400415
slot_id = 12
416+
elif data[1] >= int('25'):
417+
slot_id = int(data[1])
401418
except:
402419
print("setslot <id> <type> [value]")
403420
print("<id> must be slot number 1a - 6b")
404421
continue
405422

406423
if data[2] == 'label':
407424
only_key.setslot(slot_id, MessageField.LABEL, data[3])
425+
elif data[2] == 'ecc_key_label':
426+
only_key.setslot(slot_id+28, MessageField.LABEL, data[3])
427+
elif data[2] == 'rsa_key_label':
428+
only_key.setslot(slot_id+24, MessageField.LABEL, data[3])
408429
elif data[2] == 'url':
409430
only_key.setslot(slot_id, MessageField.URL, data[3])
410431
elif data[2] == 'add_char2':
@@ -443,7 +464,7 @@ def mprompt():
443464
only_key.setslot(slot_id, MessageField.NEXTKEY3, data[3])
444465
else:
445466
print("setslot <id> <type> [value]")
446-
print("<type> must be ['label', 'url', 'add_char1', 'delay1', 'username', 'add_char2', 'delay2', 'password', 'add_char3', 'delay3', '2fa', 'totpkey', 'add_char4', 'add_char5']")
467+
print("<type> must be ['label', 'ecc_key_label', 'rsa_key_label', 'url', 'add_char1', 'delay1', 'username', 'add_char2', 'delay2', 'password', 'add_char3', 'delay3', '2fa', 'totpkey', 'add_char4', 'add_char5']")
447468
continue
448469
elif data[0] == 'wipeslot':
449470
try:
@@ -471,6 +492,8 @@ def mprompt():
471492
slot_id = 11
472493
elif data[1] == '6b':
473494
slot_id = 12
495+
elif data[1] >= int('25'):
496+
slot_id = int(data[1])
474497
except:
475498
print("wipeslot <id>")
476499
print("<id> must be slot number 1a - 6b")
@@ -499,6 +522,31 @@ def mprompt():
499522
only_key.setslot(1, MessageField.KEYTYPESPEED, int(data[1]))
500523
except:
501524
continue
525+
elif data[0] == 'led_brightness':
526+
try:
527+
only_key.setslot(1, MessageField.LEDBRIGHTNESS, int(data[1]))
528+
except:
529+
continue
530+
elif data[0] == 'pgp_challenge_mode':
531+
try:
532+
only_key.setslot(1, MessageField.PGPCHALENGEMODE, int(data[1]))
533+
except:
534+
continue
535+
elif data[0] == 'ssh_challenge_mode':
536+
try:
537+
only_key.setslot(1, MessageField.SSHCHALENGEMODE, int(data[1]))
538+
except:
539+
continue
540+
elif data[0] == 'backup_key_mode':
541+
try:
542+
only_key.setslot(1, MessageField.BACKUPMODE, int(data[1]))
543+
except:
544+
continue
545+
elif data[0] == '2nd_profile_mode':
546+
try:
547+
only_key.setslot(1, MessageField.SECPROFILEMODE, int(data[1]))
548+
except:
549+
continue
502550
elif data[0] == 'keylayout':
503551
try:
504552
only_key.setslot(1, MessageField.KEYLAYOUT, int(data[1]))

onlykey/client.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,11 @@ class MessageField(Enum):
121121
WIPEMODE = 12
122122
KEYTYPESPEED = 13
123123
KEYLAYOUT = 14
124+
LEDBRIGHTNESS = 24
125+
SECPROFILEMODE = 23
126+
PGPCHALENGEMODE = 22
127+
SSHCHALENGEMODE = 21
128+
BACKUPMODE = 20
124129

125130
class KeyTypeEnum(Enum):
126131
ED22519 = 1
@@ -369,12 +374,10 @@ def getkeylabels(self):
369374
self.send_message(msg=Message.OKGETLABELS, slot_id=107)
370375
time.sleep(0)
371376
slots = []
372-
for _ in range(36):
377+
for _ in range(33):
373378
data = self.read_string().split('|')
374-
print 'data ', repr(data)
375379
slot_number = ord(data[0])
376-
print 'slot_number ', repr(slot_number)
377-
if 25 <= slot_number <= 60:
380+
if 25 <= slot_number <= 57:
378381
slots.append(Slot(slot_number, label=data[1]))
379382
return slots
380383

@@ -394,10 +397,9 @@ def displaykeylabels(self):
394397
tmp = {}
395398
for slot in self.getkeylabels():
396399
tmp[slot.name] = slot
397-
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', 'ECC Key 30', 'ECC Key 31', 'ECC Key 32'])
400+
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'])
398401
for slot_name in slots:
399402
print(tmp[slot_name].to_str())
400-
print(tmp[next(slots)].to_str())
401403

402404
def setslot(self, slot_number, message_field, value):
403405
"""Set a slot field to the given value.

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
setup(
1212
name='onlykey',
13-
version='0.5',
13+
version='0.6',
1414
description='OnlyKey client and command-line tool',
1515
long_description=long_description,
1616
url='https://github.com/trustcrypto/python-onlykey',

0 commit comments

Comments
 (0)