Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix to set HMAC #60

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions onlykey/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,11 @@ def prompt_pin():
slot_id = slot_id + 24
only_key.setslot(slot_id, MessageField.LABEL, sys.argv[4])
else:
only_key.setkey(slot_id, sys.argv[3], sys.argv[4], sys.argv[5])
# for HMAC we don't need key_feature
if sys.argv[3] == 'h':
only_key.setkey(slot_id, sys.argv[3], key_features=None, value=sys.argv[4])
else:
only_key.setkey(slot_id, sys.argv[3], key_features=sys.argv[4], value=sys.argv[5])
except:
print(sys.exc_info()[0])
print('Input error. See available commands with examples here https://docs.crp.to/command-line.html')
Expand Down Expand Up @@ -947,7 +951,11 @@ def mprompt():
only_key.setslot(slot_id, MessageField.LABEL, data[3])
else:
key = prompt_pass()
only_key.setkey(slot_id, data[2], data[3], key)
# for HMAC we don't need key_feature
if data[2] == 'h':
only_key.setkey(slot_id, data[2], key_features=None, value=key)
else:
only_key.setkey(slot_id, data[2], key_features=data[3], value=key)
except:
print(sys.exc_info()[0])
print('Input error. See available commands with examples here https://docs.crp.to/command-line.html')
Expand Down
8 changes: 6 additions & 2 deletions onlykey/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ def wipeslot(self, slot_number):
for _ in range(8):
print(self.read_string())

def setkey(self, slot_number, key_type, key_features, value):
def setkey(self, slot_number, key_type, value, key_features=None):
# slot 131-132 Reserved
# slot 129-130 HMAC Keys
# slot 101-116 ECC Keys
Expand Down Expand Up @@ -564,7 +564,11 @@ def setkey(self, slot_number, key_type, key_features, value):
self.send_message(msg=Message.OKSETPRIV, slot_id=slot_number, payload=format(key_type, 'x')+value[798:912])
self.send_message(msg=Message.OKSETPRIV, slot_id=slot_number, payload=format(key_type, 'x')+value[912:1024])
else:
self.send_message(msg=Message.OKSETPRIV, slot_id=slot_number, payload=format(key_type, 'x')+value)
# the key_type format must be 2 char output, the byte check later will fail
if key_type == 9:
self.send_message(msg=Message.OKSETPRIV, slot_id=slot_number, payload=format(key_type, '02x')+value)
else:
self.send_message(msg=Message.OKSETPRIV, slot_id=slot_number, payload=format(key_type, 'x')+value)
time.sleep(1)
print(self.read_string())

Expand Down