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
6
votes
1 answer

SignedXml generates invalid signatures

I've been trying to get the XMLDSIG support in .NET to behave properly, more specifically the SignedXml class. I'm implementing a third party service and they've just recently started requiring that all messages have to be digitally signed... My…
thomasjo
  • 630
  • 6
  • 20
5
votes
3 answers

XML signature verification library in C?

Are there any available libraries in C language to verify XML signatures? I could only find one library for C++ from http://santuario.apache.org/cindex.html .
LoyalBanana
  • 183
  • 6
  • 17
5
votes
3 answers

DigestValue in XMLSignature in Java is different from C#

I have a program running in C# which applies an XMLSignature to an xml document. I have the same XML documents in both cases (C# and Java), but I am not getting the same digest and signature values. I know that the results from my C program are…
user1084509
  • 1,832
  • 10
  • 33
  • 48
5
votes
2 answers

Java equivalent of C# XML signing method

I have written the following .NET Framework 3.5 C# method which takes the location of an XML document and an object representation of an X509 digital certificate (with a private key) and returns the XML document as an object with the XML Signature…
lox
  • 1,602
  • 4
  • 27
  • 41
5
votes
2 answers

javax.xml.crypto.dsig validation using the public key in the xml

Using javax.xml.crypto.dsig, how do I unmarshal and validate an XMLSignature without specifying the public key? The public key appears to be in the signed xml, but I can't figure out a way to get it. DOMValidateContext valContext = new…
HappyEngineer
  • 4,017
  • 9
  • 46
  • 60
5
votes
2 answers

Signature Validation issues using OpenSAML & OpenSSO

We are using OpenSAML on the Service Provider Site to provide SSO for our clients. Our client(ID Provider) is using OpenSSO on their end. The SAML Response being posted by OpenSSO is a little different when it comes to the signature element in that…
user464336
  • 51
  • 1
  • 5
5
votes
1 answer

XML signature validation fails in java

I have a Digitally Signed XML file and Public Certificate of signer, I want to validate the signature. Original content of response xml is returning false but when I modify the xml it returns true. My java code is as following :- import…
dpilwal
  • 361
  • 1
  • 5
  • 14
5
votes
3 answers

command line tool for XML digital signing

Are there command-line tools for XML digital signing? I have found one here: http://www.codeproject.com/KB/security/xmldsiglic.aspx but it needs .NET Framework and i would prefer it to work without .NET
Adamus
  • 51
  • 1
  • 1
  • 2
5
votes
2 answers

Is there any documentation for xmlseclibs?

I have signed the XML but I don't know how to include KeyValue element in the signature. Having some documentation would save a lot of time. The code below (if you are interested) is what I managed to do with xmlseclibs so…
mikl
  • 1,067
  • 1
  • 20
  • 34
4
votes
1 answer

SignedXml.CheckSignature throws exception: Value cannot be null. Parameter name: name

I am writing a piece of code to verify signature in Xml from X509 certificate and got the exception message in subject line. My sample code Dim cert As X509Certificate2 = GetCertificate("Certificate Name") Dim signedXml As SignedXml…
hardywang
  • 4,864
  • 11
  • 65
  • 101
4
votes
1 answer

XML Signature support on Node.js

Does anybody know if there is any node.js module to support XML Signature? Thanks!
4
votes
1 answer

"Unrecognized configuration section" after adding Signature to Config File using SignedXml.ComputeSignature

I have a Windows Forms application built using the .NET 3.5 Framework which self hosts a WCF service. The service & app function properly on their own. Concerned about having the address & binding info accessible in the app.config file, I decided…
Heather B
  • 85
  • 2
  • 8
4
votes
0 answers

`com.sun.org.slf4j.internal.Logger` in JDK and wrong usage

When dealing with XMLSignature generation and verification I had to debug and came across strange logging behavior (I would call it bugs, but maybe I don't have the full picture). The logger access method…
Peter
  • 4,752
  • 2
  • 20
  • 32
4
votes
1 answer

Unable to create the correct signature for SAML response

I am using go-saml library in our project to enable SSO in which the service provider will be Salesforce and Identity Provider will be the Golang code. Golang code will first verify the user then it will create a SAML response to allow the user to…
Rahul Satal
  • 2,107
  • 3
  • 32
  • 53
4
votes
1 answer

Get cert & key for python signxml from a PKS file

I used following command to get cert & key from a pks file. openssl pkcs12 -in ../my.pfx -nocerts -out my.key openssl pkcs12 -in ~/my.pfx -clcerts -nokeys -out cert.pem However I keep getting error. I suspect my.key is not correct. How to…
Dustin Sun
  • 5,292
  • 9
  • 49
  • 87