public class SecretsUtils extends Object
This type (including all methods, constructors and fields) is continuing to evolve and so should be expected to change, potentially in backwards-incompatible ways even in a minor release. Changes are documented at the time of product release.
Constructor and Description |
---|
SecretsUtils() |
Modifier and Type | Method and Description |
---|---|
static Key |
convertRawEncryptionKey(CryptoKey cryptoKey,
JweAlgorithm jweAlgorithm,
EncryptionMethod encryptionMethod)
Converts symmetric encryption key that was created using the RAW algorithm to a more suitable key, but
only if the key material is available.
|
static void |
createKeyStorePurposeMapping(SecretIdRegistry secretIdRegistry,
KeyStoreSecretStore keyStore,
String purposeLabel,
List<String> aliases,
Optional<Realm> realm,
SSOToken authorizationToken)
Creates a global purpose and adds a mapping for it to the given key alias in the given keystore.
|
static byte[] |
encodeAndEncryptSecret(byte[] secret)
Encrypt a secret ready to be stored in a file that will be read by a
FileSystemSecretStore using the
PropertyFormat.ENCRYPTED_BASE64 and
PropertyFormat.ENCRYPTED_HMAC_KEY formats. |
static byte[] |
encryptSecret(char[] secret)
Encrypt a secret ready to be stored in a file that will be read by a
FileSystemSecretStore using the
PropertyFormat.ENCRYPTED_PLAIN format. |
static FileSystemSecretStore |
fileSystemSecretStore(String id,
Path path,
PropertyFormat propertyFormat)
Create a
FileSystemSecretStore ready to persist in the AnnotatedServiceRegistry . |
static KeyStoreSecretStore |
getDefaultKeyStore(AnnotatedServiceRegistry serviceRegistry)
Gets the default keystore from the global scope.
|
static KeyStoreKeyIdProvider |
getKeyStoreKeyIdProvider()
Obtains a new instance of the configured keystore key ID provider implementation.
|
static String |
getStaticId(KeyUse keyUse,
String internalId,
PublicKey key)
Create the static ID for an asymmetric key secret by combining it's internal ID
|
static void |
lockDownFilePermissions(Path file)
Ensure that the given file is only readable by ourselves.
|
static PurposeMapping |
purposeMapping(String label,
List<String> aliases)
Create a purpose mapping for the label and alias valid from the current time.
|
static Purpose<KeyEncryptionKey> |
realmQualifiedEncryptionPurpose(String realm,
String rootPurpose)
Returns the purpose to use at the global scope for looking up a realm-specific encryption
key.
|
static String |
realmQualifiedPurposeLabel(String realm,
String label)
Creates a variant of the given purpose label that is qualified to the given realm.
|
static String |
sanitisePurposeLabel(String label)
Remove illegal characters from a purpose label.
|
static String |
secretId(String secretIdFormat,
String instanceName)
Returns the secret ID formatted to include the sanitized instance name as well.
|
static void |
writeSecretFile(Path secretsPath,
String purposeLabel,
byte[] content)
Writes an encrypted password file to the given secret file location.
|
public static void writeSecretFile(Path secretsPath, String purposeLabel, byte[] content) throws IOException
secretsPath
- the path to the directory for storing secrets.purposeLabel
- the purpose for this secret.content
- the content to write.IOException
- if the password file cannot be written or permissions cannot be set.public static void createKeyStorePurposeMapping(SecretIdRegistry secretIdRegistry, KeyStoreSecretStore keyStore, String purposeLabel, List<String> aliases, Optional<Realm> realm, SSOToken authorizationToken) throws SMSException, SSOException
secretIdRegistry
- the secret ID registry.keyStore
- the keystore to add the mapping to.purposeLabel
- the purpose to add the mapping for.aliases
- the keystore alias list to map the purpose to.SMSException
- if the global purpose cannot be read.SSOException
- if a permission error occurs.public static PurposeMapping purposeMapping(String label, List<String> aliases)
label
- The label.aliases
- The alias list.public static byte[] encryptSecret(char[] secret)
FileSystemSecretStore
using the
PropertyFormat.ENCRYPTED_PLAIN
format.secret
- The secret.public static byte[] encodeAndEncryptSecret(byte[] secret)
FileSystemSecretStore
using the
PropertyFormat.ENCRYPTED_BASE64
and
PropertyFormat.ENCRYPTED_HMAC_KEY
formats.secret
- The secret.public static FileSystemSecretStore fileSystemSecretStore(String id, Path path, PropertyFormat propertyFormat)
FileSystemSecretStore
ready to persist in the AnnotatedServiceRegistry
. The store
will use the provided property format
, suitable for use with files created with
SecretsUtils.encryptSecret(char[])
or SecretsUtils.encodeAndEncryptSecret(byte[])
depending on the property format.id
- The store ID.path
- The path that files will be found in.propertyFormat
- The format that the file is in.public static Purpose<KeyEncryptionKey> realmQualifiedEncryptionPurpose(String realm, String rootPurpose)
realm
- the realm name (path).rootPurpose
- the basic purpose, e.g. "PersistentCookieEncryption".public static String realmQualifiedPurposeLabel(String realm, String label)
realm
- The realm.label
- The original label.public static KeyStoreSecretStore getDefaultKeyStore(AnnotatedServiceRegistry serviceRegistry) throws SMSException, SSOException
serviceRegistry
- the service registry.SMSException
- if the configuration cannot be read.SSOException
- if a permissions error occurs.public static String secretId(String secretIdFormat, String instanceName)
secretIdFormat
- The string to format.instanceName
- The instance name to be sanitized and included.public static String sanitisePurposeLabel(String label)
label
- the labelpublic static void lockDownFilePermissions(Path file) throws IOException
file
- the file to lockdown permissions for.IOException
public static String getStaticId(KeyUse keyUse, String internalId, PublicKey key)
keyUse
- The usage for the secret that is represented.internalId
- The internal ID of the secret, e.g. the alias in the keystore.key
- The public key.public static KeyStoreKeyIdProvider getKeyStoreKeyIdProvider()
public static Key convertRawEncryptionKey(CryptoKey cryptoKey, JweAlgorithm jweAlgorithm, EncryptionMethod encryptionMethod) throws NoSuchSecretException
cryptoKey
- The cryptographic key to be converted.jweAlgorithm
- The encryption algorithm.encryptionMethod
- The encryption method.NoSuchSecretException
- If the key could not be exported.Copyright © 2010-2018, ForgeRock All Rights Reserved.