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
0
votes
2 answers

XML Digital Signature validation

I was trying to validate an XML signature. The validation according to this tutorial works fine. But I also tried to a second approach. To verify it with the verify method of the Signature class I extracted the signature and the certificate from…
iffi
  • 53
  • 1
  • 9
0
votes
1 answer

namespace and xpath

Libarary xades4j . code as following: static { try { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true); db = dbf.newDocumentBuilder(); …
chris.shi
  • 45
  • 2
  • 8
0
votes
1 answer

How to sign XML using private key contained in smartcard for a web application?

I was looking for a solution to sign XML using unexportable private key (this require passphrase/secret password to be informed by user input for create the hash using it) contained in usb token (smartcard etc) for a web application. I have made a…
0
votes
2 answers

How To User XmlDsigEnvelopedSignatureTransform independent of SignedXml class

All the examples on the internet shows the usage of the XmlDsigEnvelopedSignatureTransform class as a part of the SignedXml class. I would like to use this class by itself. Just give it a nodeList get the result without the signature…
artsince
  • 1,022
  • 20
  • 36
0
votes
1 answer

xsd to xml tool with user input

Can someone suggest me a tool or converter in java which does the following (1) User will provide XSD file to Tool. (2) Tool will interpret XSD and present a screen to allow data entry (as per the types defined in XSD). (3) User will enter values…
0
votes
1 answer

Obtain Cert issuer X500 Principal name with xmlsec

I am trying to port a Java code that made some time ago to iOS, i compiled xmlsec with openssl and no xslt support. import java.security.cert.X509Certificate; X509Certificate cert =…
Josejulio
  • 1,286
  • 1
  • 16
  • 30
0
votes
1 answer

XMLSign verify from the cert inside the xml file

My code receives the saml response in xml format. I need to verify the signature to confirm that response is not tampered, and I also need to confirm that this is coming from a trusted source. (in a settings file I have cert thumbprint and…
Mug Developer
  • 183
  • 1
  • 2
  • 15
0
votes
1 answer

Xpath transformation not working in java

This is my xml document. I want to sign only the userID part using xml signature. I am using xpath transformation to select that particular element.
Ashwin
  • 12,691
  • 31
  • 118
  • 190
0
votes
1 answer

XSLT transform in xmlsignature form, a part of xmldocument?

I have a HTML page(A Form) where user will enter his details. Details to enter are NameagesalarystateCity Now when user enters all details and click Button then I will create xml file containing the user details like…
Rakesh
  • 43
  • 1
  • 2
  • 10
0
votes
1 answer

Signature method in xml signature

In signature method in xml signature you have specify in this format : SignatureMethod.RSA_SHA1 but when using normal signature you just do Cipher c1=Cipher.getInstance("RSA"); So what is the difference between these two?
Ashwin
  • 12,691
  • 31
  • 118
  • 190
-1
votes
2 answers

Signing XML Document with Timestamp

I am in the process of setting up a service allowing to sign XML documents, for that I use the JAVA XmlSignature class. My question is how I can add a timestamp token to this signature ?
Mehdi
  • 99
  • 2
  • 10
-1
votes
1 answer

Cannot resolve element with ID while signing a part of SOAP REQUEST X509

I had the following error while trying to sign a part of SOAP Request : org.apache.xml.security.utils.resolver.ResourceResolverException: Cannot resolve element with ID _53ea293168db637b15e2d4d7894 at…
-1
votes
1 answer

Questions on Java XML Digital Signature

I need to digitally sign an XML document. The requirement given is that the input is an XML file and a private key. The signing should use SHA256/RSA-2048, and the signature should be Enveloping. I have come up with the following method to do just…
user3573403
  • 1,780
  • 5
  • 38
  • 64
-1
votes
1 answer

Signing Xml elements in same document with different keys

Business Scenario: An Update can contain packages. A Package can contain changes. Each package must be approved by somebody. After approval, a package may not be changed. To be executed, an Update must have 100% approved packages. Development…
nvoigt
  • 75,013
  • 26
  • 93
  • 142
-2
votes
1 answer

Xades-Bes convert to Xades-T

How can I do convert XAdES-BES to XAdES-T. I use Xades4j library. I have a timestamp account. My SignerBes.class package xades4j.production; import java.security.PrivateKey; import java.security.cert.X509Certificate; import…
user2496352
1 2 3
27
28