Skip to content

Commit

Permalink
Merge pull request #52 from Nitrokey/14-storage_commands
Browse files Browse the repository at this point in the history
Support Nitrokey Storage
  • Loading branch information
szszszsz authored Nov 26, 2016
2 parents d841239 + cdd16f3 commit f60f2cf
Show file tree
Hide file tree
Showing 25 changed files with 1,444 additions and 563 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
*.sw*
*.log
*.o
unittest/build/
*.pyc
core
.cache/
.idea/
CMakeFiles/
5 changes: 4 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ set(SOURCE_FILES
NitrokeyManager.cc
NK_C_API.cc include/CommandFailedException.h include/LibraryException.h
unittest/test_C_API.cpp
unittest/catch_main.cpp)
unittest/catch_main.cpp
unittest/test2.cc
include/LongOperationInProgressException.h
)

add_executable(libnitrokey ${SOURCE_FILES})
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ $(BUILD)/%.o: %.cc $(DEPENDS)
clean:
rm -f $(OBJ)
rm -f $(BUILD)/libnitrokey.so
make -C unittest clean
${MAKE} -C unittest clean

mrproper: clean
rm -f $(BUILD)/*.d
make -C unittest mrproper
${MAKE} -C unittest mrproper

unittest: $(BUILD)/libnitrokey.so
make -C unittest
${MAKE} -C unittest
cd unittest/build && ln -fs ../../build/libnitrokey.so .

.PHONY: all clean mrproper unittest
Expand Down
97 changes: 97 additions & 0 deletions NK_C_API.cc
Original file line number Diff line number Diff line change
Expand Up @@ -375,5 +375,102 @@ extern int NK_login_auto() {
});
}

// storage commands

extern int NK_send_startup(uint64_t seconds_from_epoch){
auto m = NitrokeyManager::instance();
return get_without_result([&](){
m->send_startup(seconds_from_epoch);
});
}

extern int NK_unlock_encrypted_volume(const char* user_pin){
auto m = NitrokeyManager::instance();
return get_without_result([&](){
m->unlock_encrypted_volume(user_pin);
});
}

extern int NK_unlock_hidden_volume(const char* hidden_volume_password){
auto m = NitrokeyManager::instance();
return get_without_result([&](){
m->unlock_hidden_volume(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,
hidden_volume_password);
});
}

extern int NK_set_unencrypted_read_only(const char* user_pin){
auto m = NitrokeyManager::instance();
return get_without_result([&](){
m->set_unencrypted_read_only(user_pin);
});
}

extern int NK_set_unencrypted_read_write(const char* user_pin){
auto m = NitrokeyManager::instance();
return get_without_result([&](){
m->set_unencrypted_read_write(user_pin);
});
}

extern int NK_export_firmware(const char* admin_pin) {
auto m = NitrokeyManager::instance();
return get_without_result([&](){
m->export_firmware(admin_pin) ;
});
}

extern int NK_clear_new_sd_card_warning(const char* admin_pin) {
auto m = NitrokeyManager::instance();
return get_without_result([&](){
m->clear_new_sd_card_warning(admin_pin);
});
}

extern int NK_fill_SD_card_with_random_data(const char* admin_pin) {
auto m = NitrokeyManager::instance();
return get_without_result([&](){
m->fill_SD_card_with_random_data(admin_pin);
});
}

extern int NK_change_update_password(const char* current_update_password,
const char* new_update_password) {
auto m = NitrokeyManager::instance();
return get_without_result([&](){
m->change_update_password(current_update_password, new_update_password);
});
}

extern const char* NK_get_status_storage_as_string() {
auto m = NitrokeyManager::instance();
return get_with_string_result([&](){
return m->get_status_storage_as_string();
});
}

extern const char* NK_get_SD_usage_data_as_string() {
auto m = NitrokeyManager::instance();
return get_with_string_result([&](){
return m->get_SD_usage_data_as_string();
});
}

extern int NK_get_progress_bar_value() {
auto m = NitrokeyManager::instance();
return get_with_result([&](){
return m->get_progress_bar_value();
});
}


}

123 changes: 123 additions & 0 deletions NK_C_API.h
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,129 @@ 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);

/**
* 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);

/**
* Get Storage stick status as string.
* Storage only
* @return string with devices attributes
*/
extern const char* NK_get_status_storage_as_string();

/**
* 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_as_string();

/**
* 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();

}


Expand Down
Loading

0 comments on commit f60f2cf

Please sign in to comment.