1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
#ifndef LIBNITROKEY_NITROKEYMANAGER_H
#define LIBNITROKEY_NITROKEYMANAGER_H
#include "device.h"
#include "log.h"
#include "device_proto.h"
#include "stick10_commands.h"
#include "stick20_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;
using namespace nitrokey::log;
class NitrokeyManager {
public:
static shared_ptr <NitrokeyManager> instance();
bool first_authenticate(const char *pin, const char *temporary_password);
bool write_HOTP_slot(uint8_t slot_number, const char *slot_name, const char *secret, uint8_t hotp_counter,
bool use_8_digits, bool use_enter, bool use_tokenID, const char *token_ID,
const char *temporary_password);
bool write_TOTP_slot(uint8_t slot_number, const char *slot_name, const char *secret, uint16_t time_window,
bool use_8_digits, bool use_enter, bool use_tokenID, const char *token_ID,
const char *temporary_password);
uint32_t get_HOTP_code(uint8_t slot_number, const char *user_temporary_password);
uint32_t get_TOTP_code(uint8_t slot_number, uint64_t challenge, uint64_t last_totp_time, uint8_t last_interval,
const char *user_temporary_password);
bool set_time(uint64_t time);
bool get_time();
bool erase_totp_slot(uint8_t slot_number, const char *temporary_password);
bool erase_hotp_slot(uint8_t slot_number, const char *temporary_password);
bool connect(const char *device_model);
bool connect();
bool disconnect();
void set_debug(bool state);
string get_status();
const char * get_totp_slot_name(uint8_t slot_number);
const char * get_hotp_slot_name(uint8_t slot_number);
void change_user_PIN(char *current_PIN, char *new_PIN);
void change_admin_PIN(char *current_PIN, char *new_PIN);
void enable_password_safe(const char *user_pin);
uint8_t * get_password_safe_slot_status();
uint8_t get_admin_retry_count();
uint8_t get_user_retry_count();
void lock_device();
const char *get_password_safe_slot_name(uint8_t slot_number);
const char *get_password_safe_slot_password(uint8_t slot_number);
const char *get_password_safe_slot_login(uint8_t slot_number);
void
write_password_safe_slot(uint8_t slot_number, const char *slot_name, const char *slot_login,
const char *slot_password);
void erase_password_safe_slot(uint8_t slot_number);
void user_authenticate(const char *user_password, const char *temporary_password);
void factory_reset(const char *admin_password);
void build_aes_key(const char *admin_password);
void unlock_user_password(const char *admin_password, const char *new_user_password);
void write_config(uint8_t numlock, uint8_t capslock, uint8_t scrolllock, bool enable_user_password,
bool delete_user_password, const char *admin_temporary_password);
vector<uint8_t> read_config();
bool is_AES_supported(const char *user_password);
~NitrokeyManager();
private:
NitrokeyManager();
static shared_ptr <NitrokeyManager> _instance;
bool connected;
std::shared_ptr<Device> device;
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;
uint8_t get_internal_slot_number_for_hotp(uint8_t slot_number) const;
uint8_t get_internal_slot_number_for_totp(uint8_t slot_number) const;
bool erase_slot(uint8_t slot_number, const char *temporary_password);
const char * get_slot_name(uint8_t slot_number);
template <typename ProCommand, PasswordKind StoKind>
void change_PIN_general(char *current_PIN, char *new_PIN);
};
}
#endif //LIBNITROKEY_NITROKEYMANAGER_H
|