[java-opensaml COMMIT] /trunk/opensaml-xmlsec-api/src/main/java/org/opensaml/xmlsec/encryption/support/Encrypter.java

noreply at shibboleth.net noreply at shibboleth.net
Wed Sep 24 22:19:30 EDT 2014


Author: putmanb
Date: Wed Sep 24 22:19:30 2014
New Revision: 4064

URL: http://svn.shibboleth.net/view/java-opensaml?rev=4064&view=rev
Log:
Revert last change.  Need to wait until Santuario 2.0.2 comes out to fix the ds:DigestMethod namespace decl issue.

Modified:
    trunk/opensaml-xmlsec-api/src/main/java/org/opensaml/xmlsec/encryption/support/Encrypter.java

Modified: trunk/opensaml-xmlsec-api/src/main/java/org/opensaml/xmlsec/encryption/support/Encrypter.java
URL: http://svn.shibboleth.net/view/java-opensaml/trunk/opensaml-xmlsec-api/src/main/java/org/opensaml/xmlsec/encryption/support/Encrypter.java?rev=4064&r1=4063&r2=4064&view=diff
==============================================================================
--- trunk/opensaml-xmlsec-api/src/main/java/org/opensaml/xmlsec/encryption/support/Encrypter.java (original)
+++ trunk/opensaml-xmlsec-api/src/main/java/org/opensaml/xmlsec/encryption/support/Encrypter.java Wed Sep 24 22:19:30 2014
@@ -23,6 +23,7 @@
 import java.security.interfaces.DSAPublicKey;
 import java.security.interfaces.ECPublicKey;
 import java.util.ArrayList;
+import java.util.Iterator;
 import java.util.List;
 
 import javax.annotation.Nonnull;
@@ -31,6 +32,9 @@
 
 import net.shibboleth.utilities.java.support.codec.Base64Support;
 import net.shibboleth.utilities.java.support.logic.Constraint;
+import net.shibboleth.utilities.java.support.xml.ElementSupport;
+import net.shibboleth.utilities.java.support.xml.NamespaceSupport;
+import net.shibboleth.utilities.java.support.xml.QNameSupport;
 
 import org.apache.xml.security.Init;
 import org.apache.xml.security.encryption.XMLCipher;
@@ -49,6 +53,7 @@
 import org.opensaml.xmlsec.encryption.EncryptedData;
 import org.opensaml.xmlsec.encryption.EncryptedKey;
 import org.opensaml.xmlsec.keyinfo.KeyInfoGenerator;
+import org.opensaml.xmlsec.signature.DigestMethod;
 import org.opensaml.xmlsec.signature.KeyInfo;
 import org.opensaml.xmlsec.signature.XMLSignatureBuilder;
 import org.opensaml.xmlsec.signature.support.SignatureConstants;
@@ -476,12 +481,25 @@
 
         // Workaround for XML-Security library issue. To maximize interop, explicitly express the library
         // default of SHA-1 digest method input parameter to RSA-OAEP key transport algorithm.
-        // Check and only add if the library hasn't already done so.
+        // Check and only add if the library hasn't already done so, which it currently doesn't.
         if (AlgorithmSupport.isRSAOAEP(encryptionAlgorithmURI)) {
-            org.apache.xml.security.encryption.EncryptionMethod apacheEncryptionMethod =
-                    apacheEncryptedKey.getEncryptionMethod();
-            if (apacheEncryptionMethod.getDigestAlgorithm() == null) {
-                apacheEncryptionMethod.setDigestAlgorithm(SignatureConstants.ALGO_ID_DIGEST_SHA1);
+            boolean sawDigestMethod = false;
+            Iterator childIter = apacheEncryptedKey.getEncryptionMethod().getEncryptionMethodInformation();
+            while (childIter.hasNext()) {
+                Element child = (Element) childIter.next();
+                if (DigestMethod.DEFAULT_ELEMENT_NAME.equals(QNameSupport.getNodeQName(child))) {
+                    sawDigestMethod = true;
+                    break;
+                }
+            }
+            if (!sawDigestMethod) {
+                Element digestMethodElem =
+                        ElementSupport.constructElement(containingDocument, DigestMethod.DEFAULT_ELEMENT_NAME);
+                NamespaceSupport.appendNamespaceDeclaration(digestMethodElem, SignatureConstants.XMLSIG_NS,
+                        SignatureConstants.XMLSIG_PREFIX);
+                digestMethodElem.setAttributeNS(null, DigestMethod.ALGORITHM_ATTRIB_NAME,
+                        SignatureConstants.ALGO_ID_DIGEST_SHA1);
+                apacheEncryptedKey.getEncryptionMethod().addEncryptionMethodInformation(digestMethodElem);
             }
         }
     }



More information about the commits mailing list