Skip to content

Commit 3fddc48

Browse files
rmartinccoheigea
authored andcommitted
Set attribute xmlns with the correct namespace for enc11 elements (#531)
Fixes https://issues.apache.org/jira/browse/SANTUARIO-629
1 parent ea9d6c6 commit 3fddc48

3 files changed

Lines changed: 8 additions & 2 deletions

File tree

src/main/java/org/apache/xml/security/utils/Encryption11ElementProxy.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public Encryption11ElementProxy(Document doc) {
4343
setElement(XMLUtils.createElementInEncryption11Space(doc, this.getBaseLocalName()));
4444
String prefix = ElementProxy.getDefaultPrefix(this.getBaseNamespace());
4545
if (prefix != null && prefix.length() > 0) {
46-
getElement().setAttribute("xmlns:" + prefix, this.getBaseNamespace());
46+
getElement().setAttributeNS(Constants.NamespaceSpecNS, "xmlns:" + prefix, this.getBaseNamespace());
4747
}
4848
}
4949

src/main/java/org/apache/xml/security/utils/EncryptionElementProxy.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public EncryptionElementProxy(Document doc) {
4444
setElement(XMLUtils.createElementInEncryptionSpace(doc, this.getBaseLocalName()));
4545
String prefix = ElementProxy.getDefaultPrefix(this.getBaseNamespace());
4646
if (prefix != null && !prefix.isEmpty()) {
47-
getElement().setAttribute("xmlns:" + prefix, this.getBaseNamespace());
47+
getElement().setAttributeNS(Constants.NamespaceSpecNS, "xmlns:" + prefix, this.getBaseNamespace());
4848
}
4949
}
5050

src/test/java/org/apache/xml/security/test/dom/encryption/XMLEncryption11Test.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,12 @@ void testAgreementKeyEncryptDecryptDocument(String w3cTag,
564564
Files.write(Paths.get("target","test-enc-"+w3cTag+".xml"), toString(doc.getFirstChild()).getBytes());
565565
// XMLUtils.outputDOM(doc.getFirstChild(), System.out);
566566

567+
// re-read the document and compare both are the same after canonicalization
568+
Document doc2 = XMLUtils.read(
569+
new ByteArrayInputStream(toString(doc.getFirstChild()).getBytes(java.nio.charset.StandardCharsets.UTF_8)),
570+
false);
571+
assertEquals(toString(doc.getFirstChild()), toString(doc2.getFirstChild()));
572+
567573
// Perform decryption
568574
Document dd = decryptElement(doc, ecKey, (X509Certificate)cert);
569575
// XMLUtils.outputDOM(dd.getFirstChild(), System.out);

0 commit comments

Comments
 (0)