Package org.wildfly.security.tool
Class CredentialStoreCommand
- java.lang.Object
-
- org.wildfly.security.tool.Command
-
- org.wildfly.security.tool.CredentialStoreCommand
-
class CredentialStoreCommand extends Command
Credential Store Command Performs credential store related operations.- Author:
- Peter Skopek, Darran Lofthouse
-
-
Field Summary
-
Fields inherited from class org.wildfly.security.tool.Command
INPUT_DATA_NOT_CONFIRMED, WIDTH
-
-
Constructor Summary
Constructors Constructor Description CredentialStoreCommand()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidaddAlias(String secret, CredentialStore credentialStore, String entryType, String location)private voidaliasCredentialTypes(CredentialStore credentialStore)protected Set<String>aliases()private voidaliases(CredentialStore credentialStore)private voidcheckAlias(CredentialStore credentialStore, String entryType, String storeType)private CredentialcreateCredential(String secret, String entryType)private CredentialcreateCredential(SecretKey secretKey, String entryType)private voidcreateCredentialStore(CredentialStore credentialStore)private KeyPairCredentialcreateKeyPairCredential(String algorithm, int size)private static Class<? extends Credential>defaultCredentialType(String storeType)private Stringencrypt(CredentialStore credentialStore)private Class<? extends Credential>entryTypeToCredential(String entryType, String storeType)voidexecute(String[] args)private voidexportKeyPairPublicKey(CredentialStore credentialStore, String entryType)private voidexportSecretKey(CredentialStore credentialStore)(package private) static StringformatPropertiesForCli(Map<String,String> properties)private voidgenerateKeyPair(CredentialStore credentialStore)private voidgenerateSecretKey(CredentialStore credentialStore, String entryType, int size)private intgetArgumentAsInt(String argument)private intgetArgumentAsInt(String argument, int defaultValue)(package private) static voidgetCreateDefaultSummary(Map<String,String> implProps, StringBuilder com, String password)(package private) static voidgetCreatePropertiesCredentialStoreSummary(StringBuilder com, String location)(package private) static voidgetUseExpressionExample(StringBuilder com, String cipherTextToken)voidhelp()Display help to the command.private voidimportKeyPair(CredentialStore credentialStore)private voidimportSecretKey(CredentialStore credentialStore, String entryType, String key)(package private) static Map<String,String>parseCredentialStoreProperties(String attributeString)private KeyPairCredentialparseKeyPairCredential(String privateKeyContent, String publicKeyContent, org.apache.sshd.common.config.keys.FilePasswordProvider passwordProvider)static Map<String,Object>readAttributesForPreservation(Path path)Reads the attributes that are required to be preserved in the file.private static voidreadAttributesForView(Path path, String prefix, String attributes, Map<String,Object> attrs)private voidremoveAlias(CredentialStore credentialStore, String entryType, String storeType)private static voidsafeClose(Closeable c)static voidsetAttributesForPreservation(Path path, Map<String,Object> attrs)Applies over a file all the attributes previously read by the readAttributesForPreservation method.-
Methods inherited from class org.wildfly.security.tool.Command
getProvidersSupplier, getStatus, getToolCommand, isAlias, isEnableDebug, isWindows, printDuplicatesWarning, printDuplicatesWarning, prompt, setEnableDebug, setStatus, setToolCommand
-
-
-
-
Field Detail
-
ACTION_NOT_DEFINED
public static int ACTION_NOT_DEFINED
-
ALIAS_NOT_FOUND
public static int ALIAS_NOT_FOUND
-
GENERAL_CONFIGURATION_ERROR
public static int GENERAL_CONFIGURATION_ERROR
-
RSA_ALGORITHM
public static final String RSA_ALGORITHM
- See Also:
- Constant Field Values
-
DSA_ALGORITHM
public static final String DSA_ALGORITHM
- See Also:
- Constant Field Values
-
EC_ALGORITHM
public static final String EC_ALGORITHM
- See Also:
- Constant Field Values
-
CREDENTIAL_STORE_COMMAND
public static final String CREDENTIAL_STORE_COMMAND
- See Also:
- Constant Field Values
-
STORE_LOCATION_PARAM
public static final String STORE_LOCATION_PARAM
- See Also:
- Constant Field Values
-
IMPLEMENTATION_PROPERTIES_PARAM
public static final String IMPLEMENTATION_PROPERTIES_PARAM
- See Also:
- Constant Field Values
-
CREDENTIAL_STORE_PASSWORD_PARAM
public static final String CREDENTIAL_STORE_PASSWORD_PARAM
- See Also:
- Constant Field Values
-
CREDENTIAL_STORE_TYPE_PARAM
public static final String CREDENTIAL_STORE_TYPE_PARAM
- See Also:
- Constant Field Values
-
SALT_PARAM
public static final String SALT_PARAM
- See Also:
- Constant Field Values
-
ITERATION_PARAM
public static final String ITERATION_PARAM
- See Also:
- Constant Field Values
-
PASSWORD_CREDENTIAL_VALUE_PARAM
public static final String PASSWORD_CREDENTIAL_VALUE_PARAM
- See Also:
- Constant Field Values
-
ADD_ALIAS_PARAM
public static final String ADD_ALIAS_PARAM
- See Also:
- Constant Field Values
-
ALIAS_ARGUMENT
public static final String ALIAS_ARGUMENT
- See Also:
- Constant Field Values
-
CHECK_ALIAS_PARAM
public static final String CHECK_ALIAS_PARAM
- See Also:
- Constant Field Values
-
ALIASES_PARAM
public static final String ALIASES_PARAM
- See Also:
- Constant Field Values
-
CREDENTIAL_TYPES
public static final String CREDENTIAL_TYPES
- See Also:
- Constant Field Values
-
REMOVE_ALIAS_PARAM
public static final String REMOVE_ALIAS_PARAM
- See Also:
- Constant Field Values
-
CREATE_CREDENTIAL_STORE_PARAM
public static final String CREATE_CREDENTIAL_STORE_PARAM
- See Also:
- Constant Field Values
-
HELP_PARAM
public static final String HELP_PARAM
- See Also:
- Constant Field Values
-
PRINT_SUMMARY_PARAM
public static final String PRINT_SUMMARY_PARAM
- See Also:
- Constant Field Values
-
ENTRY_TYPE_PARAM
public static final String ENTRY_TYPE_PARAM
- See Also:
- Constant Field Values
-
OTHER_PROVIDERS_PARAM
public static final String OTHER_PROVIDERS_PARAM
- See Also:
- Constant Field Values
-
DEBUG_PARAM
public static final String DEBUG_PARAM
- See Also:
- Constant Field Values
-
CUSTOM_CREDENTIAL_STORE_PROVIDER_PARAM
public static final String CUSTOM_CREDENTIAL_STORE_PROVIDER_PARAM
- See Also:
- Constant Field Values
-
SIZE_PARAM
public static final String SIZE_PARAM
- See Also:
- Constant Field Values
-
GENERATE_KEY_PAIR_PARAM
public static final String GENERATE_KEY_PAIR_PARAM
- See Also:
- Constant Field Values
-
ALGORITHM_PARAM
public static final String ALGORITHM_PARAM
- See Also:
- Constant Field Values
-
EXPORT_KEY_PAIR_PUBLIC_KEY_PARAM
public static final String EXPORT_KEY_PAIR_PUBLIC_KEY_PARAM
- See Also:
- Constant Field Values
-
IMPORT_KEY_PAIR_PARAM
public static final String IMPORT_KEY_PAIR_PARAM
- See Also:
- Constant Field Values
-
PRIVATE_KEY_LOCATION_PARAM
public static final String PRIVATE_KEY_LOCATION_PARAM
- See Also:
- Constant Field Values
-
PUBLIC_KEY_LOCATION_PARAM
public static final String PUBLIC_KEY_LOCATION_PARAM
- See Also:
- Constant Field Values
-
PRIVATE_KEY_STRING_PARAM
public static final String PRIVATE_KEY_STRING_PARAM
- See Also:
- Constant Field Values
-
PUBLIC_KEY_STRING_PARAM
public static final String PUBLIC_KEY_STRING_PARAM
- See Also:
- Constant Field Values
-
KEY_PASSPHRASE_PARAM
public static final String KEY_PASSPHRASE_PARAM
- See Also:
- Constant Field Values
-
GENERATE_SECRET_KEY
public static final String GENERATE_SECRET_KEY
- See Also:
- Constant Field Values
-
EXPORT_SECRET_KEY
public static final String EXPORT_SECRET_KEY
- See Also:
- Constant Field Values
-
IMPORT_SECRET_KEY
public static final String IMPORT_SECRET_KEY
- See Also:
- Constant Field Values
-
KEY_PARAM
public static final String KEY_PARAM
- See Also:
- Constant Field Values
-
ENCRYPT
public static final String ENCRYPT
- See Also:
- Constant Field Values
-
CLEAR_TEXT
public static final String CLEAR_TEXT
- See Also:
- Constant Field Values
-
ENTRY
public static final String ENTRY
- See Also:
- Constant Field Values
-
options
private final org.apache.commons.cli.Options options
-
parser
private org.apache.commons.cli.CommandLineParser parser
-
cmdLine
private org.apache.commons.cli.CommandLine cmdLine
-
-
Method Detail
-
readAttributesForView
private static void readAttributesForView(Path path, String prefix, String attributes, Map<String,Object> attrs)
-
readAttributesForPreservation
public static Map<String,Object> readAttributesForPreservation(Path path) throws IOException
Reads the attributes that are required to be preserved in the file. The attributes are posix, dos and acl ones that are interested to maintain.- Parameters:
path- The path to get the attributes from- Returns:
- The map of attributes (not null) with keys prefixed with the type (e.g. "posix:permissions")
- Throws:
IOException- Some error reading the file attributes
-
setAttributesForPreservation
public static void setAttributesForPreservation(Path path, Map<String,Object> attrs) throws IOException
Applies over a file all the attributes previously read by the readAttributesForPreservation method.- Parameters:
path- The path to set the attributes toattrs- The attributes to apply (key should be prefixed with the type of attr, e.g. "posix:permissions")- Throws:
IOException- Some error applying the attributes
-
addAlias
private void addAlias(String secret, CredentialStore credentialStore, String entryType, String location) throws Exception
- Throws:
Exception
-
removeAlias
private void removeAlias(CredentialStore credentialStore, String entryType, String storeType) throws Exception
- Throws:
Exception
-
checkAlias
private void checkAlias(CredentialStore credentialStore, String entryType, String storeType) throws Exception
- Throws:
Exception
-
aliases
private void aliases(CredentialStore credentialStore) throws Exception
- Throws:
Exception
-
aliasCredentialTypes
private void aliasCredentialTypes(CredentialStore credentialStore)
-
generateKeyPair
private void generateKeyPair(CredentialStore credentialStore) throws Exception
- Throws:
Exception
-
exportKeyPairPublicKey
private void exportKeyPairPublicKey(CredentialStore credentialStore, String entryType) throws Exception
- Throws:
Exception
-
importKeyPair
private void importKeyPair(CredentialStore credentialStore) throws Exception
- Throws:
Exception
-
generateSecretKey
private void generateSecretKey(CredentialStore credentialStore, String entryType, int size) throws Exception
- Throws:
Exception
-
exportSecretKey
private void exportSecretKey(CredentialStore credentialStore) throws Exception
- Throws:
Exception
-
importSecretKey
private void importSecretKey(CredentialStore credentialStore, String entryType, String key) throws Exception
- Throws:
Exception
-
encrypt
private String encrypt(CredentialStore credentialStore) throws Exception
- Throws:
Exception
-
createCredentialStore
private void createCredentialStore(CredentialStore credentialStore) throws Exception
- Throws:
Exception
-
createCredential
private Credential createCredential(String secret, String entryType)
-
createKeyPairCredential
private KeyPairCredential createKeyPairCredential(String algorithm, int size) throws NoSuchAlgorithmException
- Throws:
NoSuchAlgorithmException
-
parseKeyPairCredential
private KeyPairCredential parseKeyPairCredential(String privateKeyContent, String publicKeyContent, org.apache.sshd.common.config.keys.FilePasswordProvider passwordProvider) throws Exception
- Throws:
Exception
-
createCredential
private Credential createCredential(SecretKey secretKey, String entryType)
-
entryTypeToCredential
private Class<? extends Credential> entryTypeToCredential(String entryType, String storeType)
-
defaultCredentialType
private static Class<? extends Credential> defaultCredentialType(String storeType)
-
parseCredentialStoreProperties
static Map<String,String> parseCredentialStoreProperties(String attributeString)
-
getArgumentAsInt
private int getArgumentAsInt(String argument, int defaultValue) throws Exception
- Throws:
Exception
-
getCreateDefaultSummary
static void getCreateDefaultSummary(Map<String,String> implProps, StringBuilder com, String password)
-
getCreatePropertiesCredentialStoreSummary
static void getCreatePropertiesCredentialStoreSummary(StringBuilder com, String location)
-
getUseExpressionExample
static void getUseExpressionExample(StringBuilder com, String cipherTextToken)
-
safeClose
private static void safeClose(Closeable c)
-
-