Questions tagged [xml-signature]

XML Signatures provide integrity, message authentication, and/or signer authentication services for data of any type, whether located within the XML that includes the signature or elsewhere.

XML Signatures can be Enveloped, Enveloping or Detached.

Enveloped XML signature is when the the signature element resides within the root element of the document which contains or refers to the data to be signed.

Enveloping XML signature is when the data to be signed resides or is referenced inside the signature element itself.

Detached XML signature is when the xml data to be signed and the signature are two separate documents.

A Signature in general contains the following elements :

  • Signature - Root Element.
  • SignedInfo - Contains information on what elements should be signed and how they should be signed.
  • CanonicalizationMethod - Defines the canonicalization algorithm to be used before calculating the signature of the SignedInfo element.
  • SignatureMethod - Defines the Signature Method that should be used to sign the SignedInfo Element.
  • Reference - Points to the external document or the internal parts of the document that should be signed.
  • Transforms - Contains various transformations that are to be performed on the data to be signed before calculating the digest.
  • DigestMethod - Contains the the digest algorithm that should be used to calculate the digest of the output of the transformations.
  • DigestValue - Contains the value of the digest calculated using the algorithm specified in the DigestMethod element.
  • SignatureValue - Contains the output after calculating the signature of the whole SignedInfo element after canonicalizing it using the algorithm specified in the CanonicalizationMethod element.

Example of an Enveloped Signature.

<?xml version="1.0" encoding="ISO-8859-1"?>
<Document>
              <Pan>1234</Pan>
              <Name>Qwerty</Name>      
              <MobileNo>12335566</MobileNo>
              <Income-Salary>23000</Income-Salary>
              <Income-Other>12000</Income-Other>
              <TotalAmount>5000</TotalAmount>

              <Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
               <SignedInfo>
                <CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>
                <SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/>
                <Reference URI="">
                <Transforms>
                 <Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/>
                 <Transform Algorithm="http://www.w3.org/TR/1999/REC-xslt-19991116">
                    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
                    <xsl:output method="text"/>
                    <xsl:template match="/">
                    Pan : <xsl:copy-of select="//Pan"/>

                    MobileNo : <xsl:copy-of select="//MobileNo"/>

                    TotalAmount : <xsl:copy-of select="//TotalAmount"/>
                    </xsl:template>
                    </xsl:stylesheet>
                 </Transform>
                </Transforms>
                <DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/>
                   <DigestValue>q5RNFTQLSOlNs2GHe+35UsT2aVMMXpsHNDR1LkjuxuQ=</DigestValue>
                </Reference>
                </SignedInfo>
                <SignatureValue>QW/kE0WFj6kfJvY4+xrLzn+uRgmPvTrWEP66he0JH7WtCqmWX1CbDhb2dUQj4nhzpG0KJMZzvV/2
                                Qsrh5kiE40s6IOHIFtlM33LxRTo3bF/lo5kHb0m1GZtY7HQXN0P1cQUw9+BeyI7rFz75flVGLlkv
                                 erjENwxwCD+5DQ+VipY=
                </SignatureValue>
                </Signature>

</Document>

From the above signature element specification and the above example you must have noticed that the signature element includes a Transforms element. A list of transformations are specified in this element. A transformation defines how the data should be extracted and converted before calculating the digest. The output of the Transform is the input for the digest operation.

XML Signatures have been subject to legal disputes. When a human signs an XML document (as opposed to a machine), it is required that the data to be signed be first transformed using xslt (see the above example). If there are more than one transformations, XSLT Transformation should be the last transformation. Then this satisfies the property "What you See is What you Sign" and is thus legally valid.

420 questions
4
votes
2 answers

xml signature verification against custom CA

I need to verify an xml signature contained in the answer to a POST request. The signature is defined by:
ZioByte
  • 2,690
  • 1
  • 32
  • 68
4
votes
1 answer

WCF Soap client unable to resolve URI in signature to compute digest

I am trying to consume a SOAP 1.1 web service that runs on top of Oracle Web Logic, from a WCF client. The service implements the standard Oasis WS-Security 1.2, with body signing and encryption (sign before encrypt) and algorithms Basic256Sha256,…
Guillermo Gutiérrez
  • 17,273
  • 17
  • 89
  • 116
4
votes
0 answers

Python signxml "ValueError: Could not unserialize key data."

I'm trying Python's signxml library to signing xml and verifying the signature. But it throws following exception, what could be wrong? Traceback (most recent call last): File "C:/Users/digz/Documents/test_signxml/xml_verify_test_4.py", line 24,…
digz6666
  • 1,798
  • 1
  • 27
  • 37
4
votes
1 answer

Adding KeyInfo reference in SOAP request

So I'm having a very similar issue to this post here. SOAP KeyInfo values I am wanting to add a reference within KeyInfo but can't seem to find a way to do it through code. Here is what the expected output should be:
Kohins
  • 327
  • 6
  • 21
4
votes
1 answer

Java XML DSig and XPath

I'm signing part of an XML document using the Java XML DSig api. I'm trying to understand how it is arriving at the Digest value. My document is: bar My xpath…
Dave
  • 13,518
  • 7
  • 42
  • 51
4
votes
1 answer

how to apply XML signature on outgoing SOAP messages

I have generated stubs and bindings using cxf codegen. Everything runs fine however the server still rejects the message because of security issues. Basically I have 3 layers to take care all of which require certificates (which I have). SSL…
Newtopian
  • 7,543
  • 4
  • 48
  • 71
4
votes
1 answer

How to Sign Just a part of XML File - Java XMLSignature

I'm newbie and I'm in a hurry. I'm just trying to digital sign a part of an XML. The XML to sign is like this:
user1748166
  • 147
  • 1
  • 2
  • 14
4
votes
1 answer

Gradle build fails with cannot find symbol "org.jcp.xml.dsig.internal.dom.XMLDSigRI"

I am using gradle to build my multi-module project. In one of my class, i have the following code segment. private XMLSignatureFactory factory = XMLSignatureFactory.getInstance( "DOM", new org.jcp.xml.dsig.internal.dom.XMLDSigRI()); But…
Mayuran
  • 669
  • 2
  • 8
  • 39
4
votes
2 answers

In a WCF Client How Can I add SAML 2.0 assertion to SOAP Header?

I'm trying to add the saml 2.0 assertion node from the soap header example below - I came across the samlassertion type in the .net framework but that looks like it is only for saml 1.1.
Tone
  • 2,793
  • 6
  • 29
  • 42
4
votes
2 answers

XMLDSig: Do I have to specify Reference URI in an enveloped signature

Suppose I have such xml: Empire Burlesque Bob Dylan USA
mdzh
  • 1,030
  • 2
  • 17
  • 34
4
votes
1 answer

How to verify signatures of XML File in C# with (not cert file)?

i am making some codes for goverment billing system and after reading for some weeks i reached a dead end. I need to validate at least two signatures inside a xml file i receive from a server, i had made some code based on public MSDN to verify…
Glas
  • 169
  • 1
  • 3
  • 12
4
votes
1 answer

WSS4J - No certificates for user were found for signature

I'm trying sign a soap message using CXF, after configure my client using the knowledge I found over the internet, I'm suffering with the following error message: org.apache.ws.security.WSSecurityException: General security error (No certificates…
brevleq
  • 2,081
  • 10
  • 53
  • 97
3
votes
3 answers

Remove "ds:" in signed XML tree namespace in python's signxml

I am working with Python's lxml and signxml to generate an xml file and sign it with a pem certificate and private key. I am required to validate the signed xml in the followign website validate XML. For some reason in this website the signed XML…
Simon Capriles
  • 143
  • 2
  • 21
3
votes
1 answer

Xml Signature in Java but only on elements where attribute authenticate='true'

I have been able to sign and verify my XML signature when using Apache Santuario, but now I want to only apply the signature to fields where the attribute authenticate="true" For example:
3
votes
0 answers

How to create a CADES-BES PKCS#7 signed message in c# with a precomputed signature?

I am using key Vault HSM to compute the signature. However i need a CADES-BES PKCS#7 structure to contain the signature . I tried using CMS Signer library, however CMS Signer need private key, but in my case private key is only present in HSM.I also…
Pratik
  • 31
  • 4