aboutsummaryrefslogtreecommitdiff
path: root/rpc_pkey.c
diff options
context:
space:
mode:
authorRob Austein <sra@hactrn.net>2016-10-07 17:32:14 -0400
committerRob Austein <sra@hactrn.net>2016-10-07 17:32:14 -0400
commitdb32574d6c85bb48a2f01d80eec6e241152704ff (patch)
treeb221ddee85010b6eddbed6d23f1b5faeaeaa74a3 /rpc_pkey.c
parent378bcae718b7b8785b06c8cf82344e4f344a9215 (diff)
Checkpoint along the way to adding keystore attribute support.
This is mostly to archive a commit where PKCS #11 "make test" still works after converting the ks_volatile code to use SDRAM allocated at startup instead of (large) static variables. The attribute code itself is incomplete at this point.
Diffstat (limited to 'rpc_pkey.c')
-rw-r--r--rpc_pkey.c94
1 files changed, 93 insertions, 1 deletions
diff --git a/rpc_pkey.c b/rpc_pkey.c
index cf0975b..207d980 100644
--- a/rpc_pkey.c
+++ b/rpc_pkey.c
@@ -867,6 +867,94 @@ static hal_error_t pkey_local_list(hal_pkey_info_t *result,
return err;
}
+static hal_error_t pkey_local_match(const hal_key_type_t type,
+ const hal_curve_name_t curve,
+ const hal_key_flags_t flags,
+ hal_rpc_pkey_attribute_t *attributes,
+ const unsigned attributes_len,
+ hal_uuid_t *result,
+ unsigned *result_len,
+ const unsigned result_max,
+ hal_uuid_t *previous_uuid)
+{
+ hal_ks_t *ks = NULL;
+ hal_error_t err;
+
+ if ((err = ks_open_from_flags(&ks, flags)) == HAL_OK &&
+ (err = hal_ks_match(ks, type, curve, flags, attributes, attributes_len,
+ result, result_len, result_max, previous_uuid)) == HAL_OK)
+ err = hal_ks_close(ks);
+ else if (ks != NULL)
+ (void) hal_ks_close(ks);
+
+ return err;
+}
+
+static hal_error_t pkey_local_set_attribute(const hal_pkey_handle_t pkey,
+ const uint32_t type,
+ const uint8_t * const value,
+ const size_t value_len)
+{
+ hal_pkey_slot_t *slot = find_handle(pkey);
+
+ if (slot == NULL)
+ return HAL_ERROR_KEY_NOT_FOUND;
+
+ hal_ks_t *ks = NULL;
+ hal_error_t err;
+
+ if ((err = ks_open_from_flags(&ks, slot->flags)) == HAL_OK &&
+ (err = hal_ks_set_attribute(ks, slot, type, value, value_len)) == HAL_OK)
+ err = hal_ks_close(ks);
+ else if (ks != NULL)
+ (void) hal_ks_close(ks);
+
+ return err;
+}
+
+static hal_error_t pkey_local_get_attribute(const hal_pkey_handle_t pkey,
+ const uint32_t type,
+ uint8_t *value,
+ size_t *value_len,
+ const size_t value_max)
+{
+ hal_pkey_slot_t *slot = find_handle(pkey);
+
+ if (slot == NULL)
+ return HAL_ERROR_KEY_NOT_FOUND;
+
+ hal_ks_t *ks = NULL;
+ hal_error_t err;
+
+ if ((err = ks_open_from_flags(&ks, slot->flags)) == HAL_OK &&
+ (err = hal_ks_get_attribute(ks, slot, type, value, value_len, value_max)) == HAL_OK)
+ err = hal_ks_close(ks);
+ else if (ks != NULL)
+ (void) hal_ks_close(ks);
+
+ return err;
+}
+
+static hal_error_t pkey_local_delete_attribute(const hal_pkey_handle_t pkey,
+ const uint32_t type)
+{
+ hal_pkey_slot_t *slot = find_handle(pkey);
+
+ if (slot == NULL)
+ return HAL_ERROR_KEY_NOT_FOUND;
+
+ hal_ks_t *ks = NULL;
+ hal_error_t err;
+
+ if ((err = ks_open_from_flags(&ks, slot->flags)) == HAL_OK &&
+ (err = hal_ks_delete_attribute(ks, slot, type)) == HAL_OK)
+ err = hal_ks_close(ks);
+ else if (ks != NULL)
+ (void) hal_ks_close(ks);
+
+ return err;
+}
+
const hal_rpc_pkey_dispatch_t hal_rpc_local_pkey_dispatch = {
pkey_local_load,
pkey_local_find,
@@ -880,7 +968,11 @@ const hal_rpc_pkey_dispatch_t hal_rpc_local_pkey_dispatch = {
pkey_local_get_public_key,
pkey_local_sign,
pkey_local_verify,
- pkey_local_list
+ pkey_local_list,
+ pkey_local_match,
+ pkey_local_set_attribute,
+ pkey_local_get_attribute,
+ pkey_local_delete_attribute
};
/*