8255494: PKCS7 should use digest algorithm to verify the signature

Reviewed-by: valeriep
This commit is contained in:
Weijun Wang 2020-10-31 03:22:35 +00:00
parent 9d5c9cc78b
commit 80380d51d2
3 changed files with 124 additions and 13 deletions

View file

@ -282,6 +282,32 @@ public class SignatureUtil {
}
}
/**
* Extracts the key algorithm name from a signature
* algorithm name in either the "DIGESTwithENCRYPTION" or the
* "DIGESTwithENCRYPTIONandWHATEVER" format.
*
* @return the key algorithm name, or null if the input
* is not in either of the formats.
*/
public static String extractKeyAlgFromDwithE(String signatureAlgorithm) {
signatureAlgorithm = signatureAlgorithm.toUpperCase(Locale.ENGLISH);
int with = signatureAlgorithm.indexOf("WITH");
String keyAlgorithm = null;
if (with > 0) {
int and = signatureAlgorithm.indexOf("AND", with + 4);
if (and > 0) {
keyAlgorithm = signatureAlgorithm.substring(with + 4, and);
} else {
keyAlgorithm = signatureAlgorithm.substring(with + 4);
}
if (keyAlgorithm.equalsIgnoreCase("ECDSA")) {
keyAlgorithm = "EC";
}
}
return keyAlgorithm;
}
/**
* Returns default AlgorithmParameterSpec for a key used in a signature.
* This is only useful for RSASSA-PSS now, which is the only algorithm