This is an automated email from the ASF dual-hosted git repository. acosentino pushed a commit to branch sandbox/camel-3.x in repository https://gitbox.apache.org/repos/asf/camel.git
commit f8d08e195a60e99556211ce0779898334b8d42f3 Author: Konrad Botor <kbo...@gmail.com> AuthorDate: Sun Dec 16 17:22:25 2018 +0100 CAMEL-13009: DigestMethod and DigestValue elements created either in XAdES or DS namespace depending on XAdES version required --- .../xmlsecurity/api/XAdESSignatureProperties.java | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/components/camel-xmlsecurity/src/main/java/org/apache/camel/component/xmlsecurity/api/XAdESSignatureProperties.java b/components/camel-xmlsecurity/src/main/java/org/apache/camel/component/xmlsecurity/api/XAdESSignatureProperties.java index 594dbdb..909e13c 100644 --- a/components/camel-xmlsecurity/src/main/java/org/apache/camel/component/xmlsecurity/api/XAdESSignatureProperties.java +++ b/components/camel-xmlsecurity/src/main/java/org/apache/camel/component/xmlsecurity/api/XAdESSignatureProperties.java @@ -944,14 +944,14 @@ public class XAdESSignatureProperties implements XmlSignatureProperties { throw new XmlSignatureException( "The XAdES-EPES configuration is invalid. The digest algorithm for the signature policy is missing."); } - Element digestMethod = createDigSigElement("DigestMethod", doc, input.getPrefixForXmlSignatureNamespace()); + Element digestMethod = createElementNS(doc, input, "DigestMethod"); sigPolicyHash.appendChild(digestMethod); setAttribute(digestMethod, "Algorithm", getSignaturePolicyDigestAlgorithm()); if (getSignaturePolicyDigestValue() == null || getSignaturePolicyDigestValue().isEmpty()) { throw new XmlSignatureException( "The XAdES-EPES configuration is invalid. The digest value for the signature policy is missing."); } - Element digestValue = createDigSigElement("DigestValue", doc, input.getPrefixForXmlSignatureNamespace()); + Element digestValue = createElementNS(doc, input, "DigestValue"); sigPolicyHash.appendChild(digestValue); digestValue.setTextContent(getSignaturePolicyDigestValue()); @@ -1142,10 +1142,10 @@ public class XAdESSignatureProperties implements XmlSignatureProperties { String digest = calculateDigest(algorithm, cert.getEncoded()); Element certDigest = createElement("CertDigest", doc, input); elCert.appendChild(certDigest); - Element digestMethod = createDigSigElement("DigestMethod", doc, input.getPrefixForXmlSignatureNamespace()); + Element digestMethod = createElementNS(doc, input, "DigestMethod"); certDigest.appendChild(digestMethod); setAttribute(digestMethod, "Algorithm", getDigestAlgorithmForSigningCertificate()); - Element digestValue = createDigSigElement("DigestValue", doc, input.getPrefixForXmlSignatureNamespace()); + Element digestValue = createElementNS(doc, input, "DigestValue"); certDigest.appendChild(digestValue); digestValue.setTextContent(digest); @@ -1189,6 +1189,16 @@ public class XAdESSignatureProperties implements XmlSignatureProperties { return new Base64().encodeAsString(digestBytes); } + protected Element createElementNS(Document doc, Input input, String elementName) { + Element digestMethod; + if (HTTP_URI_ETSI_ORG_01903_V1_1_1.equals(findNamespace(input.getMessage()))) { + digestMethod = createElement(elementName, doc, input); + } else { + digestMethod = createDigSigElement(elementName, doc, input.getPrefixForXmlSignatureNamespace()); + } + return digestMethod; + } + protected Element createDigSigElement(String localName, Document doc, String prefixForXmlSignatureNamespace) { Element el = doc.createElementNS("http://www.w3.org/2000/09/xmldsig#", localName); if (prefixForXmlSignatureNamespace != null && !prefixForXmlSignatureNamespace.isEmpty()) {