summaryrefslogtreecommitdiff
path: root/NK_C_API.cc
diff options
context:
space:
mode:
Diffstat (limited to 'NK_C_API.cc')
-rw-r--r--NK_C_API.cc76
1 files changed, 45 insertions, 31 deletions
diff --git a/NK_C_API.cc b/NK_C_API.cc
index 81a18b5..d2aa38a 100644
--- a/NK_C_API.cc
+++ b/NK_C_API.cc
@@ -13,9 +13,9 @@ T* array_dup(std::vector<T>& v){
template <typename T>
uint8_t * get_with_array_result(T func){
+ NK_last_command_status = 0;
try {
return func();
- NK_last_command_status = 0;
}
catch (CommandFailedException & commandFailedException){
NK_last_command_status = commandFailedException.last_command_status;
@@ -25,9 +25,9 @@ uint8_t * get_with_array_result(T func){
template <typename T>
const char* get_with_string_result(T func){
+ NK_last_command_status = 0;
try {
return func();
- NK_last_command_status = 0;
}
catch (CommandFailedException & commandFailedException){
NK_last_command_status = commandFailedException.last_command_status;
@@ -37,21 +37,22 @@ const char* get_with_string_result(T func){
template <typename T>
auto get_with_result(T func){
+ NK_last_command_status = 0;
try {
return func();
- NK_last_command_status = 0;
}
catch (CommandFailedException & commandFailedException){
NK_last_command_status = commandFailedException.last_command_status;
return commandFailedException.last_command_status;
+// return (uint8_t) 0;
}
}
template <typename T>
uint8_t get_without_result(T func){
+ NK_last_command_status = 0;
try {
func();
- NK_last_command_status = 0;
return 0;
}
catch (CommandFailedException & commandFailedException){
@@ -71,8 +72,8 @@ extern uint8_t NK_get_last_command_status(){
extern int NK_login(const char *device_model) {
auto m = NitrokeyManager::instance();
try {
- m->connect(device_model);
NK_last_command_status = 0;
+ m->connect(device_model);
}
catch (CommandFailedException & commandFailedException){
NK_last_command_status = commandFailedException.last_command_status;
@@ -84,8 +85,8 @@ extern int NK_login(const char *device_model) {
extern int NK_logout() {
auto m = NitrokeyManager::instance();
try {
- m->disconnect();
NK_last_command_status = 0;
+ m->disconnect();
}
catch (CommandFailedException & commandFailedException){
NK_last_command_status = commandFailedException.last_command_status;
@@ -105,31 +106,32 @@ extern int NK_first_authenticate(const char* admin_password, const char* admin_t
extern int NK_user_authenticate(const char* user_password, const char* user_temporary_password){
auto m = NitrokeyManager::instance();
return get_without_result( [&](){
- return m->user_authenticate(user_password, user_temporary_password);
+ m->user_authenticate(user_password, user_temporary_password);
});
}
extern int NK_factory_reset(const char* admin_password){
auto m = NitrokeyManager::instance();
return get_without_result( [&](){
- return m->factory_reset(admin_password);
+ m->factory_reset(admin_password);
});
}
extern int NK_build_aes_key(const char* admin_password){
auto m = NitrokeyManager::instance();
return get_without_result( [&](){
- return m->build_aes_key(admin_password);
+ m->build_aes_key(admin_password);
});
}
-extern int NK_unlock_user_password(const char* admin_password){
+extern int NK_unlock_user_password(const char *admin_password, const char *new_user_password) {
auto m = NitrokeyManager::instance();
return get_without_result( [&](){
- return m->unlock_user_password(admin_password);
+ m->unlock_user_password(admin_password, new_user_password);
});
}
-extern int NK_write_config(bool numlock, bool capslock, bool scrolllock, bool enable_user_password, bool delete_user_password,
+extern int NK_write_config(uint8_t numlock, uint8_t capslock, uint8_t scrolllock, bool enable_user_password,
+ bool delete_user_password,
const char *admin_temporary_password) {
auto m = NitrokeyManager::instance();
return get_without_result( [&](){
@@ -148,10 +150,10 @@ extern uint8_t* NK_read_config(){
extern const char * NK_status() {
+ NK_last_command_status = 0;
auto m = NitrokeyManager::instance();
try {
string s = m->get_status();
- NK_last_command_status = 0;
return strdup(s.c_str()); //FIXME leak?
}
catch (CommandFailedException & commandFailedException){
@@ -166,10 +168,10 @@ extern uint32_t NK_get_hotp_code(uint8_t slot_number) {
}
extern uint32_t NK_get_hotp_code_PIN(uint8_t slot_number, const char* user_temporary_password){
+ NK_last_command_status = 0;
auto m = NitrokeyManager::instance();
try {
const auto code = m->get_HOTP_code(slot_number, user_temporary_password);
- NK_last_command_status = 0;
return code;
}
catch (CommandFailedException & commandFailedException){
@@ -185,10 +187,10 @@ extern uint32_t NK_get_totp_code(uint8_t slot_number, uint64_t challenge, uint64
extern uint32_t NK_get_totp_code_PIN(uint8_t slot_number, uint64_t challenge, uint64_t last_totp_time,
uint8_t last_interval, const char* user_temporary_password){
+ NK_last_command_status = 0;
auto m = NitrokeyManager::instance();
try {
const auto totp_code = m->get_TOTP_code(slot_number, challenge, last_totp_time, last_interval, user_temporary_password);
- NK_last_command_status = 0;
return totp_code;
}
catch (CommandFailedException & commandFailedException){
@@ -198,10 +200,10 @@ extern uint32_t NK_get_totp_code_PIN(uint8_t slot_number, uint64_t challenge, ui
}
extern int NK_erase_hotp_slot(uint8_t slot_number, const char *temporary_password) {
+ NK_last_command_status = 0;
auto m = NitrokeyManager::instance();
try {
m->erase_hotp_slot(slot_number, temporary_password);
- NK_last_command_status = 0;
}
catch (CommandFailedException & commandFailedException){
NK_last_command_status = commandFailedException.last_command_status;
@@ -211,10 +213,10 @@ extern int NK_erase_hotp_slot(uint8_t slot_number, const char *temporary_passwor
}
extern int NK_erase_totp_slot(uint8_t slot_number, const char *temporary_password) {
+ NK_last_command_status = 0;
auto m = NitrokeyManager::instance();
try {
m->erase_totp_slot(slot_number, temporary_password);
- NK_last_command_status = 0;
}
catch (CommandFailedException & commandFailedException){
NK_last_command_status = commandFailedException.last_command_status;
@@ -224,11 +226,13 @@ extern int NK_erase_totp_slot(uint8_t slot_number, const char *temporary_passwor
}
extern int NK_write_hotp_slot(uint8_t slot_number, const char *slot_name, const char *secret, uint8_t hotp_counter,
- bool use_8_digits, const char *temporary_password) {
+ bool use_8_digits, bool use_enter, bool use_tokenID, const char *token_ID,
+ const char *temporary_password) {
+ NK_last_command_status = 0;
auto m = NitrokeyManager::instance();
try {
- m->write_HOTP_slot(slot_number, slot_name, secret, hotp_counter, use_8_digits, temporary_password);
- NK_last_command_status = 0;
+ m->write_HOTP_slot(slot_number, slot_name, secret, hotp_counter, use_8_digits, use_enter, use_tokenID, token_ID,
+ temporary_password);
}
catch (CommandFailedException & commandFailedException){
NK_last_command_status = commandFailedException.last_command_status;
@@ -238,11 +242,13 @@ extern int NK_write_hotp_slot(uint8_t slot_number, const char *slot_name, const
}
extern int NK_write_totp_slot(uint8_t slot_number, const char *slot_name, const char *secret, uint16_t time_window,
- bool use_8_digits, const char *temporary_password) {
+ bool use_8_digits, bool use_enter, bool use_tokenID, const char *token_ID,
+ const char *temporary_password) {
+ NK_last_command_status = 0;
auto m = NitrokeyManager::instance();
try {
- m->write_TOTP_slot(slot_number, slot_name, secret, time_window, use_8_digits, temporary_password);
- NK_last_command_status = 0;
+ m->write_TOTP_slot(slot_number, slot_name, secret, time_window, use_8_digits, use_enter, use_tokenID, token_ID,
+ temporary_password);
}
catch (CommandFailedException & commandFailedException){
NK_last_command_status = commandFailedException.last_command_status;
@@ -252,10 +258,10 @@ extern int NK_write_totp_slot(uint8_t slot_number, const char *slot_name, const
}
extern const char* NK_get_totp_slot_name(uint8_t slot_number){
+ NK_last_command_status = 0;
auto m = NitrokeyManager::instance();
try {
const auto slot_name = m->get_totp_slot_name(slot_number);
- NK_last_command_status = 0;
return slot_name;
}
catch (CommandFailedException & commandFailedException){
@@ -264,10 +270,10 @@ extern const char* NK_get_totp_slot_name(uint8_t slot_number){
}
}
extern const char* NK_get_hotp_slot_name(uint8_t slot_number){
+ NK_last_command_status = 0;
auto m = NitrokeyManager::instance();
try {
const auto slot_name = m->get_hotp_slot_name(slot_number);
- NK_last_command_status = 0;
return slot_name;
}
catch (CommandFailedException & commandFailedException){
@@ -282,10 +288,10 @@ extern void NK_set_debug(bool state){
}
extern int NK_totp_set_time(uint64_t time){
+ NK_last_command_status = 0;
auto m = NitrokeyManager::instance();
try {
m->set_time(time);
- NK_last_command_status = 0;
}
catch (CommandFailedException & commandFailedException){
NK_last_command_status = commandFailedException.last_command_status;
@@ -295,10 +301,10 @@ extern int NK_totp_set_time(uint64_t time){
}
extern int NK_totp_get_time(){
+ NK_last_command_status = 0;
auto m = NitrokeyManager::instance();
try {
m->get_time();
- NK_last_command_status = 0;
}
catch (CommandFailedException & commandFailedException){
NK_last_command_status = commandFailedException.last_command_status;
@@ -308,10 +314,10 @@ extern int NK_totp_get_time(){
}
extern int NK_change_admin_PIN(char *current_PIN, char *new_PIN){
+ NK_last_command_status = 0;
auto m = NitrokeyManager::instance();
try {
m->change_admin_PIN(current_PIN, new_PIN);
- NK_last_command_status = 0;
}
catch (CommandFailedException & commandFailedException){
NK_last_command_status = commandFailedException.last_command_status;
@@ -321,10 +327,10 @@ extern int NK_change_admin_PIN(char *current_PIN, char *new_PIN){
}
extern int NK_change_user_PIN(char *current_PIN, char *new_PIN){
+ NK_last_command_status = 0;
auto m = NitrokeyManager::instance();
try {
m->change_user_PIN(current_PIN, new_PIN);
- NK_last_command_status = 0;
}
catch (CommandFailedException & commandFailedException){
NK_last_command_status = commandFailedException.last_command_status;
@@ -334,10 +340,10 @@ extern int NK_change_user_PIN(char *current_PIN, char *new_PIN){
}
extern int NK_enable_password_safe(const char *user_pin){
+ NK_last_command_status = 0;
auto m = NitrokeyManager::instance();
try {
m->enable_password_safe(user_pin);
- NK_last_command_status = 0;
}
catch (CommandFailedException & commandFailedException){
NK_last_command_status = commandFailedException.last_command_status;
@@ -346,12 +352,12 @@ extern int NK_enable_password_safe(const char *user_pin){
return 0;
}
extern uint8_t * NK_get_password_safe_slot_status(){
+ NK_last_command_status = 0;
auto m = NitrokeyManager::instance();
auto res = new uint8_t[16];
memset(res, 0, 16);
try {
const auto slot_status = m->get_password_safe_slot_status();
- NK_last_command_status = 0;
return slot_status; //TODO FIXME
}
catch (CommandFailedException & commandFailedException){
@@ -415,5 +421,13 @@ extern int NK_erase_password_safe_slot(uint8_t slot_number) {
});
}
+extern int NK_is_AES_supported(const char *user_password) {
+ auto m = NitrokeyManager::instance();
+ return get_with_result([&](){
+ return (uint8_t) m->is_AES_supported(user_password);
+ });
+}
+
+
}