Skip to content
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

CKA_VALUE_LEN is synthesized on every secret key #650

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions src/lib/SoftHSM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7135,12 +7135,17 @@ CK_RV SoftHSM::C_UnwrapKey
// Secret Attributes
if (objClass == CKO_SECRET_KEY)
{
ByteString value;
if (isPrivate)
token->encrypt(keydata, value);
else
value = keydata;
bOK = bOK && osobject->setAttribute(CKA_VALUE, value);
// CKA_VALUE_LEN synthetized for all secret keys
bOK = bOK && osobject->setAttribute(CKA_VALUE_LEN, keydata.size());

if(bOK) {
ByteString value;
if (isPrivate)
token->encrypt(keydata, value);
else
value = keydata;
bOK = bOK && osobject->setAttribute(CKA_VALUE, value);
}
}
else if (keyType == CKK_RSA)
{
Expand Down
10 changes: 10 additions & 0 deletions src/lib/test/SymmetricAlgorithmTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1227,9 +1227,19 @@ void SymmetricAlgorithmTests::aesWrapUnwrapGeneric(CK_MECHANISM_TYPE mechanismTy
CPPUNIT_ASSERT(rv == CKR_OK);
CPPUNIT_ASSERT(hNew != CK_INVALID_HANDLE);

CK_ULONG returned_value_len = 0;
CK_ATTRIBUTE checkattribs[] = {
{ CKA_VALUE_LEN, &returned_value_len, sizeof returned_value_len },
};

rv = CRYPTOKI_F_PTR( C_GetAttributeValue(hSession, hNew, checkattribs, sizeof(checkattribs)/sizeof(CK_ATTRIBUTE)) );
CPPUNIT_ASSERT(rv == CKR_OK);
CPPUNIT_ASSERT(returned_value_len == keyLen);

free(wrappedPtr);
wrappedPtr = NULL_PTR;
rv = CRYPTOKI_F_PTR( C_DestroyObject(hSession, hSecret) );
rv = CRYPTOKI_F_PTR( C_DestroyObject(hSession, hNew) );
CPPUNIT_ASSERT(rv == CKR_OK);
}

Expand Down