Copyright © 2001 W3C® (MIT, INRIA, Keio), All Rights Reserved. W3C liability, trademark, document use and software licensing rules apply.
This document specifies a process for encrypting data and representing the result in XML. The data may be arbitrary binary data, an XML document, or an XML element. When an element is encrypted, the element is replaced with an XML Encryption element. Otherwise, the enryption element serves as the root of the new document.
This is an editors' copy that has absolutely no standing.
This document specifies a process for encrypting data and representing the result in XML. The data may be arbitrary binary data, an XML document, or an XML element. When an element is encrypted, the element is replaced with an XML Encryption element. Otherwise, the enryption element serves as the root of the new document.
This specification uses XML Schemas [XML-schema] to describe the content model.
The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this specification are to be interpreted as described in RFC2119 [KEYWORDS]:
"they MUST only be used where it is actually required for interoperation or to limit behavior which has potential for causing harm (e.g., limiting retransmissions)"
Consequently, we use these capitalized keywords to unambiguously specify requirements over protocol and application features and behavior that affect the interoperability and security of implementations. These key words are not used (capitalized) to describe XML grammar; schema definitions unambiguously describe such requirements and we wish to reserve the prominence of these terms for the natural language descriptions of protocols and features. For instance, an XML attribute might be described as being "optional." Compliance with the XML-namespace specification [XML-NS] is described as "REQUIRED."
The design philosophy and requirements of this specification are addressed in the XML Encryption Requirements document [EncReq].
No provision is made for an explicit version number in this syntax. If a future version is needed, it will use a different namespace. The experimental XML namespace [XML-NS] URI that MUST be used by implementations of this (dated) specification is:
xmlns="http://www.w3.org/Encryption/2001/03/xmlenc#"
Additonally, this specification makes use of the XML Signature [XMLDSIG] namespace and schema definitions
xmlns:ds=http://www.w3.org/2000/09/xmldsig#
This namespace is also used as the prefix for algorithm identifiers used by this specification. While applications MUST support XML and XML namespaces, the use of internal entities [XML] or our "enc" XML namespace prefix and defaulting/scoping conventions are OPTIONAL; we use these facilities to provide compact and readable examples.
The contributions of the following working group members to this specification are gratefully acknowledged:
...
This section provides an overview and examples of XML Encryption syntax. The formal syntax is found in Core Encryption Syntax (section 3); the specific processing is given in Processing Rules (section 4).
Data that is encrypted with this specification is removed, encrypted, encoded, and replaced as part of the content of an EncryptedData's element. This element has the following structure:
<enc:EncryptedData Id="" Type=""> <enc:EncryptionMethod/>? <enc:KeyInfo> <enc:EncryptedKey/>? <enc:KeyRetrievalMethod/>? </enc:KeyInfo>? <enc:CipherData URI="">iamscrambled</enc:CipherData> </enc:EncryptedData>
This section could be interwoven in with an actual example very nicely, maybe those in the previous sectino 5. -- Reagle
EncryptedData replaces the part of an XML document that is encrypted, or serves as the root element of an XML document if a whole document (of any MIME type) is encrypted. In either case, the location of this element serves to clearly identify the location of the data that was encrypted and the location of the information necessary to decrypt it. EncryptedData will always contain either the CipherData as a base64 encoded octet sequence or a URI reference and transformation instructions necessary to obtain the CipherData as an octet sequence. The latter mechanism is provided for flexibility and to support scenarios such as the encryption of a binary content stream where it would be inefficient to include the stream content directly in an XML document.
The EncryptedData object may optionally contain information about how the CipherData may be decrypted. This can include the following:
To simplify encoding and processing, only a single CipherData may be included within an EncryptedData object. Also, it is implicit that all included information about the encryption key used will refer to the same key value.
To meet the needs of key applications, this specification supports encryption of:
This "NodeList" needs to be investigated with respect to our processing model and using InformationSet terminology, maybe those in the previous sectino 5. -- Reagle.
The type of data encrypted may be encoded as an attribute of the EncryptedData to aid the decryptor in processing it. If the data is an XML Element, it is implicit the decrypted Element replaces the EncryptedData object in a given XML Document context. Similarly, a decrypted NodeList replaces the EncryptedData object in a given XML Document. An external octet sequence is always treated as external data relative to any XML Document, i.e., there is no implied document transform to be applied when the data is decrypted.
Each EncryptedData object is assumed to be independent and there is no requirement for indicating linkage or ordering between EncryptedData objects. We do recognize that an encryptor may choose an approach in which decryption order and/or state propagation between EncryptedData objects is important. For example, one may use the output from one decryption as the IV input to a second decryption. Or, if one has two EncryptedData objects which reference doubly encrypted external data, then the decryption order is critical. In such cases, the encryptor may specify this information as part of the encryption method information.
Data transformations, such as canonicalization or compression, are outside the scope of this specification as the requirements are application dependent.
This section could be interwoven in with an actual example very nicely, maybe those in the previous sectino 5 -- Reagle
This specification's scope is limited to the (optional) conveyance of key information necessary to decrypt an EncryptedData. Anything beyond this simple exchange, (such as establishing trust relationships or negotiating pre-arranged secrets), is out of scope.
When specified, key sharing information is a first class object and encoded in a way that makes this obvious. For flexibility, we support specifying:
Depending upon the application, one may include one or more types of information within an Encrypted Data object. Typically, only one type of information will be necessary. All included key sharing information must refer to a single encryption key value. If encrypted key values for multiple recipients is included within an Encrypted Data object, we define a means of including hints as to which recipient is associated with an encrypted key value.
Specification of key attributes is based on the existing KeyInfo Element defined in [XMLDSIG]. If one is using an asymmetric encryption algorithm, then the Digital Signature defined KeyInfo is adequate. If using a symmetric key, then we support indirect key references based on a key name and/or key references. To facilitate use of key names, we provide a means of associating a name with an encrypted key value. For key references, we define a KeyRetrievalMethod to express a URI where the key may be located. This similar to ds:RetrievalMethod but the type is always of EncryptedKey. Direct inclusion of a clear text symmetric key value is not relevant in this context and is not supported.
This section could be interwoven in with an actual example very nicely, maybe those in the previous sectino 5. -- Reagle
When specifying an encrypted symmetric key value, an EncryptedKey element is used. This is distinct from, and uses a different encoding from Encrypted Data, to avoid context dependent processing. The Encrypted Key object always includes the encrypted symmetric key CipherData as a base64 encoded octet sequence. In addition, the Encrypted Key object may include:
A list of references to other Encrypted Key objects whose CipherData is encrypted with this symmetric key
The latter capability is included primarily to support key update based on existing shared symmetric keys.
The preceding sections identified some of the rules for combining encrypted data and key sharing information. This section provides a fuller treatment of this issue.
EncryptedData may include an optional information about the key used to encrypt the CipherData. This can be either in the form of a KeyInfo element referencing a known key an Encrypted Key object or both.
An XML document may contain any number of Encrypted Key objects, either as children of an Encrypted Data object, or as independent objects. An Encrypted Key object may not be a child of another Encrypted Key object. The Encrypted Key object may include a KeyInfo Element with information to help the recipient decrypt the key CipherData.
An Encrypted Key object may include references to Encrypted Data object or other Encrypted Key objects. In both cases, the reference indicates that the referenced object CipherData is encrypted using the key value contained with the referencing Encrypted Key object. As depicted below, references in the Encrypted Key-1 object indicate that the Encrypted Data-A CipherData and Encrypted Key-2 CipherData are encrypted using the symmetric key value in Encrypted Key-1.
An XML document may contain zero or more Encrypted Data objects. However, EncryptedData
can not be the parent or child of another EncryptedData element -- though the data
encrypted by this element can be anything, including EncryptedData and EncryptedKey
elements (super-encryption). During super-encryption of an EncryptedData or EncryptedKey
element, one must encrypt the entire element. Encrypting only the content of these
elements, or encrypting selected child elements, will result in invalid XML against the
schema defined in this specification.
For example, consider the following:
<EncryptedData Id='1'> <KeyInfo/>? <CipherData>encypteddata</CipherData> <EncryptedData>
A valid super-encryption of this will result in
<EncryptedData Id='2'> <KeyInfo/>? <CipherData>newencypteddata</CipherData> <EncryptedData>
where 'newencrypteddata' is the base64 encoding of the encrypted octet sequence resulting from encrypting the EncryptedData element with Id='1'.
Alternately, if one encrypted only the CipherData element of the original EncryptedData the result would be the invalid XML:
<EncryptedData Id='1'> <KeyInfo/>? <CipherData> <EncryptedData Id='3'> <KeyInfo/>? <CipherData>differentencypteddata</CipherData> </CipherData> </EncryptedData> </EncryptedData>
This section provides a detailed description of the syntax and features for XML Encryption. Features described in this section are mandatory to implement unless otherwise noted. The syntax is defined via [XML-Schema] with the following XML preamble, declaration, internal entity, and import:
<?xml version='1.0'?> <!DOCTYPE schema PUBLIC "-//W3C//DTD XMLSCHEMA 200010//EN" "http://www.w3.org/2000/10/XMLSchema.dtd" [ <!ATTLIST schema xmlns:ds CDATA #FIXED 'http://www.w3.org/2000/09/xmldsig#'> <!ATTLIST schema xmlns:xenc CDATA #FIXED 'http://www.w3.org/2001/02/xmlenc#'> ]> <schema xmlns='http://www.w3.org/2000/10/XMLSchema' version='0.1' xmlns:ds='http://www.w3.org/2000/09/xmldsig#' xmlns:xenc='http://www.w3.org/Encryption/2001/03/xmlenc#' targetNamespace='http://www.w3.org/Encryption/2001/03/xmlenc#' elementFormDefault='qualified'> <import namespace='http://www.w3.org/2000/09/xmldsig#' schemaLocation='xmldsig-core-schema.xsd'/>
EncryptedType is the abstract type from which EncryptedData and EncryptedKey are derived. While these two latter element types are very similar with respect to their content models, a syntactical distinction is useful to processing.
<complexType name='EncryptedType' abstract='true'> <sequence> <!-- this shows an enc:element being of ds:type --> <element name='EncryptionMethod' type='ds:DigestMethodType' minOccurs='0'/> <!-- this shows a enc:type being extended from ds:type --> <element ref='xenc:KeyInfo' minOccurs='0'/> <element ref='xenc:CipherData'/> </sequence> <attribute name='Id' type='ID' use='optional'/> </complexType>
EncryptionMethod is an optional element that describes the encryption algorithm applied to the CipherData contained in this element. If the element is absent, the encryption algorithm assumed to be known by the recipient.
KeyInfo is an optional element, defined by [XMLDSIG], that carries information about the key used to encrypt the CipherData. The new elements defined by this specification that may appear a children of KeyInfo are described in the subsequent sections.
CipherData is a mandatory element that provides the encrypted data.
Id is an optional attribute providing for the standard method of assigning a string id to the element within the document context.
The CipherData is a mandatory element that provides the encrypted data. It may either
contain the encrypted octet sequence as base64 encoded text or provide a reference to an
external location (subject to the same processing rules as ds:TransformsType
)
containing the encrypted octet sequence.
<element name='CipherData' type='ds:CryptoBinary'/> or <element name="CipherData"> <complexType> <choice> <element ref="ds:transforms" minOccurs="0"/> </choice> </complexType> <attribute name="URI" type="uriReference" use="required"/> </element>
This isn't valid schema. We need a schema construct that has the content (or a child with the content) of CryptoBinary, *or* a set of transforms. -- Reagle/Dillaway.
The EncryptedData element is the core element in the syntax. Not only does its CipherData child contain the encrypted data, but it also the element that replaces the encrypted element, or serves as the new document root.
There are four different ways to define the key material to be used in decrypting the CipherData. In all cases, this information is contained within a KeyInfo element. They are:
<element name='EncryptedData' type="xenc:EncryptedDataType"/> <complexType name='EncryptedDataType'> <complexContent> <extension base='xenc:EncryptedType'> <attribute name='Type' type='uriReference' use='optional'/> </extension> </complexContent> </complexType>
Type is an optional attribute identifying type information about the decrypted content. Valid values for this attribute are:
This specification defines two elements that may be used as children of the ds:KeyInfo element. These are the EncryptedKey and KeyRetrievalMethod elements described in subsequent sections.
<element name='KeyInfo' type='xenc:KeyInfoType'/> <complexType name='KeyInfoType'> <complexContent> <extension base='ds:KeyInfoType'> <sequence> <element ref='xenc:KeyRetrievalMethod' minOccurs='0'/> </sequence> </extension> </complexContent> </complexType>
This is presently broken as validators will complain of ambigous content models. I'm working on understanding this, and it relates to the question of should create a derived enc:KeyInfoType element based in ds:KeyInfoType, create a enc:KeyInfo based on ds:KeyInfoType, or just use ds:KeyInfo? -- Reagle
The EncryptedKey element is used to transport encryption keys from the originator to a known recipient(s). The key value is always encrypted to the recipient(s). It may be used as a standalone XML document, be placed within an application document, or appear inside an EncryptedData element as a child of a KeyInfo element.
<element name='EncryptedKey' type='xenc:EncryptedKeyType'/> <complexType name='EncryptedKeyType'> <complexContent> <extension base='xenc:EncryptedType'> <sequence> <element ref='xenc:ReferenceList' minOccurs='0'/> </sequence> <attribute name='NameKey' type='string' use='optional'/> </extension> </complexContent> </complexType>
ReferenceList is an optional element containing pointers to data and keys encrypted using this key. The reference list may contain multiple references to EncryptedKey and EncryptedData elements. This is done using KeyReference and DataReference elements repectively. These are defined below.
NameKey is an optional attribute for associating a user readable name with the key value. This may then be used to reference the key using the KeyName element within KeyInfo. The same NameKey label, unlike an id label, may occur multiple times within a single document. The value of the key is to be the same in all EncryptedKey elements identified with the same NameKey label.
Recipient is an optional attribute that contains a hint as to which recipient this encrypted key value is intended for. Its contents are application dependent.
The KeyRetrievalMethod element provides a way to express a link from an EncryptedData element to the EncryptedKey element containing the key used needed to decrypt it. The element may occur multiple times within a KeyInfo element referring to different EncryptedKey objects containing the same key value but encrypted in different ways or for different recipients.
<element name='KeyRetrievalMethod' type="xenc:KeyRetrievalMethodType" substitutionGroup="ds:RetrievalMethod" /> <complexType name='KeyRetrievalMethodType'> <complexContent> <restriction base='ds:RetrievalMethodType'> <sequence> <element name="Transforms" type="ds:TransformsType" minOccurs="0"/> </sequence> <attribute name="URI" type="uriReference"/> <attribute name="Type" type="uriReference" use="fixed" value="http://www.w3.org/Encryption/2001/03/xmlenc#EncryptedKey"/> </restriction> </complexContent> </complexType>
KeyRetrievalMethod uses similar syntax and dereferencing behavior to the RetrievalMethod element in [XMLDSIG], except the type attribute is absent since an EncryptedKey element is the only legal result of following the reference.
ReferenceList is an element that contains pointers from a key to data or keys encrypted by the key.
<element name='ReferenceList'> <complexType> <sequence> <element name='DataReference' type='xenc:ReferenceType' minOccurs='0' maxOccurs='unbounded'/> <element name='KeyReference' type='xenc:ReferenceType' minOccurs='0' maxOccurs='unbounded'/> </sequence> </complexType> </element> <complexType name="ReferenceType"> <sequence> <any namespace='##other' minOccurs='0' maxOccurs='unbounded'/> </sequence> <attribute name='URI' type='uriReference' use='optional'/> </complexType>
DataReference elements are used to refer to EncryptedData objects that were encrypted using the key defined in the enclosing EncryptedKey element. Multiple DataReference elements can occur if multiple EncryptedData elements exist that are encrypted by the same key.
KeyReference elements are used to refer to EncryptedKey objects thata were encrypted using the key defined in the enclosing EncryptedKey element. Multiple KeyReference elements can occur if multiple EncryptedKey elements exist that are encrypted by the same key.
For both types of references one may optionally specify child elements to aid the recipient in retrieving the EncryptedKey and/or EncryptedData objects. These could include information such as XPath transforms, decompression transforms, or information on how to retrieve the objects from a document storage facility.
This section describes the operations to be performed as part of encryption and decryption processing.
For each data item or key to be encrypted:
For each item to be decrypted:
The application of both encryption and digital signatures over portions of an XML document can make subsequent decryption and signature verification difficult. In particular, when verifying a signature one must be know whether the signature was computed over the encrypted or unencrypted representation of elements.
A separate, but important, issue is introducing cryptographic vulnerabilities when combining digital signatures and encryption over a common XML element. Hal Finney has suggested that encrypting digitally signed data, while leaving the digital signature in the clear, may allow plaintext guessing attacks.
In accordance with the requirements document [EncReq] the interaction of encryption and signing is an application issue and out of scope of the specification. However, we make the following recommendations:
...
...
...