Class SelfSignedCertificate
java.lang.Object
io.netty.handler.ssl.util.SelfSignedCertificate
Deprecated.
Generates a temporary self-signed certificate for testing purposes.
NOTE: Never use the certificate and private key generated by this class in production. It is purely for testing purposes, and thus it is very insecure. It even uses an insecure pseudo-random generator for faster generation internally.
An X.509 certificate file and a EC/RSA private key file are generated in a system's temporary directory using
File.createTempFile(String, String), and they are deleted when the JVM exits using
File.deleteOnExit().
At first, this method tries to use OpenJDK's X.509 implementation (the sun.security.x509 package).
If it fails, it tries to use Bouncy Castle as a fallback.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final X509CertificateDeprecated.private final FileDeprecated.private static final intDeprecated.FIPS 140-2 encryption requires the RSA key length to be 2048 bits or greater.private static final DateDeprecated.The maximum possible value in X.509 specification: 9999-12-31 23:59:59private static final DateDeprecated.Current time minus 1 year, just in case software clock goes back due to time synchronizationprivate final PrivateKeyDeprecated.private static final InternalLoggerDeprecated.private final FileDeprecated. -
Constructor Summary
ConstructorsModifierConstructorDescriptionDeprecated.Creates a new instance.privateDeprecated.SelfSignedCertificate(String fqdn) Deprecated.Creates a new instance.SelfSignedCertificate(String fqdn, String algorithm, int bits) Deprecated.Creates a new instance.SelfSignedCertificate(String fqdn, SecureRandom random, int bits) Deprecated.Creates a new instance.SelfSignedCertificate(String fqdn, SecureRandom random, int bits, Date notBefore, Date notAfter) Deprecated.Creates a new instance.SelfSignedCertificate(String fqdn, SecureRandom random, int bits, Date notBefore, Date notAfter, String algorithm) Deprecated.Creates a new instance.SelfSignedCertificate(String fqdn, SecureRandom random, String algorithm, int bits) Deprecated.Creates a new instance.SelfSignedCertificate(String fqdn, Date notBefore, Date notAfter) Deprecated.Creates a new instance.SelfSignedCertificate(String fqdn, Date notBefore, Date notAfter, String algorithm, int bits) Deprecated.Creates a new instance.SelfSignedCertificate(Date notBefore, Date notAfter) Deprecated.Creates a new instance.SelfSignedCertificate(Date notBefore, Date notAfter, String algorithm, int bits) Deprecated.Creates a new instance. -
Method Summary
Modifier and TypeMethodDescriptionbuilder()Deprecated.cert()Deprecated.Returns the generated X.509 certificate.Deprecated.Returns the generated X.509 certificate file in PEM format.voiddelete()Deprecated.Deletes the generated X.509 certificate file and EC/RSA private key file.private static booleanDeprecated.key()Deprecated.Returns the generated EC/RSA private key.(package private) static String[]newSelfSignedCertificate(String fqdn, PrivateKey key, X509Certificate cert) Deprecated.Deprecated.Returns the generated EC/RSA private key file in PEM format.private static voidsafeClose(File keyFile, OutputStream keyOut) Deprecated.private static voidsafeDelete(File certFile) Deprecated.
-
Field Details
-
logger
Deprecated. -
DEFAULT_NOT_BEFORE
Deprecated.Current time minus 1 year, just in case software clock goes back due to time synchronization -
DEFAULT_NOT_AFTER
Deprecated.The maximum possible value in X.509 specification: 9999-12-31 23:59:59 -
DEFAULT_KEY_LENGTH_BITS
private static final int DEFAULT_KEY_LENGTH_BITSDeprecated.FIPS 140-2 encryption requires the RSA key length to be 2048 bits or greater. Let's use that as a sane default but allow the default to be set dynamically for those that need more stringent security requirements. -
certificate
Deprecated. -
privateKey
Deprecated. -
cert
Deprecated. -
key
Deprecated.
-
-
Constructor Details
-
SelfSignedCertificate
-
SelfSignedCertificate
Deprecated.Creates a new instance.Algorithm: RSA
- Parameters:
notBefore- Certificate is not valid before this timenotAfter- Certificate is not valid after this time- Throws:
CertificateException
-
SelfSignedCertificate
public SelfSignedCertificate(Date notBefore, Date notAfter, String algorithm, int bits) throws CertificateException Deprecated.Creates a new instance.- Parameters:
notBefore- Certificate is not valid before this timenotAfter- Certificate is not valid after this timealgorithm- Key pair algorithmbits- the number of bits of the generated private key- Throws:
CertificateException
-
SelfSignedCertificate
Deprecated.Creates a new instance.Algorithm: RSA
- Parameters:
fqdn- a fully qualified domain name- Throws:
CertificateException
-
SelfSignedCertificate
Deprecated.Creates a new instance.- Parameters:
fqdn- a fully qualified domain namealgorithm- Key pair algorithmbits- the number of bits of the generated private key- Throws:
CertificateException
-
SelfSignedCertificate
public SelfSignedCertificate(String fqdn, Date notBefore, Date notAfter) throws CertificateException Deprecated.Creates a new instance.Algorithm: RSA
- Parameters:
fqdn- a fully qualified domain namenotBefore- Certificate is not valid before this timenotAfter- Certificate is not valid after this time- Throws:
CertificateException
-
SelfSignedCertificate
public SelfSignedCertificate(String fqdn, Date notBefore, Date notAfter, String algorithm, int bits) throws CertificateException Deprecated.Creates a new instance.- Parameters:
fqdn- a fully qualified domain namenotBefore- Certificate is not valid before this timenotAfter- Certificate is not valid after this timealgorithm- Key pair algorithmbits- the number of bits of the generated private key- Throws:
CertificateException
-
SelfSignedCertificate
public SelfSignedCertificate(String fqdn, SecureRandom random, int bits) throws CertificateException Deprecated.Creates a new instance.Algorithm: RSA
- Parameters:
fqdn- a fully qualified domain namerandom- theSecureRandomto usebits- the number of bits of the generated private key- Throws:
CertificateException
-
SelfSignedCertificate
public SelfSignedCertificate(String fqdn, SecureRandom random, String algorithm, int bits) throws CertificateException Deprecated.Creates a new instance.- Parameters:
fqdn- a fully qualified domain namerandom- theSecureRandomto usealgorithm- Key pair algorithmbits- the number of bits of the generated private key- Throws:
CertificateException
-
SelfSignedCertificate
public SelfSignedCertificate(String fqdn, SecureRandom random, int bits, Date notBefore, Date notAfter) throws CertificateException Deprecated.Creates a new instance.Algorithm: RSA
- Parameters:
fqdn- a fully qualified domain namerandom- theSecureRandomto usebits- the number of bits of the generated private keynotBefore- Certificate is not valid before this timenotAfter- Certificate is not valid after this time- Throws:
CertificateException
-
SelfSignedCertificate
public SelfSignedCertificate(String fqdn, SecureRandom random, int bits, Date notBefore, Date notAfter, String algorithm) throws CertificateException Deprecated.Creates a new instance.- Parameters:
fqdn- a fully qualified domain namerandom- theSecureRandomto usebits- the number of bits of the generated private keynotBefore- Certificate is not valid before this timenotAfter- Certificate is not valid after this timealgorithm- Key pair algorithm- Throws:
CertificateException
-
SelfSignedCertificate
Deprecated.- Throws:
CertificateException
-
-
Method Details
-
builder
Deprecated. -
certificate
-
privateKey
-
cert
-
key
-
delete
public void delete()Deprecated.Deletes the generated X.509 certificate file and EC/RSA private key file. -
newSelfSignedCertificate
static String[] newSelfSignedCertificate(String fqdn, PrivateKey key, X509Certificate cert) throws IOException, CertificateEncodingException Deprecated. -
safeDelete
Deprecated. -
safeClose
Deprecated. -
isBouncyCastleAvailable
private static boolean isBouncyCastleAvailable()Deprecated.
-
CertificateBuilderfromnetty-pkitestinginstead.