Digital signature for XML documents (XML signature) including XaDES

13. April 2023

XML – DSig – XaDES

XML default information

XML is a so-called markup language and is used to structure data. XML schemas can be used to specify certain XML-based data formats (e.g. web interface for XML invoices).
A special feature of XML is that one and the same XML document can have multiple physical (=byte) representations. An example:

test1.xml:
<?xml version=”1.0″ encoding=”UTF-8″ ?>
<hello>Hello World!</hello>

test2.xml:
<?xml version=”1.0″ encoding=”ISO-8859-15″ ?>
<hello>Hello World!</hello>

Although test1.xml and test2.xml have different file sizes, from an XML perspective they are one and the same file. If you simply signed test1.xml as a file, the signature for test2.xml would no longer be valid. While this doesn’t seem like a big problem looking at these 2 files, when you consider that XML is designed to be passed from machine to machine and evaluated in between, the problem becomes apparent. If a machine reads the ISO-8859-15 encoded file, evaluates it, and then outputs it again UTF-8 encoded in order to hand it over to the next processing application, the signature becomes invalid. Although only XML transformations have taken place that affect the content of the document Don’t change.

This issue can be compared with ASN.1, where DER was introduced for this reason – semantically identical data is mapped in the same way at the byte level.

With XML there is also a technology that creates the same physical representation from semantically the same XML documents: Canonical XML (C14n).

“DSig” is the W3C XML default signature

After the so-called canonicalization, an XML document is ready to be signed. Again, this could theoretically happen in a number of ways, but the most obvious is to use the W3C’s flexible “XML-Signature Syntax and Processing” standard (DSig).

This standard is so flexible that it is not only possible to sign XML documents with it, but any documents. The main point of the standard is actually that the signature is stored in XML format – no matter what type of data is signed with it.

There are 3 different ways to sign with DSig: Enveloping, Enveloped and Detached. Enveloping and enveloped signatures are primarily applied to XML documents, with the signature coexisting with the XML data in the same XML file. All document types can be signed with a detached signature; the signature is saved in a separate XML file. In principle, any number of documents can be signed at once with XML DSig – they only have to be integrated with the ds:Reference tag.

Sign the following XML file (/home/gast/test2.xml):

<invoice>
<recipient>
<firstname>Daniel</first name>
<surname>Weller</surname>
</recipient>
</invoice>

Enveloped Signature:
<invoice>
<recipient>
<firstanme>Daniel</firstname>
<surname>Weller</surname>
</recipient>
<ds:Signature xmlns:ds=”http://www.w3.org/2000/09/xmldsig#”>
<ds:SignedInfo>
<ds:CanonicalizationMethod Algorithm=”http://www.w3.org/TR/2001/REC-xml-c14n-20010315″></ds:CanonicalizationMethod>
<ds:SignatureMethod Algorithm=”http://www.w3.org/2000/09/xmldsig#rsa-sha1″></ds:SignatureMethod>
<ds:Reference URI=””>
<ds:Transforms>
<ds:Transform Algorithm=”http://www.w3.org/2000/09/xmldsig#enveloped-signature”></ds:Transform>
<ds:Transform Algorithm=”http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments”></ds:Transform>
</ds:Transforms>
<ds:DigestMethod Algorithm=”http://www.w3.org/2000/09/xmldsig#sha1″></ds:DigestMethod>
<ds:DigestValue>YHkJTgkmev7VDyv1/Iiqm6RMRYk=</ds:DigestValue>
</ds:Reference>
</ds:SignedInfo>
<ds:SignatureValue>
C377H6bQoX39eNFxcdB0GQ/CMMxstEsErhK91CHCnsYnLr+9DZd6Wv+KwdlyINtiYWInBGJJzjPg
W2dp7acCbZYO1lt60qYlnZYTvoCpC1JW9KQhkLg0h5AiRegBJqPj7h+gz6lYrZ1g3kWxg0ZzUEmB
dT0yUjwhp9SqKRoiUXQ=
</ds:SignatureValue>
<ds:KeyInfo>
<ds:X509Data>
<ds:X509Certificate>
MIIFCzCCA/OgAwIBAgICAPAwDQYJKoZIhvcNAQEFBQAwgcwxCzAJBgNVBAYTAkFUMRAwDgYDVQQI
EwdBdXN0cmlhMQ8wDQYDVQQHEwZWaWVubmExOjA4BgNVBAoTMUFSR0UgREFURU4gLSBBdXN0cmlh
biBTb2NpZXR5IGZvciBEYXRhIFByb3RlY3Rpb24xJTAjBgNVBAsTHEEtQ0VSVCBDZXJ0aWZpY2F0
aW9uIFNlcnZpY2UxGDAWBgNVBAMTD0EtQ0VSVCBBRFZBTkNFRDEdMBsGCSqGSIb3DQEJARYOaW5m
b0BhLWNlcnQuYXQwHhcNMDUwOTA2MDAwMDAwWhcNMDcwOTA2MTM0NjMzWjCBgTELMAkGA1UEBhMC
QVQxCjAIBgNVBAgT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atW3cBpxQO
4jAfxl8xqpX36e3QGXOiDPnYOJ3blmcOxZ3sNL15s+Iq6P9DPyLv/7L0La2FRh4gfWGEbh15BEfh
S65VdxR+LTr9prIt1FSTpl2qIO/nIs+6ouN6TQ6B2JUAeXXaMuQGxM7LNL4XcWVveOaC3oem+Ym7
c2omf3Sge5nRj6Eg7KYh5VCvy6Dhvk8AT25f2qimhXAyl1hMV3ESpZOJVxPqMSoQO8+hSlXbLPsC
MWk88fnm2YdRTU4RKVbmCrfjvrFO6Rvx1/3AaJQ7gFJdbmLUCOm3LUc=
</ds:X509Certificate>
</ds:X509Data>
<ds:KeyValue>
<ds:RSAKeyValue>
<ds:Modulus>
si4csbc69/NYQqm9X1VdLcgPf2nkfDgi8C4JDKji3UWoNISFA8UzuNvk65Hfm9ZNaBXK5E/sE7Bg
CuvNiTKDlyg9u0iJwKqboWoSTvSvQrLcADBtqD0wl0K1y8mF1Dra0CInPIMC/x0tJSpDs6vwSKSR
5d6yIgH6YNjBXx1Lqvc=
</ds:Modulus>
<ds:Exponent>AQAB</ds:Exponent>
</ds:RSAKeyValue>
</ds:KeyValue>
</ds:KeyInfo>
</ds:Signature></invoice>

Don’t have a digital signature yet? Order now!

Enveloping Signature:

<ds:Signature xmlns:ds=”http://www.w3.org/2000/09/xmldsig#”>
<ds:SignedInfo>
<ds:CanonicalizationMethod Algorithm=”http://www.w3.org/TR/2001/REC-xml-c14n-20010315″></ds:CanonicalizationMethod>
<ds:SignatureMethod Algorithm=”http://www.w3.org/2000/09/xmldsig#rsa-sha1″></ds:SignatureMethod>
<ds:Reference URI=”#5pg5d8xpho”>
<ds:Transforms>
<ds:Transform Algorithm=”http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments”></ds:Transform>
</ds:Transforms>
<ds:DigestMethod Algorithm=”http://www.w3.org/2000/09/xmldsig#sha1″></ds:DigestMethod>
<ds:DigestValue>FJw+7uwssGSno6pC01roT5pCrOE=</ds:DigestValue>
</ds:Reference>
</ds:SignedIn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UzuNvk65Hfm9ZNaBXK5E/sE7Bg
CuvNiTKDlyg9u0iJwKqboWoSTvSvQrLcADBtqD0wl0K1y8mF1Dra0CInPIMC/x0tJSpDs6vwSKSR
5d6yIgH6YNjBXx1Lqvc=
</ds:Modulus>
<ds:Exponent>AQAB</ds:Exponent>
</ds:RSAKeyValue>
</ds:KeyValue>
</ds:KeyInfo>
<ds:Object Id=”5pg5d8xpho”><invoice>
<recipient>
<firstname>Daniel</firstname>
<surname>Weller</surname>
</recipient>
</invoice></ds:Object>
</ds:Signature>

The big difference between these two formats is that for the enveloped signature the reference is URI=”” – meaning it refers to the entire document (excluding the content of the signature tag), while for the enveloping signature the reference is URI=”# 5pg5d8xpho” is. So this reference refers to the same document, specifically to the element with the id “5pg5d8xpho”. This element is the object element in which the data to be signed is packaged.
So these reference tags make it possible to determine exactly what the signature refers to: whole XML documents, parts of XML documents, non-XML data.
It is also possible to sign a section of an XML file defined using an XPath expression – the possibilities are virtually endless.

Detached Signature

<ds:Signature xmlns:ds=”http://www.w3.org/2000/09/xmldsig#”>
<ds:SignedInfo>
<ds:CanonicalizationMethod Algorithm=”http://www.w3.org/TR/2001/REC-xml-c14n-20010315″></ds:CanonicalizationMethod>
<ds:SignatureMethod Algorithm=”http://www.w3.org/2000/09/xmldsig#rsa-sha1″></ds:SignatureMethod>
<ds:Reference URI=”file:///home/gast/test2.xml”>
<ds:Transforms>
<ds:Transform Algorithm=”http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments”></ds:Transform>
</ds:Transforms>
<ds:DigestMethod Algorithm=”http://www.w3.org/2000/09/xmldsig#sha1″></ds:DigestMethod>
<ds:DigestValue>YHkJTgkmev7VDyv1/Iiqm6RMRYk=</ds:DigestValue>
</ds:Reference>
</ds:SignedInfo>
<ds:SignatureValue>
bdGQ7KXzwCESRRMW49Wd+Fg3LPpzs7KKjGwQfnr0EYMVqku75HaLoxjtssGzwAylvemQEkIiEhIO
szZeH/LeM97e4knNwNSXN4Wor2djqQFQ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=
</ds:Modulus>
<ds:Exponent>AQAB</ds:Exponent>
</ds:RSAKeyValue>
</ds:KeyValue>
</ds:KeyInfo>
</ds:Signature>

The Detached Signature listed signs the same document as the previous examples, only this time the XML data to be signed is included via the Reference URI file:///home/gast/test2.xml – they are therefore in a different file. It is therefore obvious that when using detached signatures, the data to be signed is stored in such a way that it can always be reached via the same URI – otherwise the signature loses its validity.

XML-Addon for qualified Signatures(XAdES)

Qualified XML signatures use the extension (XAdES) in different variants to represent the qualification properties.

You might be interested in that

What are the costs of not going paperless?

What are the costs of not going paperless?

While digitization reached almost every aspect of daily work, the necessity for handwritten signatures in B2B environments preserves printing paper its crucial role – and incurs costs. However, by implementing e-signatures, businesses can reduce expenses, streamline processes, and contribute to a more sustainable...

read more
Sign and encrypt emails using an Apple iPhone

Sign and encrypt emails using an Apple iPhone

User guide for signing and encrypting emails with the GLOBALTRUST CLIENT certificate on your Apple iPhoneAs of May 10, 2023 1 Basic 1.1 Goals of this document A step-by-step guide on how to add the certificate to your iPhone to then sign and/or encrypt emails. This guide was created for an Apple iPhone (iOS version:...

read more