diff options
Diffstat (limited to 'projects/hsm')
-rw-r--r-- | projects/hsm/mgmt-cli.c | 38 | ||||
-rw-r--r-- | projects/hsm/mgmt-keystore.c | 39 |
2 files changed, 61 insertions, 16 deletions
diff --git a/projects/hsm/mgmt-cli.c b/projects/hsm/mgmt-cli.c index 61c8c35..406d50c 100644 --- a/projects/hsm/mgmt-cli.c +++ b/projects/hsm/mgmt-cli.c @@ -34,6 +34,8 @@ #include <string.h> +/* Rename both CMSIS HAL_OK and libhal HAL_OK to disambiguate */ +#define HAL_OK CMSIS_HAL_OK #include "cmsis_os.h" #include "stm-init.h" @@ -48,6 +50,11 @@ #include "mgmt-keystore.h" #include "mgmt-masterkey.h" +#undef HAL_OK +#define HAL_OK LIBHAL_OK +#include "hal.h" +#undef HAL_OK + #ifndef CLI_UART_RECVBUF_SIZE #define CLI_UART_RECVBUF_SIZE 256 #endif @@ -134,7 +141,7 @@ int control_mgmt_uart_dma_rx(mgmt_cli_dma_state_t state) } return 1; } else if (state == DMA_RX_STOP) { - if (HAL_UART_DMAStop(&huart_mgmt) != HAL_OK) return 0; + if (HAL_UART_DMAStop(&huart_mgmt) != CMSIS_HAL_OK) return 0; uart_ringbuf.rx_state = DMA_RX_STOP; return 1; } @@ -209,13 +216,32 @@ static void mgmt_cli_init(struct cli_def *cli) cli_telnet_protocol(cli, 0); } +hal_user_t user; + static int check_auth(const char *username, const char *password) { - if (strcasecmp(username, "ct") != 0) - return CLI_ERROR; - if (strcasecmp(password, "ct") != 0) - return CLI_ERROR; - return CLI_OK; + hal_client_handle_t client = { -1 }; + + /* Old default user. Remove this soon. */ + if ((strcasecmp(username, "ct") == 0) && (strcasecmp(password, "ct") == 0)) { + user = HAL_USER_NORMAL; + return CLI_OK; + } + + /* PIN-based login */ + if (strcmp(username, "wheel") == 0) + user = HAL_USER_WHEEL; + else if (strcmp(username, "so") == 0) + user = HAL_USER_SO; + else if (strcmp(username, "user") == 0) + user = HAL_USER_NORMAL; + else + user = HAL_USER_NONE; + + if (hal_rpc_login(client, user, password, strlen(password)) == LIBHAL_OK) + return CLI_OK; + + return CLI_ERROR; } int cli_main(void) diff --git a/projects/hsm/mgmt-keystore.c b/projects/hsm/mgmt-keystore.c index 14d8e1b..fb7e753 100644 --- a/projects/hsm/mgmt-keystore.c +++ b/projects/hsm/mgmt-keystore.c @@ -57,8 +57,8 @@ int cmd_keystore_set_pin(struct cli_def *cli, const char *command, char *argv[], { const hal_ks_keydb_t *db; hal_user_t user; - hal_ks_pin_t pin; hal_error_t status; + hal_client_handle_t client = { -1 }; db = hal_ks_get_keydb(); @@ -67,28 +67,44 @@ int cmd_keystore_set_pin(struct cli_def *cli, const char *command, char *argv[], return CLI_OK; } - if (argc != 3) { + if (argc != 2) { cli_print(cli, "Wrong number of arguments (%i).", argc); - cli_print(cli, "Syntax: keystore set pin <user|so|wheel> <iterations> <pin>"); + cli_print(cli, "Syntax: keystore set pin <user|so|wheel> <pin>"); return CLI_ERROR; } user = HAL_USER_NONE; - if (strcmp(argv[0], "user") == 0) user = HAL_USER_NORMAL; - if (strcmp(argv[0], "so") == 0) user = HAL_USER_SO; + if (strcmp(argv[0], "user") == 0) user = HAL_USER_NORMAL; + if (strcmp(argv[0], "so") == 0) user = HAL_USER_SO; if (strcmp(argv[0], "wheel") == 0) user = HAL_USER_WHEEL; if (user == HAL_USER_NONE) { cli_print(cli, "First argument must be 'user', 'so' or 'wheel' - not '%s'", argv[0]); return CLI_ERROR; } - pin.iterations = strtol(argv[1], NULL, 0); + status = hal_rpc_set_pin(client, user, argv[1], strlen(argv[1])); + if (status != LIBHAL_OK) { + cli_print(cli, "Failed setting PIN: %s", hal_error_string(status)); + return CLI_ERROR; + } - /* We don't actually PBKDF2 the given PIN yet, just testing */ - strncpy((char *) pin.pin, argv[2], sizeof(pin.pin)); + return CLI_OK; +} - if ((status = hal_ks_set_pin(user, &pin)) != LIBHAL_OK) { - cli_print(cli, "Failed setting PIN: %s", hal_error_string(status)); +int cmd_keystore_set_pin_iterations(struct cli_def *cli, const char *command, char *argv[], int argc) +{ + hal_error_t status; + hal_client_handle_t client = { -1 }; + + if (argc != 1) { + cli_print(cli, "Wrong number of arguments (%i).", argc); + cli_print(cli, "Syntax: keystore set pin iterations <number>"); + return CLI_ERROR; + } + + status = hal_set_pin_default_iterations(client, strtol(argv[0], NULL, 0)); + if (status != LIBHAL_OK) { + cli_print(cli, "Failed setting iterations: %s", hal_error_string(status)); return CLI_ERROR; } @@ -269,6 +285,9 @@ void configure_cli_keystore(struct cli_def *cli) /* keystore set pin */ cli_command_node(keystore_set, pin, "Set either 'wheel', 'user' or 'so' PIN"); + /* keystore set pin iterations */ + cli_command_node(keystore_set_pin, iterations, "Set PBKDF2 iterations for PINs"); + /* keystore set key */ cli_command_node(keystore_set, key, "Set a key"); |