public class SelfSignedCertificateGenerator
extends java.lang.Object
| Modifier and Type | Class and Description |
|---|---|
private static class |
SelfSignedCertificateGenerator.CommandLineArgs
Manages command line parsing for application and the bean properties used by the generator.
|
static class |
SelfSignedCertificateGenerator.FileConverter
Command line option conversion from String to File.
|
| Modifier and Type | Field and Description |
|---|---|
private SelfSignedCertificateGenerator.CommandLineArgs |
args
Container for options that can be parsed from a command line.
|
private org.slf4j.Logger |
log
Class logger.
|
| Constructor and Description |
|---|
SelfSignedCertificateGenerator()
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
protected org.bouncycastle.asn1.ASN1Encodable[] |
buildSubjectAltNames()
Builds the subject alt names for the certificate.
|
void |
generate()
The main routine.
|
protected java.security.cert.X509Certificate |
generateCertificate(java.security.KeyPair keypair)
Generates the self-signed certificate.
|
protected java.security.KeyPair |
generateKeyPair()
Generates the key pair for the certificate.
|
static void |
main(java.lang.String[] args)
Command line entry point.
|
void |
setCertificateAlg(java.lang.String alg)
Set the certificate algorithm that will be used.
|
void |
setCertificateFile(java.io.File file)
Set the file to which the certificate will be written.
|
void |
setCertificateLifetime(int lifetime)
Set the number of years for which the certificate will be valid.
|
void |
setDNSSubjectAltNames(java.util.Collection<java.lang.String> altNames)
Set the optional DNS subject alt names.
|
void |
setHostName(java.lang.String name)
Set the hostname that will appear in the certificate's DN.
|
void |
setKeySize(int size)
Set the size of the generated key.
|
void |
setKeystoreFile(java.io.File file)
Set the file to which the keystore will be written.
|
void |
setKeystorePassword(java.lang.String password)
Set the password for the generated keystore.
|
void |
setKeystoreType(java.lang.String type)
Set the type of keystore to create.
|
void |
setKeyType(java.lang.String type)
Set the type of key that will be generated.
|
void |
setPrivateKeyFile(java.io.File file)
Set the file to which the private key will be written.
|
void |
setURISubjectAltNames(java.util.Collection<java.lang.String> altNames)
Set the optional URI subject alt names.
|
protected void |
validate()
Validates the settings.
|
@Nonnull private org.slf4j.Logger log
@Nonnull private final SelfSignedCertificateGenerator.CommandLineArgs args
public SelfSignedCertificateGenerator()
public void setKeyType(@Nonnull @NotEmpty java.lang.String type)
type - type of key that will be generatedpublic void setKeySize(@Positive int size)
size - size of the generated keypublic void setCertificateLifetime(@Positive int lifetime)
lifetime - number of years for which the certificate will be validpublic void setCertificateAlg(@Nonnull @NotEmpty java.lang.String alg)
alg - certificate algorithmpublic void setHostName(@Nonnull @NotEmpty java.lang.String name)
name - hostname that will appear in the certificate's DNpublic void setPrivateKeyFile(@Nullable
java.io.File file)
file - file to which the private key will be writtenpublic void setCertificateFile(@Nullable
java.io.File file)
file - file to which the certificate will be writtenpublic void setKeystoreType(@Nonnull @NotEmpty java.lang.String type)
type - keystore typepublic void setKeystoreFile(@Nullable
java.io.File file)
file - file to which the keystore will be writtenpublic void setKeystorePassword(@Nullable
java.lang.String password)
password - password for the generated keystorepublic void setDNSSubjectAltNames(@Nonnull @NonnullElements java.util.Collection<java.lang.String> altNames)
altNames - collection of subject alt names.public void setURISubjectAltNames(@Nonnull @NonnullElements java.util.Collection<java.lang.String> altNames)
altNames - collection of subject alt names.public void generate()
throws java.lang.Exception
java.lang.Exception - if an error occursprotected void validate()
@Nonnull
protected java.security.KeyPair generateKeyPair()
throws java.security.NoSuchAlgorithmException
java.security.NoSuchAlgorithmException - if there is a problem generating the keys@Nonnull
protected java.security.cert.X509Certificate generateCertificate(@Nonnull
java.security.KeyPair keypair)
throws java.lang.Exception
keypair - keypair associated with the certificatejava.lang.Exception - if an error occurs@Nonnull @NonnullElements protected org.bouncycastle.asn1.ASN1Encodable[] buildSubjectAltNames()
public static void main(@Nonnull
java.lang.String[] args)
throws java.lang.Exception
args - command line argumentsjava.lang.Exception