Skip to content

Commit 6c9d956

Browse files
authored
Set attribute xmlns with the correct namespace for enc11 elements (#531)
Fixes https://issues.apache.org/jira/browse/SANTUARIO-629
1 parent 2b8634f commit 6c9d956

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

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
@@ -525,6 +525,12 @@ void testAgreementKeyEncryptDecryptDocument(String w3cTag,
525525
Files.write(Path.of("target","test-enc-"+w3cTag+".xml"), toString(doc.getFirstChild()).getBytes());
526526
// XMLUtils.outputDOM(doc.getFirstChild(), System.out);
527527

528+
// re-read the document and compare both are the same after canonicalization
529+
Document doc2 = XMLUtils.read(
530+
new ByteArrayInputStream(toString(doc.getFirstChild()).getBytes(java.nio.charset.StandardCharsets.UTF_8)),
531+
false);
532+
assertEquals(toString(doc.getFirstChild()), toString(doc2.getFirstChild()));
533+
528534
// Perform decryption
529535
Document dd = decryptElement(doc, ecKey, (X509Certificate)cert);
530536
// XMLUtils.outputDOM(dd.getFirstChild(), System.out);

0 commit comments

Comments
 (0)