aboutsummaryrefslogtreecommitdiff
path: root/NitrokeyManager.cc
diff options
context:
space:
mode:
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