|
11 | 11 | import org.apache.logging.log4j.message.ParameterizedMessage;
|
12 | 12 | import org.elasticsearch.ElasticsearchSecurityException;
|
13 | 13 | import org.elasticsearch.common.Strings;
|
| 14 | +import org.elasticsearch.common.hash.MessageDigests; |
14 | 15 | import org.elasticsearch.core.CheckedFunction;
|
15 | 16 | import org.elasticsearch.core.Nullable;
|
16 | 17 | import org.elasticsearch.core.TimeValue;
|
|
27 | 28 | import org.opensaml.saml.security.impl.SAMLSignatureProfileValidator;
|
28 | 29 | import org.opensaml.security.credential.Credential;
|
29 | 30 | import org.opensaml.security.x509.X509Credential;
|
| 31 | +import org.opensaml.xmlsec.algorithm.AlgorithmSupport; |
30 | 32 | import org.opensaml.xmlsec.crypto.XMLSigningUtil;
|
31 | 33 | import org.opensaml.xmlsec.encryption.support.ChainingEncryptedKeyResolver;
|
32 | 34 | import org.opensaml.xmlsec.encryption.support.EncryptedKeyResolver;
|
@@ -167,6 +169,21 @@ void validateSignature(Signature signature) {
|
167 | 169 |
|
168 | 170 | checkIdpSignature(credential -> {
|
169 | 171 | try {
|
| 172 | + final String signatureAlg = AlgorithmSupport.getKeyAlgorithm(signature.getSignatureAlgorithm()); |
| 173 | + final String keyAlg = credential.getPublicKey().getAlgorithm(); |
| 174 | + if (signatureAlg != null && signatureAlg.equals(keyAlg) == false) { |
| 175 | + if (logger.isDebugEnabled()) { |
| 176 | + String keyFingerprint = "SHA265:" |
| 177 | + + MessageDigests.toHexString(MessageDigests.sha256().digest(credential.getPublicKey().getEncoded())); |
| 178 | + logger.debug( |
| 179 | + "Skipping [{}] key [{}] because it is not compatible with signature algorithm [{}]", |
| 180 | + keyAlg, |
| 181 | + keyFingerprint, |
| 182 | + signatureAlg |
| 183 | + ); |
| 184 | + } |
| 185 | + return false; |
| 186 | + } |
170 | 187 | return AccessController.doPrivileged((PrivilegedExceptionAction<Boolean>) () -> {
|
171 | 188 | try (RestorableContextClassLoader ignore = new RestorableContextClassLoader(SignatureValidator.class)) {
|
172 | 189 | SignatureValidator.validate(signature, credential);
|
|
0 commit comments