Integrity and Non-Repudiation: XML Signature

XML Signature is used to ensure message integrity on all or part of an XML document. The standard doesn't define new signature methods, but instead specifies how the digital signature technology we've already discussed can be used inside XML documents. As we've seen, digital signatures can be used to ensure message integrity by showing that data has not been changed through some error during transport or as the result of a malicious attack. Digital signatures also prevent a signer from repudiating a message. XML Signature is a foundational standard that is used by other standards we'll discuss in this chapter, such as SAML, because they are also based on XML.

Like any standard, XML Signature has options for numerous contingencies that make it seem complicated, but at its heart it is quite simple. An XML Signature is contained in a <Signature/> element and consists of three main parts:

Using the XML Signature standard, parts of a document can be signed, and multiple entities can sign the same or different parts of a single document.

The following example of an XML Signature shows all three parts:

    <Signature xmlns="http://www.w3.org/2000/09/xmldsig#">

     <SignedInfo Id="fizz">
      <CanonicalizationMethod
        Algorithm=
           "http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/>
      <SignatureMethod
        Algorithm="http://www.w3.org/2000/09/xmldsig#dsa-sha1" />
      <Reference
        URI="http://www.fizzco.com/news/2003/07/27.xml">
       <DigestMethod
         Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
       <DigestValue>f7dhfj38sdjdf89fjskfhweol=</DigestValue>
      </Reference>
     </SignedInfo>

     <SignatureValue>KLUR~HF=...Ax54</SignatureValue>

     <KeyInfo>
      <X509Data>
       <X509SubjectName>
         CN=Phil Windley,O=The Windley Group LLC,ST=Utah, C=US
       </X509SubjectName>
       <X509Certificate>
         MIID5jCCA0+gA...lVN
       </X509Certificate>
      </X509Data>
     </KeyInfo>

    </Signature>

Much of the example is self-explanatory. The signature method, digest method, and certificate data refer to the algorithms and formats that were described in Chapter 6 such as the X.509 standard; they are just enclosed in XML. Other elements require some explanation.

One such element is <CanonicalizationMethod/>. XML documents must be made canonical, because there is more than one way to represent a single base document in XML. As a simple example, consider that the element <foo/> is the same as <foo></foo>. Consequently, before the document can be signed, it has to be rendered in a canonical form so that the signatures match. Several canonization methods are available, and the <SignedInfo/> block specifies which was used.

This XML Signature used to sign the document is enclosed in the <SignatureValue/> element. You won't find the signed document here, however. The signature is applied to all or part of the XML document using the <Reference/> element. In the example, the <Reference/> element points to an XML document on http://www.fizzco.com by giving its URL. The <Reference/> element also specifies the digest method used to create the hash and its value.