Class DevX509KeyStore
java.lang.Object
com.irurueta.authserver.authorization.api.web.x509.DevX509KeyStore
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
FieldsModifier and TypeFieldDescription(package private) static final StringDirectory, under the user's home, that holds the per-machine files.private static final DurationLongest time the generation may take.(package private) static final StringName of the key store file.(package private) static final StringType of the generated key store.private static final StringPOSIX permissions of the generated files.private static final intNumber of random bytes of the generated password.(package private) static final StringName of the file that holds the password of the key store.private static final SecureRandomSource of the generated password.private static final StringValidity of the generated certificate, in days. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate voidCreates the password file and the key store, both readable by their owner only where the file system supports it.private static voidcreateOwnerOnly(Path file) Creates an empty file readable by its owner only, where the file system supports it.load()Reads the per-machine key store, generating it first when it does not exist yet, in the home directory of the user.(package private) X509TlsKeyStoreReads the key store of a directory, generating it first when it does not exist yet.private static voidRestricts a file to its owner, where the file system supports it.private voidrunKeytool(Path keyStore, Path passwordFile) Generates the key pair and its self-signed certificate.
-
Field Details
-
DIRECTORY
Directory, under the user's home, that holds the per-machine files.- See Also:
-
KEY_STORE_FILE
Name of the key store file.- See Also:
-
PASSWORD_FILE
Name of the file that holds the password of the key store.- See Also:
-
KEY_STORE_TYPE
Type of the generated key store.- See Also:
-
OWNER_ONLY
POSIX permissions of the generated files.- See Also:
-
PASSWORD_BYTES
private static final int PASSWORD_BYTESNumber of random bytes of the generated password.- See Also:
-
VALIDITY_DAYS
Validity of the generated certificate, in days.- See Also:
-
GENERATION_TIMEOUT
Longest time the generation may take. -
RANDOM
Source of the generated password.
-
-
Constructor Details
-
DevX509KeyStore
public DevX509KeyStore()
-
-
Method Details
-
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- ifkeytoolfails.
-
load
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- ifkeytoolfails.
-
create
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 orkeytoolcannot run.
-
runKeytool
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- ifkeytoolcannot run.
-
createOwnerOnly
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
Restricts a file to its owner, where the file system supports it.- Parameters:
file- the file.- Throws:
IOException- if the permissions cannot be changed.
-