22#ifndef LIBNITROKEY_NK_C_API_H
23#define LIBNITROKEY_NK_C_API_H
28#include "deprecated.h"
31#define NK_C_API __declspec(dllexport)
100 static const int MAXIMUM_STR_REPLY_LENGTH = 8192;
303 uint8_t FirmwareVersion_au8[2];
304 uint8_t FirmwareVersionInternal_u8;
305 uint8_t SD_Card_Size_u8;
306 uint32_t CPU_CardID_u32;
307 uint32_t SmartCardID_u32;
308 uint32_t SD_CardID_u32;
309 uint8_t SC_UserPwRetryCount;
310 uint8_t SC_AdminPwRetryCount;
311 uint8_t SD_Card_ManufacturingYear_u8;
312 uint8_t SD_Card_ManufacturingMonth_u8;
313 uint16_t SD_Card_OEM_u16;
314 uint16_t SD_WriteSpeed_u16;
315 uint8_t SD_Card_Manufacturer_u8;
506 bool enable_user_password,
bool delete_user_password,
const char *admin_temporary_password);
591 NK_C_API
int NK_write_hotp_slot(uint8_t slot_number,
const char *slot_name,
const char *secret, uint64_t hotp_counter,
592 bool use_8_digits,
bool use_enter,
bool use_tokenID,
const char *token_ID,
593 const char *temporary_password);
609 NK_C_API
int NK_write_totp_slot(uint8_t slot_number,
const char *slot_name,
const char *secret, uint16_t time_window,
610 bool use_8_digits,
bool use_enter,
bool use_tokenID,
const char *token_ID,
611 const char *temporary_password);
637 NK_C_API
char *
NK_get_totp_code(uint8_t slot_number, uint64_t challenge, uint64_t last_totp_time,
638 uint8_t last_interval);
651 uint64_t last_totp_time, uint8_t last_interval,
652 const char *user_temporary_password);
675 NK_C_API
int NK_totp_get_time();
758 const char *slot_login,
const char *slot_password);
843 const char *hidden_volume_password);
954 const char* new_update_password);
1031 NK_C_API
char* NK_list_devices_by_cpuID();
1092 uint8_t slot_name[15];
1093 uint8_t _slot_config;
1094 uint8_t slot_token_id[13];
1095 uint64_t slot_counter;
1100 uint8_t size_effective;
1104NK_C_API
int NK_get_random(
const uint8_t len,
struct GetRandom_t *out);
1106NK_C_API
int NK_read_HOTP_slot(
const uint8_t slot_num,
struct ReadSlot_t* out);
NK_C_API uint8_t * NK_get_password_safe_slot_status()
Get password safe slots' status The return value must be freed using NK_free_password_safe_slot_statu...
NK_C_API void NK_set_log_function(NK_log_function fn)
Set a custom log function.
NK_C_API int NK_erase_totp_slot(uint8_t slot_number, const char *temporary_password)
Erase TOTP slot data from the device.
NK_C_API int NK_set_unencrypted_volume_rorw_pin_type_user()
Function to determine unencrypted volume PIN type.
NK_C_API int NK_set_encrypted_read_only(const char *admin_pin)
Make encrypted volume read-only.
NK_C_API char * NK_get_password_safe_slot_password(uint8_t slot_number)
Get the password safe slot password.
NK_C_API char * NK_device_serial_number()
Return the device's serial number string in hex.
NK_C_API int NK_change_admin_PIN(const char *current_PIN, const char *new_PIN)
Change administrator PIN.
NK_C_API int NK_send_startup(uint64_t seconds_from_epoch)
This command is typically run to initiate communication with the device (altough not required).
NK_C_API int NK_user_authenticate(const char *user_password, const char *user_temporary_password)
Authenticates the user on USER privilages with user_password and sets user's temporary password on de...
NK_C_API int NK_totp_set_time(uint64_t time)
Set time on the device (for TOTP requests)
NK_C_API int NK_enable_firmware_update_pro(const char *update_password)
Enable update mode on Nitrokey Pro.
NK_C_API int NK_enable_password_safe(const char *user_pin)
Enable password safe access.
NK_C_API int NK_wink()
Blink red and green LED alternatively and infinitely (until device is reconnected).
NK_C_API int NK_lock_encrypted_volume()
Locks encrypted volume.
NK_C_API int NK_lock_device()
Lock device - cancel any user device unlocking.
NK_C_API int NK_get_status_storage(struct NK_storage_status *out)
Get the Storage stick status and return the command processing error code.
NK_C_API int NK_set_unencrypted_read_only_admin(const char *admin_pin)
Make unencrypted volume read-only.
NK_C_API int NK_login_auto()
Connect to first available device, starting checking from Pro 1st to Storage 2nd.
NK_C_API char * NK_get_status_storage_as_string()
Get Storage stick status as string.
NK_C_API int NK_lock_hidden_volume()
Locks hidden volume.
DEPRECATED NK_C_API int NK_set_unencrypted_read_only(const char *user_pin)
Make unencrypted volume read-only.
NK_C_API int NK_write_password_safe_slot(uint8_t slot_number, const char *slot_name, const char *slot_login, const char *slot_password)
Write password safe data to the slot.
NK_C_API uint8_t NK_get_last_command_status()
Get last command processing status.
NK_C_API int NK_fill_SD_card_with_random_data(const char *admin_pin)
Fill SD card with random data.
NK_C_API int NK_factory_reset(const char *admin_password)
Execute a factory reset.
NK_C_API int NK_totp_set_time_soft(uint64_t time)
Set the device time used for TOTP to the given time.
NK_C_API char * NK_get_password_safe_slot_login(uint8_t slot_number)
Get password safe slot login.
NK_C_API char * NK_get_password_safe_slot_name(uint8_t slot_number)
Get password safe slot name.
NK_C_API int NK_enable_firmware_update(const char *update_password)
Enter update mode.
NK_C_API int NK_get_progress_bar_value()
Get progress value of current long operation.
NK_C_API int NK_write_config_struct(struct NK_config config, const char *admin_temporary_password)
Write general config to the device.
NK_C_API int NK_set_encrypted_read_write(const char *admin_pin)
Make encrypted volume read-write.
NK_C_API void NK_free_config(uint8_t *config)
Free a value returned by NK_read_config.
NK_C_API int NK_connect_with_ID(const char *id)
Connects to the device with given ID.
NK_C_API uint32_t NK_device_serial_number_as_u32()
Return the device's serial number string as an integer.
NK_C_API enum NK_device_model NK_get_device_model()
Query the model of the connected device.
NK_C_API int NK_login_enum(enum NK_device_model device_model)
Connect to device of given model.
NK_C_API int NK_get_SD_usage_data(struct NK_SD_usage_data *out)
Get SD card usage attributes.
NK_C_API int NK_write_hotp_slot(uint8_t slot_number, const char *slot_name, const char *secret, uint64_t hotp_counter, bool use_8_digits, bool use_enter, bool use_tokenID, const char *token_ID, const char *temporary_password)
Write HOTP slot data to the device.
NK_C_API int NK_unlock_user_password(const char *admin_password, const char *new_user_password)
Unlock user PIN locked after 3 incorrect codes tries.
NK_C_API char * NK_get_hotp_code(uint8_t slot_number)
Get HOTP code from the device.
NK_C_API char * NK_get_totp_slot_name(uint8_t slot_number)
Get name of given TOTP slot.
NK_C_API int NK_is_AES_supported(const char *user_password)
Check whether AES is supported by the device.
NK_C_API char * NK_get_hotp_slot_name(uint8_t slot_number)
NK_C_API int NK_change_update_password(const char *current_update_password, const char *new_update_password)
Change update password.
NK_C_API char * 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)
Get TOTP code from the device (PIN protected)
NK_C_API char * NK_get_SD_usage_data_as_string()
Get SD card usage attributes as string.
NK_C_API int NK_get_status(struct NK_status *out)
Get the stick status common to all Nitrokey devices and return the command processing error code.
NK_C_API int NK_clear_new_sd_card_warning(const char *admin_pin)
Clear new SD card notification.
NK_C_API uint8_t NK_get_admin_retry_count()
Get retry count of admin PIN.
NK_C_API uint8_t NK_get_major_firmware_version()
Get device's major firmware version.
NK_C_API char * NK_get_hotp_code_PIN(uint8_t slot_number, const char *user_temporary_password)
Get HOTP code from the device (PIN protected)
NK_C_API void NK_free_password_safe_slot_status(uint8_t *status)
Free a value returned by NK_get_password_safe_slot_status.
NK_C_API 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)
Write general config to the device.
NK_C_API uint8_t NK_get_minor_firmware_version()
Get device's minor firmware version.
NK_C_API int NK_build_aes_key(const char *admin_password)
Generates AES key on the device.
NK_C_API struct NK_device_info * NK_list_devices()
Returns a linked list of all connected devices, or null if no devices are connected or an error occur...
NK_C_API int NK_create_hidden_volume(uint8_t slot_nr, uint8_t start_percent, uint8_t end_percent, const char *hidden_volume_password)
Create hidden volume.
NK_C_API int NK_first_authenticate(const char *admin_password, const char *admin_temporary_password)
Authenticates the user on ADMIN privilages with admin_password and sets user's temporary password on ...
NK_C_API char * NK_get_totp_code(uint8_t slot_number, uint64_t challenge, uint64_t last_totp_time, uint8_t last_interval)
Get TOTP code from the device.
NK_C_API int NK_connect_with_path(const char *path)
Connects to a device with the given path.
NK_C_API char * NK_get_status_as_string()
Return the debug status string.
DEPRECATED NK_C_API int NK_set_unencrypted_read_write(const char *user_pin)
Make unencrypted volume read-write.
NK_C_API int NK_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)
Write TOTP slot data to the device.
NK_C_API uint8_t NK_get_user_retry_count()
Get retry count of user PIN.
NK_C_API int NK_change_firmware_password_pro(const char *current_firmware_password, const char *new_firmware_password)
Change update-mode password on Nitrokey Pro.
NK_C_API int NK_export_firmware(const char *admin_pin)
Exports device's firmware to unencrypted volume.
NK_C_API unsigned int NK_get_minor_library_version()
Get the minor library version, e.
NK_C_API int NK_logout()
Disconnect from the device.
DEPRECATED NK_C_API char * NK_status()
Return the debug status string.
NK_C_API int NK_change_user_PIN(const char *current_PIN, const char *new_PIN)
Change user PIN.
NK_C_API int NK_set_unencrypted_read_write_admin(const char *admin_pin)
Make unencrypted volume read-write.
NK_C_API int NK_unlock_encrypted_volume(const char *user_pin)
Unlock encrypted volume.
NK_C_API void NK_set_debug_level(const int level)
Set debug level of messages written on stderr.
NK_C_API unsigned int NK_get_major_library_version()
Get the major library version, e.
NK_C_API int NK_read_config_struct(struct NK_config *out)
Get currently set config and write it to the given pointer.
NK_C_API typedef void(* NK_log_function)(int, const char *)
Callback function for NK_set_log_function.
Definition NK_C_API.h:338
NK_C_API int NK_erase_hotp_slot(uint8_t slot_number, const char *temporary_password)
Erase HOTP slot data from the device.
NK_C_API void NK_free_device_info(struct NK_device_info *device_info)
Free a linked list returned by NK_list_devices.
NK_C_API int NK_login(const char *device_model)
Connect to device of given model.
NK_C_API uint8_t * NK_read_config()
Get currently set config - status of function Numlock/Capslock/Scrollock OTP sending and is enabled P...
NK_device_model
The Nitrokey device models supported by the API.
Definition NK_C_API.h:105
@ NK_DISCONNECTED
Use, if no supported device is connected.
Definition NK_C_API.h:109
@ NK_PRO
Nitrokey Pro.
Definition NK_C_API.h:113
@ NK_LIBREM
Librem Key.
Definition NK_C_API.h:121
@ NK_STORAGE
Nitrokey Storage.
Definition NK_C_API.h:117
NK_C_API int NK_erase_password_safe_slot(uint8_t slot_number)
Erase the password safe slot from the device.
NK_C_API const char * NK_get_library_version()
Get the library version as a string.
const uint8_t NK_PWS_SLOT_COUNT
The number of slots in the password safe.
NK_C_API void NK_set_debug(bool state)
Set debug level of messages written on stderr.
NK_C_API int NK_unlock_hidden_volume(const char *hidden_volume_password)
Unlock hidden volume and lock encrypted volume.
Definition NK_C_API.h:1098
Data about the usage of the SD card.
Definition NK_C_API.h:262
uint8_t write_level_max
The maximum write level, as a percentage of the total card size.
Definition NK_C_API.h:272
uint8_t write_level_min
The minimum write level, as a percentage of the total card size.
Definition NK_C_API.h:267
The general configuration of a Nitrokey device.
Definition NK_C_API.h:278
uint8_t numlock
value in range [0-1] to send HOTP code from slot 'numlock' after double pressing numlock or outside t...
Definition NK_C_API.h:283
uint8_t scrolllock
similar to numlock but with scrolllock
Definition NK_C_API.h:291
bool enable_user_password
True to enable OTP PIN protection (require PIN each OTP code request)
Definition NK_C_API.h:295
uint8_t capslock
similar to numlock but with capslock
Definition NK_C_API.h:287
bool disable_user_password
Unused.
Definition NK_C_API.h:299
The connection info for a Nitrokey device as a linked list.
Definition NK_C_API.h:127
char * serial_number
The serial number.
Definition NK_C_API.h:139
enum NK_device_model model
The model of the Nitrokey device.
Definition NK_C_API.h:131
struct NK_device_info * next
The pointer to the next element of the linked list or null if this is the last element in the list.
Definition NK_C_API.h:144
char * path
The USB device path for NK_connect_with_path.
Definition NK_C_API.h:135
Stores the common device status for all Nitrokey devices.
Definition NK_C_API.h:150
bool otp_user_password
Indicates whether the user password is required to generate an OTP value.
Definition NK_C_API.h:185
uint8_t config_scrolllock
The HOTP slot to generate a password from if the scrolllock key is pressed twice (slot 0-1,...
Definition NK_C_API.h:180
uint8_t firmware_version_minor
The minor firmware version, e.
Definition NK_C_API.h:158
uint8_t config_capslock
The HOTP slot to generate a password from if the capslock key is pressed twice (slot 0-1,...
Definition NK_C_API.h:174
uint8_t firmware_version_major
The major firmware version, e.
Definition NK_C_API.h:154
uint8_t config_numlock
The HOTP slot to generate a password from if the numlock key is pressed twice (slot 0-1,...
Definition NK_C_API.h:168
uint32_t serial_number_smart_card
The serial number of the smart card.
Definition NK_C_API.h:162
Definition NK_C_API.h:302
Stores the status of a Storage device.
Definition NK_C_API.h:191
bool unencrypted_volume_read_only
Indicates whether the unencrypted volume is read-only.
Definition NK_C_API.h:195
bool unencrypted_volume_active
Indicates whether the unencrypted volume is active.
Definition NK_C_API.h:199
bool firmware_locked
Indicates whether the firmware is locked.
Definition NK_C_API.h:227
bool encrypted_volume_active
Indicates whether the encrypted volume is active.
Definition NK_C_API.h:207
uint8_t admin_retry_count
The number of remaining login attempts for the admin PIN.
Definition NK_C_API.h:243
bool stick_initialized
Indicates whether the stick has been initialized by generating the AES keys.
Definition NK_C_API.h:256
bool hidden_volume_read_only
Indicates whether the hidden volume is read-only.
Definition NK_C_API.h:211
uint32_t serial_number_smart_card
The serial number of the smart card in the Storage stick.
Definition NK_C_API.h:235
bool encrypted_volume_read_only
Indicates whether the encrypted volume is read-only.
Definition NK_C_API.h:203
uint8_t firmware_version_minor
The minor firmware version, e.
Definition NK_C_API.h:223
bool hidden_volume_active
Indicates whether the hidden volume is active.
Definition NK_C_API.h:215
bool filled_with_random
Indicates whether the SD card is filled with random characters.
Definition NK_C_API.h:251
bool new_sd_card_found
Indicates whether a new SD card was found.
Definition NK_C_API.h:247
uint8_t user_retry_count
The number of remaining login attempts for the user PIN.
Definition NK_C_API.h:239
uint8_t firmware_version_major
The major firmware version, e.
Definition NK_C_API.h:219
uint32_t serial_number_sd_card
The serial number of the SD card in the Storage stick.
Definition NK_C_API.h:231
Definition NK_C_API.h:1091