aboutsummaryrefslogtreecommitdiff
path: root/NitrokeyManager.cc
diff options
context:
space:
mode:
authorSzczepan Zalega <szczepan@nitrokey.com>2016-09-10 10:50:59 +0200
committerSzczepan Zalega <szczepan@nitrokey.com>2016-09-10 10:51:53 +0200
commit3632e8a32d47950102bc077fd32f9c88316370e9 (patch)
treeca690bd0aa9b69c7fa0409c5c6679ca1f9cce6fb /NitrokeyManager.cc
parent77ea27f25165302491a693051bea05c67e6dfbed (diff)
downloadlibnitrokey-3632e8a32d47950102bc077fd32f9c88316370e9.tar.gz
libnitrokey-3632e8a32d47950102bc077fd32f9c88316370e9.tar.bz2
Assume secret is coded in hex for OTP slot write #31
Signed-off-by: Szczepan Zalega <szczepan@nitrokey.com>
Diffstat (limited to 'NitrokeyManager.cc')
-rw-r--r--NitrokeyManager.cc12
1 files changed, 10 insertions, 2 deletions
diff --git a/NitrokeyManager.cc b/NitrokeyManager.cc
index 5b648b5..c88f717 100644
--- a/NitrokeyManager.cc
+++ b/NitrokeyManager.cc
@@ -157,6 +157,12 @@ namespace nitrokey{
return erase_slot(slot_number, temporary_password);
}
+ #include <cassert>
+ template <typename T, typename U>
+ void vector_copy(T& dest, std::vector<U> vec){
+ assert(sizeof(dest)>=vec.size());
+ std::copy(vec.begin(), vec.end(), dest);
+ }
bool NitrokeyManager::write_HOTP_slot(uint8_t slot_number, const char *slot_name, const char *secret, uint8_t hotp_counter,
bool use_8_digits, bool use_enter, bool use_tokenID, const char *token_ID,
@@ -166,7 +172,8 @@ namespace nitrokey{
slot_number = get_internal_slot_number_for_hotp(slot_number);
auto payload = get_payload<WriteToHOTPSlot>();
payload.slot_number = slot_number;
- strcpyT(payload.slot_secret, secret);
+ auto secret_bin = misc::hex_string_to_byte(secret);
+ vector_copy(payload.slot_secret, secret_bin);
strcpyT(payload.slot_name, slot_name);
strcpyT(payload.slot_token_id, token_ID);
payload.slot_counter = hotp_counter;
@@ -188,7 +195,8 @@ namespace nitrokey{
slot_number = get_internal_slot_number_for_totp(slot_number);
payload.slot_number = slot_number;
- strcpyT(payload.slot_secret, secret);
+ auto secret_bin = misc::hex_string_to_byte(secret);
+ vector_copy(payload.slot_secret, secret_bin);
strcpyT(payload.slot_name, slot_name);
strcpyT(payload.slot_token_id, token_ID);
payload.slot_interval = time_window; //FIXME naming