Skip to content

Commit

Permalink
DUO (#57)
Browse files Browse the repository at this point in the history
* add support for duo

* bump version
  • Loading branch information
onlykey authored Mar 9, 2022
1 parent 2165a09 commit fa8de1e
Show file tree
Hide file tree
Showing 4 changed files with 216 additions and 15 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ Or you can run commands in an interactive shell like this:

```
$ onlykey-cli
OnlyKey CLI v1.2.8
OnlyKey CLI v1.2.9
Press the right arrow to insert the suggestion.
Press Control-C to retry. Control-D to exit.
Expand Down
222 changes: 211 additions & 11 deletions onlykey/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,59 @@ def prompt_pin():
slot_id = 11
elif sys.argv[2] == '6b':
slot_id = 12
elif sys.argv[2] == 'green1a':
slot_id = 1
elif sys.argv[2] == 'green2a':
slot_id = 2
elif sys.argv[2] == 'green3a':
slot_id = 3
elif sys.argv[2] == 'green1b':
slot_id = 4
elif sys.argv[2] == 'green2b':
slot_id = 5
elif sys.argv[2] == 'green3b':
slot_id = 6
elif sys.argv[2] == 'blue1a':
slot_id = 7
elif sys.argv[2] == 'blue2a':
slot_id = 8
elif sys.argv[2] == 'blue3a':
slot_id = 9
elif sys.argv[2] == 'blue1b':
slot_id = 10
elif sys.argv[2] == 'blue2b':
slot_id = 11
elif sys.argv[2] == 'blue3b':
slot_id = 12
elif sys.argv[2] == 'yellow1a':
slot_id = 13
elif sys.argv[2] == 'yellow2a':
slot_id = 14
elif sys.argv[2] == 'yellow3a':
slot_id = 15
elif sys.argv[2] == 'yellow1b':
slot_id = 16
elif sys.argv[2] == 'yellow2b':
slot_id = 17
elif sys.argv[2] == 'yellow3b':
slot_id = 18
elif sys.argv[2] == 'purple1a':
slot_id = 19
elif sys.argv[2] == 'purple2a':
slot_id = 20
elif sys.argv[2] == 'purple3a':
slot_id = 21
elif sys.argv[2] == 'purple1b':
slot_id = 22
elif sys.argv[2] == 'purple2b':
slot_id = 23
elif sys.argv[2] == 'purple3b':
slot_id = 24
else:
slot_id = int(sys.argv[2])
except:
print("setslot [id] [type] [value]")
print("[id] must be slot number 1a - 6b")
print("[id] must be a valid slot number")
return

if sys.argv[3] == 'label':
Expand Down Expand Up @@ -219,9 +267,11 @@ def prompt_pin():
only_key.setslot(slot_id, MessageField.NEXTKEY4, sys.argv[4])
elif sys.argv[3] == 'addchar4':
only_key.setslot(slot_id, MessageField.NEXTKEY5, sys.argv[4])
elif sys.argv[3] == 'typespeed':
only_key.setslot(slot_id, MessageField.KEYTYPESPEED, int(sys.argv[4]))
else:
print("setslot [id] [type] [value]")
print("[type] must be ['label', 'ecckeylabel', 'rsakeylabel', 'url', 'addchar1', 'delay1', 'username', 'addchar2', 'delay2', 'password', 'addchar3', 'delay3', '2fa', 'totpkey', 'addchar4', 'addchar5']")
print("[type] must be ['label', 'ecckeylabel', 'rsakeylabel', 'url', 'addchar1', 'delay1', 'username', 'addchar2', 'delay2', 'password', 'addchar3', 'delay3', '2fa', 'totpkey', 'addchar4', 'addchar5', 'typespeed']")
return
elif sys.argv[1] == 'wipeslot':
try:
Expand Down Expand Up @@ -249,9 +299,59 @@ def prompt_pin():
slot_id = 11
elif sys.argv[2] == '6b':
slot_id = 12
elif sys.argv[2] == 'green1a':
slot_id = 1
elif sys.argv[2] == 'green2a':
slot_id = 2
elif sys.argv[2] == 'green3a':
slot_id = 3
elif sys.argv[2] == 'green1b':
slot_id = 4
elif sys.argv[2] == 'green2b':
slot_id = 5
elif sys.argv[2] == 'green3b':
slot_id = 6
elif sys.argv[2] == 'blue1a':
slot_id = 7
elif sys.argv[2] == 'blue2a':
slot_id = 8
elif sys.argv[2] == 'blue3a':
slot_id = 9
elif sys.argv[2] == 'blue1b':
slot_id = 10
elif sys.argv[2] == 'blue2b':
slot_id = 11
elif sys.argv[2] == 'blue3b':
slot_id = 12
elif sys.argv[2] == 'yellow1a':
slot_id = 13
elif sys.argv[2] == 'yellow2a':
slot_id = 14
elif sys.argv[2] == 'yellow3a':
slot_id = 15
elif sys.argv[2] == 'yellow1b':
slot_id = 16
elif sys.argv[2] == 'yellow2b':
slot_id = 17
elif sys.argv[2] == 'yellow3b':
slot_id = 18
elif sys.argv[2] == 'purple1a':
slot_id = 19
elif sys.argv[2] == 'purple2a':
slot_id = 20
elif sys.argv[2] == 'purple3a':
slot_id = 21
elif sys.argv[2] == 'purple1b':
slot_id = 22
elif sys.argv[2] == 'purple2b':
slot_id = 23
elif sys.argv[2] == 'purple3b':
slot_id = 24
else:
slot_id = int(sys.argv[2])
except:
print("wipeslot [id]")
print("[id] must be slot number 1a - 6b")
print("[id] must be a valid slot number")
return
only_key.wipeslot(slot_id)
elif sys.argv[1] == 'setkey' or sys.argv[1] == 'genkey':
Expand Down Expand Up @@ -374,7 +474,7 @@ def prompt_pin():
elif sys.argv[1] == 'wipemode':
only_key.setslot(1, MessageField.WIPEMODE, int(sys.argv[2]))
elif sys.argv[1] == 'keytypespeed':
only_key.setslot(int(sys.argv[2]), MessageField.KEYTYPESPEED, int(sys.argv[3]))
only_key.setslot(99, MessageField.KEYTYPESPEED, int(sys.argv[2]))
elif sys.argv[1] == 'ledbrightness':
only_key.setslot(1, MessageField.LEDBRIGHTNESS, int(sys.argv[2]))
elif sys.argv[1] == 'touchsense':
Expand All @@ -396,7 +496,7 @@ def prompt_pin():
elif sys.argv[1] == 'hmackeymode':
only_key.setslot(1, MessageField.HMACMODE, int(sys.argv[2]))
elif sys.argv[1] == 'version':
print('OnlyKey CLI v1.2.8')
print('OnlyKey CLI v1.2.9')
elif sys.argv[1] == 'fwversion':
only_key.set_time(time.time())
okversion = only_key.read_string()
Expand Down Expand Up @@ -473,7 +573,7 @@ def prompt_pin():
else:

# Print help.
print('OnlyKey CLI v1.2.8')
print('OnlyKey CLI v1.2.9')
print('Control-D to exit.')
print()

Expand Down Expand Up @@ -600,11 +700,59 @@ def mprompt():
slot_id = 11
elif data[1] == '6b':
slot_id = 12
elif data[1] == 'green1a':
slot_id = 1
elif data[1] == 'green2a':
slot_id = 2
elif data[1] == 'green3a':
slot_id = 3
elif data[1] == 'green1b':
slot_id = 4
elif data[1] == 'green2b':
slot_id = 5
elif data[1] == 'green3b':
slot_id = 6
elif data[1] == 'blue1a':
slot_id = 7
elif data[1] == 'blue2a':
slot_id = 8
elif data[1] == 'blue3a':
slot_id = 9
elif data[1] == 'blue1b':
slot_id = 10
elif data[1] == 'blue2b':
slot_id = 11
elif data[1] == 'blue3b':
slot_id = 12
elif data[1] == 'yellow1a':
slot_id = 13
elif data[1] == 'yellow2a':
slot_id = 14
elif data[1] == 'yellow3a':
slot_id = 15
elif data[1] == 'yellow1b':
slot_id = 16
elif data[1] == 'yellow2b':
slot_id = 17
elif data[1] == 'yellow3b':
slot_id = 18
elif data[1] == 'purple1a':
slot_id = 19
elif data[1] == 'purple2a':
slot_id = 20
elif data[1] == 'purple3a':
slot_id = 21
elif data[1] == 'purple1b':
slot_id = 22
elif data[1] == 'purple2b':
slot_id = 23
elif data[1] == 'purple3b':
slot_id = 24
else:
slot_id = int(data[1])
except:
print("setslot [id] [type] [value]")
print("[id] must be slot number 1a - 6b")
print("[id] must be a valid slot number")
continue
if data[2] == 'label':
only_key.setslot(slot_id, MessageField.LABEL, data[3])
Expand Down Expand Up @@ -648,9 +796,11 @@ def mprompt():
only_key.setslot(slot_id, MessageField.NEXTKEY3, data[3])
elif data[2] == 'addchar4':
only_key.setslot(slot_id, MessageField.NEXTKEY3, data[3])
elif data[2] == 'typespeed':
only_key.setslot(slot_id, MessageField.KEYTYPESPEED, int(data[3]))
else:
print("setslot [id] [type] [value]")
print("[type] must be ['label', 'ecckeylabel', 'rsakeylabel', 'url', 'addchar1', 'delay1', 'username', 'addchar2', 'delay2', 'password', 'addchar3', 'delay3', '2fa', 'totpkey', 'addchar4', 'addchar5']")
print("[type] must be ['label', 'ecckeylabel', 'rsakeylabel', 'url', 'addchar1', 'delay1', 'username', 'addchar2', 'delay2', 'password', 'addchar3', 'delay3', '2fa', 'totpkey', 'addchar4', 'addchar5', 'typespeed']")
continue
elif data[0] == 'wipeslot':
try:
Expand Down Expand Up @@ -678,9 +828,59 @@ def mprompt():
slot_id = 11
elif data[1] == '6b':
slot_id = 12
elif data[1] == 'green1a':
slot_id = 1
elif data[1] == 'green2a':
slot_id = 2
elif data[1] == 'green3a':
slot_id = 3
elif data[1] == 'green1b':
slot_id = 4
elif data[1] == 'green2b':
slot_id = 5
elif data[1] == 'green3b':
slot_id = 6
elif data[1] == 'blue1a':
slot_id = 7
elif data[1] == 'blue2a':
slot_id = 8
elif data[1] == 'blue3a':
slot_id = 9
elif data[1] == 'blue1b':
slot_id = 10
elif data[1] == 'blue2b':
slot_id = 11
elif data[1] == 'blue3b':
slot_id = 12
elif data[1] == 'yellow1a':
slot_id = 13
elif data[1] == 'yellow2a':
slot_id = 14
elif data[1] == 'yellow3a':
slot_id = 15
elif data[1] == 'yellow1b':
slot_id = 16
elif data[1] == 'yellow2b':
slot_id = 17
elif data[1] == 'yellow3b':
slot_id = 18
elif data[1] == 'purple1a':
slot_id = 19
elif data[1] == 'purple2a':
slot_id = 20
elif data[1] == 'purple3a':
slot_id = 21
elif data[1] == 'purple1b':
slot_id = 22
elif data[1] == 'purple2b':
slot_id = 23
elif data[1] == 'purple3b':
slot_id = 24
else:
slot_id = int(data[1])
except:
print("wipeslot [id]")
print("[id] must be slot number 1a - 6b")
print("[id] must be a valid slot number")
continue
only_key.wipeslot(slot_id)
elif data[0] == 'setkey' or data[0] == 'genkey':
Expand Down Expand Up @@ -818,7 +1018,7 @@ def mprompt():
continue
elif data[0] == 'keytypespeed':
try:
only_key.setslot(1, MessageField.KEYTYPESPEED, int(data[1]))
only_key.setslot(99, MessageField.KEYTYPESPEED, int(data[1]))
except:
continue
elif data[0] == 'ledbrightness':
Expand Down Expand Up @@ -873,7 +1073,7 @@ def mprompt():
continue
elif data[0] == 'version':
try:
print('OnlyKey CLI v1.2.8')
print('OnlyKey CLI v1.2.9')
except:
continue
elif data[0] == 'fwversion':
Expand Down
5 changes: 3 additions & 2 deletions onlykey/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@


SLOTS_NAME= {
0: '0',
1: '1a',
2: '2a',
3: '3a',
Expand Down Expand Up @@ -309,6 +310,8 @@ def send_message(self, payload=None, msg=None, slot_id=None, message_field=None,
# Append the slot ID if needed
if slot_id:
logging.debug('slot_id=%s', slot_id)
if slot_id == 99:
slot_id = 0
raw_bytes.append(slot_id)

# Append the message field (must be a `MessageField` enum value)
Expand Down Expand Up @@ -511,8 +514,6 @@ def displaykeylabels(self):
def setslot(self, slot_number, message_field, value):
"""Set a slot field to the given value."""
self.send_message(msg=Message.OKSETSLOT, slot_id=slot_number, message_field=message_field, payload=value, from_ascii=True)
# Set U2F
# [255, 255, 255, 255, 230, 12, 8, 117, 50, 102, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
print(self.read_string())

def wipeslot(self, slot_number):
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

setup(
name='onlykey',
version='1.2.8',
version='1.2.9',
description='OnlyKey client and command-line tool',
# long_description=long_description,
url='https://github.com/trustcrypto/python-onlykey',
Expand Down

0 comments on commit fa8de1e

Please sign in to comment.