aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSzczepan Zalega <szczepan@nitrokey.com>2017-05-13 14:20:40 +0200
committerSzczepan Zalega <szczepan@nitrokey.com>2017-05-13 14:20:40 +0200
commit1634bddb91323753546e6fe475d70d41dd79faee (patch)
treefc6c5cc9cd1f99674f433fe99124ecc362bbcc12
parentb307e84b5d67419a9fbec6e222ff51d2f917d928 (diff)
downloadlibnitrokey-1634bddb91323753546e6fe475d70d41dd79faee.tar.gz
libnitrokey-1634bddb91323753546e6fe475d70d41dd79faee.tar.bz2
Log temporary password as hexdump instead of string representation
Signed-off-by: Szczepan Zalega <szczepan@nitrokey.com>
-rw-r--r--include/command.h4
-rw-r--r--include/stick10_commands.h8
-rw-r--r--include/stick10_commands_0.8.h12
3 files changed, 14 insertions, 10 deletions
diff --git a/include/command.h b/include/command.h
index bf3cb4e..3f711c0 100644
--- a/include/command.h
+++ b/include/command.h
@@ -6,10 +6,12 @@
#define print_to_ss(x) ( ss << " " << (#x) <<":\t" << (x) << std::endl );
#ifdef LOG_VOLATILE_DATA
-#define print_to_ss_volatile(x) ( ss << " " << (#x) <<":\t" << (x) << std::endl );
+#define print_to_ss_volatile(x) print_to_ss(x);
#else
#define print_to_ss_volatile(x) ( ss << " " << (#x) <<":\t" << "***********" << std::endl );
#endif
+#define hexdump_to_ss(x) (ss << #x":\n"\
+ << ::nitrokey::misc::hexdump((const char *) (&x), sizeof x, false));
namespace nitrokey {
namespace proto {
diff --git a/include/stick10_commands.h b/include/stick10_commands.h
index b38ea06..e863328 100644
--- a/include/stick10_commands.h
+++ b/include/stick10_commands.h
@@ -683,7 +683,7 @@ class FirstAuthenticate : Command<CommandID::FIRST_AUTHENTICATE> {
std::string dissect() const {
std::stringstream ss;
print_to_ss_volatile(card_password);
- ss << "temporary_password:\t" << temporary_password << std::endl;
+ hexdump_to_ss(temporary_password);
return ss.str();
}
} __packed;
@@ -702,7 +702,7 @@ class UserAuthenticate : Command<CommandID::USER_AUTHENTICATE> {
std::string dissect() const {
std::stringstream ss;
print_to_ss_volatile(card_password);
- ss << "temporary_password:\t" << temporary_password << std::endl;
+ hexdump_to_ss(temporary_password);
return ss.str();
}
} __packed;
@@ -720,7 +720,7 @@ class Authorize : Command<CommandID::AUTHORIZE> {
std::string dissect() const {
std::stringstream ss;
ss << " crc_to_authorize:\t" << std::hex << std::setw(2) << std::setfill('0') << crc_to_authorize<< std::endl;
- ss << " temporary_password:\t" << temporary_password<< std::endl;
+ hexdump_to_ss(temporary_password);
return ss.str();
}
} __packed;
@@ -737,7 +737,7 @@ class UserAuthorize : Command<CommandID::USER_AUTHORIZE> {
std::string dissect() const {
std::stringstream ss;
ss << " crc_to_authorize:\t" << crc_to_authorize<< std::endl;
- ss << " temporary_password:\t" << temporary_password<< std::endl;
+ hexdump_to_ss(temporary_password);
return ss.str();
}
} __packed;
diff --git a/include/stick10_commands_0.8.h b/include/stick10_commands_0.8.h
index 3aa60e3..4209380 100644
--- a/include/stick10_commands_0.8.h
+++ b/include/stick10_commands_0.8.h
@@ -9,13 +9,14 @@
#include <iomanip>
#include <string>
#include <sstream>
-#include <stdint.h>
+#include <cstdint>
#include "command.h"
#include "device_proto.h"
#include "stick10_commands.h"
#pragma pack (push,1)
+
namespace nitrokey {
namespace proto {
@@ -59,6 +60,7 @@ namespace nitrokey {
std::string dissect() const {
std::stringstream ss;
ss << "slot_number:\t" << (int)(slot_number) << std::endl;
+ hexdump_to_ss(temporary_admin_password);
return ss.str();
}
} __packed;
@@ -87,7 +89,7 @@ namespace nitrokey {
std::string dissect() const {
std::stringstream ss;
- ss << "temporary_admin_password:\t" << temporary_admin_password << std::endl;
+ hexdump_to_ss(temporary_admin_password);
ss << "type:\t" << type << std::endl;
ss << "id:\t" << (int)id << std::endl;
#ifdef LOG_VOLATILE_DATA
@@ -156,7 +158,7 @@ namespace nitrokey {
std::string dissect() const {
std::stringstream ss;
- ss << "temporary_admin_password:\t" << temporary_admin_password << std::endl;
+ hexdump_to_ss(temporary_admin_password);
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;
@@ -192,7 +194,7 @@ namespace nitrokey {
bool isValid() const { return (slot_number & 0xF0); }
std::string dissect() const {
std::stringstream ss;
- ss << "temporary_user_password:\t" << temporary_user_password << std::endl;
+ hexdump_to_ss(temporary_user_password);
ss << "slot_number:\t" << (int)(slot_number) << std::endl;
return ss.str();
}
@@ -244,7 +246,7 @@ namespace nitrokey {
bool isValid() const { return !(slot_number & 0xF0); }
std::string dissect() const {
std::stringstream ss;
- ss << "temporary_user_password:\t" << temporary_user_password << std::endl;
+ hexdump_to_ss(temporary_user_password);
ss << "slot_number:\t" << (int)(slot_number) << std::endl;
ss << "challenge:\t" << (challenge) << std::endl;
ss << "last_totp_time:\t" << (last_totp_time) << std::endl;