Class SelfSignedCertificate


  • @Deprecated
    public final class SelfSignedCertificate
    extends java.lang.Object
    Deprecated.
    Use the CertificateBuilder from netty-pkitesting instead.
    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.

    • Constructor Summary

      Constructors 
      Constructor Description
      SelfSignedCertificate()
      Deprecated.
      Creates a new instance.
      SelfSignedCertificate​(java.lang.String fqdn)
      Deprecated.
      Creates a new instance.
      SelfSignedCertificate​(java.lang.String fqdn, java.lang.String algorithm, int bits)
      Deprecated.
      Creates a new instance.
      SelfSignedCertificate​(java.lang.String fqdn, java.security.SecureRandom random, int bits)
      Deprecated.
      Creates a new instance.
      SelfSignedCertificate​(java.lang.String fqdn, java.security.SecureRandom random, int bits, java.util.Date notBefore, java.util.Date notAfter)
      Deprecated.
      Creates a new instance.
      SelfSignedCertificate​(java.lang.String fqdn, java.security.SecureRandom random, int bits, java.util.Date notBefore, java.util.Date notAfter, java.lang.String algorithm)
      Deprecated.
      Creates a new instance.
      SelfSignedCertificate​(java.lang.String fqdn, java.security.SecureRandom random, java.lang.String algorithm, int bits)
      Deprecated.
      Creates a new instance.
      SelfSignedCertificate​(java.lang.String fqdn, java.util.Date notBefore, java.util.Date notAfter)
      Deprecated.
      Creates a new instance.
      SelfSignedCertificate​(java.lang.String fqdn, java.util.Date notBefore, java.util.Date notAfter, java.lang.String algorithm, int bits)
      Deprecated.
      Creates a new instance.
      SelfSignedCertificate​(java.util.Date notBefore, java.util.Date notAfter)
      Deprecated.
      Creates a new instance.
      SelfSignedCertificate​(java.util.Date notBefore, java.util.Date notAfter, java.lang.String algorithm, int bits)
      Deprecated.
      Creates a new instance.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      static SelfSignedCertificate.Builder builder()
      Deprecated.
       
      java.security.cert.X509Certificate cert()
      Deprecated.
      Returns the generated X.509 certificate.
      java.io.File certificate()
      Deprecated.
      Returns the generated X.509 certificate file in PEM format.
      void delete()
      Deprecated.
      Deletes the generated X.509 certificate file and EC/RSA private key file.
      java.security.PrivateKey key()
      Deprecated.
      Returns the generated EC/RSA private key.
      java.io.File privateKey()
      Deprecated.
      Returns the generated EC/RSA private key file in PEM format.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • SelfSignedCertificate

        public SelfSignedCertificate()
                              throws java.security.cert.CertificateException
        Deprecated.
        Creates a new instance.

        Algorithm: RSA

        Throws:
        java.security.cert.CertificateException
      • SelfSignedCertificate

        public SelfSignedCertificate​(java.util.Date notBefore,
                                     java.util.Date notAfter)
                              throws java.security.cert.CertificateException
        Deprecated.
        Creates a new instance.

        Algorithm: RSA

        Parameters:
        notBefore - Certificate is not valid before this time
        notAfter - Certificate is not valid after this time
        Throws:
        java.security.cert.CertificateException
      • SelfSignedCertificate

        public SelfSignedCertificate​(java.util.Date notBefore,
                                     java.util.Date notAfter,
                                     java.lang.String algorithm,
                                     int bits)
                              throws java.security.cert.CertificateException
        Deprecated.
        Creates a new instance.
        Parameters:
        notBefore - Certificate is not valid before this time
        notAfter - Certificate is not valid after this time
        algorithm - Key pair algorithm
        bits - the number of bits of the generated private key
        Throws:
        java.security.cert.CertificateException
      • SelfSignedCertificate

        public SelfSignedCertificate​(java.lang.String fqdn)
                              throws java.security.cert.CertificateException
        Deprecated.
        Creates a new instance.

        Algorithm: RSA

        Parameters:
        fqdn - a fully qualified domain name
        Throws:
        java.security.cert.CertificateException
      • SelfSignedCertificate

        public SelfSignedCertificate​(java.lang.String fqdn,
                                     java.lang.String algorithm,
                                     int bits)
                              throws java.security.cert.CertificateException
        Deprecated.
        Creates a new instance.
        Parameters:
        fqdn - a fully qualified domain name
        algorithm - Key pair algorithm
        bits - the number of bits of the generated private key
        Throws:
        java.security.cert.CertificateException
      • SelfSignedCertificate

        public SelfSignedCertificate​(java.lang.String fqdn,
                                     java.util.Date notBefore,
                                     java.util.Date notAfter)
                              throws java.security.cert.CertificateException
        Deprecated.
        Creates a new instance.

        Algorithm: RSA

        Parameters:
        fqdn - a fully qualified domain name
        notBefore - Certificate is not valid before this time
        notAfter - Certificate is not valid after this time
        Throws:
        java.security.cert.CertificateException
      • SelfSignedCertificate

        public SelfSignedCertificate​(java.lang.String fqdn,
                                     java.util.Date notBefore,
                                     java.util.Date notAfter,
                                     java.lang.String algorithm,
                                     int bits)
                              throws java.security.cert.CertificateException
        Deprecated.
        Creates a new instance.
        Parameters:
        fqdn - a fully qualified domain name
        notBefore - Certificate is not valid before this time
        notAfter - Certificate is not valid after this time
        algorithm - Key pair algorithm
        bits - the number of bits of the generated private key
        Throws:
        java.security.cert.CertificateException
      • SelfSignedCertificate

        public SelfSignedCertificate​(java.lang.String fqdn,
                                     java.security.SecureRandom random,
                                     int bits)
                              throws java.security.cert.CertificateException
        Deprecated.
        Creates a new instance.

        Algorithm: RSA

        Parameters:
        fqdn - a fully qualified domain name
        random - the SecureRandom to use
        bits - the number of bits of the generated private key
        Throws:
        java.security.cert.CertificateException
      • SelfSignedCertificate

        public SelfSignedCertificate​(java.lang.String fqdn,
                                     java.security.SecureRandom random,
                                     java.lang.String algorithm,
                                     int bits)
                              throws java.security.cert.CertificateException
        Deprecated.
        Creates a new instance.
        Parameters:
        fqdn - a fully qualified domain name
        random - the SecureRandom to use
        algorithm - Key pair algorithm
        bits - the number of bits of the generated private key
        Throws:
        java.security.cert.CertificateException
      • SelfSignedCertificate

        public SelfSignedCertificate​(java.lang.String fqdn,
                                     java.security.SecureRandom random,
                                     int bits,
                                     java.util.Date notBefore,
                                     java.util.Date notAfter)
                              throws java.security.cert.CertificateException
        Deprecated.
        Creates a new instance.

        Algorithm: RSA

        Parameters:
        fqdn - a fully qualified domain name
        random - the SecureRandom to use
        bits - the number of bits of the generated private key
        notBefore - Certificate is not valid before this time
        notAfter - Certificate is not valid after this time
        Throws:
        java.security.cert.CertificateException
      • SelfSignedCertificate

        public SelfSignedCertificate​(java.lang.String fqdn,
                                     java.security.SecureRandom random,
                                     int bits,
                                     java.util.Date notBefore,
                                     java.util.Date notAfter,
                                     java.lang.String algorithm)
                              throws java.security.cert.CertificateException
        Deprecated.
        Creates a new instance.
        Parameters:
        fqdn - a fully qualified domain name
        random - the SecureRandom to use
        bits - the number of bits of the generated private key
        notBefore - Certificate is not valid before this time
        notAfter - Certificate is not valid after this time
        algorithm - Key pair algorithm
        Throws:
        java.security.cert.CertificateException
    • Method Detail

      • certificate

        public java.io.File certificate()
        Deprecated.
        Returns the generated X.509 certificate file in PEM format.
      • privateKey

        public java.io.File privateKey()
        Deprecated.
        Returns the generated EC/RSA private key file in PEM format.
      • cert

        public java.security.cert.X509Certificate cert()
        Deprecated.
        Returns the generated X.509 certificate.
      • key

        public java.security.PrivateKey key()
        Deprecated.
        Returns the generated EC/RSA private key.
      • delete

        public void delete()
        Deprecated.
        Deletes the generated X.509 certificate file and EC/RSA private key file.