From 98917cffc50e7934105e874abd4a4b6ed72edc21 Mon Sep 17 00:00:00 2001 From: Robin Krahl Date: Fri, 25 May 2018 12:15:08 +0200 Subject: Add getter for Storage status to C API The C++ API currently provides the Storage status in NitrokeyManager::get_status_storage(). The C API only provides a string version of this data (NK_get_status_storage_as_string). This patch adds a struct to the C API that can store the storage status and a function that can retrieve it. The interpretation of the fields of the internal struct is based on the following code in the Nitrokey Storage firmware: - src/HighLevelFunctions/FlashStorage.h, lines 73 to 90 (struct definition with comments) - src/OTP/report_protocol.c, lines 241 to 376 (debug output of the data) --- NK_C_API.h | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) (limited to 'NK_C_API.h') diff --git a/NK_C_API.h b/NK_C_API.h index 5985c0b..97169d1 100644 --- a/NK_C_API.h +++ b/NK_C_API.h @@ -51,6 +51,77 @@ extern "C" { NK_STORAGE }; + /** + * Stores the status of a Storage device. + */ + struct NK_storage_status { + /** + * Indicates whether the unencrypted volume is read-only. + */ + bool unencrypted_volume_read_only; + /** + * Indicates whether the unencrypted volume is active. + */ + bool unencrypted_volume_active; + /** + * Indicates whether the encrypted volume is read-only. + */ + bool encrypted_volume_read_only; + /** + * Indicates whether the encrypted volume is active. + */ + bool encrypted_volume_active; + /** + * Indicates whether the hidden volume is read-only. + */ + bool hidden_volume_read_only; + /** + * Indicates whether the hidden volume is active. + */ + bool hidden_volume_active; + /** + * The major firmware version, e. g. 0 in v0.40. + */ + uint8_t firmware_version_major; + /** + * The minor firmware version, e. g. 40 in v0.40. + */ + uint8_t firmware_version_minor; + /** + * Indicates whether the firmware is locked. + */ + bool firmware_locked; + /** + * The serial number of the SD card in the Storage stick. + */ + uint32_t serial_number_sd_card; + /** + * The serial number of the smart card in the Storage stick. + */ + uint32_t serial_number_smart_card; + /** + * The number of remaining login attempts for the user PIN. + */ + uint8_t user_retry_count; + /** + * The number of remaining login attempts for the admin PIN. + */ + uint8_t admin_retry_count; + /** + * Indicates whether a new SD card was found. + */ + bool new_sd_card_found; + /** + * Indicates whether the SD card is filled with random characters. + */ + bool filled_with_random; + /** + * Indicates whether the stick has been initialized by generating + * the AES keys. + */ + bool stick_initialized; + }; + /** * Set debug level of messages written on stderr * @param state state=True - most messages, state=False - only errors level @@ -586,6 +657,17 @@ extern "C" { */ NK_C_API char* NK_get_status_storage_as_string(); + /** + * Get the Storage stick status and return the command processing + * error code. If the code is zero, i. e. the command was successful, + * the storage status is written to the output pointer's target. + * The output pointer must not be null. + * + * @param out the output pointer for the storage status + * @return command processing error code + */ + NK_C_API int NK_get_status_storage(NK_storage_status* out); + /** * Get SD card usage attributes as string. * Usable during hidden volumes creation. -- cgit v1.2.1