aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSzczepan Zalega <szczepan@nitrokey.com>2016-07-29 14:28:21 +0200
committerSzczepan Zalega <szczepan@nitrokey.com>2016-08-01 13:54:58 +0200
commitfeeb433a5625fd869e3b02c3254867c63b42086d (patch)
treea085df20148e54a03e69694381e2b4bd7debdc94
parent77e388ed2dbbe262e61ddf514f7554e236a1c1a1 (diff)
downloadlibnitrokey-feeb433a5625fd869e3b02c3254867c63b42086d.tar.gz
libnitrokey-feeb433a5625fd869e3b02c3254867c63b42086d.tar.bz2
Handle changing admin/user password on NK Storage
Signed-off-by: Szczepan Zalega <szczepan@nitrokey.com>
-rw-r--r--include/command_id.h6
-rw-r--r--include/stick20_commands.h54
2 files changed, 59 insertions, 1 deletions
diff --git a/include/command_id.h b/include/command_id.h
index 37aa5d2..87d270e 100644
--- a/include/command_id.h
+++ b/include/command_id.h
@@ -5,6 +5,9 @@
namespace nitrokey {
namespace proto {
+#define STICK20_CMD_START_VALUE 0x20
+
+
enum class CommandID : uint8_t {
GET_STATUS = 0x00,
WRITE_TO_SLOT = 0x01,
@@ -29,6 +32,9 @@ enum class CommandID : uint8_t {
CHANGE_USER_PIN = 0x14,
CHANGE_ADMIN_PIN = 0x15,
+ STICK20_CMD_SEND_PASSWORD = STICK20_CMD_START_VALUE + 18,
+ STICK20_CMD_SEND_NEW_PASSWORD = STICK20_CMD_START_VALUE + 19,
+
ENABLE_CRYPTED_PARI = 0x20,
DISABLE_CRYPTED_PARI,
ENABLE_HIDDEN_CRYPTED_PARI,
diff --git a/include/stick20_commands.h b/include/stick20_commands.h
index b84d436..66fad15 100644
--- a/include/stick20_commands.h
+++ b/include/stick20_commands.h
@@ -1,15 +1,67 @@
#ifndef STICK20_COMMANDS_H
#define STICK20_COMMANDS_H
#include "inttypes.h"
+#include "command.h"
+//#include <string>
+//#include <sstream>
+#include "device_proto.h"
+
namespace nitrokey {
namespace proto {
/*
* STICK20 protocol command ids
-* a superset of STICK10
+* a superset (almost) of STICK10
*/
namespace stick20 {
+
+ enum class PasswordKind : uint8_t {
+ User = 'P',
+ Admin = 'A'
+ };
+
+ class ChangeAdminPin20Current : Command<CommandID::STICK20_CMD_SEND_PASSWORD> {
+ public:
+ struct CommandPayload {
+ uint8_t kind;
+ uint8_t old_pin[20];
+ std::string dissect() const {
+ std::stringstream ss;
+ ss << " old_pin:\t" << old_pin<< std::endl;
+ return ss.str();
+ }
+ void set_kind(PasswordKind k){
+ kind = (uint8_t)k;
+ }
+ } __packed;
+
+ typedef Transaction<command_id(), struct CommandPayload, struct EmptyPayload>
+ CommandTransaction;
+ };
+
+
+ class ChangeAdminPin20New : Command<CommandID::STICK20_CMD_SEND_NEW_PASSWORD> {
+ public:
+
+ struct CommandPayload {
+ uint8_t kind;
+ uint8_t new_pin[20];
+ std::string dissect() const {
+ std::stringstream ss;
+ ss << " new_pin:\t" << new_pin<< std::endl;
+ return ss.str();
+ }
+ void set_kind(PasswordKind k){
+ kind = (uint8_t)k;
+ }
+
+ } __packed;
+
+ typedef Transaction<command_id(), struct CommandPayload, struct EmptyPayload>
+ CommandTransaction;
+ };
+
class EnableEncryptedPartition : semantics::non_constructible {
public:
struct CommandPayload {