HomeSecurity Page 6 - Safeguarding the Identity and Integrity of XML Messages
XML Signature Processing - Security
XML Signature and XML Encryption, two of the three major pillars of the WS-Security standard, are so predominant in current thinking about Web Services Security that some people mistake them as the only strategy for securing Web services. This is really not the case at all. Read more in this chapter from Securing Web Services with WS-Security, by Rosenberg and Remy (ISBN 0672326515, SAMS, 2004).
We have reviewed at a high level the XML Signature elements. Now let's review how an XML Signature is created and then subsequently verified before we go into each element in more detail. This process is actually relatively straightforward. The basic steps are described in the following sections. (Note that unless you are writing a signature processing engine, you won't be performing this process yourself. This description is provided mainly so that you understand what is going on under the covers.)
XML Signature Generation
XML Signature generation is broken down into two components: Reference generation and Signature generation.
Reference Generation
When generating an XML Signature, an XML Signature processing engine first creates all the References. This process involves iterating through all the data objects that are to be signed and calculating their digest value. This basic process is as follows:
Obtain the resource specified by the Reference URI or, if not specified, as determined by the application. Note that seeing XML Signatures that do not use that Reference element to refer to what is being signed is rare; however, the specification allows for the possibility that what is being signed is known from the context of the situation and therefore does not have to be specified.
In the example earlier, the reference http://www.foo.com/securePage.html would be dereferenced.
Apply the Transforms.
Transforms were used in the earlier example. A simple Transform might be an XPath statement that causes the signature to apply only to a part of an XML document. We describe Transforms in more detail later in the chapter.
Calculate the Digest using the DigestMethod specified. This step results in the creation of the DigestValue element.
Create the Reference element, including all the sub-elements described previously.
At the end of Reference generation, the XML Signature processing engine will have everything necessary to generate the Reference element. In the simple example used earlier, this looks like Listing 4.9.
After all the Reference elements are created, the XML processing engine can create the Signature itself. To do this, it must gather all the information necessary to create the SignedInfo element, which is what is actually signed in an XML Signature. Here are the steps:
Create the SignedInfo element itself, including the Reference objects created in Reference generation and the CanonicalizationMethod, SignatureMethod, and DigestMethod. The information in SignedInfo is what is actually signed. Listing 4.10 shows the SignedInfo from the earlier example.
Canonicalize SignedInfo using the CanonicalizationMethod specified. We talk in detail about canonicalization later, but suffice it to say that whenever XML is being signed, it needs to be "normalized" before creating the hash and actually signing the SignedInfo information.
Using the output from the canonicalization algorithm, create a hash of the SignedInfo element using the specified DigestMethod.
Calculate the SignatureValue using the algorithm specified in SignatureMethod against the hashed, canonicalized SignedInfo element that was calculated in step 3. Listing 4.11 shows the SignatureValue element from the earlier example:
Bundle the SignedInfo, SignatureValue, KeyInfo (if supplied), and Object (if necessary) into the Signature element.
You now have an XML Signature. The key point to remember here is that the SignedInfo element is what is really being signed, not the direct resource(s) targeted by the Reference URI(s). Of course, because a digest of the target URI(s) is included in the SignedInfo element, it is being indirectly signed along with the information about the signature in the SignedInfo element.
This chapter is from Securing Web Services Security with WS-Security, by Jothy Rosenberg and David Remy (Sams, 2004, ISBN: 0672326515). Check it out at your favorite bookstore today.