diff options
author | szszszsz <szszszsz@users.noreply.github.com> | 2016-09-10 11:02:38 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-09-10 11:02:38 +0200 |
commit | b16e89ad4445fe9bbb66e8e7f8771a6ca6b333cf (patch) | |
tree | d332db36123c80ac84474c75b9be4acdff81bf54 /NitrokeyManager.cc | |
parent | e164c5f3dc74fb2335b1fc573ce446cdd76a07dc (diff) | |
parent | a46491a97da08e495c92bba8046426678b5564f7 (diff) | |
download | libnitrokey-b16e89ad4445fe9bbb66e8e7f8771a6ca6b333cf.tar.gz libnitrokey-b16e89ad4445fe9bbb66e8e7f8771a6ca6b333cf.tar.bz2 |
Merge pull request #36 from Nitrokey/issue_31-secret_as_hex
#31 pass secret to OTP as hex (breaking change - previously any string was accepted)
Diffstat (limited to 'NitrokeyManager.cc')
-rw-r--r-- | NitrokeyManager.cc | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/NitrokeyManager.cc b/NitrokeyManager.cc index 5b648b5..d827292 100644 --- a/NitrokeyManager.cc +++ b/NitrokeyManager.cc @@ -2,6 +2,7 @@ #include <iostream> #include "include/NitrokeyManager.h" #include "include/LibraryException.h" +#include <algorithm> namespace nitrokey{ @@ -157,6 +158,15 @@ namespace nitrokey{ return erase_slot(slot_number, temporary_password); } + template <typename T, typename U> + void vector_copy(T& dest, std::vector<U> &vec){ + const size_t d_size = sizeof(dest); + if(d_size < vec.size()){ + throw TargetBufferSmallerThanSource(vec.size(), d_size); + } + std::fill(dest, dest+d_size, 0); + 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 +176,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 +199,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 |