-
Notifications
You must be signed in to change notification settings - Fork 6.1k
8302233: HSS/LMS: keytool and jarsigner changes #14254
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
Changes from all commits
438f254
7ad4e9f
2864f5f
c667ecd
e3b1a7c
ff15014
04a7a0b
fae4757
fd5473b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -398,8 +398,7 @@ SignerInfo verify(PKCS7 block, byte[] data) | |
| // to form signing algorithm. See makeSigAlg for details. | ||
| String sigAlgName = makeSigAlg( | ||
| digestAlgorithmId, | ||
| digestEncryptionAlgorithmId, | ||
| authenticatedAttributes == null); | ||
| digestEncryptionAlgorithmId); | ||
|
|
||
| KnownOIDs oid = KnownOIDs.findMatch(sigAlgName); | ||
| if (oid != null) { | ||
|
|
@@ -422,6 +421,12 @@ SignerInfo verify(PKCS7 block, byte[] data) | |
| + "critical extension(s)"); | ||
| } | ||
|
|
||
| algorithmsConformanceCheck( | ||
| digestAlgorithmId, | ||
| digestEncryptionAlgorithmId, | ||
| key, | ||
| authenticatedAttributes == null); | ||
|
|
||
| // Make sure that if the usage of the key in the certificate is | ||
| // restricted, it can be used for digital signatures. | ||
| // XXX We may want to check for additional extensions in the | ||
|
|
@@ -471,26 +476,17 @@ SignerInfo verify(PKCS7 block, byte[] data) | |
| } | ||
|
|
||
| /** | ||
| * Derives the signature algorithm name from the digest algorithm | ||
| * and the encryption algorithm inside a PKCS7 SignerInfo. | ||
| * | ||
| * The digest algorithm is in the form "DIG", and the encryption | ||
| * algorithm can be in any of the 3 forms: | ||
| * | ||
| * 1. Old style key algorithm like RSA, DSA, EC, this method returns | ||
| * DIGwithKEY. | ||
| * 2. New style signature algorithm in the form of HASHwithKEY, this | ||
| * method returns DIGwithKEY. Please note this is not HASHwithKEY. | ||
| * 3. Modern signature algorithm like RSASSA-PSS and EdDSA, this method | ||
| * returns the signature algorithm itself but ensures digAlgId is | ||
| * compatible with the algorithm as described in RFC 4056 and 8419. | ||
| * Checks if the digest algorithm and encryption algorithm combination | ||
| * inside a PKCS7 SignerInfo is legal. | ||
| * | ||
| * @param digAlgId the digest algorithm | ||
| * @param encAlgId the encryption algorithm | ||
| * @param key the public key for verification | ||
| * @param directSign whether the signature is calculated on the content | ||
| * directly. This makes difference for Ed448. | ||
| */ | ||
| public static String makeSigAlg(AlgorithmId digAlgId, AlgorithmId encAlgId, | ||
| private static void algorithmsConformanceCheck( | ||
| AlgorithmId digAlgId, AlgorithmId encAlgId, PublicKey key, | ||
| boolean directSign) throws NoSuchAlgorithmException { | ||
| String encAlg = encAlgId.getName(); | ||
| switch (encAlg) { | ||
|
|
@@ -509,12 +505,12 @@ public static String makeSigAlg(AlgorithmId digAlgId, AlgorithmId encAlgId, | |
| if (!AlgorithmId.get(spec.getDigestAlgorithm()).equals(digAlgId)) { | ||
| throw new NoSuchAlgorithmException("Incompatible digest algorithm"); | ||
| } | ||
| return encAlg; | ||
| break; | ||
| case "Ed25519": | ||
| if (!digAlgId.equals(SignatureUtil.EdDSADigestAlgHolder.sha512)) { | ||
| throw new NoSuchAlgorithmException("Incompatible digest algorithm"); | ||
| } | ||
| return encAlg; | ||
| break; | ||
| case "Ed448": | ||
| if (directSign) { | ||
| if (!digAlgId.equals(SignatureUtil.EdDSADigestAlgHolder.shake256)) { | ||
|
|
@@ -525,6 +521,40 @@ public static String makeSigAlg(AlgorithmId digAlgId, AlgorithmId encAlgId, | |
| throw new NoSuchAlgorithmException("Incompatible digest algorithm"); | ||
| } | ||
| } | ||
| break; | ||
| case "HSS/LMS": | ||
| // RFC 8708 requires the same hash algorithm used as in the HSS/LMS algorithm | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually it is RFC 8554 that requires it, RFC 8708 just references RFC 8554 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What I meant here is that, RFC 8708 requires that the hash algorithm used by the HSS/LMS signature (which should be a single one used in every corner of HSS/LMS, as required by RFC 8554) should be the same as the
https://www.rfc-editor.org/rfc/rfc8708.html#name-signed-data-conventions |
||
| if (!digAlgId.equals(AlgorithmId.get(KeyUtil.hashAlgFromHSS(key)))) { | ||
| throw new NoSuchAlgorithmException("Incompatible digest algorithm"); | ||
| } | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Derives the signature algorithm name from the digest algorithm | ||
| * and the encryption algorithm inside a PKCS7 SignerInfo. | ||
| * | ||
| * The digest algorithm is in the form "DIG", and the encryption | ||
| * algorithm can be in any of the 3 forms: | ||
| * | ||
| * 1. Old style key algorithm like RSA, DSA, EC, this method returns | ||
| * DIGwithKEY. | ||
| * 2. New style signature algorithm in the form of HASHwithKEY, this | ||
| * method returns DIGwithKEY. Please note this is not HASHwithKEY. | ||
| * 3. Modern signature algorithm like RSASSA-PSS and EdDSA, this method | ||
| * returns the signature algorithm itself. | ||
| * | ||
| * @param digAlgId the digest algorithm | ||
| * @param encAlgId the encryption algorithm | ||
| */ | ||
| public static String makeSigAlg(AlgorithmId digAlgId, AlgorithmId encAlgId) { | ||
| String encAlg = encAlgId.getName(); | ||
| switch (encAlg) { | ||
| case "RSASSA-PSS": | ||
| case "Ed25519": | ||
| case "Ed448": | ||
| case "HSS/LMS": | ||
| return encAlg; | ||
| default: | ||
| String digAlg = digAlgId.getName(); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.