aboutsummaryrefslogtreecommitdiff
path: root/ks_volatile.c
diff options
context:
space:
mode:
Diffstat (limited to 'ks_volatile.c')
-rw-r--r--ks_volatile.c182
1 files changed, 10 insertions, 172 deletions
diff --git a/ks_volatile.c b/ks_volatile.c
index b69c3c0..8767458 100644
--- a/ks_volatile.c
+++ b/ks_volatile.c
@@ -470,131 +470,6 @@ static hal_error_t ks_match(hal_ks_t *ks,
return HAL_OK;
}
-static hal_error_t ks_set_attribute(hal_ks_t *ks,
- hal_pkey_slot_t *slot,
- const uint32_t type,
- const uint8_t * const value,
- const size_t value_len)
-{
- if (ks == NULL || slot == NULL)
- return HAL_ERROR_BAD_ARGUMENTS;
-
- ks_t *ksv = ks_to_ksv(ks);
- hal_error_t err;
- unsigned b;
-
- if (ksv->db == NULL)
- return HAL_ERROR_KEYSTORE_ACCESS;
-
- if ((err = hal_ks_index_find(&ksv->db->ksi, &slot->name, 0, &b, &slot->hint)) != HAL_OK)
- return err;
-
- ks_key_t * const k = &ksv->db->keys[b];
-
- if (!key_visible_to_session(ksv, slot->client_handle, slot->session_handle, k))
- return HAL_ERROR_KEY_NOT_FOUND;
-
- hal_rpc_pkey_attribute_t attributes[k->attributes_len + 1];
- uint8_t *bytes = k->der + k->der_len;
- size_t bytes_len = sizeof(k->der) - k->der_len;
- size_t total_len;
-
- err = hal_ks_attribute_scan(bytes, bytes_len, attributes, k->attributes_len, &total_len);
-
- if (err != HAL_OK)
- return err;
-
- return hal_ks_attribute_insert(bytes, bytes_len, attributes, &k->attributes_len, &total_len,
- type, value, value_len);
-}
-
-static hal_error_t ks_get_attribute(hal_ks_t *ks,
- hal_pkey_slot_t *slot,
- const uint32_t type,
- uint8_t *value,
- size_t *value_len,
- const size_t value_max)
-{
- if (ks == NULL || slot == NULL)
- return HAL_ERROR_BAD_ARGUMENTS;
-
- ks_t *ksv = ks_to_ksv(ks);
- hal_error_t err;
- unsigned b;
-
- if (ksv->db == NULL)
- return HAL_ERROR_KEYSTORE_ACCESS;
-
- if ((err = hal_ks_index_find(&ksv->db->ksi, &slot->name, 0, &b, &slot->hint)) != HAL_OK)
- return err;
-
- const ks_key_t * const k = &ksv->db->keys[b];
-
- if (!key_visible_to_session(ksv, slot->client_handle, slot->session_handle, k))
- return HAL_ERROR_KEY_NOT_FOUND;
-
- if (k->attributes_len == 0)
- return HAL_ERROR_ATTRIBUTE_NOT_FOUND;
-
- hal_rpc_pkey_attribute_t attributes[k->attributes_len];
-
- if ((err = hal_ks_attribute_scan(k->der + k->der_len, sizeof(k->der) - k->der_len,
- attributes, k->attributes_len, NULL)) != HAL_OK)
- return err;
-
- int i = 0;
-
- while (attributes[i].type != type)
- if (++i >= k->attributes_len)
- return HAL_ERROR_ATTRIBUTE_NOT_FOUND;
-
- if (attributes[i].length > value_max && value != NULL)
- return HAL_ERROR_RESULT_TOO_LONG;
-
- if (value != NULL)
- memcpy(value, attributes[i].value, attributes[i].length);
-
- if (value_len != NULL)
- *value_len = attributes[i].length;
-
- return HAL_OK;
-}
-
-static hal_error_t ks_delete_attribute(hal_ks_t *ks,
- hal_pkey_slot_t *slot,
- const uint32_t type)
-{
- if (ks == NULL || slot == NULL)
- return HAL_ERROR_BAD_ARGUMENTS;
-
- ks_t *ksv = ks_to_ksv(ks);
- hal_error_t err;
- unsigned b;
-
- if (ksv->db == NULL)
- return HAL_ERROR_KEYSTORE_ACCESS;
-
- if ((err = hal_ks_index_find(&ksv->db->ksi, &slot->name, 0, &b, &slot->hint)) != HAL_OK)
- return err;
-
- ks_key_t * const k = &ksv->db->keys[b];
-
- if (!key_visible_to_session(ksv, slot->client_handle, slot->session_handle, k))
- return HAL_ERROR_KEY_NOT_FOUND;
-
- hal_rpc_pkey_attribute_t attributes[k->attributes_len + 1];
- uint8_t *bytes = k->der + k->der_len;
- size_t bytes_len = sizeof(k->der) - k->der_len;
- size_t total_len;
-
- err = hal_ks_attribute_scan(bytes, bytes_len, attributes, k->attributes_len, &total_len);
-
- if (err != HAL_OK)
- return err;
-
- return hal_ks_attribute_delete(bytes, bytes_len, attributes, &k->attributes_len, &total_len, type);
-}
-
static hal_error_t ks_set_attributes(hal_ks_t *ks,
hal_pkey_slot_t *slot,
const hal_rpc_pkey_attribute_t *attributes,
@@ -626,10 +501,16 @@ static hal_error_t ks_set_attributes(hal_ks_t *ks,
if ((err = hal_ks_attribute_scan(bytes, bytes_len, attrs, k->attributes_len, &total_len)) != HAL_OK)
return err;
- for (const hal_rpc_pkey_attribute_t *a = attributes; a < attributes + attributes_len; a++)
- if ((err = hal_ks_attribute_insert(bytes, bytes_len, attrs, &k->attributes_len, &total_len,
- a->type, a->value, a->length)) != HAL_OK)
+ for (const hal_rpc_pkey_attribute_t *a = attributes; a < attributes + attributes_len; a++) {
+ if (a->length > 0 && a->value != NULL)
+ err = hal_ks_attribute_insert(bytes, bytes_len, attrs, &k->attributes_len, &total_len,
+ a->type, a->value, a->length);
+ else
+ err = hal_ks_attribute_delete(bytes, bytes_len, attrs, &k->attributes_len, &total_len,
+ a->type);
+ if (err != HAL_OK)
return err;
+ }
return HAL_OK;
}
@@ -690,45 +571,6 @@ static hal_error_t ks_get_attributes(hal_ks_t *ks,
return HAL_OK;
}
-static hal_error_t ks_delete_attributes(hal_ks_t *ks,
- hal_pkey_slot_t *slot,
- const uint32_t *types,
- const unsigned types_len)
-{
- if (ks == NULL || slot == NULL || types == NULL || types_len == 0)
- return HAL_ERROR_BAD_ARGUMENTS;
-
- ks_t *ksv = ks_to_ksv(ks);
- hal_error_t err;
- unsigned b;
-
- if (ksv->db == NULL)
- return HAL_ERROR_KEYSTORE_ACCESS;
-
- if ((err = hal_ks_index_find(&ksv->db->ksi, &slot->name, 0, &b, &slot->hint)) != HAL_OK)
- return err;
-
- ks_key_t * const k = &ksv->db->keys[b];
-
- if (!key_visible_to_session(ksv, slot->client_handle, slot->session_handle, k))
- return HAL_ERROR_KEY_NOT_FOUND;
-
- hal_rpc_pkey_attribute_t attrs[k->attributes_len + 1];
- uint8_t *bytes = k->der + k->der_len;
- size_t bytes_len = sizeof(k->der) - k->der_len;
- size_t total_len;
-
- if ((err = hal_ks_attribute_scan(bytes, bytes_len, attrs, k->attributes_len, &total_len)) != HAL_OK)
- return err;
-
- for (int i = 0; i < types_len; i++)
- if ((err = hal_ks_attribute_delete(bytes, bytes_len, attrs, &k->attributes_len,
- &total_len, types[i])) != HAL_OK)
- return err;
-
- return HAL_OK;
-}
-
const hal_ks_driver_t hal_ks_volatile_driver[1] = {{
ks_volatile_init,
ks_volatile_shutdown,
@@ -739,12 +581,8 @@ const hal_ks_driver_t hal_ks_volatile_driver[1] = {{
ks_delete,
ks_list,
ks_match,
- ks_set_attribute,
- ks_get_attribute,
- ks_delete_attribute,
ks_set_attributes,
- ks_get_attributes,
- ks_delete_attributes
+ ks_get_attributes
}};
#endif /* STATIC_KS_VOLATILE_SLOTS > 0 */