public class KeyAndCertificateSource extends java.lang.Object implements KeyAndCertContainer
There are two basic ways to use this class. One is to supply a
User object, and let default values be extracted from there.
The default values can later be changed via the set methods.
The other way is to supply a CertVerifier object to
the constructor, and manually set the required information via the
set methods.
The methods of this class are not thread-safe. However, once the object
is initialized, the get methods can be safely used in multiple
threads.
User| Constructor and Description |
|---|
KeyAndCertificateSource()
Create a new
KeyAndCertificateSource object. |
KeyAndCertificateSource(CertVerifier certVerifier)
Create a new
KeyAndCertificateSource object. |
KeyAndCertificateSource(User user)
Create a new
KeyAndCertificateSource object. |
| Modifier and Type | Method and Description |
|---|---|
void |
addDecryptionKeyInfo(java.security.PrivateKey decryptionKey,
X509Certificate encryptionCertificate)
Adds the given key as a decryption key.
|
X509Certificate[] |
getCaCertificateChain()
Returns the CaCertificate chain that was added using the
setCaChain(X509Certificate[]) method. |
X509Certificate |
getCertificate(Name issuerDN,
java.math.BigInteger serialNumber)
Returns the certificate that matches the given issuer DN and serial
number.
|
X509Certificate[] |
getCertificateChain()
Returns the certificate chain associated with this object.
|
CollectionCS |
getCertificateStore()
Returns the Certificate Store associated with this object.
|
CollectionCS |
getCertStore()
Deprecated.
use getCertificateStore()
|
CertVerifier |
getCertVerifier()
Returns the Certificate verifier associated with this object.
|
java.security.PrivateKey |
getDecryptionKey(Name issuerDN,
java.math.BigInteger serialNumber)
Returns the private key that matches the given issuer DN and serial
number.
|
java.security.PrivateKey |
getDecryptionKey(Name issuer,
java.lang.String serialNumber)
Convienance method for returning the private key that matches the given issuer DN and serial
number.
|
X509Certificate |
getEncryptionCertificate()
Returns the encryption certificate associated with this object.
|
java.security.PrivateKey |
getSigningKey()
Returns the private signing key associated with this object.
|
X509Certificate |
getVerificationCertificate()
Returns the verification certificate associated with this object.
|
void |
setCaChain(X509Certificate[] certChain)
Sets the certificate chain.
|
void |
setEncryptionCertificate(X509Certificate encryptionCertificate)
Sets the encryption certificate to be used when encrypting a
message.
|
void |
setSigningInfo(java.security.PrivateKey signingKey,
X509Certificate verificationCertificate)
Sets the private signing key and verification certificate to be used
when signing a message.
|
public KeyAndCertificateSource()
KeyAndCertificateSource object. All certificate
and key fields are initialized to null.public KeyAndCertificateSource(CertVerifier certVerifier)
KeyAndCertificateSource object. All certificate
and key fields are initialized to null.certVerifier - the object that will perform all certificate validation.public KeyAndCertificateSource(User user) throws UserFatalException, UserNotLoggedInException
KeyAndCertificateSource object. All certificate
and key fields are initialized to fields extracted from the given
User object, via the User.getSigningKey(),
User.getVerificationCertificate(), and
User.getEncryptionCertificate() methods. When needed,
decryption keys are obtained from the given User object
via the User.getUserPrivateKey(Name, BigInteger) method.user - the User object from which to extract all certificates
and keys.UserFatalException - if no certificate chain can be found to a root CA.UserNotLoggedInException - if user is not logged in.Userpublic CollectionCS getCertStore()
public CollectionCS getCertificateStore()
getCertificateStore in interface KeyAndCertContainerpublic CertVerifier getCertVerifier()
public java.security.PrivateKey getSigningKey()
null if there is no key.getSigningKey in interface KeyAndCertContainerpublic X509Certificate getVerificationCertificate()
null if there is no certificate.getVerificationCertificate in interface KeyAndCertContainerpublic X509Certificate getEncryptionCertificate()
null if there is no certificate.getEncryptionCertificate in interface KeyAndCertContainerpublic java.security.PrivateKey getDecryptionKey(Name issuerDN, java.math.BigInteger serialNumber)
null if there is no matching key.
If this object was constructed by supplying a User object,
keys are obtained from there. If not, or if the user did not have the
required key, the given issuer name and serial
number must match those of one of the certificates added via
addDecryptionKeyInfo(PrivateKey,X509Certificate).
issuerDN - the name of the key issuerserialNumber - the serial number of the key.public X509Certificate getCertificate(Name issuerDN, java.math.BigInteger serialNumber)
null if there is no matching certificate.
This method first checks certificates from the underlying
User object. If a certificate is not found, all
certificates added by the addDecryptionKeyInfo(PrivateKey,
X509Certificate) method are checked.
issuerDN - the name of the certificate issuerserialNumber - the serial number of the certificate.null.public X509Certificate[] getCertificateChain()
public void setSigningInfo(java.security.PrivateKey signingKey,
X509Certificate verificationCertificate)
throws java.security.InvalidKeyException,
java.lang.NullPointerException
Note that no check is made to ensure the public key in the certificate matches the given private key, but if they do not match, and message created will not be verifiable.
signingKey - the private key to be used for signing.verificationCertificate - the certificate to be included in the signed message for signature
verification purposes.java.security.InvalidKeyException - if the given key is not appropriate for signing.java.lang.NullPointerException - if any of the parameters are null.public void setEncryptionCertificate(X509Certificate encryptionCertificate)
encryptionCertificate - The message encryptor's encryption certificate.public void addDecryptionKeyInfo(java.security.PrivateKey decryptionKey,
X509Certificate encryptionCertificate)
Note that no check is made to ensure the public key in the certificate matches the given private key.
When searching for keys using getDecryptionKey(Name,BigInteger),
or certificates using getCertificate(Name,BigInteger)
matching is done against the issuer DN and serial number fields of
encryptionCertificate
Even if this object was created with the constructor that accepts a
User, this method can be used to add additional decryption keys.
decryptionKey - The private decryption key to add.encryptionCertificate - The encryption certificate that matches the decryption key.public void setCaChain(X509Certificate[] certChain)
certChain - the certificate chain.public X509Certificate[] getCaCertificateChain()
setCaChain(X509Certificate[]) method. If the
chain is null, it will check to see if
a CertVerifier has been set, and if so it will
retrieve the trusted root from this object.getCaCertificateChain in interface KeyAndCertContainergetCertificateChain()public java.security.PrivateKey getDecryptionKey(Name issuer, java.lang.String serialNumber) throws UserNotLoggedInException
KeyAndCertContainer interface.
getDecryptionKey in interface KeyAndCertContainerissuer - the name of the key issuerserialNumber - the String of the serial number.UserNotLoggedInException - if the user is not logged in.getDecryptionKey(Name, BigInteger)