Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor function and devices names #60

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ set(SOURCE_FILES
include/log.h
include/misc.h
include/NitrokeyManager.h
include/stick10_commands.h
include/stick20_commands.h
include/NKPro_commands.h
include/NKStorage_commands.h
include/CommandFailedException.h
include/LibraryException.h
include/LongOperationInProgressException.h
include/stick10_commands_0.8.h
include/NKPro_commands_0.8.h
command_id.cc
device.cc
log.cc
Expand Down
116 changes: 58 additions & 58 deletions NitrokeyManager.cc

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# libnitrokey
Libnitrokey is a project to communicate with Nitrokey Pro and Storage devices in a clean and easy manner. Written in C++14, testable with `py.test` and `Catch` frameworks, with C API, Python access (through CFFI and C API, in future with Pybind11).

The development of this project is aimed to make it itself a living documentation of communication protocol between host and the Nitrokey stick devices. The command packets' format is described here: [Pro v0.7](include/stick10_commands.h), [Pro v0.8](include/stick10_commands_0.8.h), [Storage](include/stick20_commands.h). Handling and additional operations are described here: [NitrokeyManager.cc](NitrokeyManager.cc).
The development of this project is aimed to make it itself a living documentation of communication protocol between host and the Nitrokey stick devices. The command packets' format is described here: [Pro v0.7](include/NKPro_commands.h), [Pro v0.8](include/NKPro_commands_0.8.h), [Storage](include/NKStorage_commands.h). Handling and additional operations are described here: [NitrokeyManager.cc](NitrokeyManager.cc).

A C++14 complying compiler is required due to heavy use of variable templates. For feature support tables please check [table 1](https://gcc.gnu.org/projects/cxx-status.html#cxx14) or [table 2](http://en.cppreference.com/w/cpp/compiler_support).

Expand Down Expand Up @@ -131,7 +131,7 @@ All available functions for C and Python are listed in [NK_C_API.h](NK_C_API.h).

## Documentation
The documentation of C API is included in the sources (could be generated with doxygen if requested).
Please check NK_C_API.h (C API) for high level commands and include/NitrokeyManager.h (C++ API). All devices' commands are listed along with packet format in include/stick10_commands.h and include/stick20_commands.h respectively for Nitrokey Pro and Nitrokey Storage products.
Please check NK_C_API.h (C API) for high level commands and include/NitrokeyManager.h (C++ API). All devices' commands are listed along with packet format in include/NKPro_commands.h and include/NKStorage_commands.h respectively for Nitrokey Pro and Nitrokey Storage products.

# Tests
Warning! Before you run unittests please either change both your Admin and User PINs on your Nitrostick to defaults (`12345678` and `123456` respectively) or change the values in tests source code. If you do not change them the tests might lock your device. If it's too late, you can always reset your Nitrokey using instructions from [homepage](https://www.nitrokey.com/de/documentation/how-reset-nitrokey).
Expand Down
4 changes: 2 additions & 2 deletions device.cc
Original file line number Diff line number Diff line change
Expand Up @@ -190,14 +190,14 @@ void Device::set_retry_delay(const std::chrono::milliseconds delay){
m_retry_timeout = delay;
}

Stick10::Stick10():
Device_NKPro::Device_NKPro():
Device(0x20a0, 0x4108, DeviceModel::PRO, 100ms, 5, 100ms)
{
setDefaultDelay();
}


Stick20::Stick20():
Device_NKStorage::Device_NKStorage():
Device(0x20a0, 0x4109, DeviceModel::STORAGE, 20ms, 20, 20ms)
{
setDefaultDelay();
Expand Down
2 changes: 1 addition & 1 deletion include/CommandFailedException.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include "log.h"
#include "command_id.h"

using cs = nitrokey::proto::stick10::command_status;
using cs = nitrokey::proto::NKPro::command_status;

class CommandFailedException : public std::exception {
public:
Expand Down
8 changes: 4 additions & 4 deletions include/stick10_commands.h → include/NKPro_commands.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef STICK10_COMMANDS_H
#define STICK10_COMMANDS_H
#ifndef NKPRO_COMMANDS_H
#define NKPRO_COMMANDS_H

#include <bitset>
#include <iomanip>
Expand All @@ -17,9 +17,9 @@ namespace proto {


/*
* Stick10 protocol definition
* Device_NKPro protocol definition
*/
namespace stick10 {
namespace NKPro {
class GetSlotName : public Command<CommandID::READ_SLOT_NAME> {
public:
// reachable as a typedef in Transaction
Expand Down
62 changes: 31 additions & 31 deletions include/stick10_commands_0.8.h → include/NKPro_commands_0.8.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// Created by sz on 08.11.16.
//

#ifndef LIBNITROKEY_STICK10_COMMANDS_0_8_H
#define LIBNITROKEY_STICK10_COMMANDS_0_8_H
#ifndef LIBNITROKEY_NKPRO_COMMANDS_0_8_H
#define LIBNITROKEY_NKPRO_COMMANDS_0_8_H

#include <bitset>
#include <iomanip>
Expand All @@ -12,40 +12,40 @@
#include <stdint.h>
#include "command.h"
#include "device_proto.h"
#include "stick10_commands.h"
#include "NKPro_commands.h"

namespace nitrokey {
namespace proto {

/*
* Stick10 protocol definition
* Device_NKPro protocol definition
*/
namespace stick10_08 {
using stick10::FirstAuthenticate;
using stick10::UserAuthenticate;
using stick10::SetTime;
using stick10::GetStatus;
using stick10::BuildAESKey;
using stick10::ChangeAdminPin;
using stick10::ChangeUserPin;
using stick10::EnablePasswordSafe;
using stick10::ErasePasswordSafeSlot;
using stick10::FactoryReset;
using stick10::GetPasswordRetryCount;
using stick10::GetUserPasswordRetryCount;
using stick10::GetPasswordSafeSlotLogin;
using stick10::GetPasswordSafeSlotName;
using stick10::GetPasswordSafeSlotPassword;
using stick10::GetPasswordSafeSlotStatus;
using stick10::GetSlotName;
using stick10::IsAESSupported;
using stick10::LockDevice;
using stick10::PasswordSafeInitKey;
using stick10::PasswordSafeSendSlotViaHID;
using stick10::SetPasswordSafeSlotData;
using stick10::SetPasswordSafeSlotData2;
using stick10::UnlockUserPassword;
using stick10::ReadSlot;
namespace NKPro_08 {
using NKPro::FirstAuthenticate;
using NKPro::UserAuthenticate;
using NKPro::SetTime;
using NKPro::GetStatus;
using NKPro::BuildAESKey;
using NKPro::ChangeAdminPin;
using NKPro::ChangeUserPin;
using NKPro::EnablePasswordSafe;
using NKPro::ErasePasswordSafeSlot;
using NKPro::FactoryReset;
using NKPro::GetPasswordRetryCount;
using NKPro::GetUserPasswordRetryCount;
using NKPro::GetPasswordSafeSlotLogin;
using NKPro::GetPasswordSafeSlotName;
using NKPro::GetPasswordSafeSlotPassword;
using NKPro::GetPasswordSafeSlotStatus;
using NKPro::GetSlotName;
using NKPro::IsAESSupported;
using NKPro::LockDevice;
using NKPro::PasswordSafeInitKey;
using NKPro::PasswordSafeSendSlotViaHID;
using NKPro::SetPasswordSafeSlotData;
using NKPro::SetPasswordSafeSlotData2;
using NKPro::UnlockUserPassword;
using NKPro::ReadSlot;

class EraseSlot : Command<CommandID::ERASE_SLOT> {
public:
Expand Down Expand Up @@ -309,4 +309,4 @@ namespace nitrokey {
}
}
}
#endif //LIBNITROKEY_STICK10_COMMANDS_0_8_H
#endif //LIBNITROKEY_NKPRO_COMMANDS_0_8_H
10 changes: 5 additions & 5 deletions include/stick20_commands.h → include/NKStorage_commands.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef STICK20_COMMANDS_H
#define STICK20_COMMANDS_H
#ifndef NKSTORAGE_COMMANDS_H
#define NKSTORAGE_COMMANDS_H



Expand All @@ -15,11 +15,11 @@ namespace nitrokey {
namespace proto {

/*
* STICK20 protocol command ids
* a superset (almost) of STICK10
* NKSTORAGE protocol command ids
* a superset (almost) of NKPRO
*/
#define print_to_ss(x) ( ss << " " << (#x) <<":\t" << (x) << std::endl );
namespace stick20 {
namespace NKStorage {

class ChangeAdminUserPin20Current :
public PasswordCommand<CommandID::SEND_PASSWORD, PasswordKind::Admin> {};
Expand Down
20 changes: 10 additions & 10 deletions include/NitrokeyManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@
#include "device.h"
#include "log.h"
#include "device_proto.h"
#include "stick10_commands.h"
#include "stick10_commands_0.8.h"
#include "stick20_commands.h"
#include "NKPro_commands.h"
#include "NKPro_commands_0.8.h"
#include "NKStorage_commands.h"
#include <vector>
#include <memory>

namespace nitrokey {
using namespace nitrokey::device;
using namespace std;
using namespace nitrokey::proto::stick10;
using namespace nitrokey::proto::stick20;
using namespace nitrokey::proto::NKPro;
using namespace nitrokey::proto::NKStorage;
using namespace nitrokey::proto;
using namespace nitrokey::log;

Expand All @@ -34,8 +34,8 @@ namespace nitrokey {
uint8_t last_interval,
const char *user_temporary_password);
string get_TOTP_code(uint8_t slot_number, const char *user_temporary_password);
stick10::ReadSlot::ResponsePayload get_TOTP_slot_data(const uint8_t slot_number);
stick10::ReadSlot::ResponsePayload get_HOTP_slot_data(const uint8_t slot_number);
NKPro::ReadSlot::ResponsePayload get_TOTP_slot_data(const uint8_t slot_number);
NKPro::ReadSlot::ResponsePayload get_HOTP_slot_data(const uint8_t slot_number);

bool set_time(uint64_t time);
bool get_time(uint64_t time = 0);
Expand All @@ -50,7 +50,7 @@ namespace nitrokey {

DeviceModel get_connected_device_model() const;
void set_debug(bool state);
stick10::GetStatus::ResponsePayload get_status();
NKPro::GetStatus::ResponsePayload get_status();
string get_status_as_string();
string get_serial_number();

Expand Down Expand Up @@ -121,7 +121,7 @@ namespace nitrokey {
void send_startup(uint64_t seconds_from_epoch);

const char * get_status_storage_as_string();
stick20::DeviceConfigurationResponsePacket::ResponsePayload get_status_storage();
NKStorage::DeviceConfigurationResponsePacket::ResponsePayload get_status_storage();

const char *get_SD_usage_data_as_string();
std::pair<uint8_t,uint8_t> get_SD_usage_data();
Expand All @@ -145,7 +145,7 @@ namespace nitrokey {
static shared_ptr <NitrokeyManager> _instance;
std::shared_ptr<Device> device;

stick10::ReadSlot::ResponsePayload get_OTP_slot_data(const uint8_t slot_number);
NKPro::ReadSlot::ResponsePayload get_OTP_slot_data(const uint8_t slot_number);
bool is_valid_hotp_slot_number(uint8_t slot_number) const;
bool is_valid_totp_slot_number(uint8_t slot_number) const;
bool is_valid_password_safe_slot_number(uint8_t slot_number) const;
Expand Down
2 changes: 1 addition & 1 deletion include/command.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace nitrokey {
};

#define print_to_ss(x) ( ss << " " << (#x) <<":\t" << (x) << std::endl );
namespace stick20{
namespace NKStorage{
enum class PasswordKind : uint8_t {
User = 'P',
Admin = 'A',
Expand Down
4 changes: 2 additions & 2 deletions include/command_id.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace nitrokey {
namespace proto {
namespace stick20 {
namespace NKStorage {
enum class device_status : uint8_t {
idle = 0,
ok,
Expand All @@ -19,7 +19,7 @@ namespace proto {
const int CMD_START_VALUE = 0x20;
const int CMD_END_VALUE = 0x60;
}
namespace stick10 {
namespace NKPro {
enum class command_status : uint8_t {
ok = 0,
wrong_CRC,
Expand Down
8 changes: 4 additions & 4 deletions include/device.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,15 @@ class Device {
static std::chrono::milliseconds default_delay ;
};

class Stick10 : public Device {
class Device_NKPro : public Device {
public:
Stick10();
Device_NKPro();

};

class Stick20 : public Device {
class Device_NKStorage : public Device {
public:
Stick20();
Device_NKStorage();
};
}
}
Expand Down
Loading