Signing of payload
This chapter describes how to digitally sign XML documents using OCES (Offentlige Certifikater til Elektronisk Service) certificates. The implementation supports multiple signature types for different use cases in Danish digital infrastructure. Signing the document remains the same between SOAP and HTTP.
Signature types
-
System Certificate Signing
Used for standard document operations such as data retrieval and searching. This must be used as the default unless stated otherwise.
-
Non-Repudiation Certificate Signing
Used for legally binding documents that modify existing data.
-
Disponent Role Signing
Used for legally binding documents where a person acts on behalf of another individual or company.
Most endpoints still require you to sign the document. If you are unsure about which signature type to use, check the request message XSD in the controller documentation. In most cases, system certificate signing will be the correct option.
Usage and implementation of signature types can be found in the reference client by examining these methods:
1
Unresolved directive in signing.adoc - include::{javaDir}/SigningMethodsOverview.java[]
Signature body
The signature takes the form of an encrypted string appended to the XML sent in the request body
Currently, the S2S server supports RSA_SHA1, RSA_SHA256, and RSA_SHA512 algorithms for signature methods and RSA_SHA1, RSA_SHA256 for digest. Creating signatures with other algorithms will result in document rejection. Due to security reasons, it is recommended to use at least RSA_SHA256, as RSA_SHA1 is not considered secure anymore.
All signatures follow the XML Digital Signature specification and include:
-
SignedInfo: Contains canonicalization method, signature algorithm, and references
-
KeyInfo: Embeds the X.509 certificate used for signing
-
Signature Value: The actual cryptographic signature
Differences between signing methods:
| Disponent signatures | Basic signatures |
|---|---|
Use XPath filtering to sign only specific parts of the document while excluding metadata and administrative elements |
The full document is signed in a designated element at the end of the XML |
Use CanonicalizationMethod.INCLUSIVE |
Use CanonicalizationMethod.EXCLUSIVE |
For disponent signatures, HTTP XML API will check for the correct XPath expression. Either one of following expressions could be used to exclude parts of the document from signing.
Unresolved directive in signing.adoc - include::{javaDir}/XpathSubsetv1.java[]
Unresolved directive in signing.adoc - include::{javaDir}/XpathSubsetv2.java[]
Here is example from reference client on how you can include XPath into your project:
1
Unresolved directive in signing.adoc - include::{javaDir}/XpathInclude.java[]
Example usages
Since the S2S reference client expects the XML to be passed as String, current examples will parse to the Document using helper methods.
For data retrieval, a simple signature will suffice:
1
Unresolved directive in signing.adoc - include::{javaDir}/SignBasic.java[]
When you need to change or add new data, signing with repudiation must be used. The example below shows a case when a disponent is involved in document creation. This requires two types of signatures at the same time:
1
Unresolved directive in signing.adoc - include::{javaDir}/SignDisponentRepudiation.java[]