Class DevKeyEncryptionSecret
java.lang.Object
com.irurueta.authserver.authorization.infrastructure.keys.DevKeyEncryptionSecret
@Configuration(proxyBeanMethods=false)
@Profile("dev")
public class DevKeyEncryptionSecret
extends Object
Provides the key-encryption inputs when the
dev profile is active, so a developer does not have to
configure anything: a random passphrase and salt are generated once per machine, stored in a file under
~/.irurueta-auth-server/ that only the owner can read, and reused at every start, which keeps the signing
keys persisted in the development database decryptable across restarts. Values configured explicitly
(authserver.keys.encryption.password and .salt), as the end-to-end tests do, win over the file.
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 (the same reason as for the
demo data initializer of the persistence adapter). It is inert everywhere else: without the dev profile
the bean is not created and the inputs must be configured. Nothing is ever written inside the repository.
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) static final StringDirectory, under the user's home, that holds the per-machine secret.(package private) static final StringName of the file that holds the per-machine secret.private static final StringPOSIX permissions of the secret file.private static final intNumber of random bytes of the generated passphrase.private static final SecureRandomSource of the generated values.private static final intNumber of random bytes of the generated salt. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static voidCreates the secret file, readable by its owner only where the file system supports it.keyEncryptionProperties(String password, String salt) Creates the key-encryption inputs from configuration or, when that is missing, from the per-machine file.(package private) static KeyEncryptionPropertiesReads the per-machine secret from a directory, creating it first when it does not exist yet.
-
Field Details
-
DIRECTORY
Directory, under the user's home, that holds the per-machine secret.- See Also:
-
FILE_NAME
Name of the file that holds the per-machine secret.- See Also:
-
RANDOM
Source of the generated values. -
OWNER_ONLY
POSIX permissions of the secret file.- See Also:
-
PASSPHRASE_BYTES
private static final int PASSPHRASE_BYTESNumber of random bytes of the generated passphrase.- See Also:
-
SALT_BYTES
private static final int SALT_BYTESNumber of random bytes of the generated salt.- See Also:
-
-
Constructor Details
-
DevKeyEncryptionSecret
public DevKeyEncryptionSecret()
-
-
Method Details
-
keyEncryptionProperties
@Bean public KeyEncryptionProperties keyEncryptionProperties(@Value("${authserver.keys.encryption.password:}") String password, @Value("${authserver.keys.encryption.salt:}") String salt) Creates the key-encryption inputs from configuration or, when that is missing, from the per-machine file.- Parameters:
password- configured passphrase, empty when not configured.salt- configured hex-encoded salt, empty when not configured.- Returns:
- the inputs.
-
load
Reads the per-machine secret from a directory, creating it first when it does not exist yet.- Parameters:
directory- directory that holds the secret.- Returns:
- the inputs.
- Throws:
UncheckedIOException- if the secret cannot be read or created.
-
create
Creates the secret file, readable by its owner only where the file system supports it.- Parameters:
file- the file to create.- Throws:
IOException- if it cannot be written.
-