Fix C_SetAttributeValue for CKA_VALUE for data obj

This commit is contained in:
konstantinpersidskiy 2018-04-09 07:18:44 -07:00 committed by Frank Morgner
parent ccdb314d49
commit 0c3412bb37
3 changed files with 57 additions and 18 deletions

View File

@ -3260,6 +3260,14 @@ pkcs15_set_attrib(struct sc_pkcs11_session *session, struct sc_pkcs15_object *p1
case CKA_SUBJECT:
rv = SC_SUCCESS;
break;
case CKA_VALUE:
if ((p15_object->type & SC_PKCS15_TYPE_CLASS_MASK) != SC_PKCS15_TYPE_DATA_OBJECT) {
ck_rv = CKR_ATTRIBUTE_READ_ONLY;
goto set_attr_done;
}
rv = sc_pkcs15init_change_attrib(fw_data->p15_card, profile, p15_object,
P15_ATTR_TYPE_VALUE, attr->pValue, attr->ulValueLen);
break;
default:
ck_rv = CKR_ATTRIBUTE_READ_ONLY;
goto set_attr_done;
@ -4351,11 +4359,8 @@ pkcs15_dobj_get_value(struct sc_pkcs11_session *session,
if (dobj->info->data.len == 0)
/* CKA_VALUE is empty */
{
struct sc_pkcs15_data *data = calloc(sizeof(struct sc_pkcs15_data), 1);
data->data_len = 0;
data->data = NULL;
*out_data = data;
return SC_SUCCESS;
*out_data = NULL;
return sc_to_cryptoki_error(SC_SUCCESS, "C_GetAttributeValue");
}
fw_data = (struct pkcs15_fw_data *) p11card->fws_data[session->slot->fw_data_idx];
@ -4382,14 +4387,6 @@ data_value_to_attr(CK_ATTRIBUTE_PTR attr, struct sc_pkcs15_data *data)
if (!attr || !data)
return CKR_ATTRIBUTE_VALUE_INVALID;
if (data->data_len == 0)
/* value is empty */
{
attr->ulValueLen = data->data_len;
attr->pValue = NULL_PTR;
return CKR_OK;
}
sc_log(context,
"data_value_to_attr(): data(%p,len:%"SC_FORMAT_LEN_SIZE_T"u)",
data, data->data_len);
@ -4467,12 +4464,19 @@ pkcs15_dobj_get_attribute(struct sc_pkcs11_session *session, void *object, CK_AT
free(buf);
break;
case CKA_VALUE:
/* if CKA_VALUE is empty, sets data to NULL */
rv = pkcs15_dobj_get_value(session, dobj, &data);
if (rv == CKR_OK)
rv = data_value_to_attr(attr, data);
if (rv == CKR_OK) {
if (data) {
rv = data_value_to_attr(attr, data);
}
else {
attr->ulValueLen = 0;
attr->pValue = NULL_PTR;
}
}
if (data) {
if (data->data)
free(data->data);
free(data->data);
free(data);
}
if (rv != CKR_OK)

View File

@ -290,6 +290,7 @@ struct sc_pkcs15init_certargs {
#define P15_ATTR_TYPE_LABEL 0
#define P15_ATTR_TYPE_ID 1
#define P15_ATTR_TYPE_VALUE 2
extern struct sc_pkcs15_object *sc_pkcs15init_new_object(int, const char *,

View File

@ -3303,8 +3303,42 @@ sc_pkcs15init_change_attrib(struct sc_pkcs15_card *p15card, struct sc_profile *p
LOG_TEST_RET(ctx, SC_ERROR_NOT_SUPPORTED, "Cannot change ID attribute");
}
break;
case P15_ATTR_TYPE_VALUE:
switch(df_type) {
case SC_PKCS15_DODF: {
u8 *nv;
struct sc_pkcs15_data_info *info = (struct sc_pkcs15_data_info *) object->data;
struct sc_path old_data_path = info->path;
struct sc_path new_data_path;
struct sc_pkcs15_der new_data;
new_data.len = new_len;
new_data.value = (u8 *) new_value;
/* save new data as a new data file on token */
r = sc_pkcs15init_store_data(p15card, profile, object, &new_data, &new_data_path);
profile->dirty = 1;
LOG_TEST_RET(ctx, r, "Failed to store new data");
nv = (u8 *) malloc (new_len * sizeof(u8));
memcpy(nv, new_value, new_len * sizeof(u8));
free(info->data.value);
/* set object members to represent new CKA_VALUE value,
new path will be written to DODF later in this function*/
info->data.len = new_len;
info->data.value = nv;
info->path = new_data_path;
/* delete old data file from token */
r = sc_pkcs15init_delete_by_path(profile, p15card, &old_data_path);
break;
}
default:
LOG_TEST_RET(ctx, SC_ERROR_NOT_SUPPORTED, "Cannot change value attribute");
}
break;
default:
LOG_TEST_RET(ctx, SC_ERROR_NOT_SUPPORTED, "Only 'LABEL' or 'ID' attributes can be changed");
LOG_TEST_RET(ctx, SC_ERROR_NOT_SUPPORTED, "Only 'LABEL' or 'ID' or 'VALUE'(for data objects) attributes can be changed");
}
if (profile->ops->emu_update_any_df) {