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

How to verify an XML signature in an iOS application?

I've been tossed into the world of XML digital signatures with an iOS project I'm working on; I need to verify the digital signature of a SAML assertion. I've been reading a lot about validating XML signatures, and I think I get the basics about how…
Daniel
  • 872
  • 1
  • 11
  • 20
7
votes
0 answers

javax.xml.crypto.URIReferenceException: Cannot resolve element with ID 1234. Solution provided at the end

I'm having the following workflow process: Get XML as a String Convert String to Document, Sign(some elements) the document and return it back in String Get Signed XML as a String, convert it to a Document and Validate the Signature Here is the…
7
votes
1 answer

XSD Signature issue

I cannot resolve this error about . I need some help please. Copyright (C) Microsoft Corporation. All rights reserved. Schema validation warning: The 'http://www.w3.org/2000/09/xmldsig#:Signature' el ement is not…
NoWar
  • 36,338
  • 80
  • 323
  • 498
7
votes
1 answer

xmlsec fails to verify signature

I am trying to verify XML (attached on the bottom of the question) signature with xmlsec1 utility. However, when executing a command xmlsec1 --verify test.xml I am getting following stack…
Artur Rychlewicz
  • 495
  • 6
  • 16
7
votes
4 answers

How To Use XmlDsigC14NTransform Class in C#

I am trying to canonicalize an xml node by using System.Security.Cryptography.Xml.XMLDsigC14nTransform class of c# .net Framework 2.0. The instance expects three different input types, NodeList, Stream and XMLDocument. I try the transform with all…
artsince
  • 1,022
  • 20
  • 36
7
votes
1 answer

RSASSA-PSS without parameters using SHA-256 .Net 4.5 support

I'm trying to use System.Security.Cryptography (targeted framework .NET 4.5) to create xml digital signatures, so far I managed to create and verify signatures using the following scheme : RSA PKCS#1 v1.5 and SHA-256:…
Ahmad
  • 1,462
  • 15
  • 23
7
votes
2 answers

How to sign only specific part of XML

I am trying to do some XML Signature by signing only parts of the xml however after much searching I have not been able to find a solution. I am using java to sign an XML using Xpath2 transform and EXCLUSIVE canonicalization. If I have the following…
Alexandre Thenorio
  • 2,288
  • 3
  • 31
  • 50
6
votes
2 answers

Open Source XPath Filter 2.0 implementation

Does anyone know of an open source implementation for XPath Filter 2.0, preferrably in Java? But any other language would also be fine. The standard is not that new, so something should exist, but I can't find anything... If there really is nothing…
emboss
  • 38,880
  • 7
  • 101
  • 108
6
votes
1 answer

Configure TSA in Xml Signature in C#

I am trying to sign an XML file in C# using Signature Class library by Microsoft. What I have done is like this- using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Security.Cryptography; using…
Abrar Jahin
  • 13,970
  • 24
  • 112
  • 161
6
votes
1 answer

Receiving side failing to validate signed XML message

I'm trying to sign some XML with C# according to the spec sheet laid out to us for our test application. We have to: Canonicalize the message. Use the Digest algorithm to create digest of the entire message. Add the digest to the Signed Info…
Jimenemex
  • 3,104
  • 3
  • 24
  • 56
6
votes
0 answers

Signature validation false

I'm try to verify signature like this (it's PARes from Mastercard) and receive false every time, but xml from VISA work ok Mastercard
koa73
  • 861
  • 2
  • 10
  • 27
6
votes
1 answer

SignedXml reports "Unknown transform has been encountered."

I need to verify a signed xml. When running in c# the next error appears: "Unknown transform has been encountered.". However running in java it correctly validates the xml. It looks like the the xmldsig-filter2 is not recognized by .net framework.…
csg
  • 2,047
  • 2
  • 22
  • 35
6
votes
2 answers

How to extract "original" content by xml-signed file

I'm dealing with XML-signature. As you know, there are three types of XML signatures: enveloped, enveloping, detached. I found nice tutorials about how to use java standard API to sign/verify file but I would like to know how to extract the (almost)…
Mirko
  • 135
  • 1
  • 8
6
votes
1 answer

'SignatureMethod' Algorithm vs. 'DigestMethod' Algorithm in XML Signature

If we take the following Signature element as an example:
drox
  • 7,523
  • 4
  • 23
  • 34
6
votes
2 answers

How to Verify a RSA-SHA512 XML Signature in .NET?

With the help of the MSDN site about SignedXml, I can easily verify if an XML DSig is correct. It works perfectly if the signature method sha1 was used. However, when I receive the SignatureMethod RSA-SHA512…
chanser
  • 181
  • 2
  • 8
1 2
3
27 28