Class SelfSignedCertificateGenerator
java.lang.Object
net.shibboleth.shared.security.impl.SelfSignedCertificateGenerator
A helper class to generate self-signed keypairs.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static classManages command line parsing for application and the bean properties used by the generator.static classCommand line option conversion from String to File. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final SelfSignedCertificateGenerator.CommandLineArgsContainer for options that can be parsed from a command line.private org.slf4j.LoggerClass logger. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected org.bouncycastle.asn1.ASN1Encodable[]Builds the subject alt names for the certificate.voidgenerate()The main routine.protected X509CertificategenerateCertificate(KeyPair keypair) Generates the self-signed certificate.protected KeyPairGenerates the key pair for the certificate.static voidCommand line entry point.voidsetCertificateAlg(String alg) Set the certificate algorithm that will be used.voidsetCertificateFile(File file) Set the file to which the certificate will be written.voidsetCertificateLifetime(int lifetime) Set the number of years for which the certificate will be valid.voidsetDNSSubjectAltNames(Collection<String> altNames) Set the optional DNS subject alt names.voidsetHostName(String name) Set the hostname that will appear in the certificate's DN.voidsetKeySize(int size) Set the size of the generated key.voidsetKeystoreFile(File file) Set the file to which the keystore will be written.voidsetKeystorePassword(String password) Set the password for the generated keystore.voidsetKeystoreType(String type) Set the type of keystore to create.voidsetKeyType(String type) Set the type of key that will be generated.voidsetPrivateKeyFile(File file) Set the file to which the private key will be written.voidsetURISubjectAltNames(Collection<String> altNames) Set the optional URI subject alt names.protected voidvalidate()Validates the settings.
-
Field Details
-
log
@Nonnull private org.slf4j.Logger logClass logger. -
args
Container for options that can be parsed from a command line.
-
-
Constructor Details
-
SelfSignedCertificateGenerator
public SelfSignedCertificateGenerator()Constructor.
-
-
Method Details
-
setKeyType
Set the type of key that will be generated. Defaults to RSA.- Parameters:
type- type of key that will be generated
-
setKeySize
Set the size of the generated key. Defaults to 2048- Parameters:
size- size of the generated key
-
setCertificateLifetime
Set the number of years for which the certificate will be valid.- Parameters:
lifetime- number of years for which the certificate will be valid
-
setCertificateAlg
Set the certificate algorithm that will be used. Defaults to SHA256withRSA.- Parameters:
alg- certificate algorithm
-
setHostName
Set the hostname that will appear in the certificate's DN.- Parameters:
name- hostname that will appear in the certificate's DN
-
setPrivateKeyFile
Set the file to which the private key will be written.- Parameters:
file- file to which the private key will be written
-
setCertificateFile
Set the file to which the certificate will be written.- Parameters:
file- file to which the certificate will be written
-
setKeystoreType
Set the type of keystore to create.- Parameters:
type- keystore type
-
setKeystoreFile
Set the file to which the keystore will be written.- Parameters:
file- file to which the keystore will be written
-
setKeystorePassword
Set the password for the generated keystore.- Parameters:
password- password for the generated keystore
-
setDNSSubjectAltNames
Set the optional DNS subject alt names.- Parameters:
altNames- collection of subject alt names.
-
setURISubjectAltNames
Set the optional URI subject alt names.- Parameters:
altNames- collection of subject alt names.
-
generate
The main routine.- Throws:
Exception- if an error occurs
-
validate
protected void validate()Validates the settings. -
generateKeyPair
Generates the key pair for the certificate.- Returns:
- key pair for the certificate
- Throws:
NoSuchAlgorithmException- if there is a problem generating the keys
-
generateCertificate
Generates the self-signed certificate.- Parameters:
keypair- keypair associated with the certificate- Returns:
- self-signed certificate
- Throws:
Exception- if an error occurs
-
buildSubjectAltNames
@Nonnull protected org.bouncycastle.asn1.ASN1Encodable[] buildSubjectAltNames()Builds the subject alt names for the certificate.- Returns:
- subject alt names for the certificate
-
main
Command line entry point.- Parameters:
args- command line arguments- Throws:
Exception- if something goes wrong
-