W3C

XML-Signature XPath Filter 2.0

W3C Working Draft 25 April 2002

This version:
http://www.w3.org/TR/2002/WD-xmldsig-filter2-20020425/
Latest version:
http://www.w3.org/TR/xmldsig-filter2/
Previous version:
n/a
Authors/Editors:
John Boyer, PureEdge Solutions Inc., <jboyer@PureEdge.com>
Merlin Hughes, Baltimore Technologies Ltd., <merlin@baltimore.ie>
Joseph Reagle, W3C, <reagle@w3.org>

Abstract

XML Signature [XML-DSig] recommends a standard means for specifying information content to be digitally signed and for representing the resulting digital signatures in XML. Some applications require the ability to specify a subset of a given XML document as the information content to be signed. The XML Signature specification meets this requirement with the XPath transform. However, this transform can be difficult to implement efficiently with existing technologies. This specification defines a new XML Signature transform to facilitate the development of efficient document subsetting technologies that interoperate under similar performance profiles.

Status of this document

This is the first publication for the "Signature Filter Transform" Working Draft from the IETF/W3C XML Signature Working Group (Activity Statement). This specification defines an alternative to behaviour of the XPath transform of the XML Signature Recommendation [XML-DSig]. The goal is to (1) more easily specify XPath transforms and (2) more efficiently process those transforms. This specification has already received a large amount of discussion and implementation within the Working Group. We hope to move to and through Last Call and then Candidate Recommendation very quickly.

Publication of this document does not imply endorsement by the W3C membership. This is a draft document and may be updated, replaced, or obsoleted by other documents at any time. It is inappropriate to cite a W3C Working Draft as anything other than a "work in progress." Please send comments to the editors and cc: the list w3c-ietf-xmldsig@w3.org (archives).

Patent disclosures relevant to this specification may be found on the Working Group's patent disclosure page in conformance with W3C.

A list of current W3C working drafts can be found at http://www.w3.org/TR/.

Table of Contents

  1. Introduction
  2. Terminology
  3. Specification of Signature Filter Transform
    1. Algorithm Identifier
    2. Syntax of Signature Filter Transform
    3. Input and Evaluation Context of Signature Filter Transform
    4. Processing Model of Signature Filter Transform
  4. Examples of Signature Filter Transform
  5. References
  6. Acknowledgements

1. Introduction

The XML Recommendation [XML] specifies the syntax of a class of objects called XML documents. The Namespaces in XML Recommendation [XML-NS] specifies additional syntax and semantics for XML documents. The XML Signature Recommendation [XML-DSig] defines standard means for specifying information content to be digitally signed, including the ability to select a portion of an XML document to be signed using an XPath transform.

This specification describes a new signature filter transform that, like the XPath transform [XML-DSig, section 6.6.3], provides a method for computing a portion of a document to be signed. In the interest of simplifying the creation of efficient implementations, the architecture of this transform is not based on evaluating an XPath expression for every node of the XML parse tree (as defined by the XPath data model [XPath]). Instead, the XPath expression in this transform is used to identify a set of nodes that, along with all nodes having an ancestor in the identified set, is used to transform the input node set by set intersection, subtraction, or union. The principal differences from the XPath transform are:

As with the original XPath transform, the primary purpose of this transform is to ensure that only specifically defined changes to the input XML document are permitted after the signature is affixed. This can be done by excluding precisely those nodes that are allowed to change once the signature is affixed, and including all other input nodes in the output. It is the responsibility of the signature filter transform author to ensure that nodes are not excluded which could affect the interpretation of the transform output in the application context.

Consider the motivating scenario where an application wishes to affix two enveloped signatures signatures to the document; any other change to the document must cause the signatures to be invalid. When the application creates the first signature that signature is automatically omitted from its own digest calculations. However, it will also be necessary to exclude the subsequent (second) signature element from the digest calculations of the first signature. This specification can be used to efficiently satisfy this requirement using the set subtraction operation.

This transform also supports the ability to specify a set of nodes that will be included in a signature, with all non-specified nodes being excluded. This formulation is useful for isolating a portion of a document, such as a chapter of a document, or a payload in a protocol message, and can be expressed using the set intersection operation.

Complete familiarity with the first XML Signature XPath Transform [XML-DSig, section 6.6.3] is required.

2. Terminology

The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in RFC 2119 [Keywords].

The XPath 1.0 Recommendation [XPath] defines the term node-set as "(an unordered collection of nodes without duplicates)" and specifies a data model for representing an input XML document as a set of nodes of various types (element, attribute, namespace, text, comment, processing instruction, and root).

An input document is the document that contains all the nodes available to processing by this transform. A document subset is a portion of an XML document indicated by an XPath node-set that, which may not include all of the nodes in the document. For example, the input-node set is a collection of XPath nodes from the input document that is passed as a parameter to this transform.

A subtree rooted by a given node is a document subset containing the given node and every node having the given node as an ancestor. An intersect filter is a signature filter transform whose output node-set contains only those nodes from the input node set that are in the subtrees identified by a given XPath expression. A subtract filter is a signature filter transform whose output node-set contains only those nodes from the input node set that are not in the subtrees identified by a given XPath expression. A union filter is a signature filter transform whose output node set contains all those nodes in the input node set or the subtrees identified by a given XPath expression.

The XML Signature Recommendation [XML-DSig] defines a reference as a sequence of steps performed to obtain an octet stream to be digitally signed. A transform is an identified algorithm to be used as a step in the reference processing model. A transform takes an octet stream or XPath node-set as input, and it produces an octet stream or XPath node-set as output (the reference processing model automatically converts the final output to an octet stream if it is an XPath node-set).

3. Specification of Signature Filter Transform

3.1 Algorithm Identifier

The XML Signature Recommendation [XML-DSig] uses a URI [URI] to identify each algorithm to be performed when creating or validating a signature. The signature filter transform is identified as follows:

Algorithm Identifier
http://www.w3.org/2002/04/xmldsig-filter2

3.2 Syntax of Signature Filter Transform

The signature filter transform shall be represented by an element named XPath. The content of XPath is character data containing an XPath expression. The XPath has an attribute named Filter whose possible values are intersect, subtract, and union. The Filter attribute indicates the set operation that is performed by this transform; set intersection, subtraction, or union, respectively. The following is an example of markup for a signature filter that signs the entire input node set except for elements with identifier foo and bar (and all nodes with one of those elements as an ancestor):

   <XPath Filter="subtract"
    xmlns="http://www.w3.org/2002/04/xmldsig-filter2">
      id("foo") | id("bar")
   </XPath>
   Schema Definition:  

   <?xml version="1.0" encoding="utf-8"?>
   <!DOCTYPE schema
    PUBLIC "-//W3C//DTD XMLSchema 200102//EN" "http://www.w3.org/2001/XMLSchema.dtd"
   [
     <!ATTLIST schema
       xmlns:xx CDATA #FIXED 'http://www.w3.org/2002/04/xmldsig-filter2'>
     <!ENTITY xx 'http://www.w3.org/2002/04/xmldsig-filter2'>
     <!ENTITY % p ''>
     <!ENTITY % s ''>
    ]>

   <schema xmlns="http://www.w3.org/2001/XMLSchema"
           xmlns:xx="http://www.w3.org/2002/04/xmldsig-filter2"
           targetNamespace="http://www.w3.org/2002/04/xmldsig-filter2"
           version="0.1" elementFormDefault="qualified">

   <element name="XPath"
            type="xx:XPathType"/>
   <complexType name="XPathType" content="textOnly">
     <attribute name="Filter">
       <simpleType>
         <restriction base="NOTATION">
           <enumeration value="intersect"/>
           <enumeration value="subtract"/>
           <enumeration value="union"/>
         </restriction>
       </simpleType>
     </attribute>
   </complexType>

   </schema>
   DTD:
   <!ELEMENT XPath    (#PCDATA) >
   <!ATTLIST XPath
      Filter         (intersect|subtract|union) #REQUIRED >

3.3 Input and Evaluation Context of Signature Filter Transform

The input required by this transform is an XPath node-set over the input document. If the input document is an octet stream, then the application MUST convert the octet stream to an XPath node-set that contains all of the document nodes (including comment nodes). The XPath evaluation context for the node-set will be:

The function here() is defined as follows:

Function: node-set here()

The here function returns a node-set containing the attribute or processing instruction node or the parent element of the text node that directly bears the XPath expression. This expression results in an error if the containing XPath expression does not appear in the same XML document against which the XPath expression is being evaluated.

3.4 Processing Model of Signature Filter Transform

Using the aforementioned evaluation context, the signature filter transform evaluates the XPath expression appearing in the character content of the XPath element. The result is a node-set S. The output node-set O is computed using S, and the input node set I, as follows:

In this processing model, the conversion from a subtree interpretation of the XPath expression to a node-set containing all nodes that must be used during the set operation is described explicitly. Implementors may find it more efficient to use an alternative representation, such as a set of subtree roots, when performing the operations. In particular, it should be possible to implement common set operations to be linear in the output document size, rather than the input document size.

4. Examples of Signature Filter Transform

The example below illustrates one way to create an enveloped signature with the signature filter transform. The function here identifies the XPath element, and the subsequent location path obtains the nearest ancestor Signature element. Due to the subtract value of the Filter attribute, the output of the signature filter transform is a node-set containing every node from the input node set except the nodes in the subtree rooted by the Signature element containing the example signature filter transform below.

   <XPath Filter="subtract"
    xmlns="http://www.w3.org/2002/04/xmldsig-filter2"
    xmlns:dsig="http://www.w3.org/2000/09/xmldsig#">
      here()/ancestor::dsig:Signature[1]
   </XPath>

A suitable signature reference URI to use with this subtract filter would be URI="" (the entire signature document, without comments), URI="#xpointer(/)" (the entire signature document, with comments) or any same-document reference that includes the signature itself.

An example of an intersect filter is a signature that co-signs another signature. In this example, a Signature element identified by PrimaryBorrowSig must be signed. The XPath expression obtains the element node, and the transform expands the output node-set to contain all nodes from the input node set that are also in the subtree rooted by the element node.

   <XPath Filter="intersect"
    xmlns="http://www.w3.org/2002/04/xmldsig-filter2">
      id("PrimaryBorrowerSig")
   </XPath>

This type of intersect filter is useful for efficiently signing subsets of a document, whether this is the same document as the signature or an external document. For example, if the signature reference URI is URI="document.xml", then this document will be automatically parsed and just the identified element and its descendants will be signed.

Union filters are less common then the other two forms of filter, however they can be effectively utilized to include part of a document subtree that was removed by a previous transform, such as a subtract filter. For example, a union filter could be used to add an embedded signature object to the node set resulting from an enveloped signature transform (which normally removes the signature element and all its descendants). Such a reference would then exhibit characteristics of both an enveloped signature and an enveloping signature.

   <XPath Filter="union"
    xmlns="http://www.w3.org/2002/04/xmldsig-filter2">
      id("Object-1")
   </XPath>

This filter could be utilized with a same-document reference, if preceded by an enveloped signature transform. In general, however, alternative solutions may be more appropriate; for example, using multiple signature references.

Finally, consider the following document which contains a same-document enveloped signature reference with three XPath filter transforms applied:

   <Document>
     <ToBeSigned>
       <!-- comment -->
       <Data />
       <NotToBeSigned>
         <ReallyToBeSigned>
           <!-- comment -->
           <Data />
         </ReallyToBeSigned>
       </NotToBeSigned>
     </ToBeSigned>
     <ToBeSigned>
       <Data />
       <NotToBeSigned>
         <Data />
       </NotToBeSigned>
     </ToBeSigned>
     <dsig:Signature
      xmlns:dsig="http://www.w3.org/2000/09/xmldsig#"
      xmlns:dsig-xpath="http://www.w3.org/2002/04/xmldsig-filter2">
       <dsig:SignedInfo>
         ...
         <dsig:Reference URI="">
           <dsig:Transforms>
             <dsig:Transform 
              Algorithm="http://www.w3.org/2002/04/xmldsig-filter2">
               <dsig-xpath:XPath Filter="intersect"> //ToBeSigned </dsig-xpath:XPath>
             </dsig:Transform>
             <dsig:Transform 
              Algorithm="http://www.w3.org/2002/04/xmldsig-filter2">
               <dsig-xpath:XPath Filter="subtract"> //NotToBeSigned </dsig-xpath:XPath>
             </dsig:Transform>
             <dsig:Transform 
              Algorithm="http://www.w3.org/2002/04/xmldsig-filter2">
               <dsig-xpath:XPath Filter="union"> //ReallyToBeSigned </dsig-xpath:XPath>
             </dsig:Transform>
           </dsig:Transforms>
           ...
         </dsig:Reference>
       </dsig:SignedInfo>
       ...
     </dsig:Signature>
   </Document>

The intersect filter computes the intersection of the XPath-selected subtrees with the input node set. In this case, the input node set is the entire document with all comments removed, and the XPath expression evaluates to the two ToBeSigned elements; these are expanded to include all their descendents and intersected with the input node set:

     <ToBeSigned>
      
       <Data />
       <NotToBeSigned>
         <ReallyToBeSigned>
          
           <Data />
         </ReallyToBeSigned>
       </NotToBeSigned>
     </ToBeSigned><ToBeSigned>
       <Data />
       <NotToBeSigned>
         <Data />
       </NotToBeSigned>
     </ToBeSigned>

The subtract filter computes the subtraction of the XPath-selected subtrees from the input node set. In this case, the XPath expression evaluates to the two NotToBeSigned elements; these are expanded to include all their descendents and subtracted from the input node set:

   <ToBeSigned>
      
           <Data />
      
     </ToBeSigned><ToBeSigned>
       <Data />
      
   </ToBeSigned>

Finally, the union filter computes the union of the XPath-selected subtrees with the input node set. In this case, the XPath expression evaluates to the ReallyToBeSigned element; this is expanded to include all its descendents and added to the input node set:

   <ToBeSigned>
      
       <Data />
         <ReallyToBeSigned>
           <!-- comment -->
           <Data />
         </ReallyToBeSigned>
     </ToBeSigned><ToBeSigned>
       <Data />
      
   </ToBeSigned>

Note that the node set includes a comment node that was stripped during dereferencing of the reference URI. The default reference processing model will still eliminate this during application of the default canonical XML algorithm (without comments) unless an alternative canonicalization transform is applied.

This signature filter does not provide any increased capability over the original XPath transform. For example, this reference could be replicated using the XPath transform as follows.

   <dsig:Reference URI="#xpointer(/)">
     <dsig:Transforms>
       <dsig:Transform 
        Algorithm="http://www.w3.org/TR/1999/REC-xpath-19991116">
         <dsig:XPath Filter="intersect">
           (not (self::comment()) and
            ancestor-or-self::ToBeSigned and
            not (ancestor-or-self::NotToBeSigned))
            or ancestor-or-self::ReallyToBeSigned
         </dsig:XPath>
       </dsig:Transform>
     </dsig:Transforms>
     ...
   </dsig:Reference>

The advantage of the signature filter transform over the XPath transform is that the latter requires evaluation of a potentially-complex expression against every node in the input set, which has proved costly in practice for many useful operations, whereas the former requires evaluation of simple XPath expressions and then the execution of some basic set operations, which can be implemented significantly more efficiently.

5. References

Keywords
RFC 2119. Key words for use in RFCs to Indicate Requirement Levels. Best Current Practice. S. Bradner. March 1997.S. Bradner. March 1997.
http://www.ietf.org/rfc/rfc2119.txt
URI
RFC 2396 . Uniform Resource Identifiers (URI): Generic Syntax. T. Berners-Lee, R. Fielding, L. Masinter. August 1998.
http://www.ietf.org/rfc/rfc2396.txt
XML
Extensible Markup Language (XML) 1.0 (Second Edition). W3C Recommendation. T. Bray, E. Maler, J. Paoli, C. M. Sperberg-McQueen. October 2000.
http://www.w3.org/TR/2000/REC-xml-20001006 .
XML-C14N
Canonical XML. W3C Recommendation. J. Boyer. March 2001.
http://www.w3.org/TR/2001/REC-xml-c14n-20010315
http://www.ietf.org/rfc/rfc3076.txt
XML DSig
XML-Signature Syntax and Processing. IETF Draft/W3C Proposed Recommendation. D. Eastlake, J. Reagle, and D. Solo. 31 August 2001.
http://www.w3.org/TR/2001/PR-xmldsig-core-20010820/
XML-NS
Namespaces in XML. Recommendation. T. Bray, D. Hollander, and A. Layman. Janaury 1999.
http://www.w3.org/TR/1999/REC-xml-names-19990114/
XPath
XML Path Language (XPath) Version 1.0 , W3C Recommendation. eds. James Clark and Steven DeRose. 16 November 1999. http://www.w3.org/TR/1999/REC-xpath-19991116.

6. Acknowledgements (Informative)

The following people provided valuable feedback that improved the quality of this specification: