Package org.jboss.netty.handler.ssl.util
Class SelfSignedCertificate
java.lang.Object
org.jboss.netty.handler.ssl.util.SelfSignedCertificate
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.
A X.509 certificate file and a 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.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final File
private static final InternalLogger
(package private) static final Date
The maximum possible value in X.509 specification: 9999-12-31 23:59:59(package private) static final Date
Current time minus 1 year, just in case software clock goes back due to time synchronizationprivate final File
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a new instance.SelfSignedCertificate
(String fqdn) Creates a new instance.SelfSignedCertificate
(String fqdn, SecureRandom random, int bits) Creates a new instance. -
Method Summary
Modifier and TypeMethodDescriptionReturns the generated X.509 certificate file in PEM format.void
delete()
Deletes the generated X.509 certificate file and RSA private key file.(package private) static String[]
newSelfSignedCertificate
(String fqdn, PrivateKey key, X509Certificate cert) Returns the generated RSA private key file in PEM format.private static void
safeClose
(File keyFile, OutputStream keyOut) private static void
safeDelete
(File certFile)
-
Field Details
-
logger
-
NOT_BEFORE
Current time minus 1 year, just in case software clock goes back due to time synchronization -
NOT_AFTER
The maximum possible value in X.509 specification: 9999-12-31 23:59:59 -
certificate
-
privateKey
-
-
Constructor Details
-
SelfSignedCertificate
Creates a new instance.- Throws:
CertificateException
-
SelfSignedCertificate
Creates a new instance.- Parameters:
fqdn
- a fully qualified domain name- Throws:
CertificateException
-
SelfSignedCertificate
public SelfSignedCertificate(String fqdn, SecureRandom random, int bits) throws CertificateException Creates a new instance.- Parameters:
fqdn
- a fully qualified domain namerandom
- theSecureRandom
to usebits
- the number of bits of the generated private key- Throws:
CertificateException
-
-
Method Details
-
certificate
Returns the generated X.509 certificate file in PEM format. -
privateKey
Returns the generated RSA private key file in PEM format. -
delete
public void delete()Deletes the generated X.509 certificate file and RSA private key file. -
newSelfSignedCertificate
static String[] newSelfSignedCertificate(String fqdn, PrivateKey key, X509Certificate cert) throws IOException, CertificateEncodingException -
safeDelete
-
safeClose
-