summaryrefslogtreecommitdiff
path: root/NitrokeyManager.cc
diff options
context:
space:
mode:
authorSzczepan Zalega <szczepan@nitrokey.com>2016-07-20 08:12:20 +0200
committerSzczepan Zalega <szczepan@nitrokey.com>2016-08-01 13:54:56 +0200
commitfb37116ea77f7961b12b1e289c3d48e6e517ea88 (patch)
treeba67e240be3d94bfb9d45d7d3b0e17bd0b834d7b /NitrokeyManager.cc
parent6d42e3d56a6851fa2463ef45226fd027867d74a7 (diff)
downloadlibnitrokey-fb37116ea77f7961b12b1e289c3d48e6e517ea88.tar.gz
libnitrokey-fb37116ea77f7961b12b1e289c3d48e6e517ea88.tar.bz2
Write to TOTP slot
Signed-off-by: Szczepan Zalega <szczepan@nitrokey.com>
Diffstat (limited to 'NitrokeyManager.cc')
-rw-r--r--NitrokeyManager.cc21
1 files changed, 19 insertions, 2 deletions
diff --git a/NitrokeyManager.cc b/NitrokeyManager.cc
index 6058cbb..5955330 100644
--- a/NitrokeyManager.cc
+++ b/NitrokeyManager.cc
@@ -8,7 +8,7 @@ namespace nitrokey{
void initialize(T& st){ bzero(&st, sizeof(st)); }
template <typename T>
- auto get_payload(){
+ typename T::CommandPayload get_payload(){
//Create, initialize and return by value command payload
typename T::CommandPayload st;
bzero(&st, sizeof(st));
@@ -119,9 +119,26 @@ namespace nitrokey{
return false;
}
- bool NitrokeyManager::write_TOTP_slot(uint8_t slot_number, const char *secret, uint16_t time_window) {
+ bool NitrokeyManager::write_TOTP_slot(uint8_t slot_number, const char *slot_name, const char *secret,
+ uint16_t time_window, const char *temporary_password) {
assert(is_valid_totp_slot_number(slot_number));
+ assert(strlen(secret)==20); //160 bits
+ assert(strlen(slot_name)<=15);
+
slot_number = get_internal_slot_number_for_totp(slot_number);
+ auto payload = get_payload<WriteToTOTPSlot>();
+ payload.slot_number = slot_number;
+ strcpy((char *) payload.slot_secret, secret);
+ strcpy((char *) payload.slot_name, slot_name);
+ payload.slot_interval = time_window; //FIXME naming
+ payload.slot_config; //TODO
+
+ auto auth = get_payload<Authorize>();
+ strcpy((char *) (auth.temporary_password), temporary_password);
+ auth.crc_to_authorize = WriteToTOTPSlot::CommandTransaction::getCRC(payload);
+ Authorize::CommandTransaction::run(*device, auth);
+
+ auto resp = WriteToTOTPSlot::CommandTransaction::run(*device, payload);
return false;
}