Changes

Jump to navigation Jump to search
563 bytes removed ,  15:38, 26 May 2012
no edit summary
=Conventions=
All functions in this module are assigned to the <code>{{Code|http://expath.org/ns/crypto</code> }} namespace, which is statically bound to the <code>{{Code|crypto</code> }} prefix.<br/>All errors are assigned to the <code>{{Code|http://expath.org/ns/error</code> }} namespace, which is statically bound to the <code>{{Code|experr</code> }} prefix.
=Message Authentication=
|-
| width='90' | '''Signatures'''
|<code><b>{{Func|crypto:hmac</b>(|$message as xs:string(), $secret-key as xs:string(), algorithm as xs:string()) as |xs:string()</code>}}<br/><code><b>{{Func|crypto:hmac</b>(|$message as xs:string(), $secret-key as xs:string(), algorithm as xs:string(), $encoding as xs:string()) as |xs:string()</code>}}
|-
| '''Summary'''
|Creates a message authentication code via a cryptographic hash function and a secret key. <br/>
<code>{{Code|$encoding</code> }} must either be <code>{{Code|hex</code>}}, <code>{{Code|base64</code> }} or the empty string and specifies the encoding of the returned authentication code. <b>Default is <code>{{Code|base64</code>}}</b>.<br/><code>{{Code|$algorithm</code> }} describes the hash algorithm which is used for encryption. Currently supported are <code>{{Code|md5</code>}}, <code>{{Code|sha1</code>}}, <code>{{Code|sha256</code>}}, <code>{{Code|sha384</code>}}, <code>{{Code|sha512</code>}}. <b>Default is <code>{{Code|md5</code>}}</b>.
|-
| '''Errors'''
=Encryption & Decryption=
The encryption and decryption functions underlie several limitations:
* Cryptographic algorithms are currently limited to <code>{{Code|symmetric</code> }} algorithms only. This means that the same secret key is used for encryption and decryption. * Available algorithms are <code>{{Code|DES</code> }} and <code>{{Code|AES</code>}}.* Padding is fixed to <code>{{Code|PKCS5Padding</code>}}.
* The result of an encryption using the same message, algorithm and key looks different each time it is executed. This is due to a random initialization vector (IV) which is appended to the message and simply increases security.
* As the IV has to be passed along with the encrypted message somehow, data which has been encrypted by the <code>{{Code|crypto:encrypt</code> }} function in BaseX can only be decrypted by calling the <code>{{Code|crypto:decrypt</code> }} function.
==crypto:encrypt==
|-
| width='90' | '''Signatures'''
|<code><b>{{Func|crypto:encrypt</b>(|$input as xs:string(), $encryption-type as xs:string(), $secret-key as xs:string(), $cryptographic-algorithm as xs:string()) as |xs:string()</code>}}
|-
| '''Summary'''
|Encrypts the given input string.<br/>
<code>{{Code|$encryption-type</code> }} must be <code>{{Code|symmetric</code>}}, as asymmetric encryption is not supported so far. <b>Default is <code>{{Code|symmetric</code>}}</b>.<br/><code>{{Code|$secret-key</code> }} is the secret key which is used for both encryption and decryption of input data. Its length is fixed and depends on the chosen algorithm: <code>{{Code|8 bytes for DES</code>}}, <code>{{Code|16 bytes for AES</code>}}.<br/><code>{{Code|$cryptographic-algorithm</code> }} must either be <code>{{Code|DES</code> }} or <code>{{Code|AES</code>}}. Other algorithms are not supported so far, but, of course, can be added on demand. <b>Default is <code>{{Code|DES</code>}}</b>.
|-
| '''Errors'''
|-
| width='90' | '''Signatures'''
|<code><b>{{Func|crypto:decrypt</b>(|$input as xs:string(), $decryption-type as xs:string(), $secret-key as xs:string(), $cryptographic-algorithm as xs:string()) as |xs:string()</code>}}
|-
| '''Summary'''
|Decrypts the encrypted <code>{{Code|$input</code>}}.<br/><code>{{Code|$decryption-type</code> }} must be <code>{{Code|symmetric</code>}}. An option for asymmetric encryption will most likely be added with another version of BaseX. <b>Default is <code>{{Code|symmetric</code>}}</b>.<br/><code>{{Code|$secret-key</code> }} is the secret key which is used for both encryption and decryption of input data. Its length is fixed and depends on the chosen algorithm: <code>{{Code|8 bytes for DES</code>}}, <code>{{Code|16 bytes for AES</code>}}.<br/><code>{{Code|$cryptographic-algorithm</code> }} must either be <code>{{Code|DES</code> }} or <code>{{Code|AES</code>}}. Other algorithms are not supported so far, but, of course, can be added on demand. <b>Default is <code>{{Code|DES</code>}}</b>.
|-
| '''Errors'''
* '''Transforms''' contains transformations (i.e. XPath expressions) that are applied to the input node in order to sign a subset
* '''DigestValue''' holds digest value of the transformed references
* '''SignatureValue''' contains the Base64 encoded value of the encrypted digest of the <code>{{Code|SignedInfo</code> }} element
* '''KeyInfo''' provides information on the key that is used to validate the signature
* '''Object''' contains the node which is signed if the signature is of type <code>{{Code|enveloping</code>}}
'''Signature Types'''
Depending on the signature type, the <code>{{Code|signature</code> }} element is either placed as a child of the signed node (<code>{{Code|enveloped</code> }} type), or directly contains the signed node (<code>{{Code|enveloping</code> }} type). <code>{{Code|Detached</code> }} signatures are so far not supported.
'''Digital Certificate'''
The <code>{{Code|generate-signature</code> }} function allows to pass a <code>{{Code|digital certificate</code>}}. This certificate holds parameters that allow to access key information stored in a Java key store which is then used to sign the input document. Passing a <code>{{Code|digital certificate</code> }} simply helps re-using the same key pair to sign and validate data. The <code>{{Code|digital certificate</code> }} is passed as a node and has the following form:
<pre class="brush:xml">
|-
| width='90' | '''Signatures'''
|<code><b>{{Func|crypto:generate-signature</b>(|$input-doc node(), $canonicalization-algorithm as xs:string(), $digest-algorithm as xs:string(), $signature-algorithm as xs:string(), $signature-namespace-prefix as xs:string(), $signature-type as xs:string()) as |node()</code>}}<br/><code><b>{{Func|crypto:generate-signature</b>(|$input-doc node(), $canonicalization-algorithm as xs:string(), $digest-algorithm as xs:string(), $signature-algorithm as xs:string(), $signature-namespace-prefix as xs:string(), $signature-type as xs:string(), $xpath-expression as xs:string()) as |node()</code>}}<br/><code><b>{{Func|crypto:generate-signature</b>(|$input-doc node(), $canonicalization-algorithm as xs:string(), $digest-algorithm as xs:string(), $signature-algorithm as xs:string(), $signature-namespace-prefix as xs:string(), $signature-type as xs:string(), $digital-certificate as node()) as |node()</code>}}<br/><code><b>{{Func|crypto:generate-signature</b>(|$input-doc node(), $canonicalization-algorithm as xs:string(), $digest-algorithm as xs:string(), $signature-algorithm as xs:string(), $signature-namespace-prefix as xs:string(), $signature-type as xs:string(), $xpath-expression as xs:string(), $digital-certificate as node()) as |node()</code>}}
|-
| '''Summary'''
|<code>{{Code|$canonicalization-algorithm</code> }} must either be <code>{{Code|inclusive-with-comments</code>}}, <code>{{Code|inclusive</code>}}, <code>{{Code|exclusive-with-comments</code> }} or <code>{{Code|exclusive</code>}}. <b>Default is <code>{{Code|inclusive-with-comments</code>}}</b>.<br/><code>{{Code|$digest-algorithm</code> }} must be one of the following: <code>{{Code|SHA1</code>}}, <code>{{Code|SHA256</code> }} or <code>{{Code|SHA512</code>}}. <b>Default is <code>{{Code|SHA1</code>}}</b>.<br/><code>{{Code|$signature-algorithm</code> }} must either be <code>{{Code|RSA_SHA1</code> }} or <code>{{Code|DSA_SHA1</code>}}. <b>Default is <code>{{Code|RSA_SHA1</code>}}</b>.<br/><code>{{Code|$signature-namespace-prefix</code> }} may be empty and prefixes the <code>{{Code|Signature</code> }} element accordingly.<br/><code>{{Code|$signature-type</code> }} must either be <code>{{Code|enveloped</code> }} or <code>{{Code|enveloping</code>}}. Detached signatures are so far not supported. <b>Default is <code>{{Code|enveloped</code>}}</b>.<br/><code>{{Code|$xpath-expression</code> }} is an arbitrary XPath expression which specifies a subset of the document that is to be signed.<br/><code>{{Code|$digital-certificate</code> }} is the digitial certificate used to sign the input document.
|-
| '''Errors'''
<b>[[XQuery Errors#Cryptographic Functions Errors|FOCX0002]]</b> is raised if the digest algorithm is not supported.<br/>
<b>[[XQuery Errors#Cryptographic Functions Errors|FOCX0003]]</b> is raised if the signature algorithm is not supported.<br/>
<b>[[XQuery Errors#Cryptographic Functions Errors|FOCX0004]]</b> is raised if the <code>{{Code|$xpath-expression</code> }} is invalid.<br/><b>[[XQuery Errors#Cryptographic Functions Errors|FOCX0005]]</b> is raised if the root name of <code>{{Code|$digital-certificate</code> }} is not 'digital-certificate.<br/>
<b>[[XQuery Errors#Cryptographic Functions Errors|FOCX0007]]</b> is raised if the key store is null.<br/>
<b>[[XQuery Errors#Cryptographic Functions Errors|FOCX0012]]</b> is raised if the key cannot be found in the specified key store.<br/>
|-
| width='90' | '''Signatures'''
|<code><b>{{Func|crypto:validate-signature</b>(|$input-doc as node()) as |xs:boolean()</code>}}
|-
| '''Summary'''
|Checks if the given node contains a <code>{{Code|Signature</code> }} element and whether the signature is valid. In this case <code>{{Code|true</code> }} is returned. If the signature is invalid the function returns <code>{{Code|false</code>}}.
|-
| '''Errors'''
! width="95%"|Description
|-
|<code>{{Code|FOCX0001</code>}}
|The canonicalization algorithm is not supported.
|-
|<code>{{Code|FOCX0002</code>}}
|The digest algorithm is not supported.
|-
|<code>{{Code|FOCX0003</code>}}
|The signature algorithm is not supported.
|-
|<code>{{Code|FOCX0004</code>}}
|The XPath expression is invalid.
|-
|<code>{{Code|FOCX0005</code>}}
|The root element of argument $digital-certificate must have the name 'digital-certificate'.
|-
|<code>{{Code|FOCX0006</code>}}
|The child element of argument $digital-certificate having position $position must have the name $child-element-name.
|-
|<code>{{Code|FOCX0007</code>}}
|The keystore is null.
|-
|<code>{{Code|FOCX0008</code>}}
|I/O error while reading keystore.
|-
|<code>{{Code|FOCX0009</code>}}
|Permission denied to read keystore.
|-
|<code>{{Code|FOCX0010</code>}}
|The keystore URL is invalid.
|-
|<code>{{Code|FOCX0011</code>}}
|The keystore type is not supported.
|-
|<code>{{Code|FOCX0012</code>}}
|Cannot find key for alias in given keystore.
|-
|<code>{{Code|FOCX0013</code>}}
|The hashing algorithm is not supported.
|-
|<code>{{Code|FOCX0014</code>}}
|The encoding method is not supported.
|-
|<code>{{Code|FOCX0015</code>}}
|Cannot find Signature element.
|-
|<code>{{Code|FOCX0016</code>}}
|No such padding.
|-
|<code>{{Code|FOCX0017</code>}}
|Incorrect padding.
|-
|<code>{{Code|FOCX0018</code>}}
|The encryption type is not supported.
|-
|<code>{{Code|FOCX0019</code>}}
|The secret key is invalid.
|-
|<code>{{Code|FOCX0020</code>}}
|Illegal block size.
|-
|<code>{{Code|FOCX0021</code>}}
|The algorithm is not supported.
|-
|<code>{{Code|FOCX0023</code>}}
|An invalid certificate alias is specified. Added to the official specification.
|-
|<code>{{Code|FOCX0024</code>}}
|The algorithm is invalid. Added to the official specification.
|-
|<code>{{Code|FOCX0025</code>}}
|Signature cannot be processed. Added to the official specification.
|-
|<code>{{Code|FOCX0026</code>}}
|Keystore cannot be processed. Added to the official specification.
|-
|<code>{{Code|FOCX0027</code>}}
|An I/O Exception occurred. Added to the official specification.
|-
|<code>{{Code|FOCX0028</code>}}
|The specified signature type is not supported. Added to the official specification.
|}
Bureaucrats, editor, reviewer, Administrators
13,554

edits

Navigation menu