public class Session extends Provider
The session can be used to create signature configuration to sign documents.
To acquire a session, the following steps must be performed:
Module.load(java.lang.String).
Module.getDevices().
If it can be assumed that there is only a single device available, the DeviceList.getSingle() can be used.
Device.createSession(java.lang.String).
| Modifier and Type | Method | Description |
|---|---|---|
SignatureConfiguration |
createSignature(Certificate certificate) |
Create a signature configuration based on signing certificate
|
SignatureConfiguration |
createSignatureFromKeyId(byte[] id,
Stream certificate) |
Create a signature configuration based on the private key's ID and an external certificate
|
SignatureConfiguration |
createSignatureFromKeyLabel(java.lang.String label,
Stream certificate) |
Create a signature configuration based on the private key's label (name) and an external certificate
|
SignatureConfiguration |
createSignatureFromName(java.lang.String name) |
Create a signature configuration based on certificate name
|
TimestampConfiguration |
createTimestamp() |
Create a time-stamp configuration
|
CertificateList |
getCertificates() |
The cerfificates of the device (Getter)
|
java.net.URI |
getTimestampUrl() |
The URL of the trusted time-stamp authority (TSA) from which time-stamps shall be acquired (Getter)
|
void |
login(java.lang.String password) |
Log in user into the cryptographic device
|
void |
setTimestampUrl(java.net.URI value) |
The URL of the trusted time-stamp authority (TSA) from which time-stamps shall be acquired (Setter)
|
equals, hashCodepublic void login(java.lang.String password)
throws PasswordException,
PermissionException
Login is typically required to enable cryptographic operations. Furthermore, some of the device's objects such as certificates or private keys might only be visible when logged in.
Note that many devices are locked after a number of failed login attempts.
Therefore, it is crucial to not retry this method using the same password after a failed attempt.
password - The user's passwordPasswordException - If the password is not correctPermissionException - If the password has been locked or is expiredjava.lang.UnsupportedOperationException - If the user has already logged inpublic SignatureConfiguration createSignature(Certificate certificate)
certificate - The signing certificate from getCertificates()java.lang.IllegalArgumentException - If the certificate is not a valid signing certificate.java.lang.IllegalArgumentException - If the certificate has expired.java.lang.IllegalArgumentException - if certificate is nullpublic SignatureConfiguration createSignatureFromName(java.lang.String name) throws NotFoundException
name - The name of the signing certificate (pdftools.crypto.providers.Certificate.getName)NotFoundException - If the certificate cannot be found in getCertificates()java.lang.IllegalArgumentException - If the certificate is not a valid signing certificatejava.lang.IllegalArgumentException - if name is nullpublic SignatureConfiguration createSignatureFromKeyId(byte[] id, Stream certificate) throws NotFoundException
Create a signature configuration where only the private key is contained in the PKCS#11 device and the signing certificate is provided externally. This is intended for PKCS#11 devices that can only store private keys, e.g. the Google Cloud Key Management (KMS).
The private key object is identified using its ID,
i.e. the CKA_ID object attribute in the PKCS#11 store.
The certificates of the trust chain should be added using SignatureConfiguration.addCertificate(com.pdftools.sys.Stream).
id - The ID of the private key object in the PKCS#11 storecertificate - The signing certificate in either PEM (.pem, ASCII text) or DER (.cer, binary) formNotFoundException - If the private key cannot be found in the PKCS#11 storejava.lang.IllegalArgumentException - If the certificate is not a valid signing certificatejava.lang.IllegalArgumentException - If the key specification matches more than one keyjava.lang.IllegalArgumentException - if id is nulljava.lang.IllegalArgumentException - if certificate is nullpublic SignatureConfiguration createSignatureFromKeyLabel(java.lang.String label, Stream certificate) throws NotFoundException
Create a signature configuration where only the private key is contained in the PKCS#11 device and the signing certificate is provided externally. This is intended for PKCS#11 devices that can only store private keys, e.g. the Google Cloud Key Management (KMS).
The private key object is identified using its label,
i.e. the CKA_LABEL object attribute in the PKCS#11 store.
The certificates of the trust chain should be added using SignatureConfiguration.addCertificate(com.pdftools.sys.Stream).
label - The label of the private key object in the PKCS#11 storecertificate - The signing certificate in either PEM (.pem, ASCII text) or DER (.cer, binary) formNotFoundException - If the private key cannot be found in the PKCS#11 storejava.lang.IllegalArgumentException - If the certificate is not a valid signing certificatejava.lang.IllegalArgumentException - If the key specification matches more than one keyjava.lang.IllegalArgumentException - if label is nulljava.lang.IllegalArgumentException - if certificate is nullpublic TimestampConfiguration createTimestamp()
getTimestampUrl() must be set.public java.net.URI getTimestampUrl()
The TSA must support the time-stamp protocol as defined in RFC 3161.
The property’s value must be a URL with the following elements:
http[s]://[\u2039user\u203a[:\u2039password\u203a]@]\u2039host\u203a[:\u2039port\u203a][/\u2039resource\u203a]
Where:
http/https: Protocol for connection to TSA.\u2039user\u203a:\u2039password\u203a (optional): Credentials for connection to TSA (basic authorization).\u2039host\u203a: Hostname of TSA.\u2039port\u203a: Port for connection to TSA.\u2039resource\u203a: The resource.
Applying a time-stamp requires an online connection to a time server; the firewall must be configured accordingly.
If a web proxy is used (see pdftools.Sdk.getProxy), make sure the following MIME types are supported:
application/timestamp-queryapplication/timestamp-replypublic void setTimestampUrl(java.net.URI value)
The TSA must support the time-stamp protocol as defined in RFC 3161.
The property’s value must be a URL with the following elements:
http[s]://[\u2039user\u203a[:\u2039password\u203a]@]\u2039host\u203a[:\u2039port\u203a][/\u2039resource\u203a]
Where:
http/https: Protocol for connection to TSA.\u2039user\u203a:\u2039password\u203a (optional): Credentials for connection to TSA (basic authorization).\u2039host\u203a: Hostname of TSA.\u2039port\u203a: Port for connection to TSA.\u2039resource\u203a: The resource.
Applying a time-stamp requires an online connection to a time server; the firewall must be configured accordingly.
If a web proxy is used (see pdftools.Sdk.getProxy), make sure the following MIME types are supported:
application/timestamp-queryapplication/timestamp-replypublic CertificateList getCertificates()
pdftools.crypto.providers.Certificate.getHasPrivateKey) might only be visible
after login(java.lang.String).