-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Add support of key check value CKA_CHECK_VALUE to PKCS11 TA #6494
Conversation
Added commit |
By the way, could you add a test case in optee_test pkcs11_1000.c? Maybe start with a basic test to read the attribute, destroy the attribute empty, and set the attribute to a valid and an invalid value. Also I wonder if there should be a |
db6b79c
to
dbf7647
Compare
Addressed comments above. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The implementation lacks C_CopyObject and C_DeriveObject cases (I don't think there are other cases but I should cross-check).
If you prefer to go step by step, I think we definitely need a config switch ,default disabled, so that the attribute is not half supported as the specs says that if supported, it must be fully supported.
ta/pkcs11/src/pkcs11_attributes.c
Outdated
return rc; | ||
|
||
/* Remove the default empty check value attribute if found */ | ||
rc = remove_empty_attribute(head, PKCS11_CKA_CHECK_VALUE); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should not remove the attribute if present.
If present and of size 0, then PKCS11_CKA_CHECK_VALUE
should be that one.
If present and of non-0 size, we should compute the value and succeed only if the provided value matches the expected value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@etienne-lms could you clarify which "that one" you are referring to you mean the one calculated from the resulting key ?
For the second case, the specs says that if provided the value provided should be taken even if it conflicts with the expected value.
Could you please precesie ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure.
Extracts from the PKCS#11 Base Specification, section 4.10 Secret key objects:
- The attribute is optional, but if supported, regardless of how the key object is created or derived, the value of the attribute is always supplied.
- If a value is supplied in the application template (allowed but never necessary) then, if supported, it MUST match what the library calculates it to be or the library returns a CKR_ATTRIBUTE_VALUE_INVALID.
- The generation of the KCV may be prevented by the application supplying the attribute in the template as a no-value (0 length) entry.
- The application can query the value at any time like any other attribute using C_GetAttributeValue.
- C_SetAttributeValue may be used to destroy the attribute, by supplying no-value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry i was wrong in one point: it seems at object creation, the client template cannot prevent generation of CKA_CHECK_VALUE attribute : ".. it MUST match what the library calculates.". To destroy it, the client must later use C_SetAttributeValue and set a "no-value" (that is a zero-sized value) for the attribute.
ta/pkcs11/src/processing.c
Outdated
goto out; | ||
|
||
/* Remove the default empty check value attribute if found */ | ||
rc = remove_empty_attribute(head, PKCS11_CKA_CHECK_VALUE); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto about not removing the attribute if present.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a new randomly generated key. I guess the statement should be simply removed ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The template passed to C_GenerateKey can set CKA_CHECK_VALUE attribute. In which case we should not omit it but ensure it complies with a valid value, that is either a zero-sized value or the value the pkcs11 TA also computes. Other values for this attribute should error with return code CKR_ATTRIBUTE_VALUE_INVALID.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@etienne-lms Stills unclear, For randomly generated key we can't beforehand determine the KCV to be provided in the template. So if we provide a zero-sized value, should we set the value computed by the TA ? The spec says:The generation of the KCV may be prevented by the application supplying the attribute in the template as a no-value (0 length) entry. Confused.
My understatding, the KCV will be always computed, if the client provides zero-sized value then it will be removed from attribute list remove_empty_attribute()
as done before , when invalid value we return CKR_ATTRIBUTE_VALUE_INVALID. Is my understanding correct ?
@etienne-lms My understatding is that |
You right for C_DeriveKey, it ends in calls |
bfb7c90
to
99cd3c5
Compare
Updated the commit "ta: pkcs11: processing.c: calculate KCV on key generation" to comply with the specifications. |
99cd3c5
to
0dffcae
Compare
Update: Moving the key check value handeling to a single function Commits will be squashed later, for now just to make sure the control flow is okay. |
65260eb
to
7910432
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the update. The implementation looks quite nice. I have few comments (see below) but I think the main needed pieces are in place.
Since the spec says the attribute is optional, I really think a CFG_PCSK11_TA_CHECK_VALUE_ATTRIBUTE=y|n
would be nice. Note this can be discussed in a separated P-R.
7910432
to
c32570e
Compare
Addressed most of the comments. Stills need to implement |
c32570e
to
e785c55
Compare
Update: introduced |
e785c55
to
47a8331
Compare
47a8331
to
6d40227
Compare
All comments have been addressed. |
6d40227
to
12331b5
Compare
Comments addressed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think all commits should be squashed in a single one, inlcuding the change in ta/pkcs11/sub.mk that describes CFG_PKCS11_TA_CHECK_VALUE_ATTRIBUTE
.
I'll make another review round on the changes but they look good to me.
12331b5
to
ee15a31
Compare
Commits squashed into one single commit. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the update.
The commit message is far too verbose. You don't need to describe everything that is done in the change, readers can look at the modification. The commit message should rather briefly describe what is changed and why.
Suggestion:
Add PKCS11_CKA_CHECK_VALUE as an optional attribute of symmetric
key and certificate objects . As per the PKCS#11 specification, key
check value attribute is optional therefore add pkcs11 TA configuration
switch CFG_PKCS11_TA_CHECK_VALUE_ATTRIBUTE to embed or not the support.
When supported, as per the spec, the attribute can be either the
legitimate value recomputed by the PKCS#11 token or a zero-sized value
called a no-value for when client does not want the attribute to set
in an object.
This change adds the support for the pcks11 TA commands related to
Cryptoki API functions C_GenerateKey(), C_CreateObject(), C_CopyObject(),
C_SetAttributeValue(), C_UnwrapKey() and C_DeriveKey(). TA command
related to C_FindOjects() support the attribute without any change.
de7f231
to
a5a4f86
Compare
Comments addressed |
@etienne-lms any more comments or tags to apply ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed-by: Etienne Carriere <etienne.carriere@foss.st.com>
Could you provide few tests in a new test case in xtest pkcs11_1000.c to test this? By using CFG_PKCS11_TA_CHECK_VALUE_ATTRIBUTE=y
in Qemu based CI test config, we would run regression test covering the feature.
@vesajaaskelainen, maybe are you interested in looking at this change. |
ta/pkcs11/src/object.c
Outdated
@@ -1051,6 +1056,11 @@ enum pkcs11_rc entry_set_attribute_value(struct pkcs11_client *client, | |||
if (rc) | |||
goto out; | |||
|
|||
/* Set key check value attribute */ | |||
rc = set_check_value_attr(&head); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@etienne-lms I have a concern here, as per your recommandation set_check_value_attr()
has been moved before check_attrs_against_modification()
to santize CKA_CHECK_VALUE
against modification, however, at this stage the object is object attributes are required to compute the KCV such as the class and key type. Here, the template and object are both needed to compute/test the KCV. My question, should this call moved elsewhere where all attributes are consolidated/merged together ?
PR which adds test cases OP-TEE/optee_test#719 |
a5a4f86
to
b3154d2
Compare
Change: For |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One last comment otherwise looks good to me. Let's see it tested.
Last minute, I think the certificate part lacks the attribute definition.
Here is the test result:
|
b3154d2
to
778d0f6
Compare
Comments addressed and tag applied. |
Add PKCS11_CKA_CHECK_VALUE as an optional attribute of symmetric key and certificate objects . As per the PKCS#11 specification, key check value attribute is optional therefore add pkcs11 TA configuration switch CFG_PKCS11_TA_CHECK_VALUE_ATTRIBUTE to embed or not the support. When supported, as per the spec, the attribute can be either the legitimate value recomputed by the PKCS#11 token or a zero-sized value called a no-value for when client does not want the attribute to set in an object. This change adds the support for the pcks11 TA commands related to Cryptoki API functions C_GenerateKey(), C_CreateObject(), C_CopyObject(), C_SetAttributeValue(), C_UnwrapKey() and C_DeriveKey(). TA command related to C_FindOjects() support the attribute without any change. Signed-off-by: Marouene Boubakri <marouene.boubakri@nxp.com> Reviewed-by: Etienne Carriere <etienne.carriere@foss.st.com>
I've fetched your test (OP-TEE/optee_test#719) and added few others tests (see etienne-lms/optee_test@f6f4cb5 temp link). I see an issue with C_SetAttribute. |
@etienne-lms this has been asked in my comment above, for C_SetAttributeValue() both the template attributes and object attributes are required to make the computation and the check. My question was somehow if there is any way where these are merged together to proceed with check value computation and it seems that there is ony a way after the checks are done. |
C_SetAttributeValue is specific among the other cryptoki service is that it modifies an existing object. I'll propose a way, where this sequence preserves the object original data (attributes) if the service fails at any point. The idea is to copy the object attributes in a temporary reference. |
Thanks @etienne-lms, I'll update accordingly. |
See #6550. |
An attempt to support CKA_CHECK_VALUE attribute in PKCS 11 TA. For AES, the value of this attribute is derived from the key object by taking the first three bytes of the ECB encryption of a single block of null (0x00) bytes, using the default cipher associated with the key type of the secret key object. This is useful to detect that a key object has not tampered with.
For now, we try to calculate the value when a symmetric key is randomly generated. Still need to add for (Create, Unwarp, Derive and Copy) in incoming commits.
Related issues: #6453, #6431