You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@santuario.apache.org by "Brent Putman (Jira)" <ji...@apache.org> on 2024/04/03 01:21:00 UTC
[jira] [Commented] (SANTUARIO-616) ClassCastException regression in XMLCipher related to new KeyAgreement support
[ https://issues.apache.org/jira/browse/SANTUARIO-616?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17833351#comment-17833351 ]
Brent Putman commented on SANTUARIO-616:
----------------------------------------
In my testing a simple condition check in {{XMLCipher}} avoids the {{ClassCastException}} and all our tests pass (diff against 3.0.4):
{code:java}
diff --git a/src/main/java/org/apache/xml/security/encryption/XMLCipher.java b/src/main/java/org/apache/xml/security/encryption/XMLCipher.java
index 24160835..dc350008 100644
--- a/src/main/java/org/apache/xml/security/encryption/XMLCipher.java
+++ b/src/main/java/org/apache/xml/security/encryption/XMLCipher.java
@@ -1607,7 +1607,7 @@ public class XMLCipher {
}
KeyInfoEnc keyInfo = encryptedKey.getKeyInfo() instanceof KeyInfoEnc ? (KeyInfoEnc) encryptedKey.getKeyInfo(): null;
- if (keyInfo != null && keyInfo.containsAgreementMethod()) {
+ if (keyInfo != null && keyInfo.containsAgreementMethod() && this.key instanceof PrivateKey) {
// resolve the agreement method
LOG.debug("EncryptedKey key is using Key agreement data");
AgreementMethod agreementMethod = keyInfo.itemAgreementMethod(0);
{code}
The line immediately below the diff above (still inside the 'if' block) is where the invalid cast is occurring:
{code:java}
return XMLCipherUtil.constructRecipientKeyAgreementParameters(encryptionAlgorithm,
agreementMethod, (PrivateKey) this.key); {code}
I also verified that this doesn't cause any failures in Santuario's unit tests. But since I'm not terribly familiar with these changes yet, I'm not 100% confident in the correctness of this.
Also not sure if there are other areas of the new AgreementMethod support which also need to be examined for similar questionable assumptions. For example, there is another use of the new {{KeyInfoEnc#containsAgreementMethod()}} up in {{decryptKey(...).}}
> ClassCastException regression in XMLCipher related to new KeyAgreement support
> ------------------------------------------------------------------------------
>
> Key: SANTUARIO-616
> URL: https://issues.apache.org/jira/browse/SANTUARIO-616
> Project: Santuario
> Issue Type: Bug
> Components: Java
> Affects Versions: Java 3.0.4, Java 4.0.2
> Environment: Java 17
> Reporter: Brent Putman
> Assignee: Colm O hEigeartaigh
> Priority: Major
>
> The 3.0.4 release (and I assume also the corresponding 4.0.x release, but I can't test that) introduced a regression in {{XMLCipher}} related to the new support for ECDH and {{{}AgreementMethod{}}}.
> The code in {{XMLCipher#getAlgorithmParameters(EncryptedKey)}} seems to implicitly assume that if there are {{AgreementMethod}} elements present in the KeyInfo, that it needs to actually "do" key agreement, so it unconditionally casts the supplied input {{Key}} to {{PrivateKey}} (assuming it is an {{{}ECPrivateKey{}}}, for example).
> This assumption doesn't hold, because the caller may have already performed the key agreement op independently on the {{KeyInfo}} data, and has inited {{XMLCipher}} with the resulting {{{}SecretKey{}}}. OpenSAML implemented ECDH (and DH classic) support several years ago using this approach.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)