summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorSzczepan Zalega <szczepan@nitrokey.com>2016-11-09 14:29:18 +0100
committerSzczepan Zalega <szczepan@nitrokey.com>2016-12-03 16:01:35 +0100
commitf76ac655fff3df7eb0e645ca39d18510714b0039 (patch)
tree62e185b9f4d68507922431976270a3bba8cf8326 /include
parent119ea0b111c9ca46fda32911c1c8c33b36aad3db (diff)
downloadlibnitrokey-f76ac655fff3df7eb0e645ca39d18510714b0039.tar.gz
libnitrokey-f76ac655fff3df7eb0e645ca39d18510714b0039.tar.bz2
Authorization fix: GetTOTP and WriteToTOTPSLot + test
Signed-off-by: Szczepan Zalega <szczepan@nitrokey.com>
Diffstat (limited to 'include')
-rw-r--r--include/stick10_commands_0.8.h77
1 files changed, 77 insertions, 0 deletions
diff --git a/include/stick10_commands_0.8.h b/include/stick10_commands_0.8.h
index 0c6633c..cee0d78 100644
--- a/include/stick10_commands_0.8.h
+++ b/include/stick10_commands_0.8.h
@@ -23,6 +23,7 @@ namespace nitrokey {
namespace stick10_08 {
using stick10::FirstAuthenticate;
using stick10::UserAuthenticate;
+ using stick10::SetTime;
class EraseSlot : Command<CommandID::ERASE_SLOT> {
public:
@@ -120,6 +121,82 @@ namespace nitrokey {
CommandTransaction;
};
+
+ class WriteToTOTPSlot : Command<CommandID::WRITE_TO_SLOT> {
+ //admin auth
+ public:
+ struct CommandPayload {
+ uint8_t temporary_admin_password[25];
+ uint8_t slot_secret[20];
+ union {
+ uint8_t _slot_config;
+ struct {
+ bool use_8_digits : 1;
+ bool use_enter : 1;
+ bool use_tokenID : 1;
+ };
+ };
+ union {
+ uint8_t slot_token_id[13]; /** OATH Token Identifier */
+ struct { /** @see https://openauthentication.org/token-specs/ */
+ uint8_t omp[2];
+ uint8_t tt[2];
+ uint8_t mui[8];
+ uint8_t keyboard_layout; //disabled feature in nitroapp as of 20160805
+ } slot_token_fields;
+ };
+
+ bool isValid() const { return true; }
+
+ std::string dissect() const {
+ std::stringstream ss;
+ ss << "temporary_admin_password:\t" << temporary_admin_password << std::endl;
+ ss << "slot_secret:" << std::endl
+ << ::nitrokey::misc::hexdump((const char *) (&slot_secret), sizeof slot_secret);
+ ss << "slot_config:\t" << std::bitset<8>((int) _slot_config) << std::endl;
+ ss << "\tuse_8_digits(0):\t" << use_8_digits << std::endl;
+ ss << "\tuse_enter(1):\t" << use_enter << std::endl;
+ ss << "\tuse_tokenID(2):\t" << use_tokenID << std::endl;
+
+ ss << "slot_token_id:\t";
+ for (auto i : slot_token_id)
+ ss << std::hex << std::setw(2) << std::setfill('0') << (int) i << " ";
+ ss << std::endl;
+
+ return ss.str();
+ }
+ } __packed;
+
+ typedef Transaction<command_id(), struct CommandPayload, struct EmptyPayload>
+ CommandTransaction;
+ };
+
+ class WriteToTOTPSlot_2 : Command<CommandID::WRITE_TO_SLOT_2> {
+ public:
+ struct CommandPayload {
+ uint8_t temporary_admin_password[25];
+ uint8_t slot_number;
+ uint8_t slot_name[15];
+ uint16_t slot_interval;
+
+ bool isValid() const { return !(slot_number & 0xF0); }
+
+ std::string dissect() const {
+ std::stringstream ss;
+ ss << "temporary_admin_password:\t" << temporary_admin_password << std::endl;
+ ss << "slot_number:\t" << (int) (slot_number) << std::endl;
+ ss << "slot_name:\t" << slot_name << std::endl;
+ ss << "slot_interval:\t" << (int)slot_interval << std::endl;
+
+ return ss.str();
+ }
+ } __packed;
+
+ typedef Transaction<command_id(), struct CommandPayload, struct EmptyPayload>
+ CommandTransaction;
+ };
+
+
class GetHOTP : Command<CommandID::GET_CODE> {
public:
struct CommandPayload {