public final class X509Bundle extends Object
| Modifier and Type | Method and Description |
|---|---|
static X509Bundle |
fromCertificatePath(X509Certificate[] certPath,
X509Certificate root,
KeyPair keyPair)
Construct a bundle from a given certificate path, root certificate, and
KeyPair. |
static X509Bundle |
fromRootCertificateAuthority(X509Certificate root,
KeyPair keyPair)
Construct a bundle for a certificate authority.
|
X509Certificate |
getCertificate()
Get the leaf certificate of the bundle.
|
X509Certificate[] |
getCertificatePath()
Get the certificate path, starting with the leaf certificate up to but excluding the root certificate.
|
List<X509Certificate> |
getCertificatePathList()
Get the certificate path as a list, starting with the leaf certificate up to but excluding the root certificate.
|
String |
getCertificatePathPEM()
Get the certificate path as a PEM encoded string.
|
X509Certificate[] |
getCertificatePathWithRoot()
Get the certificate path, starting with the leaf certificate up to and including the root certificate.
|
String |
getCertificatePEM()
Get the PEM encoded string of the leaf certificate.
|
KeyPair |
getKeyPair()
Get the key pair.
|
String |
getPrivateKeyPEM()
Get the private key as a PEM encoded PKCS#8 string.
|
X509Certificate |
getRootCertificate()
Get the root certificate that anchors the certificate path.
|
String |
getRootCertificatePEM()
Get the root certificate as a PEM encoded string.
|
TrustAnchor |
getTrustAnchor()
Get the root certificate as a new
TrustAnchor object. |
boolean |
isCertificateAuthority()
Query if this bundle is for a certificate authority root certificate.
|
boolean |
isSelfSigned()
Query if this bundle is for a self-signed certificate.
|
KeyManagerFactory |
toKeyManagerFactory()
Create a
KeyManagerFactory from this bundle. |
KeyManagerFactory |
toKeyManagerFactory(String algorithm)
Create a
KeyManagerFactory from this bundle, using the given algorithm. |
KeyStore |
toKeyStore(char[] keyEntryPassword)
Create a
KeyStore with the contents of this bundle. |
KeyStore |
toKeyStore(String algorithm,
char[] keyEntryPassword)
Create a
KeyStore with the contents of this bundle. |
File |
toTempCertChainPem()
Create a temporary PEM file with the certificate chain of this bundle.
|
File |
toTempKeyStoreFile(char[] password)
Create a temporary PKCS#12 file with the key store of this bundle.
|
File |
toTempKeyStoreFile(char[] pkcs12Password,
char[] keyEntryPassword)
Create a temporary PKCS#12 file with the key store of this bundle.
|
File |
toTempPrivateKeyPem()
Create a temporary PEM file with the private key of this bundle.
|
File |
toTempRootCertPem()
Create a temporary PEM file with the root certificate of this bundle.
|
TrustManager |
toTrustManager()
Create a
TrustManager instance that trusts the root certificate in this bundle. |
TrustManagerFactory |
toTrustManagerFactory()
Create
TrustManagerFactory instance that trusts the root certificate in this bundle. |
TrustManagerFactory |
toTrustManagerFactory(String algorithm)
Create
TrustManagerFactory instance that trusts the root certificate in this bundle,
with the given algorithm. |
public static X509Bundle fromRootCertificateAuthority(X509Certificate root, KeyPair keyPair)
root - The self-signed root certificate.keyPair - The key pair.public static X509Bundle fromCertificatePath(X509Certificate[] certPath, X509Certificate root, KeyPair keyPair)
KeyPair.certPath - The certificate path, starting with the leaf certificate.The path can end either with the
root certificate, or the intermediate certificate signed by the root certificate.root - The self-signed root certificate.keyPair - The key pair.public X509Certificate getCertificate()
getRootCertificate().public String getCertificatePEM()
public X509Certificate[] getCertificatePath()
public X509Certificate[] getCertificatePathWithRoot()
public List<X509Certificate> getCertificatePathList()
public String getCertificatePathPEM()
public KeyPair getKeyPair()
public X509Certificate getRootCertificate()
public String getRootCertificatePEM()
public String getPrivateKeyPEM()
public TrustAnchor getTrustAnchor()
TrustAnchor object.
Note that TrustAnchor instance have object identity, so if this method is called twice,
the two trust anchors will not be equal to each other.TrustAnchor instance containing the root certificate.public boolean isCertificateAuthority()
true if the leaf certificate is a certificate authority,
otherwise false.public boolean isSelfSigned()
true if the leaf certificate is self-signed.public TrustManager toTrustManager()
TrustManager instance that trusts the root certificate in this bundle.TrustManager.public TrustManagerFactory toTrustManagerFactory()
TrustManagerFactory instance that trusts the root certificate in this bundle.
The trust manager factory will use the default algorithm.
TrustManagerFactory.public TrustManagerFactory toTrustManagerFactory(String algorithm)
TrustManagerFactory instance that trusts the root certificate in this bundle,
with the given algorithm.TrustManagerFactory.public KeyStore toKeyStore(char[] keyEntryPassword) throws KeyStoreException
KeyStore with the contents of this bundle.
The root certificate will be a trusted root in the key store.
If this bundle has a private key,
then the private key and certificate path will also be added to the key store.
The key store will use the PKCS#12 format.
keyEntryPassword - The password used to encrypt the private key entry in the key store.KeyStoreException - If an error occurred when adding entries to the key store.public KeyStore toKeyStore(String algorithm, char[] keyEntryPassword) throws KeyStoreException
KeyStore with the contents of this bundle.
The root certificate will be a trusted root in the key store.
If this bundle has a private key,
then the private key and certificate path will also be added to the key store.
The key store will use the format defined by the given algorithm.
keyEntryPassword - The password used to encrypt the private key entry in the key store.KeyStoreException - If an error occurred when adding entries to the key store.public File toTempKeyStoreFile(char[] password) throws Exception
public File toTempKeyStoreFile(char[] pkcs12Password, char[] keyEntryPassword) throws Exception
pkcs12Password - The password used to encrypt the PKCS#12 file.keyEntryPassword - The password used to encrypt the private key entry in the PKCS#12 file.File object with the path to the PKCS#12 key store.Exception - If something went wrong with creating the key store file.public File toTempRootCertPem() throws IOException
File object with the path to the trust root PEM file.IOException - If an IO error occurred when creating the trust root file.public File toTempCertChainPem() throws IOException
File object with the path to the certificate chain PEM file.IOException - If an IO error occurred when creating the certificate chain file.public File toTempPrivateKeyPem() throws IOException
File object with the path to the private key PEM file.IOException - If an IO error occurred when creating the private key file.public KeyManagerFactory toKeyManagerFactory() throws KeyStoreException, UnrecoverableKeyException, NoSuchAlgorithmException
KeyManagerFactory from this bundle.
The KeyManagerFactory will use the
default algorithm.
KeyManagerFactory.KeyStoreException - If there was a problem creating or initializing the key store.UnrecoverableKeyException - If the private key could not be recovered,
for instance if this bundle is a certificate authority.NoSuchAlgorithmException - If the key manager factory algorithm is not supported by the current
security provider.public KeyManagerFactory toKeyManagerFactory(String algorithm) throws KeyStoreException, UnrecoverableKeyException, NoSuchAlgorithmException
KeyManagerFactory from this bundle, using the given algorithm.KeyManagerFactory.KeyStoreException - If there was a problem creating or initializing the key store.UnrecoverableKeyException - If the private key could not be recovered,
for instance if this bundle is a certificate authority.NoSuchAlgorithmException - If the key manager factory algorithm is not supported by the current
security provider.Copyright © 2008–2024 The Netty Project. All rights reserved.