Skip to content

Commit

Permalink
Merge branch 'rsa_key'
Browse files Browse the repository at this point in the history
Add missing RSA key as module

Fixes Nitrokey#14
Fixes Nitrokey#13
  • Loading branch information
szszszsz committed Jun 18, 2020
2 parents 9d13dd6 + d2ef7d5 commit 74be26c
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
13 changes: 13 additions & 0 deletions solo/start/rsa.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,19 @@ def read_key_from_file(file):
raise ValueError("wrong key", p, q, n)
return (unhexlify(n_str), unhexlify(e_str), unhexlify(p_str), unhexlify(q_str), e, p, q, n)

def read_key_from_list(data):
n_str, e_str, p_str, q_str = data
e = int(e_str, 16)
p = int(p_str, 16)
q = int(q_str, 16)
n = int(n_str, 16)
if n != p * q:
raise ValueError("wrong key", p, q, n)
return (unhexlify(n_str), unhexlify(e_str), unhexlify(p_str), unhexlify(q_str), e, p, q, n)




# egcd and modinv are from wikibooks
# https://en.wikibooks.org/wiki/Algorithm_Implementation/Mathematics/Extended_Euclidean_algorithm

Expand Down
4 changes: 0 additions & 4 deletions solo/start/rsa_example.key

This file was deleted.

7 changes: 7 additions & 0 deletions solo/start/rsa_pub_key.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
rsa_key_data = [
"9cf7192b51a574d1ad3ccb08ba09b87f228573893eee355529ff243e90fd4b86f79a82097cc7922c0485bed1616b1656a9b0b19ef78ea8ec34c384019adc5d5bf4db2d2a0a2d9cf14277bdcb7056f48b81214e3f7f7742231e29673966f9b1106862112cc798dba8d4a138bb5abfc6d4c12d53a5d39b2f783da916da20852ee139bbafda61d429caf2a4f30847ce7e7ae32ab4061e27dd9e4d00d60910249db8d8559dd85f7ca59659ef400c8f6318700f4e97f0c6f4165de80641490433c88da8682befe68eb311f54af2b07d97ac74edb5399cf054764211694fbb8d1d333f3269f235abe025067f811ff83a2224826219b309ea3e6c968f42b3e52f245dc9",
"010001",
"b5ab7b159220b18e363258f61ebde08bae83d6ce2dbfe4adc143628c527887acde9de09bf9b49f438019004d71855f30c2d69b6c29bb9882ab641b3387409fe9199464a7faa4b5230c56d9e17cd9ed074bc00180ebed62bae3af28e6ff2ac2654ad968834c5d5c88f8d9d3cc5e167b10453b049d4e454a5761fb0ac717185907",
"dd2fffa9814296156a6926cd17b65564187e424dcadce9b032246ad7e46448bb0f9e0ff3c64f987424b1a40bc694e2e9ac4fb1930d163582d7acf20653a1c44b97846c1c5fd8a7b19bb225fb39c30e25410483deaf8c2538d222b748c4d8103b11cec04f666a5c0dbcbf5d5f625f158f65746c3fafe6418145f7cffa5fadeeaf"
]

4 changes: 3 additions & 1 deletion solo/start/upgrade_by_passwd.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@
from solo.start.kdf_calc import kdf_calc
from solo.start.threaded_log import ThreadLog
from solo.start.usb_strings import get_devices, print_device
from solo.start.rsa_pub_key import rsa_key_data


LOG_FORMAT_STDOUT = '*** %(asctime)-15s %(levelname)6s %(name)10s %(message)s'
LOG_FORMAT = '%(relativeCreated)-8d %(levelname)6s %(name)10s %(message)s'
Expand Down Expand Up @@ -130,7 +132,7 @@ def main(wait_e, keyno, passwd, data_regnual, data_upgrade, skip_bootloader, ver
local_print("CRC32: %04x\n" % crc32code)
data_regnual += pack('<I', crc32code)

rsa_key = rsa.read_key_from_file('solo/start/rsa_example.key')
rsa_key = rsa.read_key_from_list(rsa_key_data)
rsa_raw_pubkey = rsa.get_raw_pubkey(rsa_key)

gnuk = get_gnuk_device(logger=logger)
Expand Down

0 comments on commit 74be26c

Please sign in to comment.