Este conteúdo não está disponível no idioma selecionado.
Chapter 2. Providing an initial key to JBoss EAP to unlock secured resources
2.1. Encrypted expressions in Elytron Copiar o linkLink copiado para a área de transferência!
To maintain the secrecy of your sensitive strings, you can use encrypted expressions instead of the sensitive strings in the server configuration file.
An encrypted expression is one that results from encrypting a string with a SecretKeyCredential, then combining it with its encoding prefix and resolver name. The encoding prefix tells Elytron that the expression is an encrypted expression. The resolver maps the encrypted expression to its corresponding SecretKeyCredential in a credential store.
The expression=encryption resource in Elytron uses an encrypted expression to decode the encrypted string inside it at run time. By using an encrypted expression instead of the sensitive string itself in the configuration file, you protect the secrecy of the string. An encrypted expression takes the following format:
Syntax when using a specific resolver
${ENC::RESOLVER_NAME:ENCRYPTED_STRING}
${ENC::RESOLVER_NAME:ENCRYPTED_STRING}
ENC is the prefix that denotes an encrypted expression.
RESOLVER_NAME is the resolver Elytron uses to decrypt the encrypted string.
Example
${ENC::initialresolver:RUxZAUMQE+L5zx9LmCRLyh5fjdfl1WM7lhfthKjeoEU+x+RMi6s=}
${ENC::initialresolver:RUxZAUMQE+L5zx9LmCRLyh5fjdfl1WM7lhfthKjeoEU+x+RMi6s=}
If you create an encrypted expression with a default resolver, it looks like this:
Syntax when using the default resolver
${ENC::ENCRYPTED_STRING}
${ENC::ENCRYPTED_STRING}
Example
${ENC::RUxZAUMQE+L5zx9LmCRLyh5fjdfl1WM7lhfthKjeoEU+x+RMi6s=}
${ENC::RUxZAUMQE+L5zx9LmCRLyh5fjdfl1WM7lhfthKjeoEU+x+RMi6s=}
In this case, Elytron uses the default resolver you defined in the expression=encryption resource to decrypt an expression. You can use an encrypted expression on any resource attribute that supports it. To find out whether an attribute supports encrypted expression, use the read-resource-description operation, for example:
Example read-resource-description on mail/mail-session
In this example, the attribute from supports encrypted expressions. This means that you can hide your email address in the from field by encrypting it and then using the encrypted expression instead.
2.2. Creating an encrypted expression in Elytron Copiar o linkLink copiado para a área de transferência!
Create an encrypted expression from a sensitive string and a SecretKeyCredential. Use this encrypted expression instead of the sensitive string in the management model - the server configuration file, to maintain the secrecy of the sensitive string.
Prerequisites
You have created a PropertiesCredentialStore and a secret key in it.
For more information, see Creating a PropertiesCredentialStore/
secret-key-credential-storefor a standalone server.
Procedure
Create a resolver that references the alias of an existing SecretKeyCredential in a credential store using the following management CLI command:
Syntax
/subsystem=elytron/expression=encryption:add(resolvers=[{name=<name_of_the_resolver>, credential-store=<name_of_credential_store>, secret-key=<secret_key_alias>}])/subsystem=elytron/expression=encryption:add(resolvers=[{name=<name_of_the_resolver>, credential-store=<name_of_credential_store>, secret-key=<secret_key_alias>}])Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example
/subsystem=elytron/expression=encryption:add(resolvers=[{name=exampleResolver, credential-store=examplePropertiesCredentialStore, secret-key=key}])/subsystem=elytron/expression=encryption:add(resolvers=[{name=exampleResolver, credential-store=examplePropertiesCredentialStore, secret-key=key}])Copy to Clipboard Copied! Toggle word wrap Toggle overflow If an error message about a duplicate resource displays, use the
list-addoperation instead ofadd, as follows:Syntax
/subsystem=elytron/expression=encryption:list-add(name=resolvers, value={name=<name_of_the_resolver>, credential-store=<name_of_credential_store>, secret-key=<secret_key_alias>})/subsystem=elytron/expression=encryption:list-add(name=resolvers, value={name=<name_of_the_resolver>, credential-store=<name_of_credential_store>, secret-key=<secret_key_alias>})Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Reload the server.
reload
reloadCopy to Clipboard Copied! Toggle word wrap Toggle overflow Disable caching of commands in the management CLI:
ImportantIf you do not disable caching, the secret key is visible to anyone who can access the management CLI history file.
history --disable
history --disableCopy to Clipboard Copied! Toggle word wrap Toggle overflow Create an encrypted expression using the following management CLI command:
Syntax
/subsystem=elytron/expression=encryption:create-expression(resolver=<existing_resolver>, clear-text=<sensitive_string_to_protect>)
/subsystem=elytron/expression=encryption:create-expression(resolver=<existing_resolver>, clear-text=<sensitive_string_to_protect>)Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example
/subsystem=elytron/expression=encryption:create-expression(resolver=exampleResolver, clear-text=TestPassword) { "outcome" => "success", "result" => {"expression" => "${ENC::exampleResolver:RUxZAUMQgtpG7oFlHR2j1Gkn3GKIHff+HR8GcMX1QXHvx2uGurI=}"} }/subsystem=elytron/expression=encryption:create-expression(resolver=exampleResolver, clear-text=TestPassword) { "outcome" => "success", "result" => {"expression" => "${ENC::exampleResolver:RUxZAUMQgtpG7oFlHR2j1Gkn3GKIHff+HR8GcMX1QXHvx2uGurI=}"} }Copy to Clipboard Copied! Toggle word wrap Toggle overflow ${ENC::exampleResolver:RUxZAUMQgtpG7oFlHR2j1Gkn3GKIHff+HR8GcMX1QXHvx2uGurI=}is the encrypted expression you use instead ofTestPasswordin the management model.If you use the same plain text in different locations, repeat this command each time before you use the encrypted expression instead of the plain text in that location. When you repeat the same command for the same plain text, you get a different result for the same key because Elytron uses a unique initialization vector for each call.
By using different encrypted expressions you make sure that, if one encrypted expression on a string is somehow compromised, users cannot discover that any other encrypted expressions might also contain the same string.
Re-enable the command caching using the following management CLI command:
history --enable
history --enableCopy to Clipboard Copied! Toggle word wrap Toggle overflow
2.3. Using an encrypted expression to secure a KeyStoreCredentialStore/credential-store Copiar o linkLink copiado para a área de transferência!
You can use an encrypted expression to secure a KeyStoreCredentialStore.
Prerequisites
You have created an encrypted expression.
For information about creating an encrypted expression, see Creating an encrypted expression in Elytron.
Procedure
Create a KeyStoreCredentialStore that uses an encrypted expression as the
clear-text:Syntax
/subsystem=elytron/credential-store=<name_of_credential_store>:add(path=<path_to_the_credential_store>, create=true, modifiable=true, credential-reference={clear-text=<encrypted_expression>})/subsystem=elytron/credential-store=<name_of_credential_store>:add(path=<path_to_the_credential_store>, create=true, modifiable=true, credential-reference={clear-text=<encrypted_expression>})Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example
/subsystem=elytron/credential-store=secureKeyStoreCredentialStore:add(path="secureKeyStoreCredentialStore.jceks", relative-to=jboss.server.data.dir, create=true, modifiable=true, credential-reference={clear-text=${ENC::exampleResolver:RUxZAUMQgtpG7oFlHR2j1Gkn3GKIHff+HR8GcMX1QXHvx2uGurI=}}) {"outcome" => "success"}/subsystem=elytron/credential-store=secureKeyStoreCredentialStore:add(path="secureKeyStoreCredentialStore.jceks", relative-to=jboss.server.data.dir, create=true, modifiable=true, credential-reference={clear-text=${ENC::exampleResolver:RUxZAUMQgtpG7oFlHR2j1Gkn3GKIHff+HR8GcMX1QXHvx2uGurI=}}) {"outcome" => "success"}Copy to Clipboard Copied! Toggle word wrap Toggle overflow
After you have secured a KeyStoreCredentialStore with an encrypted expression, you can generate a SecretKeyCredential in the KeyStoreCredentialStore and use the secret key to create another encrypted expression. You can then use this new encrypted expression instead of a sensitive string in the management model - the server configuration file. You can create an entire chain of credential stores for security. Such a chain makes it harder to guess the sensitive string because the string is protected as follows:
- The first encrypted expression secures a KeyStoreCredentialStore.
- Another encrypted expression secures a sensitive string.
- To decode the sensitive string, you would need to decrypt both the encrypted expressions.
As the chain of encrypted expressions becomes longer, it gets harder to decrypt the sensitive string.