From 42d98519724319a3fad92fc40cca5aefa30276d7 Mon Sep 17 00:00:00 2001 From: Rob Austein Date: Tue, 1 Nov 2016 12:21:17 -0400 Subject: Tweak CLI keystore commands for latest libhal RPC keystore API. Using {-1} as a client handle in the CLI is a kludge, but the new stricter libhal keystore code really wants us to be consistent about this, so as long as any part of the CLI is using client {-1}, it all needs to do so. This still isn't really right, the CLI probably needs a different set of access rules than those which apply to the RPC calls, but I'm deferring that until we know what the "final" (for this branch) version of the RPC API looks like, and have done whatever refactoring might be required in the libhal keystore drivers. --- projects/hsm/mgmt-keystore.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/projects/hsm/mgmt-keystore.c b/projects/hsm/mgmt-keystore.c index e9f27af..6f20fdd 100644 --- a/projects/hsm/mgmt-keystore.c +++ b/projects/hsm/mgmt-keystore.c @@ -139,7 +139,7 @@ static int cmd_keystore_set_pin_iterations(struct cli_def *cli, const char *comm static int cmd_keystore_delete_key(struct cli_def *cli, const char *command, char *argv[], int argc) { - const hal_client_handle_t client = { HAL_HANDLE_NONE }; + const hal_client_handle_t client = { -1 }; const hal_session_handle_t session = { HAL_HANDLE_NONE }; hal_pkey_handle_t pkey = { HAL_HANDLE_NONE }; hal_error_t status; @@ -156,8 +156,12 @@ static int cmd_keystore_delete_key(struct cli_def *cli, const char *command, cha return CLI_ERROR; } - if ((status = hal_rpc_pkey_find(client, session, &pkey, &name, HAL_KEY_FLAG_TOKEN)) != LIBHAL_OK || - (status = hal_rpc_pkey_delete(pkey)) != LIBHAL_OK) { + status = hal_rpc_pkey_find(client, session, &pkey, &name, HAL_KEY_FLAG_TOKEN); + + if (status == HAL_ERROR_KEY_NOT_FOUND) + status = hal_rpc_pkey_find(client, session, &pkey, &name, 0); + + if (status != LIBHAL_OK || (status = hal_rpc_pkey_delete(pkey)) != LIBHAL_OK) { cli_print(cli, "Failed deleting key: %s", hal_error_string(status)); return CLI_ERROR; } @@ -206,11 +210,11 @@ static int show_keys(struct cli_def *cli, const hal_pkey_info_t * const keys, co static int cmd_keystore_show_keys(struct cli_def *cli, const char *command, char *argv[], int argc) { - hal_pkey_info_t keys[64]; + hal_pkey_info_t keys[128]; unsigned n; hal_error_t status; - hal_client_handle_t client = {HAL_HANDLE_NONE}; - hal_session_handle_t session = {HAL_HANDLE_NONE}; + hal_client_handle_t client = { -1 }; + hal_session_handle_t session = { HAL_HANDLE_NONE }; if ((status = hal_rpc_pkey_list(client, session, keys, &n, sizeof(keys)/sizeof(*keys), 0)) != LIBHAL_OK) { -- cgit v1.2.3