diff --git a/test/features/030_key_registration.feature b/test/features/030_key_registration.feature index b71dc90..73f1c10 100644 --- a/test/features/030_key_registration.feature +++ b/test/features/030_key_registration.feature @@ -16,3 +16,33 @@ Feature: import keys to token Given a RSA key pair 2 And importing it to the token as OPENPGP.3 Then it should get success + + Scenario: setup data object Finger print sig + Given a fingerprint of OPENPGP.1 key + And put the data to c7 + Then it should get success + + Scenario: setup data object Finger print dec + Given a fingerprint of OPENPGP.2 key + And put the data to c8 + Then it should get success + + Scenario: setup data object Finger print aut + Given a fingerprint of OPENPGP.3 key + And put the data to c9 + Then it should get success + + Scenario: setup data object keygeneration data/time sig + Given a timestamp of OPENPGP.1 key + And put the data to ce + Then it should get success + + Scenario: setup data object keygeneration data/time dec + Given a timestamp of OPENPGP.2 key + And put the data to cf + Then it should get success + + Scenario: setup data object keygeneration data/time aut + Given a timestamp of OPENPGP.3 key + And put the data to d0 + Then it should get success diff --git a/test/features/steps.py b/test/features/steps.py index 9d2cc77..dfe798b 100644 --- a/test/features/steps.py +++ b/test/features/steps.py @@ -46,6 +46,23 @@ def import_key(openpgp_keyno_str): t = rsa_keys.build_privkey_template(openpgp_keyno, scc.keyno) scc.result = ftc.token.cmd_put_data_odd(0x3f, 0xff, t) +@Given("a fingerprint of OPENPGP.(.*) key") +def get_key_fpr(openpgp_keyno_str): + openpgp_keyno = int(openpgp_keyno_str) + scc.result = rsa_keys.fpr[openpgp_keyno - 1] + +@Given("a timestamp of OPENPGP.(.*) key") +def get_key_timestamp(openpgp_keyno_str): + openpgp_keyno = int(openpgp_keyno_str) + scc.result = rsa_keys.timestamp[openpgp_keyno - 1] + +@Given("put the data to (.*)") +def cmd_put_data_with_result(tag_str): + tag = int(tag_str, 16) + tagh = tag >> 8 + tagl = tag & 0xff + scc.result = ftc.token.cmd_put_data(tagh, tagl, scc.result) + @When("requesting (.+): ([0-9a-fA-F]+)") def get_data(name, tag_str): tag = int(tag_str, 16) diff --git a/test/rsa_keys.py b/test/rsa_keys.py index 698fbe3..b81f551 100644 --- a/test/rsa_keys.py +++ b/test/rsa_keys.py @@ -1,4 +1,7 @@ from binascii import unhexlify +from time import time +from struct import pack +from hashlib import sha1 def read_key_from_file(file): f = open(file) @@ -15,11 +18,27 @@ 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)) +def calc_fpr(n,e): + timestamp = int(time()) + timestamp_data = pack('>I', timestamp) + m_len = 6 + 2 + 256 + 2 + 4 + m = '\x99' + pack('>H', m_len) + '\x04' + timestamp_data + '\x01' + \ + pack('>H', 2048) + n + pack('>H', 17) + e + fpr = sha1(m).digest() + return (fpr, timestamp_data) + key = [ None, None, None ] +fpr = [ None, None, None ] +timestamp = [ None, None, None ] + key[0] = read_key_from_file('rsa-sig.key') key[1] = read_key_from_file('rsa-dec.key') key[2] = read_key_from_file('rsa-aut.key') +(fpr[0], timestamp[0]) = calc_fpr(key[0][0], key[0][1]) +(fpr[1], timestamp[1]) = calc_fpr(key[1][0], key[1][1]) +(fpr[2], timestamp[2]) = calc_fpr(key[2][0], key[2][1]) + def build_privkey_template(openpgp_keyno, keyno): n_str = key[keyno][0] e_str = '\x00' + key[keyno][1]