Class TestCertificates

java.lang.Object
com.irurueta.authserver.testsupport.TestCertificates

public final class TestCertificates extends Object
Generates self-signed client certificates at run time for the tests of the sign-in with a client certificate, so no certificate, key or key store is ever kept in the repository. It drives the keytool of the JDK that runs the tests: the JDK has no public API to issue a certificate, and a key store file only exists in a temporary directory for the time it takes to read the certificate back.
  • Field Details

    • ALIAS

      private static final String ALIAS
      Alias of the generated key.
      See Also:
    • KEY_STORE_TYPE

      private static final String KEY_STORE_TYPE
      Type of the key store the certificate is read from.
      See Also:
    • EXPIRED_START

      private static final String EXPIRED_START
      Start of the validity of an expired certificate: five days ago, so that its two days are long gone.
      See Also:
    • PASSWORD_BYTES

      private static final int PASSWORD_BYTES
      Number of random bytes of the password of the temporary key store.
      See Also:
    • PEM_LINE_LENGTH

      private static final int PEM_LINE_LENGTH
      Characters of a line of a PEM certificate.
      See Also:
    • RANDOM

      private static final SecureRandom RANDOM
      Source of the password of the temporary key store.
  • Constructor Details

    • TestCertificates

      private TestCertificates()
      Not instantiable.
  • Method Details

    • generate

      public static TestCertificates.GeneratedCertificate generate(String commonName)
      Generates a self-signed certificate.
      Parameters:
      commonName - common name of the subject.
      Returns:
      the certificate, with its PEM text and its SHA-256 fingerprint.
    • generateExpired

      public static TestCertificates.GeneratedCertificate generateExpired(String commonName)
      Generates a self-signed certificate that expired days ago.
      Parameters:
      commonName - common name of the subject.
      Returns:
      the certificate, with its PEM text and its SHA-256 fingerprint.
    • generate

      private static TestCertificates.GeneratedCertificate generate(String commonName, List<String> extra)
      Generates a self-signed certificate.
      Parameters:
      commonName - common name of the subject.
      extra - additional keytool arguments.
      Returns:
      the certificate, with its PEM text and its SHA-256 fingerprint.
    • of

      Describes a certificate.
      Parameters:
      certificate - the certificate.
      Returns:
      the certificate with its PEM text and its SHA-256 fingerprint.