summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSzczepan Zalega <szczepan@nitrokey.com>2017-02-17 16:29:21 +0100
committerSzczepan Zalega <szczepan@nitrokey.com>2017-03-11 15:41:47 +0100
commit5650e48b114529075d89dbdde0330901351b8460 (patch)
treec07b6715adaa10bafd76841ef1226a3659ca7d9d
parent4e26fdee0c1435016d6642cf8c1f88c3dd5495fa (diff)
downloadlibnitrokey-5650e48b114529075d89dbdde0330901351b8460.tar.gz
libnitrokey-5650e48b114529075d89dbdde0330901351b8460.tar.bz2
Get proper card serial for Storage. Get serial as one number.
Signed-off-by: Szczepan Zalega <szczepan@nitrokey.com>
-rw-r--r--NitrokeyManager.cc17
-rw-r--r--include/misc.h11
-rw-r--r--include/stick10_commands.h19
-rw-r--r--misc.cc2
4 files changed, 36 insertions, 13 deletions
diff --git a/NitrokeyManager.cc b/NitrokeyManager.cc
index 20d1a98..ac1074b 100644
--- a/NitrokeyManager.cc
+++ b/NitrokeyManager.cc
@@ -138,9 +138,22 @@ namespace nitrokey{
}
}
+
string NitrokeyManager::get_serial_number() {
- auto response = GetStatus::CommandTransaction::run(device);
- return response.data().get_card_serial_hex();
+ switch (device->get_device_model()) {
+ case DeviceModel::PRO: {
+ auto response = GetStatus::CommandTransaction::run(device);
+ return nitrokey::misc::toHex(response.data().card_serial_i);
+ }
+ break;
+
+ case DeviceModel::STORAGE:
+ {
+ auto response = stick20::GetDeviceStatus::CommandTransaction::run(device);
+ return nitrokey::misc::toHex(response.data().ActiveSmartCardID_u32);
+ }
+ break;
+ }
}
stick10::GetStatus::ResponsePayload NitrokeyManager::get_status(){
diff --git a/include/misc.h b/include/misc.h
index 330654a..c39c741 100644
--- a/include/misc.h
+++ b/include/misc.h
@@ -6,10 +6,21 @@
#include <string.h>
#include "log.h"
#include "LibraryException.h"
+#include <sstream>
+#include <iomanip>
+
namespace nitrokey {
namespace misc {
+ template<typename T>
+ std::string toHex(T value){
+ using namespace std;
+ std::ostringstream oss;
+ oss << std::hex << std::setw(sizeof(value)*2) << std::setfill('0') << value;
+ return oss.str();
+ }
+
template <typename T>
void strcpyT(T& dest, const char* src){
diff --git a/include/stick10_commands.h b/include/stick10_commands.h
index 3d9e234..843d8bd 100644
--- a/include/stick10_commands.h
+++ b/include/stick10_commands.h
@@ -348,7 +348,10 @@ class GetStatus : Command<CommandID::GET_STATUS> {
public:
struct ResponsePayload {
uint16_t firmware_version;
- uint8_t card_serial[4];
+ union{
+ uint8_t card_serial[4];
+ uint32_t card_serial_i;
+ } __packed;
union {
uint8_t general_config[5];
struct{
@@ -357,19 +360,12 @@ class GetStatus : Command<CommandID::GET_STATUS> {
uint8_t scrolllock; /** same as numlock */
uint8_t enable_user_password;
uint8_t delete_user_password;
- };
- };
+ } __packed;
+ } __packed;
bool isValid() const { return enable_user_password!=delete_user_password; }
std::string get_card_serial_hex() const {
-// return ::nitrokey::misc::hexdump((const char *)(card_serial),
-// sizeof card_serial, false, false, false);
- std::stringstream ss;
- ss << std::hex << std::setfill('0');
- for (int i = 0; i < sizeof(card_serial); ++i) {
- ss << std::setw(2) << static_cast<unsigned>(card_serial[i]);
- }
- return ss.str();
+ return nitrokey::misc::toHex(card_serial_i);
}
std::string dissect() const {
@@ -378,6 +374,7 @@ class GetStatus : Command<CommandID::GET_STATUS> {
<< "[" << firmware_version << "]" << "\t"
<< ::nitrokey::misc::hexdump(
(const char *)(&firmware_version), sizeof firmware_version, false);
+ ss << "card_serial_i:\t" << std::hex << card_serial_i << std::endl;
ss << "card_serial:\t"
<< ::nitrokey::misc::hexdump((const char *)(card_serial),
sizeof card_serial, false);
diff --git a/misc.cc b/misc.cc
index f85d486..5eb81b5 100644
--- a/misc.cc
+++ b/misc.cc
@@ -10,6 +10,8 @@
namespace nitrokey {
namespace misc {
+
+
::std::vector<uint8_t> hex_string_to_byte(const char* hexString){
const size_t big_string_size = 256; //arbitrary 'big' number
const size_t s_size = strlen(hexString);