Conversation
dc2ce63 to
957b1be
Compare
djc
left a comment
There was a problem hiding this comment.
I think there's probably too much going on in the single commit here.
Can it be split into two or three commits? Maybe start by introducing the new algorithm type and replacing only one (the simplest) usage site, then do one commit per additional usage site?
@jgreeer do you think you can figure that out? There's a little more guidance on what we typically look for here.
957b1be to
8d48370
Compare
sure thing, I split the changes into 4 commits. let me know if we should split these changes further or not |
|
|
||
| /// Retrieve the `SignatureAlgorithm` matching a `subjectPublicKeyInfo` algorithm identifier | ||
| #[cfg(feature = "x509-parser")] | ||
| pub(crate) fn from_alg_id( |
There was a problem hiding this comment.
Nit: since this calls iter(), it should be defined before it.
I'll be tied up at a conference for the next few days but this is on my list. |
Summary
This PR splits the SPKI public key identification of
SignatureAlgorithminto its own separate type,PublicKeyAlgorithm. Bundling them together is fine for key generation, but it leads to us making incorrect assumptions when parsing. We also move closer to removingKeyPairfor #450, since we move the signing algorithm fromKeyPairto theSigningKeytrait. This change is inspired by the crypto/x509 package in go.No DER output changes for anything that worked before.
write_alg_idis byte-identical to the oldwrite_oids_sign_algfor every algorithm, which the unchanged openssl/webpki/botan verify-tests cover.Changes
sign_algo.rsPublicKeyAlgorithmstruct with three methods:from_alg_id(),write_alg_id(), anditer()SignatureAlgorithmchangesoids_sign_algand replaced withkey_alg, which holds aPublicKeyAlgorithmfrom_oid(), we've replaced the only usage incsr.rs. For ECDSA, some of the values have the same OIDs, so they were being shadowed.from_oid(ecdsa-with-SHA256)always returnedECDSA_P256_SHA256, soECDSA_P521_SHA256could never be returned at all.key_algmodule, which stores the static public key typeswrite_oids_sign_alg(), this is now done inwrite_alg_id()key_pair.rsalgorithm()fromKeyPair. It lives in theSigningKeytrait asalgorithm()PublicKeyData::algorithm()is renamed tokey_algorithm()and now returns aPublicKeyAlgorithminstead of aSignatureAlgorithm. The names have to differ becauseSigningKey: PublicKeyData, so a sharedalgorithm()is ambiguous at the call site.SubjectPublicKeyInfostruct now stores aPublicKeyAlgorithm, since it implementsPublicKeyDatafrom_der()in the SPKI struct now uses thefrom_alg_idmethod ofPublicKeyAlgorithmserialize_public_key_der()now uses thewrite_alg_idmethod ofPublicKeyAlgorithmcsr.rsPublicKeystructsalgfield is now aPublicKeyAlgorithminstead of aSignatureAlgorithmfrom_der(), we read the public key algorithm from the SPKI's AlgorithmIdentifier using thefrom_alg_id()method instead of using the csr's signature algorithm.sha1WithRSAEncryptionor RSASSA-PSS now parse instead of erroring, sincefrom_oidwas acting as a second gate and x509-parser accepts both.NULLis now rejected.crl.rserror.rsError::UnsupportedPublicKeyAlgorithmvariantrustls-cert-gen/src/cert.rsSigningKeyto reachalgorithm()lib.rsverify-testsopenssl.rs- Added a test for the issue CertificateSigningRequestParams::from_der can parse the wrong key type #448webpki.rs- Fixed its PublicKeyData implementation to return aPublicKeyAlgorithmFixes #448