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

How to get X509Certificate from certificate store and generate xml signature data?

How can I get X509Certificate from certificate store and then generate XML SignatureData in .net C#?
valisimo
  • 613
  • 2
  • 9
  • 14
27
votes
4 answers

XML Signature: How to calculate the digest value?

I have an XML like this A B C
user252816
  • 563
  • 4
  • 12
  • 21
26
votes
4 answers

'Malformed Reference Element' when adding a reference based on an Id attribute with SignedXml class

Unable to sign element by Id attribute when there's a namespace prefix: void Main() { var doc = new XmlDocument(); doc.LoadXml("Zebra"); SignedXml signedXml = new SignedXml(doc); …
Dog Ears
  • 9,637
  • 5
  • 37
  • 54
20
votes
3 answers

Is there an easier way to sign an XML document in Java?

I'm trying to digitally sign an XML document using Java. I've got an implementation working with some references I've found that use various implementations in the javax.xml.crypto.dsig package. However, my current implementation is like many of the…
Rob Hruska
  • 118,520
  • 32
  • 167
  • 192
19
votes
3 answers

What do I need to know about XML Signatures to get SAML working?

At work we have a web app that we'll need to interface with another company's web app using Single Sign On validated by SAML. Our web apps are written in PHP, and it's obviously irrelevant what language choice the other company is using.…
soapergem
  • 9,263
  • 18
  • 96
  • 152
16
votes
2 answers

signing a xml document with x509 certificate

Every time I try to send a signed XML, the web service verifier rejects it. To sign the document I just adapted this sample code provided by Microsoft: http://msdn.microsoft.com/es-es/library/ms229745(v=vs.110).aspx My implementation: public…
Michael Knight
  • 648
  • 2
  • 10
  • 26
14
votes
3 answers

Library to manage XAdES signatures in Java

I'm looking for a Java library that allows the creation and verification of XAdES signatures (the more formats, the better: XAdES-BES, XAdES-C, XAdES-X-L, etc.). The most interesting implementations I found are: Java XML Digital Signature API (JSR…
Jhack
  • 510
  • 1
  • 6
  • 20
14
votes
2 answers

Asp.Net Core SAML Response Signature Validation

I'm working on a web application that needs to implement a SAML SSO using a third party idP (SP-initiated). I've reached the point where I am receiving the SAMLResponse from the idP which looks like this:
Jared
  • 153
  • 1
  • 8
14
votes
1 answer

XML Signature not validating when adding an element explicitly to the document (JAVA)?

I am creating the following XML document, using JAXB of a given XSD that is provided by third party. The third party request to sign the document and add to it an extra element that holds the signature. Using JDK 1.7. Below is the code sample for…
KAD
  • 10,972
  • 4
  • 31
  • 73
14
votes
1 answer

XML to PEM in Node.js

I'm stuck with the crypto api because I know little about cryptography. I have this XML: 1znidPBIcMcO7K/53tkTSyKqxlG5Mcws8kVtijS4tyEU4W/FEVWYpOtv+Stnb4Vt
dododedodonl
  • 4,585
  • 6
  • 30
  • 43
13
votes
2 answers

"Manifest XML signature is not valid"

OS: Windows 7 64 bit using Visual Studio Pro 2012 with .NET 4.5 installed. I used the Publish option within Visual Studios and ensured that I had clicked the Sign the clickOnce manifest and Sign the Assembly. It will still not run on another…
user1506808
  • 139
  • 1
  • 1
  • 4
13
votes
2 answers

How to compute RSA-SHA1(sha1WithRSAEncryption) value with OpenSSL

I'm confused about RSA-SHA1, I thought it's RSA_private_encrypt(SHA1(message)). But I can't get the correct signature value. Is there anything wrong?
iOS Padawan
  • 418
  • 1
  • 5
  • 16
12
votes
1 answer

Problem with custom namespace with SignedXml

The problem occurs when I sign XML documents containing namespace prefixes and namespace references and then validate it. The validation always fails (returns false) in this case. When I remove the namespace prefixes and namespace references from…
Aziz Mirzaev
  • 145
  • 1
  • 1
  • 8
12
votes
3 answers

Authoritative source on XML-sig

We have a question with regards to XML-sig and need detail about the optional elements as well as some of the canonicalization and transform stuff. We're writing a spec for a very small XML-syntax payload that will go into the metadata of media…
11
votes
3 answers

.NET Signed XML Prefix

Is there a way to set the prefix on the Signature of a Signed XML Document (SignedXml class in .Net)? So instead of:
mjmcinto
  • 218
  • 5
  • 8
1
2 3
27 28