From 8cb4f03c841e7035af1893f260db5690cf6b4aa5 Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Thu, 3 Nov 2016 17:02:02 +0100 Subject: Document Storage methods in C API Use uint8_t instead of int where appropriate Signed-off-by: Szczepan Zalega --- NK_C_API.cc | 4 +- NK_C_API.h | 113 ++++++++++++++++++++++++++++++++++++++++++++-- NitrokeyManager.cc | 9 +--- include/NitrokeyManager.h | 3 +- 4 files changed, 115 insertions(+), 14 deletions(-) diff --git a/NK_C_API.cc b/NK_C_API.cc index 2a28ede..aeb6920 100644 --- a/NK_C_API.cc +++ b/NK_C_API.cc @@ -398,8 +398,8 @@ extern int NK_unlock_hidden_volume(const char* hidden_volume_password){ }); } -extern int NK_create_hidden_volume(int slot_nr, int start_percent, int end_percent, - const char* hidden_volume_password){ +extern int NK_create_hidden_volume(uint8_t slot_nr, uint8_t start_percent, uint8_t end_percent, + const char *hidden_volume_password){ auto m = NitrokeyManager::instance(); return get_without_result([&](){ m->create_hidden_volume( slot_nr, start_percent, end_percent, diff --git a/NK_C_API.h b/NK_C_API.h index b71aeb8..2d958d6 100644 --- a/NK_C_API.h +++ b/NK_C_API.h @@ -325,22 +325,127 @@ extern int NK_erase_password_safe_slot(uint8_t slot_number); extern int NK_is_AES_supported(const char *user_password); + + + +/** + * This command is typically run to initiate + * communication with the device (altough not required). + * It sets time on device and returns its current status + * - a combination of set_time and get_status_storage commands + * Storage only + * @param seconds_from_epoch date and time expressed in seconds + */ extern int NK_send_startup(uint64_t seconds_from_epoch); + +/** + * Unlock encrypted volume. + * Storage only + * @param user_pin user pin 20 characters + * @return command processing error code + */ extern int NK_unlock_encrypted_volume(const char* user_pin); + +/** + * Unlock hidden volume and lock encrypted volume. + * Requires encrypted volume to be unlocked. + * Storage only + * @param hidden_volume_password 20 characters + * @return command processing error code + */ extern int NK_unlock_hidden_volume(const char* hidden_volume_password); -extern int NK_create_hidden_volume(int slot_nr, int start_percent, int end_percent, - const char* hidden_volume_password); + +/** + * Create hidden volume. + * Requires encrypted volume to be unlocked. + * Storage only + * @param slot_nr slot number in range 0-3 + * @param start_percent volume begin expressed in percent of total available storage, int in range 0-99 + * @param end_percent volume end expressed in percent of total available storage, int in range 1-100 + * @param hidden_volume_password 20 characters + * @return command processing error code + */ +extern int NK_create_hidden_volume(uint8_t slot_nr, uint8_t start_percent, uint8_t end_percent, + const char *hidden_volume_password); + +/** + * Make unencrypted volume read-only. + * Device hides unencrypted volume for a second therefore make sure + * buffers are flushed before running. + * Storage only + * @param user_pin 20 characters + * @return command processing error code + */ extern int NK_set_unencrypted_read_only(const char* user_pin); + +/** + * Make unencrypted volume read-write. + * Device hides unencrypted volume for a second therefore make sure + * buffers are flushed before running. + * Storage only + * @param user_pin 20 characters + * @return command processing error code + */ extern int NK_set_unencrypted_read_write(const char* user_pin); + +/** + * Exports device's firmware to unencrypted volume. + * Storage only + * @param admin_pin 20 characters + * @return command processing error code + */ extern int NK_export_firmware(const char* admin_pin) ; + +/** + * Clear new SD card notification. It is set after factory reset. + * Storage only + * @param admin_pin 20 characters + * @return command processing error code + */ extern int NK_clear_new_sd_card_warning(const char* admin_pin) ; + +/** + * Fill SD card with random data. + * Should be done on first stick initialization after creating keys. + * Storage only + * @param admin_pin 20 characters + * @return command processing error code + */ extern int NK_fill_SD_card_with_random_data(const char* admin_pin) ; + +/** + * Change update password. + * Update password is used for entering update mode, where firmware + * could be uploaded using dfu-programmer or other means. + * Storage only + * @param current_update_password 20 characters + * @param new_update_password 20 characters + * @return command processing error code + */ extern int NK_change_update_password(const char* current_update_password, - const char* new_update_password); + const char* new_update_password); + +/** + * Get Storage stick status as string. + * Storage only + * @return string with devices attributes + */ extern const char* NK_get_status_storage(); + +/** + * Get SD card usage attributes as string. + * Usable during hidden volumes creation. + * Storage only + * @return string with SD card usage attributes + */ extern const char* NK_get_SD_usage_data(); -extern int NK_get_progress_bar_value(); +/** + * Get progress value of current long operation. + * Storage only + * @return int in range 0-100 or -1 if device is not busy + */ +extern int NK_get_progress_bar_value(); } diff --git a/NitrokeyManager.cc b/NitrokeyManager.cc index fdf1e05..bba06a3 100644 --- a/NitrokeyManager.cc +++ b/NitrokeyManager.cc @@ -489,11 +489,6 @@ namespace nitrokey{ //storage commands - /** - * TODO rename to set_time ? - * TODO check what exactly this one is doing - * @param seconds_from_epoch - */ void NitrokeyManager::send_startup(uint64_t seconds_from_epoch){ auto p = get_payload(); // p.set_defaults(); @@ -512,8 +507,8 @@ namespace nitrokey{ //TODO check is encrypted volume unlocked before execution //if not return library exception - void NitrokeyManager::create_hidden_volume(int slot_nr, int start_percent, int end_percent, - const char* hidden_volume_password) { + void NitrokeyManager::create_hidden_volume(uint8_t slot_nr, uint8_t start_percent, uint8_t end_percent, + const char *hidden_volume_password) { auto p = get_payload(); p.SlotNr_u8 = slot_nr; p.StartBlockPercent_u8 = start_percent; diff --git a/include/NitrokeyManager.h b/include/NitrokeyManager.h index 2d5859f..11c2be4 100644 --- a/include/NitrokeyManager.h +++ b/include/NitrokeyManager.h @@ -98,7 +98,8 @@ namespace nitrokey { void change_update_password(const char *current_update_password, const char *new_update_password); - void create_hidden_volume(int slot_nr, int start_percent, int end_percent, const char *hidden_volume_password); + void create_hidden_volume(uint8_t slot_nr, uint8_t start_percent, uint8_t end_percent, + const char *hidden_volume_password); void send_startup(uint64_t seconds_from_epoch); -- cgit v1.2.1