Skip to content

Commit 6a676fd

Browse files
committed
Add googletotpkey command
This matches the web app where the value entered is only converted from base32 to hex if Google OTP is selected.
1 parent 63aa205 commit 6a676fd

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

onlykey/cli.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# coding: utf-8
22
from __future__ import unicode_literals, print_function
33

4+
import base64
5+
import binascii
46
import time
57
import logging
68
import os
@@ -121,7 +123,6 @@ def prompt_key():
121123
key = prompt('Key: ',
122124
is_password=Condition(lambda cli: hidden[0]),
123125
key_bindings_registry=key_bindings_manager.registry)
124-
#need base32 to hex conversion
125126
return key
126127

127128
def prompt_pin():
@@ -201,6 +202,14 @@ def mprompt():
201202
only_key.setslot(slot_id, MessageField.DELAY3, data[3])
202203
elif data[2] == 'type':
203204
only_key.setslot(slot_id, MessageField.TFATYPE, data[3])
205+
elif data[2] == 'googletotpkey':
206+
totpkey = prompt_key()
207+
totpkey = base64.b32decode(totpkey)
208+
totpkey = binascii.hexlify(totpkey)
209+
# pad with zeros for even digits
210+
totpkey = totpkey.zfill(len(totpkey) + len(totpkey) % 2)
211+
payload = [int(totpkey[i: i+2], 16) for i in range(0, len(totpkey), 2)]
212+
only_key.setslot(slot_id, MessageField.TOTPKEY, payload)
204213
elif data[2] == 'totpkey':
205214
totpkey = prompt_key()
206215
only_key.setslot(slot_id, MessageField.TOTPKEY, totpkey)

0 commit comments

Comments
 (0)