New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Question about C_GetAttributeValue implementation #292
Comments
Ok, so we agree that all the behavior, except "CK_ATTRIBUTE structures with CK_ATTRIBUTE_TYPE type set to zero", is according to the specification. Right? And this is what you are asking about? PKCS#11 does not explicitly say how the CK_ATTRIBUTE_TYPE within the array should be handled. However, one could say that it is part of the attribute value for e.g. CKA_WRAP_TEMPLATE that we want to extract using C_GetAttributeValue() and should thus be set by the PKCS#11 library. If we forget that we were the ones who created the object with its CKA_WRAP_TEMPLATE, how would we know the value of each CK_ATTRIBUTE_TYPE in the attribute array? This is why we have C_GetAttributeValue() to get this information. If this was not set by the PKCS#11 library, all we would know are pointers and data lengths to unknown attributes within the template. Also, the order of the attributes are undefined. |
PKCS#11 2.40 has:
There are only 3 attributes that are arrays of other attributes. #define CKA_WRAP_TEMPLATE (CKF_ARRAY_ATTRIBUTE|0x00000211UL) PKCS#11 also defines: So it could be possible to define objects that have one or more arrays of attributes But for now, there are only 3 attributes that are arrays of other attributes. |
But we are not asking about a specific attribute within the array. We are asking about all attributes in the array. Any implementation should thus ignore the value of the attribute type in the array. As I said earlier, we have no way of knowing which type value we should use as the content of the array is unknown. Setting it to CK_ATTRIBUTE_TYPE = 0 or any other value should have no meaning. |
My opinion is that SoftHSMv2 approach adds ambiguity to the way C_GetAttributeValue() can be called. At first I'd like to discuss common attributes. Let's assume the following object for example:
According to my understanding of specification it is correct to pass the following pTemplate to C_GetAttributeValue():
And C_GetAttributeValue() should update buffers that pointer_1 and pointer_2 point to with value CKO_DATA. If we will develop this approach to array attributes, then the call to C_GetAttributeValue() with sub pTemplate attributes set with zeros should mean that the caller wants to obtain the same sub value (value of CKA_CLASS to be precise) several times. But SoftHSMv2 approach defines a very specific behavior in this situation. I would also like to introduce a way to figure out types of sub attributes. The caller can definitely figure out quantity of sub attributes by requesting the size of array attribute. Then the caller can enumerate all available in PKCS#11 attribute classes and filter the ones that are not present in sub template:
|
I do not see any problem with this behavior w.r.t. PKCS#11. PKCS#11 has not clearly defined the handling of array attributes and we have made an interpretation that fits the handling of other types of attributes. The behavior of getting an array attribute:
Do you have examples from other PKCS#11 libraries and how they are handling attribute arrays? |
Thank you for explanations, but I would like to discuss two possible issues:
|
You can see the behavior here: SoftHSMv2/src/lib/P11Attributes.cpp Line 135 in 6f2ad63
If pValue for all array attributes are set to NULL_PTR, then all type and ulValueLen will be updated. Thus resetting any incoming type value. If the attribute in the array template is too small then SoftHSM will return with CKR_BUFFER_TOO_SMALL. If the array template will not fit all attributes, then it will return with CKR_BUFFER_TOO_SMALL. If the array template has an attribute that is not part of the array attribute, then it will return CKR_ATTRIBUTE_TYPE_INVALID. Please read the code and experiment with SoftHSM for more details. |
Thank you again for explanations, and excuse me for bothering you! By the way I am aware only of two OSS PKCS11 implementations: But both of them do not support array attributes. |
Good day!
I have a question regarding implementation of function C_GetAttributeValue in SoftHSMv2, specifically about how attributes, which values are arrays of attributes, are handled.
According to the test: https://github.com/opendnssec/SoftHSMv2/blob/master/src/lib/test/ObjectTests.cpp#L1909)
SoftHSMv2 allows to pass to C_GetAttributeValue an array attribute value (CKA_WRAP_TEMPLATE for example) as an array of CK_ATTRIBUTE structures with CK_ATTRIBUTE_TYPE type set to zero (https://github.com/opendnssec/SoftHSMv2/blob/master/src/lib/test/ObjectTests.cpp#L1967) and C_GetAttributeValue will set CK_ATTRIBUTE_TYPE type in the structures to appropriate types.
But I can not find such behavior in the specification: http://docs.oasis-open.org/pkcs11/pkcs11-base/v2.40/pkcs11-base-v2.40.html
As far as I understand the specification of C_GetAttributeValue in context of a special case when template (pTemplate) value is an array, C_GetAttributeValue can be called:
So the question is: Is there any source of documentation that specific implementation of function C_GetAttributeValue in SoftHSMv2 relies on?
The text was updated successfully, but these errors were encountered: