diff --git a/gck-rpc-dispatch.c b/gck-rpc-dispatch.c index 9b4718f3b0d78160073c52c0128e37213f95305b..6d36115f502ef08533726351ca54b81b71876532 100644 --- a/gck-rpc-dispatch.c +++ b/gck-rpc-dispatch.c @@ -369,18 +369,6 @@ proto_read_attribute_buffer(CallState * cs, CK_ATTRIBUTE_PTR * result, (&msg->buffer, msg->parsed, &msg->parsed, &value)) return PARSE_ERROR; - /* FIXME - + if (value == sizeof (uint64_t) && - + value != sizeof (CK_ULONG)) { - + CK_ULONG attr; - + - + value = sizeof (CK_ULONG); - + attr = *(uint64_t *)data; - + *(CK_ULONG *)data = attr; - + } - + attrs[i].pValue = (CK_VOID_PTR)data; - + attrs[i].ulValueLen = value; - */ if (value == 0) { attrs[i].pValue = NULL; attrs[i].ulValueLen = 0; @@ -458,6 +446,16 @@ proto_read_attribute_array(CallState * cs, CK_ATTRIBUTE_PTR * result, return PARSE_ERROR; } + CK_ULONG a; + + if (value == sizeof (uint64_t) && + value != sizeof (CK_ULONG) && + gck_rpc_has_ulong_parameter(attrs[i].type)) { + + value = sizeof (CK_ULONG); + a = *(uint64_t *)data; + *(CK_ULONG *)data = a; + } attrs[i].pValue = (CK_VOID_PTR) data; attrs[i].ulValueLen = value; } else { diff --git a/gck-rpc-message.c b/gck-rpc-message.c index 87eacefebdf47a4b696234f816687defce747777..079b21f114bea185dd0e6203e6bb7f4679c447fa 100644 --- a/gck-rpc-message.c +++ b/gck-rpc-message.c @@ -248,19 +248,6 @@ gck_rpc_message_write_attribute_buffer(GckRpcMessage * msg, return !egg_buffer_has_error(&msg->buffer); } -static int -gck_rpc_attribute_need_resize(CK_ATTRIBUTE_PTR attr) -{ - if (sizeof(CK_ULONG) == attr->ulValueLen && - sizeof(CK_ULONG) != sizeof(uint64_t) && attr->pValue) { - if (attr->type == CKA_CLASS || attr->type == CKA_KEY_TYPE - || attr->type == CKA_CERTIFICATE_TYPE - || attr->type == CKA_HW_FEATURE_TYPE) - return 1; - } - return 0; -} - int gck_rpc_message_write_attribute_array(GckRpcMessage * msg, CK_ATTRIBUTE_PTR arr, CK_ULONG num) @@ -291,15 +278,10 @@ gck_rpc_message_write_attribute_array(GckRpcMessage * msg, /* The attribute length and value */ if (validity) { egg_buffer_add_uint32(&msg->buffer, attr->ulValueLen); - if (gck_rpc_attribute_need_resize(attr)) { - /* FIXME - uint64_t val = *(CK_ULONG *)attr->pValue; + if (gck_rpc_has_bad_sized_ulong_parameter(attr)) { + uint64_t val = *(CK_ULONG *)attr->pValue; - attr->ulValueLen = sizeof (uint64_t); - egg_buffer_add_byte_array (&msg->buffer, (unsigned char *)&val, attr->ulValueLen); - */ - egg_buffer_add_byte_array(&msg->buffer, attr->pValue, - attr->ulValueLen); + egg_buffer_add_byte_array (&msg->buffer, (unsigned char *)&val, sizeof (val)); } else egg_buffer_add_byte_array(&msg->buffer, attr->pValue, attr->ulValueLen); diff --git a/gck-rpc-module.c b/gck-rpc-module.c index 228dc017298869d705d2c6d9aa18825b8bccc62d..67794acc1bba43bf501196c067aa02fa464c7bed 100644 --- a/gck-rpc-module.c +++ b/gck-rpc-module.c @@ -763,13 +763,14 @@ proto_read_attribute_array(GckRpcMessage * msg, CK_ATTRIBUTE_PTR arr, /* Wants attribute data, enough space */ } else { + CK_ULONG a; + /* Attribute len is an integer, but * does not match CK_ULONG size, it's certainly * a CK_ULONG from a different platform */ if (attrlen == sizeof(uint64_t) && - attrlen != sizeof(CK_ULONG)) { - CK_ULONG a; - + sizeof(CK_ULONG) != sizeof(uint64_t) && + gck_rpc_has_ulong_parameter(attr->type)) { attrlen = sizeof(CK_ULONG); a = *(uint64_t *) attrval; attrval = (unsigned char *)&a; diff --git a/gck-rpc-private.h b/gck-rpc-private.h index 770e02ee2c6989f055e58e349267455109d74bdd..403e6bd83a292eec70b0e8544112cd870e624983 100644 --- a/gck-rpc-private.h +++ b/gck-rpc-private.h @@ -322,5 +322,7 @@ void gck_rpc_mechanism_list_purge(CK_MECHANISM_TYPE_PTR mechs, CK_ULONG_PTR n_mechs); int gck_rpc_mechanism_has_sane_parameters(CK_MECHANISM_TYPE type); int gck_rpc_mechanism_has_no_parameters(CK_MECHANISM_TYPE mech); +int gck_rpc_has_bad_sized_ulong_parameter(CK_ATTRIBUTE_PTR attr); +int gck_rpc_has_ulong_parameter(CK_ATTRIBUTE_TYPE type); #endif /* GCK_RPC_CALLS_H */ diff --git a/gck-rpc-util.c b/gck-rpc-util.c index 52f65ccf31bfc81266a643824c71e208052b8f5a..85a458755df9d9232499d15e3cf0ae2b4e3d85b8 100644 --- a/gck-rpc-util.c +++ b/gck-rpc-util.c @@ -201,3 +201,31 @@ int gck_rpc_mechanism_has_no_parameters(CK_MECHANISM_TYPE mech) return 0; }; } + +int +gck_rpc_has_ulong_parameter(CK_ATTRIBUTE_TYPE type) +{ + switch (type) { + case CKA_CLASS: + case CKA_KEY_TYPE: + case CKA_CERTIFICATE_TYPE: + case CKA_HW_FEATURE_TYPE: + return 1; + default: + return 0; + } +} + +int +gck_rpc_has_bad_sized_ulong_parameter(CK_ATTRIBUTE_PTR attr) +{ + if (!attr->pValue) + return 0; + /* All this parameters are transmited on the network + * as 64bit integers */ + if (sizeof (uint64_t) != attr->ulValueLen) + return 0; + if (sizeof (CK_ULONG) == attr->ulValueLen) + return 0; + return gck_rpc_has_ulong_parameter(attr->type); +}