diff options
author | Szczepan Zalega <szczepan@nitrokey.com> | 2019-06-22 08:59:46 +0200 |
---|---|---|
committer | Szczepan Zalega <szczepan@nitrokey.com> | 2019-06-22 17:31:02 +0200 |
commit | 89187c76143c981819c380e5f163308a0e5e6702 (patch) | |
tree | 96c60e3817a61dcfbdbd3a6ac6f63b475bcc3dc6 | |
parent | 3fc4193776b4ea29354838df024a72d7c8349ea9 (diff) | |
download | libnitrokey-89187c76143c981819c380e5f163308a0e5e6702.tar.gz libnitrokey-89187c76143c981819c380e5f163308a0e5e6702.tar.bz2 |
Test writing edge OTP slots
This tests encountered bug in the Storage v0.54 RC.
Write either TOTP15 or HOTP1, and try to access the other.
Signed-off-by: Szczepan Zalega <szczepan@nitrokey.com>
-rw-r--r-- | unittest/test_pro.py | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/unittest/test_pro.py b/unittest/test_pro.py index b8ae290..d145fc4 100644 --- a/unittest/test_pro.py +++ b/unittest/test_pro.py @@ -1003,3 +1003,39 @@ def test_HOTP_counter_getter(C, counter_mid: int): assert read_slot_st.slot_counter == counter +def test_edge_OTP_slots(C): + # -> shows TOTP15 is not written + # -> assuming HOTP1 is written + # (optional) Write slot HOTP1 + # Write slot TOTP15 + # Wait + # Read slot TOTP15 details + # Read HOTP1 details + # returns SLOT_NOT_PROGRAMMED + # (next nkapp execution) + # -> shows HOTP1 is not written + # briefly writing TOTP15 clears HOTP1, and vice versa + + read_slot_st = ffi.new('struct ReadSlot_t *') + if not read_slot_st: + raise Exception("Could not allocate status") + use_pin_protection = False + use_8_digits = False + assert C.NK_first_authenticate(DefaultPasswords.ADMIN, DefaultPasswords.ADMIN_TEMP) == DeviceErrorCode.STATUS_OK + assert C.NK_write_config(255, 255, 255, use_pin_protection, not use_pin_protection, + DefaultPasswords.ADMIN_TEMP) == DeviceErrorCode.STATUS_OK + counter = 0 + HOTP_slot_number = 1 -1 + TOTP_slot_number = 15 -1 # 0 based + assert C.NK_write_totp_slot(TOTP_slot_number, b'python_test', bbRFC_SECRET, 30, False, False, False, b'', + DefaultPasswords.ADMIN_TEMP) == DeviceErrorCode.STATUS_OK + assert C.NK_write_hotp_slot(HOTP_slot_number, b'python_test', bbRFC_SECRET, counter, use_8_digits, False, False, b'', DefaultPasswords.ADMIN_TEMP) == DeviceErrorCode.STATUS_OK + for i in range(5): + code_hotp = gs(C.NK_get_hotp_code(HOTP_slot_number)) + assert code_hotp + assert C.NK_get_last_command_status() == DeviceErrorCode.STATUS_OK + assert C.NK_read_HOTP_slot(HOTP_slot_number, read_slot_st) == DeviceErrorCode.STATUS_OK + assert read_slot_st.slot_counter == (i+1) + helper_set_time_on_device(C, 1) + code_totp = gs((C.NK_get_totp_code(TOTP_slot_number, 0, 0, 30))) + assert C.NK_get_last_command_status() == DeviceErrorCode.STATUS_OK |