This proposal defines a set of XPath 3.0 extension functions to perform cryptographic operations. It defines extension functions related to XML Digital Signature, to encryption and decryption, and to hash and digest messages. It has been designed to be compatible with XQuery 3.0 and XSLT 3.0, as well as any other standard based on XPath 3.0.

Introduction

Cryptography is the science of communicating in secret code, by conversion of data with the help of a key. In modern times, cryptography is necessary when communicating over any untrusted medium, particularly the Internet.

Encryption of data can be of two types: symmetric and asymmetric. Symmetric encryption means that the same key is used for encryption and decryption. Asymmetric encryption means that a message can be encrypted by using a key that is public, but the decryption can be made only by using a private key, which form a pair with the respective public key.

A related technique of cryptography is to apply a one-way hash or digest function to data; replicating the operation with the same data and function can check the integrity and authentication of the data.

Namespace conventions

The module defined by this document defines functions and elements in the namespace http://expath.org/ns/crypto. In this document, the crypto prefix, when used, is bound to this namespace URI.

Error codes are defined in the same namespace (http://expath.org/ns/crypto), and in this document are displayed with the same prefix, crypto.

Error management

Error conditions are identified by a code (a QName). When such an error condition is reached during the execution of the function, a dynamic error is thrown, with the corresponding error code (as if the standard XPath function error had been called).

Cryptographic Service Providers

Cryptographic providers provide cryptographic services, involving cryptographic operations (encryption, digital signatures, message digests, message authentication), generators and converters of cryptographic material and cryptographic objects (keystores or certificates) containing the cryptographic data. They can be implemented using software, hardware, or both.

Cryptographic services described by this specification
Cryptographic Service QName Cryptographic Service Description
crypto:hash See .
crypto:hmac See .

The crypto:list-providers function

This function lists the available cryptographic providers.

The crypto:providers-list element

The crypto:providers-list element represents the list of the available cryptographic providers:

The crypto:provider element

The crypto:provider element contains the name of an available cryptographic provider:

The crypto:list-services function

This function lists the cryptographic services a provider provides.

The crypto:services-list element

The crypto:services-list element represents the list of the available cryptographic services for a provider:

The crypto:service element

The crypto:service element contains details about an available cryptographic service:

Integrity and Authentication of Data

The crypto:hash function

This function generates a "message digest" of the input data, by using a cryptographic algorithm. It returns the hash value as a string.

The crypto:hmac function

HMAC (Keyed-Hashing for Message Authentication) is a mechanism for message authentication using cryptographic hash functions. HMAC can be used with any iterative cryptographic hash function, e.g. MD5 or SHA-1, in combination with a secret shared key. Typically, message authentication codes are used between two parties that share a secret key in order to validate information transmitted between these parties.

This function generates a message authentication code, based on the input message, by using a cryptographic algorithm and a secret key. It returns the hash-based message authentication code as base64 string.

Key Management

TBD.

The crypto:generate-key-pair function

This function generates a new pair of public and private cryptographic keys, to be used with a specific cryptographic algorithm.

The crypto:generate-secret-key function

This function generates a new secret key, to be used with a specific cryptographic algorithm.

The crypto:compare-keys function

The crypto:key-agrement function

The crypto:convert-key-specification-to-key-object, crypto:convert-key-object-to-key-specification function

Digital Signature

The XML Signature is a method of associating a key with referenced data (octets); it does not normatively specify how keys are associated with persons or institutions, nor the meaning of the data being referenced and signed. XML Signatures are applied to arbitrary digital content (data objects) via an indirection. Data objects are digested, the resulting value is placed in an element (with other information) and that element is then digested and cryptographically signed.

The crypto:generate-signature function

The function has its parameters passed as a map(xs:string, item()). If any of these parameters is missing, a default value will be used instead. After the function's signature, an example of parameters is given. The syntax for the $references parameter is inspired by [[xmldsig-core]].

Example of parameters:

The crypto:validate-signature function

This function validates an XML Digital Signature.

Encryption and Decryption

Encryption represents the process of conversion of data, by using a secret key (a cipher), in a form (called cipher text) that cannot be understood by unautorized persons.

The decryption represents the reverse process, of converting encrypted data back to plain text (original text).

There are two main types of encryption: symmetric encryption, when both parties, the sender and the receiver, use the same secret key, previously exchanged, and asymmetric encryption, when a key pair, consisting of a private key and a private key, is used, of which the public key is used by sender to encrypt a message that can only be decrypted by the receiver, who holds the private key of that key pair.

The crypto:encrypt function

This function encrypts data.

The crypto:decrypt function

This function decrypts data.

Secure Storing of Sensitive Keying and Data Material

A secure storage is a collection of CRLs, cryptographic keys, cryptographic certificates, cryptographic certificate chains, various secrets, and extensions. It may have different implementation, according to different cryptographic providers. Every entry has a unique alias name and can be protected by its own password.

The crypto:create-secure-store function

This function creates a secure store. It returns the store as xs:base64binary if successfully completed, empty sequence if not.

The crypto:load-secure-store function

This function loads a secure store in order to operate against it. It returns an xs:long representing the secure store handle.

The crypto:convert-secure-store function

This function converts a secure store from one format to another. It returns the converted store as xs:base64binary if successfully completed, empty sequence if not.

The crypto:get-secure-store-metadata function

This function gets metadata for a secure store. It returns a crypto:metadata element.

The crypto:metadata element

The crypto:metadata element contains metadata about a resource.

  • secure-store-type is the type of the secure store.

  • provider is the provider that generated the secure store.

  • aliases-list is the list of all the aliases in the secure store.

  • size is the number of entries in the secure store.

The crypto:add-entry function

This function adds an entry to a secure store. It returns true if successfully completed, false if not.

The crypto:get-entry function

This function gets an entry from a secure store. It returns the entry.

The crypto:delete-entry function

This function delets an entry from a secure store. It returns true if successfully completed, false if not.

The crypto:get-entry-metadata function

This function gets metadata for a secure store entry. It returns a crypto:metadata element if entry exists, empty sequence if the entry does not exist.

The crypto:metadata element

The crypto:metadata element contains metadata about a resource.

  • creation-date is the entry's creation date.

  • type is the entry's type.

The crypto:list-trusted-certificate-authorities function

This function lists the most-trusted certificate authorities in a secure store.

Digital Certificates

TBD.

The crypto:generate-certificate function

This function generates a digital certificate.

The crypto:validate-certificate function

This function validates a digital certificate.

The crypto:parse-certificate function

This function parses a digital certificate.

The crypto:generate-certification-path function

This function validates the certification path for a digital certificate.

The crypto:validate-certification-path function

This function validates the certification path for a digital certificate.

The crypto:generate-certification-request function

This function generates a certificate signing request, in order to apply for a digital identity certificate, which is to be issued by a Certificate Authority .

The crypto:validate-certification-request function

This function validates a certificate signing request.

The crypto:validate-certificate-revocation-list function

This function validates a certificate revocation list.

Cryptographic Hardware

TBD.

Random Sequences Generation

TBD.

The crypto:generate-random-number function

This function generates a random number that is cryptographically strong.

The crypto:options element

The crypto:options element represents the options needed for the functions included in this module. Users will specify for a certain functions only the options mentioned in function's description above. In case a needed option is not mentioned for a function, its default value will be used.

The provider option

Represents the provider for the current operation. If the provider does not exist, this is an error [=crypto:no-provider=].

The canonicalization-algorithm option

This option represents the canonicalization algorithm applied to the SignedInfo element prior to performing signature calculations. The default value is "inclusive-with-comments". If the parameter specifies an unsupported algorithm, this is an error [=crypto:unknown-algorithm=].

The digest-algorithm option

This option represents the digest algorithm to be applied to the signed object. If the parameter specifies an unsupported algorithm, this is an error [=crypto:unknown-algorithm=].

The signature-algorithm option

This option represents the algorithm used for signature generation and validation. If the parameter specifies an unsupported algorithm, this is an error [=crypto:unknown-algorithm=].

The signature-namespace-prefix option

This option represents the namespace prefix for signature.

Summary of Error Conditions

crypto:unknown-algorithm
The specified algorithm is not supported.
crypto:signature-type
The specified signature type is not supported.
crypto:unreadable-keystore
I/O error while reading keystore, or the password is incorrect.
crypto:denied-keystore
Permission denied to read keystore.
crypto:keystore-url
The keystore URL is invalid.
crypto:keystore-type
The keystore type is not supported.
crypto:alias-key
Cannot find key for alias in given keystore.
crypto:signature-element
Cannot find Signature element.
crypto:inexistent-padding
No such padding.
crypto:incorrect-padding
Incorrect padding.
crypto:encryption-type
The encryption type is not supported.
crypto:secret-key
The secret key is invalid.
crypto:block-size
Illegal block size.
crypto:decryption-type
The decryption type is not supported.
crypto:no-provider
The provider is not set.
crypto:output-format
The output format is not supported.