pkcs11: Change how unavailable attributes like CKA_TRUSTED are handled

If a PKCS#11 library/token doesn't provide one or more attributes via
C_GetAttributeValue(), we get back CKR_ATTRIBUTE_TYPE_INVALID (similar
for protected attributes where CKR_ATTRIBUTE_SENSITIVE is returned).
This is not an error as the spec demands that all attributes have been
processed with the unavailable attributes having set their length
field to CK_UNAVAILABLE_INFORMATION.

We use this to handle the CKA_TRUSTED attribute, which some tokens
apparently don't support.  We previously used a version check to remove
the attribute from the call but even the latest spec doesn't make the
attribute mandatory (it's just in a list of "common" attributes for
CKO_CERTIFICATE objects, without a default value), so there are current
tokens that don't support it and prevent us from enumerating certificates.
This commit is contained in:
Tobias Brunner
2021-06-14 13:58:48 +02:00
parent a90716cd4d
commit 6537be9c8d
6 changed files with 78 additions and 36 deletions
@@ -888,7 +888,8 @@ static private_pkcs11_public_key_t *find_key_by_keyid(pkcs11_library_t *p11,
enumerator = p11->create_object_enumerator(p11, session, tmpl, count, attr,
countof(attr));
if (enumerator->enumerate(enumerator, &object))
if (enumerator->enumerate(enumerator, &object) &&
attr[0].ulValueLen != CK_UNAVAILABLE_INFORMATION)
{
switch (type)
{