diff options
Diffstat (limited to 'rpc_api.c')
-rw-r--r-- | rpc_api.c | 111 |
1 files changed, 67 insertions, 44 deletions
@@ -75,7 +75,7 @@ static inline int check_pkey_flags(const hal_key_flags_t flags) return (flags &~ (HAL_KEY_FLAG_USAGE_DIGITALSIGNATURE | HAL_KEY_FLAG_USAGE_KEYENCIPHERMENT | HAL_KEY_FLAG_USAGE_DATAENCIPHERMENT | - HAL_KEY_FLAG_PROXIMATE)) == 0; + HAL_KEY_FLAG_TOKEN)) == 0; } static inline int check_pkey_type_curve_flags(const hal_key_type_t type, @@ -218,36 +218,30 @@ hal_error_t hal_rpc_pkey_load(const hal_client_handle_t client, hal_pkey_handle_t *pkey, const hal_key_type_t type, const hal_curve_name_t curve, - const uint8_t * const name, const size_t name_len, + hal_uuid_t *name, const uint8_t * const der, const size_t der_len, const hal_key_flags_t flags) { - if (pkey == NULL || name == NULL || der == NULL || der_len == 0 || - !check_pkey_type_curve_flags(type, curve, flags)) + if (pkey == NULL || name == NULL || der == NULL || der_len == 0 || !check_pkey_type_curve_flags(type, curve, flags)) return HAL_ERROR_BAD_ARGUMENTS; - if (name_len > HAL_RPC_PKEY_NAME_MAX) - return HAL_ERROR_KEY_NAME_TOO_LONG; - return hal_rpc_pkey_dispatch->load(client, session, pkey, type, curve, name, name_len, der, der_len, flags); + return hal_rpc_pkey_dispatch->load(client, session, pkey, type, curve, name, der, der_len, flags); } -hal_error_t hal_rpc_pkey_find(const hal_client_handle_t client, +hal_error_t hal_rpc_pkey_open(const hal_client_handle_t client, const hal_session_handle_t session, hal_pkey_handle_t *pkey, - const hal_key_type_t type, - const uint8_t * const name, const size_t name_len, + const hal_uuid_t * const name, const hal_key_flags_t flags) { - if (pkey == NULL || name == NULL || !check_pkey_type(type)) + if (pkey == NULL || name == NULL) return HAL_ERROR_BAD_ARGUMENTS; - if (name_len > HAL_RPC_PKEY_NAME_MAX) - return HAL_ERROR_KEY_NAME_TOO_LONG; - return hal_rpc_pkey_dispatch->find(client, session, pkey, type, name, name_len, flags); + return hal_rpc_pkey_dispatch->open(client, session, pkey, name, flags); } hal_error_t hal_rpc_pkey_generate_rsa(const hal_client_handle_t client, const hal_session_handle_t session, hal_pkey_handle_t *pkey, - const uint8_t * const name, const size_t name_len, + hal_uuid_t *name, const unsigned key_len, const uint8_t * const exp, const size_t exp_len, const hal_key_flags_t flags) @@ -255,24 +249,20 @@ hal_error_t hal_rpc_pkey_generate_rsa(const hal_client_handle_t client, if (pkey == NULL || name == NULL || key_len == 0 || (key_len & 7) != 0 || exp == NULL || exp_len == 0 || !check_pkey_flags(flags)) return HAL_ERROR_BAD_ARGUMENTS; - if (name_len > HAL_RPC_PKEY_NAME_MAX) - return HAL_ERROR_KEY_NAME_TOO_LONG; - return hal_rpc_pkey_dispatch->generate_rsa(client, session, pkey, name, name_len, key_len, exp, exp_len, flags); + return hal_rpc_pkey_dispatch->generate_rsa(client, session, pkey, name, key_len, exp, exp_len, flags); } hal_error_t hal_rpc_pkey_generate_ec(const hal_client_handle_t client, const hal_session_handle_t session, hal_pkey_handle_t *pkey, - const uint8_t * const name, const size_t name_len, + hal_uuid_t *name, const hal_curve_name_t curve, const hal_key_flags_t flags) { if (pkey == NULL || name == NULL || !check_pkey_type_curve_flags(HAL_KEY_TYPE_EC_PRIVATE, curve, flags)) return HAL_ERROR_BAD_ARGUMENTS; - if (name_len > HAL_RPC_PKEY_NAME_MAX) - return HAL_ERROR_KEY_NAME_TOO_LONG; - return hal_rpc_pkey_dispatch->generate_ec(client, session, pkey, name, name_len, curve, flags); + return hal_rpc_pkey_dispatch->generate_ec(client, session, pkey, name, curve, flags); } hal_error_t hal_rpc_pkey_close(const hal_pkey_handle_t pkey) @@ -285,16 +275,6 @@ hal_error_t hal_rpc_pkey_delete(const hal_pkey_handle_t pkey) return hal_rpc_pkey_dispatch->delete(pkey); } -hal_error_t hal_rpc_pkey_rename(const hal_pkey_handle_t pkey, - const uint8_t * const name, const size_t name_len) -{ - if (name == NULL) - return HAL_ERROR_BAD_ARGUMENTS; - if (name_len > HAL_RPC_PKEY_NAME_MAX) - return HAL_ERROR_KEY_NAME_TOO_LONG; - return hal_rpc_pkey_dispatch->rename(pkey, name, name_len); -} - hal_error_t hal_rpc_pkey_get_key_type(const hal_pkey_handle_t pkey, hal_key_type_t *type) { @@ -303,6 +283,14 @@ hal_error_t hal_rpc_pkey_get_key_type(const hal_pkey_handle_t pkey, return hal_rpc_pkey_dispatch->get_key_type(pkey, type); } +hal_error_t hal_rpc_pkey_get_key_curve(const hal_pkey_handle_t pkey, + hal_curve_name_t *curve) +{ + if (curve == NULL) + return HAL_ERROR_BAD_ARGUMENTS; + return hal_rpc_pkey_dispatch->get_key_curve(pkey, curve); +} + hal_error_t hal_rpc_pkey_get_key_flags(const hal_pkey_handle_t pkey, hal_key_flags_t *flags) { @@ -324,8 +312,7 @@ hal_error_t hal_rpc_pkey_get_public_key(const hal_pkey_handle_t pkey, return hal_rpc_pkey_dispatch->get_public_key(pkey, der, der_len, der_max); } -hal_error_t hal_rpc_pkey_sign(const hal_session_handle_t session, - const hal_pkey_handle_t pkey, +hal_error_t hal_rpc_pkey_sign(const hal_pkey_handle_t pkey, const hal_hash_handle_t hash, const uint8_t * const input, const size_t input_len, uint8_t * signature, size_t *signature_len, const size_t signature_max) @@ -333,11 +320,10 @@ hal_error_t hal_rpc_pkey_sign(const hal_session_handle_t session, if (signature == NULL || signature_len == NULL || signature_max == 0 || (hash.handle == HAL_HANDLE_NONE) == (input == NULL || input_len == 0)) return HAL_ERROR_BAD_ARGUMENTS; - return hal_rpc_pkey_dispatch->sign(session, pkey, hash, input, input_len, signature, signature_len, signature_max); + return hal_rpc_pkey_dispatch->sign(pkey, hash, input, input_len, signature, signature_len, signature_max); } -hal_error_t hal_rpc_pkey_verify(const hal_session_handle_t session, - const hal_pkey_handle_t pkey, +hal_error_t hal_rpc_pkey_verify(const hal_pkey_handle_t pkey, const hal_hash_handle_t hash, const uint8_t * const input, const size_t input_len, const uint8_t * const signature, const size_t signature_len) @@ -345,17 +331,54 @@ hal_error_t hal_rpc_pkey_verify(const hal_session_handle_t session, if (signature == NULL || signature_len == 0 || (hash.handle == HAL_HANDLE_NONE) == (input == NULL || input_len == 0)) return HAL_ERROR_BAD_ARGUMENTS; - return hal_rpc_pkey_dispatch->verify(session, pkey, hash, input, input_len, signature, signature_len); + return hal_rpc_pkey_dispatch->verify(pkey, hash, input, input_len, signature, signature_len); +} + +hal_error_t hal_rpc_pkey_match(const hal_client_handle_t client, + const hal_session_handle_t session, + const hal_key_type_t type, + const hal_curve_name_t curve, + const hal_key_flags_t flags, + const hal_pkey_attribute_t *attributes, + const unsigned attributes_len, + hal_uuid_t *result, + unsigned *result_len, + const unsigned result_max, + const hal_uuid_t * const previous_uuid) +{ + if ((attributes == NULL && attributes_len > 0) || previous_uuid == NULL || + result == NULL || result_len == NULL || result_max == 0) + return HAL_ERROR_BAD_ARGUMENTS; + + if (attributes != NULL) + for (int i = 0; i < attributes_len; i++) + if (attributes[i].value == NULL) + return HAL_ERROR_BAD_ARGUMENTS; + + return hal_rpc_pkey_dispatch->match(client, session, type, curve, flags, + attributes, attributes_len, + result, result_len, result_max, previous_uuid); +} + +hal_error_t hal_rpc_pkey_set_attributes(const hal_pkey_handle_t pkey, + const hal_pkey_attribute_t *attributes, + const unsigned attributes_len) +{ + if (attributes == NULL || attributes_len == 0) + return HAL_ERROR_BAD_ARGUMENTS; + return hal_rpc_pkey_dispatch->set_attributes(pkey, attributes, attributes_len); } -hal_error_t hal_rpc_pkey_list(hal_pkey_info_t *result, - unsigned *result_len, - const unsigned result_max, - hal_key_flags_t flags) +hal_error_t hal_rpc_pkey_get_attributes(const hal_pkey_handle_t pkey, + hal_pkey_attribute_t *attributes, + const unsigned attributes_len, + uint8_t *attributes_buffer, + const size_t attributes_buffer_len) { - if (result == NULL || result_len == NULL || result_max == 0) + if (attributes == NULL || attributes_len == 0) return HAL_ERROR_BAD_ARGUMENTS; - return hal_rpc_pkey_dispatch->list(result, result_len, result_max, flags); + return hal_rpc_pkey_dispatch->get_attributes(pkey, attributes, attributes_len, + attributes_buffer, attributes_buffer_len); } /* |