Package io.smallrye.certs.ca
Class CaGenerator
java.lang.Object
io.smallrye.certs.ca.CaGenerator
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionCaGenerator(File ca, File key, File ks, String password) Create a new instance ofCaGenerator. -
Method Summary
Modifier and TypeMethodDescriptionGenerate a Root CA certificate and store it in a keystore.voidgenerateTrustStore(File trustStore) Generate a PKCS#12 truststore containing the CA certificate.voidInstall the CA certificate in the system truststore.
-
Field Details
-
KEYSTORE_KEY_ENTRY
- See Also:
-
KEYSTORE_CERT_ENTRY
- See Also:
-
-
Constructor Details
-
CaGenerator
Create a new instance ofCaGenerator.- Parameters:
ca- the file where the CA certificate should be stored (PEM file), must not be nullkey- the file where the private key should be stored (PEM file), must not be nullks- the file where the keystore should be stored (P12 file), must not be nullpassword- the password to protect the keystore, and the private key, must not be null or empty
-
-
Method Details
-
generate
public X509Certificate generate(String cn, String org, String unit, String location, String state, String country) throws Exception Generate a Root CA certificate and store it in a keystore.This method writes the CA certificate to a PEM file, the private key to a PEM file, and the key and cert to a PKCS12 keystore. It also returns the
X509Certificateinstance.- Parameters:
cn- the common name of the certificate, must not be nullorg- the organization, can be null, must not be emptyunit- the organizational unit, can be null, must not be emptylocation- the location, can be null, must not be emptystate- the state, can be null, must not be emptycountry- , the country, can be null, must not be empty- Returns:
- the generated CA certificate
- Throws:
Exception- if the generation fails
-
generateTrustStore
Generate a PKCS#12 truststore containing the CA certificate.The generated truststore is a PKCS12 file containing the CA certificate at the entry
ca. The truststore is protected by the password provided when creating the instance ofCaGenerator.- Parameters:
trustStore- the truststore file, must not be null- Throws:
KeyStoreException- if the truststore cannot be generatedException
-
installToSystem
Install the CA certificate in the system truststore.The behavior of this method depends on the operating system. It requires elevated privileges.
- Throws:
Exception
-