-
Notifications
You must be signed in to change notification settings - Fork 48
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 for RSA-PSS Keys #514
Conversation
(sorry for huge one-commit, but it was pile of different interleaving changes I did not manage to separate to sensible smaller chunks yet) The failed test on macos times out in uri test as it is likely much slower with the new keys -- I can probably increase the timeout if we will agree that this is the right direction. |
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 wish the ASN.1 code was more straightforward and weren't obfuscated by all these OpenSSL Opaque structures.
For example all of the MD and MFG1 EVP_md stuff is ultimately only need to translate from the Hash name to the corresponding OID used in X509 ... I wonder if we shouldn't just store ASN1_OBJECT * pointers instead of the EVP_md ones in our structures to avoid all the churn. Even better if there was a way to just store the serialized ASN.1 once instead of reconstructing it from scratch at every invocation ...
After all there is nothing really dynamic in this information from our POV, the same fixed algorithm will always generate a very defined ASN.1 output.
Maybe we should just generate it once via some ASN.1 utility and store the pre-generated ASN.1 in the rsa-pss_map ?
Is there any need for runtime generation ?
1eb982a
to
55cbfdf
Compare
When we force all operation in pkcs11 provider, key comparison and matching of RSA-PSS did not work. Signed-off-by: Jakub Jelen <[email protected]>
... instead of the removed autotools Signed-off-by: Jakub Jelen <[email protected]>
I have the signature parameters rewritten to use static structures, but Edit: The ASN1_STRING is just a wrapper for any string so I can just feed it with the static buffer using |
You already amended your comment, yeah an ASN1_STRING is a lightweight wrapper for a "bunch of bytes", so is not a big deal. |
b24c863
to
542a6ea
Compare
This is not as straightforward as it looked like initially and consists of several changes that surface on different occasions: * The private RSA keys in PKCS#11 can have `CKA_ALLOWED_MECHANISMS` which can be used to determine if a key is generic key (can be used for any operation) or RSA-PSS key, so that it could be used only for any or specified operations. * These keys get different identifier on OpenSSL level. They also get different OIDs on the ASN.1 in various places of the X.509 certificates: * The signatures in X.509 has a OID + parameters describing the hashes, mgf and salt length used to create the signature. This is mandatory. * The public key encoding can contain the RSA-PSS restrictions. These are not mandatory so it allows us to indicate the key is restricted to any PSS operations without the need to stick to specific combination of parameters. But it allows to specify only one of the parameters (hash, MGF1-hash, salt size). But there is no way to express this in PKCS#11. We can limit ourselves to specific hash. Note, from this only the diffentiation between RSA and RSA-PSS SPKI is done Given that the certtool we use for signing certificates during setup can not distinguish RSA-PSS restricted keys and therefore generates unrestricted certificates, we need to generate the certificate later using openssl, making the tests a bit more ugly. Fixes: latchset#489 Signed-off-by: Jakub Jelen <[email protected]>
At this moment, this was already copied into two places. This also generates second restricted RSA-PSS key during setup to avoid the need to generate key as part of rsapssam test, which makes it reentrant and should make the uri test a bit faster as we will have less keys. Signed-off-by: Jakub Jelen <[email protected]>
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.
LGTM
Signed-off-by: Jakub Jelen <[email protected]>
URI test still very slow on Mac + softhsm, but URI+softhsm is v. slow on other platforms too, pushing for now, and we'll investigate later |
Description
This is not as straightforward as it looked like initially and consists of several changes that surface on different occasions:
The private RSA keys can have CKA_ALLOWED_MECHANISMS which can be used to determine if a key is generic key (can be used for any operation) or RSA-PSS key, so that it could be used only for any or specific RSA-PSS operations.
These keys get different identifier on OpenSSL level. They also get different OIDs on the ASN.1 in various places of the X.509 certificates:
The signatures in X.509 has a OID + parameters describing the hashes, mgf and salt length used. This is mandatory.
The public key encoding can contain the RSA-PSS restrictions. These are not mandatory so it allows us to indicate the key is restricted to PSS operations without the need to stick to specific combination of parameters.
When we force all operation in pkcs11 provider, the rsapss table was missing the match() callback, making key comparison fail when using RSA-PSS keys.
Given that the certtool we use for signing certificates during setup can not distinguish RSA-PSS restricted keys and therefore generates unrestricted certificates, we need to generate the certificate later using openssl, making the tests a bit more ugly.
Fixes: #489
Checklist
Reviewer's checklist: