Package se.digg.dgc.signatures.impl
Class DefaultDGCSigner
- java.lang.Object
-
- se.digg.dgc.signatures.impl.DefaultDGCSigner
-
-
Constructor Summary
Constructors Constructor Description DefaultDGCSigner(PrivateKey signerKey, X509Certificate signerCertificate)
Constructor.DefaultDGCSigner(PkiCredential signerCredential)
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description String
getSignerCountry()
Gets the ISO-3166 country code of the signer (issuer).Instant
getSignerExpiration()
Gets the point in time when this signer's certificate expires.void
setAlgorithmIdentifier(SignatureAlgorithm algorithmIdentifier)
Assigns the algorithm to use.void
setSecurityProvider(Provider securityProvider)
Assigns a specific Java Security Provider that should be used when signing.byte[]
sign(byte[] dgcPayload, Instant expiration)
Creates a CWT including the CBOR encoded DGC payload and signs it.
-
-
-
Constructor Detail
-
DefaultDGCSigner
public DefaultDGCSigner(PrivateKey signerKey, X509Certificate signerCertificate) throws CertificateException
Constructor.- Parameters:
signerKey
- the signer keysignerCertificate
- the certificate holding the public key corresponding to the signer key- Throws:
CertificateException
- for certificate decoding errors
-
DefaultDGCSigner
public DefaultDGCSigner(PkiCredential signerCredential) throws CertificateException
Constructor.- Parameters:
signerCredential
- the signer credential- Throws:
CertificateException
- for certificate decoding errors
-
-
Method Detail
-
sign
public byte[] sign(byte[] dgcPayload, Instant expiration) throws SignatureException
Creates a CWT including the CBOR encoded DGC payload and signs it.Note: It is the caller's responsibility to ensure that the validity of the issued DGC does not exceed the validity of the signer's certificate (see
DGCSigner.getSignerExpiration()
).- Specified by:
sign
in interfaceDGCSigner
- Parameters:
dgcPayload
- the CBOR encoding of the DGC payloadexpiration
- the expiration time for the DGC- Returns:
- the CBOR encoding of the signed CWT holding the DGC payload
- Throws:
SignatureException
- for signature errors
-
getSignerExpiration
public Instant getSignerExpiration()
Gets the point in time when this signer's certificate expires. For maximum interoperability, the validity of a DGC should not stretch beyond this time.- Specified by:
getSignerExpiration
in interfaceDGCSigner
- Returns:
- the signer certificate expiration time
-
getSignerCountry
public String getSignerCountry()
Gets the ISO-3166 country code of the signer (issuer).- Specified by:
getSignerCountry
in interfaceDGCSigner
- Returns:
- the country code of the signer
-
setAlgorithmIdentifier
public void setAlgorithmIdentifier(SignatureAlgorithm algorithmIdentifier)
Assigns the algorithm to use.SignatureAlgorithm.ES256
is the default for EC keys andSignatureAlgorithm.PS256
is the default for RSA keys.- Parameters:
algorithmIdentifier
- the algorithm to use
-
setSecurityProvider
public void setSecurityProvider(Provider securityProvider)
Assigns a specific Java Security Provider that should be used when signing. If not assigned, a default provider will be used.- Parameters:
securityProvider
- the security provider
-
-