java.lang.Object
com.irurueta.authserver.authorization.api.web.x509.DevX509KeyStore

public class DevX509KeyStore extends Object
Provides the server certificate of the dedicated TLS port when the dev profile is active and none is configured, so a developer does not have to create one: a self-signed certificate for localhost is generated once per machine with the JDK's keytool, stored in a key store under ~/.irurueta-auth-server/ that only the owner can read (its password in a file next to it, as DevKeyEncryptionSecret keeps its secret) and reused at every start. Nothing is ever written inside the repository.

Why it lives in src/main although it only serves development: the end-to-end tests run the packaged jar with the dev profile, and a class under src/test never reaches it. It is inert everywhere else: the bean exists only under the dev profile, and the port itself is off unless authserver.x509.port is set. The clients' certificates are never validated by the connector (the fingerprint binding is what identifies them), so the key store holds the server's certificate only.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    (package private) static final String
    Directory, under the user's home, that holds the per-machine files.
    private static final Duration
    Longest time the generation may take.
    (package private) static final String
    Name of the key store file.
    (package private) static final String
    Type of the generated key store.
    private static final String
    POSIX permissions of the generated files.
    private static final int
    Number of random bytes of the generated password.
    (package private) static final String
    Name of the file that holds the password of the key store.
    private static final SecureRandom
    Source of the generated password.
    private static final String
    Validity of the generated certificate, in days.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    private void
    create(Path keyStore, Path passwordFile)
    Creates the password file and the key store, both readable by their owner only where the file system supports it.
    private static void
    Creates an empty file readable by its owner only, where the file system supports it.
    Reads the per-machine key store, generating it first when it does not exist yet, in the home directory of the user.
    (package private) X509TlsKeyStore
    load(Path directory)
    Reads the key store of a directory, generating it first when it does not exist yet.
    private static void
    Restricts a file to its owner, where the file system supports it.
    private void
    runKeytool(Path keyStore, Path passwordFile)
    Generates the key pair and its self-signed certificate.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • DIRECTORY

      static final String DIRECTORY
      Directory, under the user's home, that holds the per-machine files.
      See Also:
    • KEY_STORE_FILE

      static final String KEY_STORE_FILE
      Name of the key store file.
      See Also:
    • PASSWORD_FILE

      static final String PASSWORD_FILE
      Name of the file that holds the password of the key store.
      See Also:
    • KEY_STORE_TYPE

      static final String KEY_STORE_TYPE
      Type of the generated key store.
      See Also:
    • OWNER_ONLY

      private static final String OWNER_ONLY
      POSIX permissions of the generated files.
      See Also:
    • PASSWORD_BYTES

      private static final int PASSWORD_BYTES
      Number of random bytes of the generated password.
      See Also:
    • VALIDITY_DAYS

      private static final String VALIDITY_DAYS
      Validity of the generated certificate, in days.
      See Also:
    • GENERATION_TIMEOUT

      private static final Duration GENERATION_TIMEOUT
      Longest time the generation may take.
    • RANDOM

      private static final SecureRandom RANDOM
      Source of the generated password.
  • Constructor Details

    • DevX509KeyStore

      public DevX509KeyStore()
  • Method Details

    • load

      public X509TlsKeyStore load()
      Reads the per-machine key store, generating it first when it does not exist yet, in the home directory of the user.
      Returns:
      the key store.
      Throws:
      UncheckedIOException - if the files cannot be read or created.
      IllegalStateException - if keytool fails.
    • load

      X509TlsKeyStore load(Path directory)
      Reads the key store of a directory, generating it first when it does not exist yet.
      Parameters:
      directory - directory that holds the key store and its password.
      Returns:
      the key store.
      Throws:
      UncheckedIOException - if the files cannot be read or created.
      IllegalStateException - if keytool fails.
    • create

      private void create(Path keyStore, Path passwordFile) throws IOException
      Creates the password file and the key store, both readable by their owner only where the file system supports it.
      Parameters:
      keyStore - the key store to create.
      passwordFile - the file that holds its password.
      Throws:
      IOException - if a file cannot be written or keytool cannot run.
    • runKeytool

      private void runKeytool(Path keyStore, Path passwordFile) throws IOException
      Generates the key pair and its self-signed certificate.
      Parameters:
      keyStore - the key store to create.
      passwordFile - the file that holds its password.
      Throws:
      IOException - if keytool cannot run.
    • createOwnerOnly

      private static void createOwnerOnly(Path file) throws IOException
      Creates an empty file readable by its owner only, where the file system supports it.
      Parameters:
      file - the file to create.
      Throws:
      IOException - if the file cannot be created.
    • ownerOnly

      private static void ownerOnly(Path file) throws IOException
      Restricts a file to its owner, where the file system supports it.
      Parameters:
      file - the file.
      Throws:
      IOException - if the permissions cannot be changed.