@Ignore("Issue #15 - bypass prompting using callback handler") @Test(expected = CredentialStoreException.class) public void noPasswordSpecified() throws Exception { ElytronTool tool = new ElytronTool(); Command command = tool.findCommand(CredentialStoreCommand.CREDENTIAL_STORE_COMMAND); String storeFileName = getStoragePathForNewFile(); String[] args = {"--location=" + storeFileName, "--create", "--add", "testalias", "--secret", "secret2", "--summary", "--salt", "A1B2C3D4", "--iteration", "100"}; command.execute(args); }
@Override public void execute(String[] args) throws Exception { setStatus(GENERAL_CONFIGURATION_ERROR); cmdLine = parser.parse(options, args, false); setEnableDebug(cmdLine.hasOption(DEBUG_PARAM)); if (cmdLine.hasOption(HELP_PARAM)) { help(); setStatus(ElytronTool.ElytronToolExitStatus_OK); return; } printDuplicatesWarning(cmdLine); String location = cmdLine.getOptionValue(STORE_LOCATION_PARAM); if ((cmdLine.hasOption(ALIASES_PARAM) || cmdLine.hasOption(CHECK_ALIAS_PARAM)) && location != null && !Files.exists(Paths.get(location))) { setStatus(GENERAL_CONFIGURATION_ERROR); throw ElytronToolMessages.msg.storageFileDoesNotExist(location); } String csPassword = cmdLine.getOptionValue(CREDENTIAL_STORE_PASSWORD_PARAM); String password = csPassword == null ? "" : csPassword; String salt = cmdLine.getOptionValue(SALT_PARAM); String csType = cmdLine.getOptionValue(CREDENTIAL_STORE_TYPE_PARAM, KeyStoreCredentialStore.KEY_STORE_CREDENTIAL_STORE); int iterationCount = getArgumentAsInt(cmdLine.getOptionValue(ITERATION_PARAM)); String entryType = cmdLine.getOptionValue(ENTRY_TYPE_PARAM); String otherProviders = cmdLine.getOptionValue(OTHER_PROVIDERS_PARAM); String csProvider = cmdLine.getOptionValue(CUSTOM_CREDENTIAL_STORE_PROVIDER_PARAM); boolean createStorage = cmdLine.hasOption(CREATE_CREDENTIAL_STORE_PARAM); if (createStorage && cmdLine.getArgs().length > 0) { setStatus(GENERAL_CONFIGURATION_ERROR); throw ElytronToolMessages.msg.noArgumentOption(CREATE_CREDENTIAL_STORE_PARAM); } boolean printSummary = cmdLine.hasOption(PRINT_SUMMARY_PARAM); String secret = cmdLine.getOptionValue(PASSWORD_CREDENTIAL_VALUE_PARAM); Map<String, String> implProps = parseCredentialStoreProperties(cmdLine.getOptionValue(IMPLEMENTATION_PROPERTIES_PARAM)); CredentialStore credentialStore; if (csProvider != null) { credentialStore = CredentialStore.getInstance(csType, csProvider, getProvidersSupplier(csProvider)); } else { try { credentialStore = CredentialStore.getInstance(csType); } catch (NoSuchAlgorithmException e) { credentialStore = CredentialStore.getInstance(csType, getProvidersSupplier(null)); } } implProps.put("location", location); implProps.putIfAbsent("modifiable", Boolean.TRUE.toString()); implProps.putIfAbsent("create", Boolean.valueOf(createStorage).toString()); if (csType.equals(KeyStoreCredentialStore.KEY_STORE_CREDENTIAL_STORE)) { implProps.putIfAbsent("keyStoreType", "JCEKS"); } String implPropsKeyStoreType = implProps.get("keyStoreType"); if (location == null && implPropsKeyStoreType != null && filebasedKeystoreTypes.contains(implPropsKeyStoreType.toUpperCase(Locale.ENGLISH))) { throw ElytronToolMessages.msg.filebasedKeystoreLocationMissing(implPropsKeyStoreType); } CredentialStore.CredentialSourceProtectionParameter credentialSourceProtectionParameter = null; if (csPassword == null) { csPassword = prompt(false, ElytronToolMessages.msg.credentialStorePasswordPrompt(), createStorage, ElytronToolMessages.msg.credentialStorePasswordPromptConfirm()); if (csPassword == null) { setStatus(GENERAL_CONFIGURATION_ERROR); throw ElytronToolMessages.msg.optionNotSpecified(CREDENTIAL_STORE_PASSWORD_PARAM); } } if (csPassword != null) { char[] passwordCredential; if (csPassword.startsWith("MASK-")) { passwordCredential = MaskCommand.decryptMasked(csPassword); } else { passwordCredential = csPassword.toCharArray(); } credentialSourceProtectionParameter = new CredentialStore.CredentialSourceProtectionParameter( IdentityCredentials.NONE.withCredential( new PasswordCredential(ClearPassword.createRaw(ClearPassword.ALGORITHM_CLEAR, passwordCredential)))); } credentialStore.initialize(implProps, credentialSourceProtectionParameter, getProvidersSupplier(otherProviders).get()); if (csPassword != null && !csPassword.startsWith("MASK-") && salt != null && iterationCount > -1) { password = MaskCommand.computeMasked(csPassword, salt, iterationCount); } if (cmdLine.hasOption(ADD_ALIAS_PARAM)) { String alias = cmdLine.getOptionValue(ADD_ALIAS_PARAM); if (alias.length() == 0) { setStatus(GENERAL_CONFIGURATION_ERROR); throw ElytronToolMessages.msg.optionNotSpecified(ADD_ALIAS_PARAM); } if (secret == null) { secret = prompt(false, ElytronToolMessages.msg.secretToStorePrompt(), true, ElytronToolMessages.msg.secretToStorePromptConfirm()); if (secret == null) { setStatus(GENERAL_CONFIGURATION_ERROR); throw ElytronToolMessages.msg.optionNotSpecified(PASSWORD_CREDENTIAL_VALUE_PARAM); } } Map<String, Object> locationAttributes = readAttributesForPreservation(Paths.get(location)); credentialStore.store(alias, createCredential(secret, entryType)); credentialStore.flush(); if (entryType != null) { System.out.println(ElytronToolMessages.msg.aliasStored(alias, entryType)); } else { System.out.println(ElytronToolMessages.msg.aliasStored(alias)); } setStatus(ElytronTool.ElytronToolExitStatus_OK); setAttributesForPreservation(Paths.get(location), locationAttributes); } else if (cmdLine.hasOption(REMOVE_ALIAS_PARAM)) { String alias = cmdLine.getOptionValue(REMOVE_ALIAS_PARAM); if (credentialStore.exists(alias, entryTypeToCredential(entryType))) { credentialStore.remove(alias, entryTypeToCredential(entryType)); credentialStore.flush(); if (entryType != null) { System.out.println(ElytronToolMessages.msg.aliasRemoved(alias, entryType)); } else { System.out.println(ElytronToolMessages.msg.aliasRemoved(alias)); } setStatus(ElytronTool.ElytronToolExitStatus_OK); } else { if (entryType != null) { System.out.println(ElytronToolMessages.msg.aliasDoesNotExist(alias, entryType)); } else { System.out.println(ElytronToolMessages.msg.aliasDoesNotExist(alias)); } setStatus(ALIAS_NOT_FOUND); } } else if (cmdLine.hasOption(CHECK_ALIAS_PARAM)) { String alias = cmdLine.getOptionValue(CHECK_ALIAS_PARAM); if (credentialStore.exists(alias, entryTypeToCredential(entryType))) { setStatus(ElytronTool.ElytronToolExitStatus_OK); System.out.println(ElytronToolMessages.msg.aliasExists(alias)); } else { setStatus(ALIAS_NOT_FOUND); if (entryType != null) { System.out.println(ElytronToolMessages.msg.aliasDoesNotExist(alias, entryType)); } else { System.out.println(ElytronToolMessages.msg.aliasDoesNotExist(alias)); } } } else if (cmdLine.hasOption(ALIASES_PARAM)) { Set<String> aliases = credentialStore.getAliases(); if (aliases.size() != 0) { StringBuilder list = new StringBuilder(); for (String alias: aliases) { list.append(alias).append(" "); } System.out.println(ElytronToolMessages.msg.aliases(list.toString())); } else { System.out.println(ElytronToolMessages.msg.noAliases()); } setStatus(ElytronTool.ElytronToolExitStatus_OK); } else if (cmdLine.hasOption(GENERATE_KEY_PAIR_PARAM)) { String alias = cmdLine.getOptionValue(GENERATE_KEY_PAIR_PARAM); if (alias == null || alias.isEmpty()) { setStatus(GENERAL_CONFIGURATION_ERROR); throw ElytronToolMessages.msg.optionNotSpecified(GENERATE_KEY_PAIR_PARAM); } int size = getArgumentAsInt(cmdLine.getOptionValue(SIZE_PARAM)); String algorithm = cmdLine.getOptionValue(ALGORITHM_PARAM); if (algorithm == null) algorithm = RSA_ALGORITHM; credentialStore.store(alias, createKeyPairCredential(algorithm, size)); credentialStore.flush(); System.out.println(ElytronToolMessages.msg.aliasStored(alias, KeyPairCredential.class.getName())); setStatus(ElytronTool.ElytronToolExitStatus_OK); } else if (cmdLine.hasOption(EXPORT_KEY_PAIR_PUBLIC_KEY_PARAM)) { String alias = cmdLine.getOptionValue(EXPORT_KEY_PAIR_PUBLIC_KEY_PARAM); if (alias == null || alias.isEmpty()) { setStatus(GENERAL_CONFIGURATION_ERROR); throw ElytronToolMessages.msg.optionNotSpecified(EXPORT_KEY_PAIR_PUBLIC_KEY_PARAM); } if (credentialStore.exists(alias, KeyPairCredential.class)) { KeyPairCredential credential = credentialStore.retrieve(alias, KeyPairCredential.class); System.out.println(PublicKeyEntry.toString(credential.getKeyPair().getPublic())); setStatus(ElytronTool.ElytronToolExitStatus_OK); } else { setStatus(ALIAS_NOT_FOUND); if (entryType != null) { System.out.println(ElytronToolMessages.msg.aliasDoesNotExist(alias, entryType)); } else { System.out.println(ElytronToolMessages.msg.aliasDoesNotExist(alias)); } } } else if (cmdLine.hasOption(IMPORT_KEY_PAIR_PARAM)) { String alias = cmdLine.getOptionValue(IMPORT_KEY_PAIR_PARAM); if (alias == null || alias.isEmpty()) { setStatus(GENERAL_CONFIGURATION_ERROR); throw ElytronToolMessages.msg.optionNotSpecified(IMPORT_KEY_PAIR_PARAM); } String passphrase = cmdLine.getOptionValue(KEY_PASSPHRASE_PARAM); if (passphrase == null || passphrase.isEmpty()) { passphrase = prompt(false, ElytronToolMessages.msg.keyPassphrasePrompt(), true, ElytronToolMessages.msg.keyPassphrasePromptConfirm()); } ElytronFilePasswordProvider passwordProvider = new ElytronFilePasswordProvider(createCredential(passphrase, PasswordCredential.class.getName())); KeyPairCredential keyPairCredential; String privateKeyContent; String publicKeyContent = null; String privateKeyString = cmdLine.getOptionValue(PRIVATE_KEY_STRING_PARAM); String publicKeyString = cmdLine.getOptionValue(PUBLIC_KEY_STRING_PARAM); String privateKeyFile = cmdLine.getOptionValue(PRIVATE_KEY_LOCATION_PARAM); String publicKeyFile = cmdLine.getOptionValue(PUBLIC_KEY_LOCATION_PARAM); if (privateKeyFile != null) { if (!Files.exists(Paths.get(privateKeyFile))) { setStatus(GENERAL_CONFIGURATION_ERROR); throw ElytronToolMessages.msg.keyFileDoesNotExist(privateKeyFile); } File keyFile = new File(privateKeyFile); FileInputStream stream = new FileInputStream(keyFile); byte[] keyData = new byte[stream.available()]; try { stream.read(keyData, 0, stream.available()); } finally { safeClose(stream); } privateKeyContent = new String(keyData); } else if (privateKeyString != null) { privateKeyContent = privateKeyString; } else { setStatus(GENERAL_CONFIGURATION_ERROR); throw ElytronToolMessages.msg.noPrivateKeySpecified(); } if (privateKeyContent.isEmpty()) { setStatus(GENERAL_CONFIGURATION_ERROR); throw ElytronToolMessages.msg.noPrivateKeySpecified(); } if (publicKeyFile != null) { if (!Files.exists(Paths.get(publicKeyFile))) { setStatus(GENERAL_CONFIGURATION_ERROR); throw ElytronToolMessages.msg.keyFileDoesNotExist(publicKeyFile); } File keyFile = new File(publicKeyFile); FileInputStream stream = new FileInputStream(keyFile); byte[] keyData = new byte[stream.available()]; try { stream.read(keyData, 0, stream.available()); } finally { safeClose(stream); } publicKeyContent = new String(keyData); } else if (publicKeyString != null) { publicKeyContent = publicKeyString; } keyPairCredential = parseKeyPairCredential(privateKeyContent, publicKeyContent, passwordProvider); credentialStore.store(alias, keyPairCredential); credentialStore.flush(); System.out.println(ElytronToolMessages.msg.aliasStored(alias, KeyPairCredential.class.getName())); setStatus(ElytronTool.ElytronToolExitStatus_OK); } else if (cmdLine.hasOption(CREATE_CREDENTIAL_STORE_PARAM)) { credentialStore.flush(); System.out.println(ElytronToolMessages.msg.credentialStoreCreated()); setStatus(ElytronTool.ElytronToolExitStatus_OK); } else { setStatus(ACTION_NOT_DEFINED); throw ElytronToolMessages.msg.actionToPerformNotDefined(); } if (printSummary) { StringBuilder com = new StringBuilder(); if (cmdLine.hasOption(ADD_ALIAS_PARAM)) { if (implProps.get("create") != null && implProps.get("create").equals("true")) { getCreateSummary(implProps, com, password); com.append("\n"); } com.append("/subsystem=elytron/credential-store=test:add-alias(alias="); com.append(cmdLine.getOptionValue(ADD_ALIAS_PARAM)); if (entryType != null) { com.append(",entry-type=\"").append(entryType).append("\""); } com.append(",secret-value=\""); com.append(secret); com.append("\")"); } else if (cmdLine.hasOption(REMOVE_ALIAS_PARAM)) { com.append("/subsystem=elytron/credential-store=test:remove-alias(alias="); com.append(cmdLine.getOptionValue(REMOVE_ALIAS_PARAM)); com.append(")"); } else if (cmdLine.hasOption(ALIASES_PARAM) || cmdLine.hasOption(CHECK_ALIAS_PARAM) ) { com.append("/subsystem=elytron/credential-store=test:read-aliases()"); } else if (cmdLine.hasOption(CREATE_CREDENTIAL_STORE_PARAM)){ getCreateSummary(implProps, com, password); } System.out.println(ElytronToolMessages.msg.commandSummary(com.toString())); } }
CredentialStoreCommand extends Command { @Override public void execute(String[] args) throws Exception { setStatus(GENERAL_CONFIGURATION_ERROR); cmdLine = parser.parse(options, args, false); setEnableDebug(cmdLine.hasOption(DEBUG_PARAM)); if (cmdLine.hasOption(HELP_PARAM)) { help(); setStatus(ElytronTool.ElytronToolExitStatus_OK); return; } printDuplicatesWarning(cmdLine); String location = cmdLine.getOptionValue(STORE_LOCATION_PARAM); if ((cmdLine.hasOption(ALIASES_PARAM) || cmdLine.hasOption(CHECK_ALIAS_PARAM)) && location != null && !Files.exists(Paths.get(location))) { setStatus(GENERAL_CONFIGURATION_ERROR); throw ElytronToolMessages.msg.storageFileDoesNotExist(location); } String csPassword = cmdLine.getOptionValue(CREDENTIAL_STORE_PASSWORD_PARAM); String password = csPassword == null ? "" : csPassword; String salt = cmdLine.getOptionValue(SALT_PARAM); String csType = cmdLine.getOptionValue(CREDENTIAL_STORE_TYPE_PARAM, KeyStoreCredentialStore.KEY_STORE_CREDENTIAL_STORE); int iterationCount = getArgumentAsInt(cmdLine.getOptionValue(ITERATION_PARAM)); String entryType = cmdLine.getOptionValue(ENTRY_TYPE_PARAM); String otherProviders = cmdLine.getOptionValue(OTHER_PROVIDERS_PARAM); String csProvider = cmdLine.getOptionValue(CUSTOM_CREDENTIAL_STORE_PROVIDER_PARAM); boolean createStorage = cmdLine.hasOption(CREATE_CREDENTIAL_STORE_PARAM); if (createStorage && cmdLine.getArgs().length > 0) { setStatus(GENERAL_CONFIGURATION_ERROR); throw ElytronToolMessages.msg.noArgumentOption(CREATE_CREDENTIAL_STORE_PARAM); } boolean printSummary = cmdLine.hasOption(PRINT_SUMMARY_PARAM); String secret = cmdLine.getOptionValue(PASSWORD_CREDENTIAL_VALUE_PARAM); Map<String, String> implProps = parseCredentialStoreProperties(cmdLine.getOptionValue(IMPLEMENTATION_PROPERTIES_PARAM)); CredentialStore credentialStore; if (csProvider != null) { credentialStore = CredentialStore.getInstance(csType, csProvider, getProvidersSupplier(csProvider)); } else { try { credentialStore = CredentialStore.getInstance(csType); } catch (NoSuchAlgorithmException e) { credentialStore = CredentialStore.getInstance(csType, getProvidersSupplier(null)); } } implProps.put("location", location); implProps.putIfAbsent("modifiable", Boolean.TRUE.toString()); implProps.putIfAbsent("create", Boolean.valueOf(createStorage).toString()); if (csType.equals(KeyStoreCredentialStore.KEY_STORE_CREDENTIAL_STORE)) { implProps.putIfAbsent("keyStoreType", "JCEKS"); } String implPropsKeyStoreType = implProps.get("keyStoreType"); if (location == null && implPropsKeyStoreType != null && filebasedKeystoreTypes.contains(implPropsKeyStoreType.toUpperCase(Locale.ENGLISH))) { throw ElytronToolMessages.msg.filebasedKeystoreLocationMissing(implPropsKeyStoreType); } CredentialStore.CredentialSourceProtectionParameter credentialSourceProtectionParameter = null; if (csPassword == null) { csPassword = prompt(false, ElytronToolMessages.msg.credentialStorePasswordPrompt(), createStorage, ElytronToolMessages.msg.credentialStorePasswordPromptConfirm()); if (csPassword == null) { setStatus(GENERAL_CONFIGURATION_ERROR); throw ElytronToolMessages.msg.optionNotSpecified(CREDENTIAL_STORE_PASSWORD_PARAM); } } if (csPassword != null) { char[] passwordCredential; if (csPassword.startsWith("MASK-")) { passwordCredential = MaskCommand.decryptMasked(csPassword); } else { passwordCredential = csPassword.toCharArray(); } credentialSourceProtectionParameter = new CredentialStore.CredentialSourceProtectionParameter( IdentityCredentials.NONE.withCredential( new PasswordCredential(ClearPassword.createRaw(ClearPassword.ALGORITHM_CLEAR, passwordCredential)))); } credentialStore.initialize(implProps, credentialSourceProtectionParameter, getProvidersSupplier(otherProviders).get()); if (csPassword != null && !csPassword.startsWith("MASK-") && salt != null && iterationCount > -1) { password = MaskCommand.computeMasked(csPassword, salt, iterationCount); } if (cmdLine.hasOption(ADD_ALIAS_PARAM)) { String alias = cmdLine.getOptionValue(ADD_ALIAS_PARAM); if (alias.length() == 0) { setStatus(GENERAL_CONFIGURATION_ERROR); throw ElytronToolMessages.msg.optionNotSpecified(ADD_ALIAS_PARAM); } if (secret == null) { secret = prompt(false, ElytronToolMessages.msg.secretToStorePrompt(), true, ElytronToolMessages.msg.secretToStorePromptConfirm()); if (secret == null) { setStatus(GENERAL_CONFIGURATION_ERROR); throw ElytronToolMessages.msg.optionNotSpecified(PASSWORD_CREDENTIAL_VALUE_PARAM); } } Map<String, Object> locationAttributes = readAttributesForPreservation(Paths.get(location)); credentialStore.store(alias, createCredential(secret, entryType)); credentialStore.flush(); if (entryType != null) { System.out.println(ElytronToolMessages.msg.aliasStored(alias, entryType)); } else { System.out.println(ElytronToolMessages.msg.aliasStored(alias)); } setStatus(ElytronTool.ElytronToolExitStatus_OK); setAttributesForPreservation(Paths.get(location), locationAttributes); } else if (cmdLine.hasOption(REMOVE_ALIAS_PARAM)) { String alias = cmdLine.getOptionValue(REMOVE_ALIAS_PARAM); if (credentialStore.exists(alias, entryTypeToCredential(entryType))) { credentialStore.remove(alias, entryTypeToCredential(entryType)); credentialStore.flush(); if (entryType != null) { System.out.println(ElytronToolMessages.msg.aliasRemoved(alias, entryType)); } else { System.out.println(ElytronToolMessages.msg.aliasRemoved(alias)); } setStatus(ElytronTool.ElytronToolExitStatus_OK); } else { if (entryType != null) { System.out.println(ElytronToolMessages.msg.aliasDoesNotExist(alias, entryType)); } else { System.out.println(ElytronToolMessages.msg.aliasDoesNotExist(alias)); } setStatus(ALIAS_NOT_FOUND); } } else if (cmdLine.hasOption(CHECK_ALIAS_PARAM)) { String alias = cmdLine.getOptionValue(CHECK_ALIAS_PARAM); if (credentialStore.exists(alias, entryTypeToCredential(entryType))) { setStatus(ElytronTool.ElytronToolExitStatus_OK); System.out.println(ElytronToolMessages.msg.aliasExists(alias)); } else { setStatus(ALIAS_NOT_FOUND); if (entryType != null) { System.out.println(ElytronToolMessages.msg.aliasDoesNotExist(alias, entryType)); } else { System.out.println(ElytronToolMessages.msg.aliasDoesNotExist(alias)); } } } else if (cmdLine.hasOption(ALIASES_PARAM)) { Set<String> aliases = credentialStore.getAliases(); if (aliases.size() != 0) { StringBuilder list = new StringBuilder(); for (String alias: aliases) { list.append(alias).append(" "); } System.out.println(ElytronToolMessages.msg.aliases(list.toString())); } else { System.out.println(ElytronToolMessages.msg.noAliases()); } setStatus(ElytronTool.ElytronToolExitStatus_OK); } else if (cmdLine.hasOption(GENERATE_KEY_PAIR_PARAM)) { String alias = cmdLine.getOptionValue(GENERATE_KEY_PAIR_PARAM); if (alias == null || alias.isEmpty()) { setStatus(GENERAL_CONFIGURATION_ERROR); throw ElytronToolMessages.msg.optionNotSpecified(GENERATE_KEY_PAIR_PARAM); } int size = getArgumentAsInt(cmdLine.getOptionValue(SIZE_PARAM)); String algorithm = cmdLine.getOptionValue(ALGORITHM_PARAM); if (algorithm == null) algorithm = RSA_ALGORITHM; credentialStore.store(alias, createKeyPairCredential(algorithm, size)); credentialStore.flush(); System.out.println(ElytronToolMessages.msg.aliasStored(alias, KeyPairCredential.class.getName())); setStatus(ElytronTool.ElytronToolExitStatus_OK); } else if (cmdLine.hasOption(EXPORT_KEY_PAIR_PUBLIC_KEY_PARAM)) { String alias = cmdLine.getOptionValue(EXPORT_KEY_PAIR_PUBLIC_KEY_PARAM); if (alias == null || alias.isEmpty()) { setStatus(GENERAL_CONFIGURATION_ERROR); throw ElytronToolMessages.msg.optionNotSpecified(EXPORT_KEY_PAIR_PUBLIC_KEY_PARAM); } if (credentialStore.exists(alias, KeyPairCredential.class)) { KeyPairCredential credential = credentialStore.retrieve(alias, KeyPairCredential.class); System.out.println(PublicKeyEntry.toString(credential.getKeyPair().getPublic())); setStatus(ElytronTool.ElytronToolExitStatus_OK); } else { setStatus(ALIAS_NOT_FOUND); if (entryType != null) { System.out.println(ElytronToolMessages.msg.aliasDoesNotExist(alias, entryType)); } else { System.out.println(ElytronToolMessages.msg.aliasDoesNotExist(alias)); } } } else if (cmdLine.hasOption(IMPORT_KEY_PAIR_PARAM)) { String alias = cmdLine.getOptionValue(IMPORT_KEY_PAIR_PARAM); if (alias == null || alias.isEmpty()) { setStatus(GENERAL_CONFIGURATION_ERROR); throw ElytronToolMessages.msg.optionNotSpecified(IMPORT_KEY_PAIR_PARAM); } String passphrase = cmdLine.getOptionValue(KEY_PASSPHRASE_PARAM); if (passphrase == null || passphrase.isEmpty()) { passphrase = prompt(false, ElytronToolMessages.msg.keyPassphrasePrompt(), true, ElytronToolMessages.msg.keyPassphrasePromptConfirm()); } ElytronFilePasswordProvider passwordProvider = new ElytronFilePasswordProvider(createCredential(passphrase, PasswordCredential.class.getName())); KeyPairCredential keyPairCredential; String privateKeyContent; String publicKeyContent = null; String privateKeyString = cmdLine.getOptionValue(PRIVATE_KEY_STRING_PARAM); String publicKeyString = cmdLine.getOptionValue(PUBLIC_KEY_STRING_PARAM); String privateKeyFile = cmdLine.getOptionValue(PRIVATE_KEY_LOCATION_PARAM); String publicKeyFile = cmdLine.getOptionValue(PUBLIC_KEY_LOCATION_PARAM); if (privateKeyFile != null) { if (!Files.exists(Paths.get(privateKeyFile))) { setStatus(GENERAL_CONFIGURATION_ERROR); throw ElytronToolMessages.msg.keyFileDoesNotExist(privateKeyFile); } File keyFile = new File(privateKeyFile); FileInputStream stream = new FileInputStream(keyFile); byte[] keyData = new byte[stream.available()]; try { stream.read(keyData, 0, stream.available()); } finally { safeClose(stream); } privateKeyContent = new String(keyData); } else if (privateKeyString != null) { privateKeyContent = privateKeyString; } else { setStatus(GENERAL_CONFIGURATION_ERROR); throw ElytronToolMessages.msg.noPrivateKeySpecified(); } if (privateKeyContent.isEmpty()) { setStatus(GENERAL_CONFIGURATION_ERROR); throw ElytronToolMessages.msg.noPrivateKeySpecified(); } if (publicKeyFile != null) { if (!Files.exists(Paths.get(publicKeyFile))) { setStatus(GENERAL_CONFIGURATION_ERROR); throw ElytronToolMessages.msg.keyFileDoesNotExist(publicKeyFile); } File keyFile = new File(publicKeyFile); FileInputStream stream = new FileInputStream(keyFile); byte[] keyData = new byte[stream.available()]; try { stream.read(keyData, 0, stream.available()); } finally { safeClose(stream); } publicKeyContent = new String(keyData); } else if (publicKeyString != null) { publicKeyContent = publicKeyString; } keyPairCredential = parseKeyPairCredential(privateKeyContent, publicKeyContent, passwordProvider); credentialStore.store(alias, keyPairCredential); credentialStore.flush(); System.out.println(ElytronToolMessages.msg.aliasStored(alias, KeyPairCredential.class.getName())); setStatus(ElytronTool.ElytronToolExitStatus_OK); } else if (cmdLine.hasOption(CREATE_CREDENTIAL_STORE_PARAM)) { credentialStore.flush(); System.out.println(ElytronToolMessages.msg.credentialStoreCreated()); setStatus(ElytronTool.ElytronToolExitStatus_OK); } else { setStatus(ACTION_NOT_DEFINED); throw ElytronToolMessages.msg.actionToPerformNotDefined(); } if (printSummary) { StringBuilder com = new StringBuilder(); if (cmdLine.hasOption(ADD_ALIAS_PARAM)) { if (implProps.get("create") != null && implProps.get("create").equals("true")) { getCreateSummary(implProps, com, password); com.append("\n"); } com.append("/subsystem=elytron/credential-store=test:add-alias(alias="); com.append(cmdLine.getOptionValue(ADD_ALIAS_PARAM)); if (entryType != null) { com.append(",entry-type=\"").append(entryType).append("\""); } com.append(",secret-value=\""); com.append(secret); com.append("\")"); } else if (cmdLine.hasOption(REMOVE_ALIAS_PARAM)) { com.append("/subsystem=elytron/credential-store=test:remove-alias(alias="); com.append(cmdLine.getOptionValue(REMOVE_ALIAS_PARAM)); com.append(")"); } else if (cmdLine.hasOption(ALIASES_PARAM) || cmdLine.hasOption(CHECK_ALIAS_PARAM) ) { com.append("/subsystem=elytron/credential-store=test:read-aliases()"); } else if (cmdLine.hasOption(CREATE_CREDENTIAL_STORE_PARAM)){ getCreateSummary(implProps, com, password); } System.out.println(ElytronToolMessages.msg.commandSummary(com.toString())); } } }
CredentialStoreCommand extends Command { @Override public void execute(String[] args) throws Exception { setStatus(GENERAL_CONFIGURATION_ERROR); cmdLine = parser.parse(options, args, false); setEnableDebug(cmdLine.hasOption(DEBUG_PARAM)); if (cmdLine.hasOption(HELP_PARAM)) { help(); setStatus(ElytronTool.ElytronToolExitStatus_OK); return; } printDuplicatesWarning(cmdLine); String location = cmdLine.getOptionValue(STORE_LOCATION_PARAM); if ((cmdLine.hasOption(ALIASES_PARAM) || cmdLine.hasOption(CHECK_ALIAS_PARAM)) && location != null && !Files.exists(Paths.get(location))) { setStatus(GENERAL_CONFIGURATION_ERROR); throw ElytronToolMessages.msg.storageFileDoesNotExist(location); } String csPassword = cmdLine.getOptionValue(CREDENTIAL_STORE_PASSWORD_PARAM); String password = csPassword == null ? "" : csPassword; String salt = cmdLine.getOptionValue(SALT_PARAM); String csType = cmdLine.getOptionValue(CREDENTIAL_STORE_TYPE_PARAM, KeyStoreCredentialStore.KEY_STORE_CREDENTIAL_STORE); int iterationCount = getArgumentAsInt(cmdLine.getOptionValue(ITERATION_PARAM)); String entryType = cmdLine.getOptionValue(ENTRY_TYPE_PARAM); String otherProviders = cmdLine.getOptionValue(OTHER_PROVIDERS_PARAM); String csProvider = cmdLine.getOptionValue(CUSTOM_CREDENTIAL_STORE_PROVIDER_PARAM); boolean createStorage = cmdLine.hasOption(CREATE_CREDENTIAL_STORE_PARAM); if (createStorage && cmdLine.getArgs().length > 0) { setStatus(GENERAL_CONFIGURATION_ERROR); throw ElytronToolMessages.msg.noArgumentOption(CREATE_CREDENTIAL_STORE_PARAM); } boolean printSummary = cmdLine.hasOption(PRINT_SUMMARY_PARAM); String secret = cmdLine.getOptionValue(PASSWORD_CREDENTIAL_VALUE_PARAM); Map<String, String> implProps = parseCredentialStoreProperties(cmdLine.getOptionValue(IMPLEMENTATION_PROPERTIES_PARAM)); CredentialStore credentialStore; if (csProvider != null) { credentialStore = CredentialStore.getInstance(csType, csProvider, getProvidersSupplier(csProvider)); } else { try { credentialStore = CredentialStore.getInstance(csType); } catch (NoSuchAlgorithmException e) { credentialStore = CredentialStore.getInstance(csType, getProvidersSupplier(null)); } } implProps.put("location", location); implProps.putIfAbsent("modifiable", Boolean.TRUE.toString()); implProps.putIfAbsent("create", Boolean.valueOf(createStorage).toString()); if (csType.equals(KeyStoreCredentialStore.KEY_STORE_CREDENTIAL_STORE)) { implProps.putIfAbsent("keyStoreType", "JCEKS"); } String implPropsKeyStoreType = implProps.get("keyStoreType"); if (location == null && implPropsKeyStoreType != null && filebasedKeystoreTypes.contains(implPropsKeyStoreType.toUpperCase(Locale.ENGLISH))) { throw ElytronToolMessages.msg.filebasedKeystoreLocationMissing(implPropsKeyStoreType); } CredentialStore.CredentialSourceProtectionParameter credentialSourceProtectionParameter = null; if (csPassword == null) { csPassword = prompt(false, ElytronToolMessages.msg.credentialStorePasswordPrompt(), createStorage, ElytronToolMessages.msg.credentialStorePasswordPromptConfirm()); if (csPassword == null) { setStatus(GENERAL_CONFIGURATION_ERROR); throw ElytronToolMessages.msg.optionNotSpecified(CREDENTIAL_STORE_PASSWORD_PARAM); } } if (csPassword != null) { char[] passwordCredential; if (csPassword.startsWith("MASK-")) { passwordCredential = MaskCommand.decryptMasked(csPassword); } else { passwordCredential = csPassword.toCharArray(); } credentialSourceProtectionParameter = new CredentialStore.CredentialSourceProtectionParameter( IdentityCredentials.NONE.withCredential( new PasswordCredential(ClearPassword.createRaw(ClearPassword.ALGORITHM_CLEAR, passwordCredential)))); } credentialStore.initialize(implProps, credentialSourceProtectionParameter, getProvidersSupplier(otherProviders).get()); if (csPassword != null && !csPassword.startsWith("MASK-") && salt != null && iterationCount > -1) { password = MaskCommand.computeMasked(csPassword, salt, iterationCount); } if (cmdLine.hasOption(ADD_ALIAS_PARAM)) { String alias = cmdLine.getOptionValue(ADD_ALIAS_PARAM); if (alias.length() == 0) { setStatus(GENERAL_CONFIGURATION_ERROR); throw ElytronToolMessages.msg.optionNotSpecified(ADD_ALIAS_PARAM); } if (secret == null) { secret = prompt(false, ElytronToolMessages.msg.secretToStorePrompt(), true, ElytronToolMessages.msg.secretToStorePromptConfirm()); if (secret == null) { setStatus(GENERAL_CONFIGURATION_ERROR); throw ElytronToolMessages.msg.optionNotSpecified(PASSWORD_CREDENTIAL_VALUE_PARAM); } } Map<String, Object> locationAttributes = readAttributesForPreservation(Paths.get(location)); credentialStore.store(alias, createCredential(secret, entryType)); credentialStore.flush(); if (entryType != null) { System.out.println(ElytronToolMessages.msg.aliasStored(alias, entryType)); } else { System.out.println(ElytronToolMessages.msg.aliasStored(alias)); } setStatus(ElytronTool.ElytronToolExitStatus_OK); setAttributesForPreservation(Paths.get(location), locationAttributes); } else if (cmdLine.hasOption(REMOVE_ALIAS_PARAM)) { String alias = cmdLine.getOptionValue(REMOVE_ALIAS_PARAM); if (credentialStore.exists(alias, entryTypeToCredential(entryType))) { credentialStore.remove(alias, entryTypeToCredential(entryType)); credentialStore.flush(); if (entryType != null) { System.out.println(ElytronToolMessages.msg.aliasRemoved(alias, entryType)); } else { System.out.println(ElytronToolMessages.msg.aliasRemoved(alias)); } setStatus(ElytronTool.ElytronToolExitStatus_OK); } else { if (entryType != null) { System.out.println(ElytronToolMessages.msg.aliasDoesNotExist(alias, entryType)); } else { System.out.println(ElytronToolMessages.msg.aliasDoesNotExist(alias)); } setStatus(ALIAS_NOT_FOUND); } } else if (cmdLine.hasOption(CHECK_ALIAS_PARAM)) { String alias = cmdLine.getOptionValue(CHECK_ALIAS_PARAM); if (credentialStore.exists(alias, entryTypeToCredential(entryType))) { setStatus(ElytronTool.ElytronToolExitStatus_OK); System.out.println(ElytronToolMessages.msg.aliasExists(alias)); } else { setStatus(ALIAS_NOT_FOUND); if (entryType != null) { System.out.println(ElytronToolMessages.msg.aliasDoesNotExist(alias, entryType)); } else { System.out.println(ElytronToolMessages.msg.aliasDoesNotExist(alias)); } } } else if (cmdLine.hasOption(ALIASES_PARAM)) { Set<String> aliases = credentialStore.getAliases(); if (aliases.size() != 0) { StringBuilder list = new StringBuilder(); for (String alias: aliases) { list.append(alias).append(" "); } System.out.println(ElytronToolMessages.msg.aliases(list.toString())); } else { System.out.println(ElytronToolMessages.msg.noAliases()); } setStatus(ElytronTool.ElytronToolExitStatus_OK); } else if (cmdLine.hasOption(GENERATE_KEY_PAIR_PARAM)) { String alias = cmdLine.getOptionValue(GENERATE_KEY_PAIR_PARAM); if (alias == null || alias.isEmpty()) { setStatus(GENERAL_CONFIGURATION_ERROR); throw ElytronToolMessages.msg.optionNotSpecified(GENERATE_KEY_PAIR_PARAM); } int size = getArgumentAsInt(cmdLine.getOptionValue(SIZE_PARAM)); String algorithm = cmdLine.getOptionValue(ALGORITHM_PARAM); if (algorithm == null) algorithm = RSA_ALGORITHM; credentialStore.store(alias, createKeyPairCredential(algorithm, size)); credentialStore.flush(); System.out.println(ElytronToolMessages.msg.aliasStored(alias, KeyPairCredential.class.getName())); setStatus(ElytronTool.ElytronToolExitStatus_OK); } else if (cmdLine.hasOption(EXPORT_KEY_PAIR_PUBLIC_KEY_PARAM)) { String alias = cmdLine.getOptionValue(EXPORT_KEY_PAIR_PUBLIC_KEY_PARAM); if (alias == null || alias.isEmpty()) { setStatus(GENERAL_CONFIGURATION_ERROR); throw ElytronToolMessages.msg.optionNotSpecified(EXPORT_KEY_PAIR_PUBLIC_KEY_PARAM); } if (credentialStore.exists(alias, KeyPairCredential.class)) { KeyPairCredential credential = credentialStore.retrieve(alias, KeyPairCredential.class); System.out.println(PublicKeyEntry.toString(credential.getKeyPair().getPublic())); setStatus(ElytronTool.ElytronToolExitStatus_OK); } else { setStatus(ALIAS_NOT_FOUND); if (entryType != null) { System.out.println(ElytronToolMessages.msg.aliasDoesNotExist(alias, entryType)); } else { System.out.println(ElytronToolMessages.msg.aliasDoesNotExist(alias)); } } } else if (cmdLine.hasOption(IMPORT_KEY_PAIR_PARAM)) { String alias = cmdLine.getOptionValue(IMPORT_KEY_PAIR_PARAM); if (alias == null || alias.isEmpty()) { setStatus(GENERAL_CONFIGURATION_ERROR); throw ElytronToolMessages.msg.optionNotSpecified(IMPORT_KEY_PAIR_PARAM); } String passphrase = cmdLine.getOptionValue(KEY_PASSPHRASE_PARAM); if (passphrase == null || passphrase.isEmpty()) { passphrase = prompt(false, ElytronToolMessages.msg.keyPassphrasePrompt(), true, ElytronToolMessages.msg.keyPassphrasePromptConfirm()); } ElytronFilePasswordProvider passwordProvider = new ElytronFilePasswordProvider(createCredential(passphrase, PasswordCredential.class.getName())); KeyPairCredential keyPairCredential; String privateKeyContent; String publicKeyContent = null; String privateKeyString = cmdLine.getOptionValue(PRIVATE_KEY_STRING_PARAM); String publicKeyString = cmdLine.getOptionValue(PUBLIC_KEY_STRING_PARAM); String privateKeyFile = cmdLine.getOptionValue(PRIVATE_KEY_LOCATION_PARAM); String publicKeyFile = cmdLine.getOptionValue(PUBLIC_KEY_LOCATION_PARAM); if (privateKeyFile != null) { if (!Files.exists(Paths.get(privateKeyFile))) { setStatus(GENERAL_CONFIGURATION_ERROR); throw ElytronToolMessages.msg.keyFileDoesNotExist(privateKeyFile); } File keyFile = new File(privateKeyFile); FileInputStream stream = new FileInputStream(keyFile); byte[] keyData = new byte[stream.available()]; try { stream.read(keyData, 0, stream.available()); } finally { safeClose(stream); } privateKeyContent = new String(keyData); } else if (privateKeyString != null) { privateKeyContent = privateKeyString; } else { setStatus(GENERAL_CONFIGURATION_ERROR); throw ElytronToolMessages.msg.noPrivateKeySpecified(); } if (privateKeyContent.isEmpty()) { setStatus(GENERAL_CONFIGURATION_ERROR); throw ElytronToolMessages.msg.noPrivateKeySpecified(); } if (publicKeyFile != null) { if (!Files.exists(Paths.get(publicKeyFile))) { setStatus(GENERAL_CONFIGURATION_ERROR); throw ElytronToolMessages.msg.keyFileDoesNotExist(publicKeyFile); } File keyFile = new File(publicKeyFile); FileInputStream stream = new FileInputStream(keyFile); byte[] keyData = new byte[stream.available()]; try { stream.read(keyData, 0, stream.available()); } finally { safeClose(stream); } publicKeyContent = new String(keyData); } else if (publicKeyString != null) { publicKeyContent = publicKeyString; } keyPairCredential = parseKeyPairCredential(privateKeyContent, publicKeyContent, passwordProvider); credentialStore.store(alias, keyPairCredential); credentialStore.flush(); System.out.println(ElytronToolMessages.msg.aliasStored(alias, KeyPairCredential.class.getName())); setStatus(ElytronTool.ElytronToolExitStatus_OK); } else if (cmdLine.hasOption(CREATE_CREDENTIAL_STORE_PARAM)) { credentialStore.flush(); System.out.println(ElytronToolMessages.msg.credentialStoreCreated()); setStatus(ElytronTool.ElytronToolExitStatus_OK); } else { setStatus(ACTION_NOT_DEFINED); throw ElytronToolMessages.msg.actionToPerformNotDefined(); } if (printSummary) { StringBuilder com = new StringBuilder(); if (cmdLine.hasOption(ADD_ALIAS_PARAM)) { if (implProps.get("create") != null && implProps.get("create").equals("true")) { getCreateSummary(implProps, com, password); com.append("\n"); } com.append("/subsystem=elytron/credential-store=test:add-alias(alias="); com.append(cmdLine.getOptionValue(ADD_ALIAS_PARAM)); if (entryType != null) { com.append(",entry-type=\"").append(entryType).append("\""); } com.append(",secret-value=\""); com.append(secret); com.append("\")"); } else if (cmdLine.hasOption(REMOVE_ALIAS_PARAM)) { com.append("/subsystem=elytron/credential-store=test:remove-alias(alias="); com.append(cmdLine.getOptionValue(REMOVE_ALIAS_PARAM)); com.append(")"); } else if (cmdLine.hasOption(ALIASES_PARAM) || cmdLine.hasOption(CHECK_ALIAS_PARAM) ) { com.append("/subsystem=elytron/credential-store=test:read-aliases()"); } else if (cmdLine.hasOption(CREATE_CREDENTIAL_STORE_PARAM)){ getCreateSummary(implProps, com, password); } System.out.println(ElytronToolMessages.msg.commandSummary(com.toString())); } } CredentialStoreCommand(); }
CredentialStoreCommand extends Command { @Override public void execute(String[] args) throws Exception { setStatus(GENERAL_CONFIGURATION_ERROR); cmdLine = parser.parse(options, args, false); setEnableDebug(cmdLine.hasOption(DEBUG_PARAM)); if (cmdLine.hasOption(HELP_PARAM)) { help(); setStatus(ElytronTool.ElytronToolExitStatus_OK); return; } printDuplicatesWarning(cmdLine); String location = cmdLine.getOptionValue(STORE_LOCATION_PARAM); if ((cmdLine.hasOption(ALIASES_PARAM) || cmdLine.hasOption(CHECK_ALIAS_PARAM)) && location != null && !Files.exists(Paths.get(location))) { setStatus(GENERAL_CONFIGURATION_ERROR); throw ElytronToolMessages.msg.storageFileDoesNotExist(location); } String csPassword = cmdLine.getOptionValue(CREDENTIAL_STORE_PASSWORD_PARAM); String password = csPassword == null ? "" : csPassword; String salt = cmdLine.getOptionValue(SALT_PARAM); String csType = cmdLine.getOptionValue(CREDENTIAL_STORE_TYPE_PARAM, KeyStoreCredentialStore.KEY_STORE_CREDENTIAL_STORE); int iterationCount = getArgumentAsInt(cmdLine.getOptionValue(ITERATION_PARAM)); String entryType = cmdLine.getOptionValue(ENTRY_TYPE_PARAM); String otherProviders = cmdLine.getOptionValue(OTHER_PROVIDERS_PARAM); String csProvider = cmdLine.getOptionValue(CUSTOM_CREDENTIAL_STORE_PROVIDER_PARAM); boolean createStorage = cmdLine.hasOption(CREATE_CREDENTIAL_STORE_PARAM); if (createStorage && cmdLine.getArgs().length > 0) { setStatus(GENERAL_CONFIGURATION_ERROR); throw ElytronToolMessages.msg.noArgumentOption(CREATE_CREDENTIAL_STORE_PARAM); } boolean printSummary = cmdLine.hasOption(PRINT_SUMMARY_PARAM); String secret = cmdLine.getOptionValue(PASSWORD_CREDENTIAL_VALUE_PARAM); Map<String, String> implProps = parseCredentialStoreProperties(cmdLine.getOptionValue(IMPLEMENTATION_PROPERTIES_PARAM)); CredentialStore credentialStore; if (csProvider != null) { credentialStore = CredentialStore.getInstance(csType, csProvider, getProvidersSupplier(csProvider)); } else { try { credentialStore = CredentialStore.getInstance(csType); } catch (NoSuchAlgorithmException e) { credentialStore = CredentialStore.getInstance(csType, getProvidersSupplier(null)); } } implProps.put("location", location); implProps.putIfAbsent("modifiable", Boolean.TRUE.toString()); implProps.putIfAbsent("create", Boolean.valueOf(createStorage).toString()); if (csType.equals(KeyStoreCredentialStore.KEY_STORE_CREDENTIAL_STORE)) { implProps.putIfAbsent("keyStoreType", "JCEKS"); } String implPropsKeyStoreType = implProps.get("keyStoreType"); if (location == null && implPropsKeyStoreType != null && filebasedKeystoreTypes.contains(implPropsKeyStoreType.toUpperCase(Locale.ENGLISH))) { throw ElytronToolMessages.msg.filebasedKeystoreLocationMissing(implPropsKeyStoreType); } CredentialStore.CredentialSourceProtectionParameter credentialSourceProtectionParameter = null; if (csPassword == null) { csPassword = prompt(false, ElytronToolMessages.msg.credentialStorePasswordPrompt(), createStorage, ElytronToolMessages.msg.credentialStorePasswordPromptConfirm()); if (csPassword == null) { setStatus(GENERAL_CONFIGURATION_ERROR); throw ElytronToolMessages.msg.optionNotSpecified(CREDENTIAL_STORE_PASSWORD_PARAM); } } if (csPassword != null) { char[] passwordCredential; if (csPassword.startsWith("MASK-")) { passwordCredential = MaskCommand.decryptMasked(csPassword); } else { passwordCredential = csPassword.toCharArray(); } credentialSourceProtectionParameter = new CredentialStore.CredentialSourceProtectionParameter( IdentityCredentials.NONE.withCredential( new PasswordCredential(ClearPassword.createRaw(ClearPassword.ALGORITHM_CLEAR, passwordCredential)))); } credentialStore.initialize(implProps, credentialSourceProtectionParameter, getProvidersSupplier(otherProviders).get()); if (csPassword != null && !csPassword.startsWith("MASK-") && salt != null && iterationCount > -1) { password = MaskCommand.computeMasked(csPassword, salt, iterationCount); } if (cmdLine.hasOption(ADD_ALIAS_PARAM)) { String alias = cmdLine.getOptionValue(ADD_ALIAS_PARAM); if (alias.length() == 0) { setStatus(GENERAL_CONFIGURATION_ERROR); throw ElytronToolMessages.msg.optionNotSpecified(ADD_ALIAS_PARAM); } if (secret == null) { secret = prompt(false, ElytronToolMessages.msg.secretToStorePrompt(), true, ElytronToolMessages.msg.secretToStorePromptConfirm()); if (secret == null) { setStatus(GENERAL_CONFIGURATION_ERROR); throw ElytronToolMessages.msg.optionNotSpecified(PASSWORD_CREDENTIAL_VALUE_PARAM); } } Map<String, Object> locationAttributes = readAttributesForPreservation(Paths.get(location)); credentialStore.store(alias, createCredential(secret, entryType)); credentialStore.flush(); if (entryType != null) { System.out.println(ElytronToolMessages.msg.aliasStored(alias, entryType)); } else { System.out.println(ElytronToolMessages.msg.aliasStored(alias)); } setStatus(ElytronTool.ElytronToolExitStatus_OK); setAttributesForPreservation(Paths.get(location), locationAttributes); } else if (cmdLine.hasOption(REMOVE_ALIAS_PARAM)) { String alias = cmdLine.getOptionValue(REMOVE_ALIAS_PARAM); if (credentialStore.exists(alias, entryTypeToCredential(entryType))) { credentialStore.remove(alias, entryTypeToCredential(entryType)); credentialStore.flush(); if (entryType != null) { System.out.println(ElytronToolMessages.msg.aliasRemoved(alias, entryType)); } else { System.out.println(ElytronToolMessages.msg.aliasRemoved(alias)); } setStatus(ElytronTool.ElytronToolExitStatus_OK); } else { if (entryType != null) { System.out.println(ElytronToolMessages.msg.aliasDoesNotExist(alias, entryType)); } else { System.out.println(ElytronToolMessages.msg.aliasDoesNotExist(alias)); } setStatus(ALIAS_NOT_FOUND); } } else if (cmdLine.hasOption(CHECK_ALIAS_PARAM)) { String alias = cmdLine.getOptionValue(CHECK_ALIAS_PARAM); if (credentialStore.exists(alias, entryTypeToCredential(entryType))) { setStatus(ElytronTool.ElytronToolExitStatus_OK); System.out.println(ElytronToolMessages.msg.aliasExists(alias)); } else { setStatus(ALIAS_NOT_FOUND); if (entryType != null) { System.out.println(ElytronToolMessages.msg.aliasDoesNotExist(alias, entryType)); } else { System.out.println(ElytronToolMessages.msg.aliasDoesNotExist(alias)); } } } else if (cmdLine.hasOption(ALIASES_PARAM)) { Set<String> aliases = credentialStore.getAliases(); if (aliases.size() != 0) { StringBuilder list = new StringBuilder(); for (String alias: aliases) { list.append(alias).append(" "); } System.out.println(ElytronToolMessages.msg.aliases(list.toString())); } else { System.out.println(ElytronToolMessages.msg.noAliases()); } setStatus(ElytronTool.ElytronToolExitStatus_OK); } else if (cmdLine.hasOption(GENERATE_KEY_PAIR_PARAM)) { String alias = cmdLine.getOptionValue(GENERATE_KEY_PAIR_PARAM); if (alias == null || alias.isEmpty()) { setStatus(GENERAL_CONFIGURATION_ERROR); throw ElytronToolMessages.msg.optionNotSpecified(GENERATE_KEY_PAIR_PARAM); } int size = getArgumentAsInt(cmdLine.getOptionValue(SIZE_PARAM)); String algorithm = cmdLine.getOptionValue(ALGORITHM_PARAM); if (algorithm == null) algorithm = RSA_ALGORITHM; credentialStore.store(alias, createKeyPairCredential(algorithm, size)); credentialStore.flush(); System.out.println(ElytronToolMessages.msg.aliasStored(alias, KeyPairCredential.class.getName())); setStatus(ElytronTool.ElytronToolExitStatus_OK); } else if (cmdLine.hasOption(EXPORT_KEY_PAIR_PUBLIC_KEY_PARAM)) { String alias = cmdLine.getOptionValue(EXPORT_KEY_PAIR_PUBLIC_KEY_PARAM); if (alias == null || alias.isEmpty()) { setStatus(GENERAL_CONFIGURATION_ERROR); throw ElytronToolMessages.msg.optionNotSpecified(EXPORT_KEY_PAIR_PUBLIC_KEY_PARAM); } if (credentialStore.exists(alias, KeyPairCredential.class)) { KeyPairCredential credential = credentialStore.retrieve(alias, KeyPairCredential.class); System.out.println(PublicKeyEntry.toString(credential.getKeyPair().getPublic())); setStatus(ElytronTool.ElytronToolExitStatus_OK); } else { setStatus(ALIAS_NOT_FOUND); if (entryType != null) { System.out.println(ElytronToolMessages.msg.aliasDoesNotExist(alias, entryType)); } else { System.out.println(ElytronToolMessages.msg.aliasDoesNotExist(alias)); } } } else if (cmdLine.hasOption(IMPORT_KEY_PAIR_PARAM)) { String alias = cmdLine.getOptionValue(IMPORT_KEY_PAIR_PARAM); if (alias == null || alias.isEmpty()) { setStatus(GENERAL_CONFIGURATION_ERROR); throw ElytronToolMessages.msg.optionNotSpecified(IMPORT_KEY_PAIR_PARAM); } String passphrase = cmdLine.getOptionValue(KEY_PASSPHRASE_PARAM); if (passphrase == null || passphrase.isEmpty()) { passphrase = prompt(false, ElytronToolMessages.msg.keyPassphrasePrompt(), true, ElytronToolMessages.msg.keyPassphrasePromptConfirm()); } ElytronFilePasswordProvider passwordProvider = new ElytronFilePasswordProvider(createCredential(passphrase, PasswordCredential.class.getName())); KeyPairCredential keyPairCredential; String privateKeyContent; String publicKeyContent = null; String privateKeyString = cmdLine.getOptionValue(PRIVATE_KEY_STRING_PARAM); String publicKeyString = cmdLine.getOptionValue(PUBLIC_KEY_STRING_PARAM); String privateKeyFile = cmdLine.getOptionValue(PRIVATE_KEY_LOCATION_PARAM); String publicKeyFile = cmdLine.getOptionValue(PUBLIC_KEY_LOCATION_PARAM); if (privateKeyFile != null) { if (!Files.exists(Paths.get(privateKeyFile))) { setStatus(GENERAL_CONFIGURATION_ERROR); throw ElytronToolMessages.msg.keyFileDoesNotExist(privateKeyFile); } File keyFile = new File(privateKeyFile); FileInputStream stream = new FileInputStream(keyFile); byte[] keyData = new byte[stream.available()]; try { stream.read(keyData, 0, stream.available()); } finally { safeClose(stream); } privateKeyContent = new String(keyData); } else if (privateKeyString != null) { privateKeyContent = privateKeyString; } else { setStatus(GENERAL_CONFIGURATION_ERROR); throw ElytronToolMessages.msg.noPrivateKeySpecified(); } if (privateKeyContent.isEmpty()) { setStatus(GENERAL_CONFIGURATION_ERROR); throw ElytronToolMessages.msg.noPrivateKeySpecified(); } if (publicKeyFile != null) { if (!Files.exists(Paths.get(publicKeyFile))) { setStatus(GENERAL_CONFIGURATION_ERROR); throw ElytronToolMessages.msg.keyFileDoesNotExist(publicKeyFile); } File keyFile = new File(publicKeyFile); FileInputStream stream = new FileInputStream(keyFile); byte[] keyData = new byte[stream.available()]; try { stream.read(keyData, 0, stream.available()); } finally { safeClose(stream); } publicKeyContent = new String(keyData); } else if (publicKeyString != null) { publicKeyContent = publicKeyString; } keyPairCredential = parseKeyPairCredential(privateKeyContent, publicKeyContent, passwordProvider); credentialStore.store(alias, keyPairCredential); credentialStore.flush(); System.out.println(ElytronToolMessages.msg.aliasStored(alias, KeyPairCredential.class.getName())); setStatus(ElytronTool.ElytronToolExitStatus_OK); } else if (cmdLine.hasOption(CREATE_CREDENTIAL_STORE_PARAM)) { credentialStore.flush(); System.out.println(ElytronToolMessages.msg.credentialStoreCreated()); setStatus(ElytronTool.ElytronToolExitStatus_OK); } else { setStatus(ACTION_NOT_DEFINED); throw ElytronToolMessages.msg.actionToPerformNotDefined(); } if (printSummary) { StringBuilder com = new StringBuilder(); if (cmdLine.hasOption(ADD_ALIAS_PARAM)) { if (implProps.get("create") != null && implProps.get("create").equals("true")) { getCreateSummary(implProps, com, password); com.append("\n"); } com.append("/subsystem=elytron/credential-store=test:add-alias(alias="); com.append(cmdLine.getOptionValue(ADD_ALIAS_PARAM)); if (entryType != null) { com.append(",entry-type=\"").append(entryType).append("\""); } com.append(",secret-value=\""); com.append(secret); com.append("\")"); } else if (cmdLine.hasOption(REMOVE_ALIAS_PARAM)) { com.append("/subsystem=elytron/credential-store=test:remove-alias(alias="); com.append(cmdLine.getOptionValue(REMOVE_ALIAS_PARAM)); com.append(")"); } else if (cmdLine.hasOption(ALIASES_PARAM) || cmdLine.hasOption(CHECK_ALIAS_PARAM) ) { com.append("/subsystem=elytron/credential-store=test:read-aliases()"); } else if (cmdLine.hasOption(CREATE_CREDENTIAL_STORE_PARAM)){ getCreateSummary(implProps, com, password); } System.out.println(ElytronToolMessages.msg.commandSummary(com.toString())); } } CredentialStoreCommand(); static Map<String, Object> readAttributesForPreservation(Path path); static void setAttributesForPreservation(Path path, Map<String, Object> attrs); @Override void execute(String[] args); @Override void help(); }
CredentialStoreCommand extends Command { @Override public void execute(String[] args) throws Exception { setStatus(GENERAL_CONFIGURATION_ERROR); cmdLine = parser.parse(options, args, false); setEnableDebug(cmdLine.hasOption(DEBUG_PARAM)); if (cmdLine.hasOption(HELP_PARAM)) { help(); setStatus(ElytronTool.ElytronToolExitStatus_OK); return; } printDuplicatesWarning(cmdLine); String location = cmdLine.getOptionValue(STORE_LOCATION_PARAM); if ((cmdLine.hasOption(ALIASES_PARAM) || cmdLine.hasOption(CHECK_ALIAS_PARAM)) && location != null && !Files.exists(Paths.get(location))) { setStatus(GENERAL_CONFIGURATION_ERROR); throw ElytronToolMessages.msg.storageFileDoesNotExist(location); } String csPassword = cmdLine.getOptionValue(CREDENTIAL_STORE_PASSWORD_PARAM); String password = csPassword == null ? "" : csPassword; String salt = cmdLine.getOptionValue(SALT_PARAM); String csType = cmdLine.getOptionValue(CREDENTIAL_STORE_TYPE_PARAM, KeyStoreCredentialStore.KEY_STORE_CREDENTIAL_STORE); int iterationCount = getArgumentAsInt(cmdLine.getOptionValue(ITERATION_PARAM)); String entryType = cmdLine.getOptionValue(ENTRY_TYPE_PARAM); String otherProviders = cmdLine.getOptionValue(OTHER_PROVIDERS_PARAM); String csProvider = cmdLine.getOptionValue(CUSTOM_CREDENTIAL_STORE_PROVIDER_PARAM); boolean createStorage = cmdLine.hasOption(CREATE_CREDENTIAL_STORE_PARAM); if (createStorage && cmdLine.getArgs().length > 0) { setStatus(GENERAL_CONFIGURATION_ERROR); throw ElytronToolMessages.msg.noArgumentOption(CREATE_CREDENTIAL_STORE_PARAM); } boolean printSummary = cmdLine.hasOption(PRINT_SUMMARY_PARAM); String secret = cmdLine.getOptionValue(PASSWORD_CREDENTIAL_VALUE_PARAM); Map<String, String> implProps = parseCredentialStoreProperties(cmdLine.getOptionValue(IMPLEMENTATION_PROPERTIES_PARAM)); CredentialStore credentialStore; if (csProvider != null) { credentialStore = CredentialStore.getInstance(csType, csProvider, getProvidersSupplier(csProvider)); } else { try { credentialStore = CredentialStore.getInstance(csType); } catch (NoSuchAlgorithmException e) { credentialStore = CredentialStore.getInstance(csType, getProvidersSupplier(null)); } } implProps.put("location", location); implProps.putIfAbsent("modifiable", Boolean.TRUE.toString()); implProps.putIfAbsent("create", Boolean.valueOf(createStorage).toString()); if (csType.equals(KeyStoreCredentialStore.KEY_STORE_CREDENTIAL_STORE)) { implProps.putIfAbsent("keyStoreType", "JCEKS"); } String implPropsKeyStoreType = implProps.get("keyStoreType"); if (location == null && implPropsKeyStoreType != null && filebasedKeystoreTypes.contains(implPropsKeyStoreType.toUpperCase(Locale.ENGLISH))) { throw ElytronToolMessages.msg.filebasedKeystoreLocationMissing(implPropsKeyStoreType); } CredentialStore.CredentialSourceProtectionParameter credentialSourceProtectionParameter = null; if (csPassword == null) { csPassword = prompt(false, ElytronToolMessages.msg.credentialStorePasswordPrompt(), createStorage, ElytronToolMessages.msg.credentialStorePasswordPromptConfirm()); if (csPassword == null) { setStatus(GENERAL_CONFIGURATION_ERROR); throw ElytronToolMessages.msg.optionNotSpecified(CREDENTIAL_STORE_PASSWORD_PARAM); } } if (csPassword != null) { char[] passwordCredential; if (csPassword.startsWith("MASK-")) { passwordCredential = MaskCommand.decryptMasked(csPassword); } else { passwordCredential = csPassword.toCharArray(); } credentialSourceProtectionParameter = new CredentialStore.CredentialSourceProtectionParameter( IdentityCredentials.NONE.withCredential( new PasswordCredential(ClearPassword.createRaw(ClearPassword.ALGORITHM_CLEAR, passwordCredential)))); } credentialStore.initialize(implProps, credentialSourceProtectionParameter, getProvidersSupplier(otherProviders).get()); if (csPassword != null && !csPassword.startsWith("MASK-") && salt != null && iterationCount > -1) { password = MaskCommand.computeMasked(csPassword, salt, iterationCount); } if (cmdLine.hasOption(ADD_ALIAS_PARAM)) { String alias = cmdLine.getOptionValue(ADD_ALIAS_PARAM); if (alias.length() == 0) { setStatus(GENERAL_CONFIGURATION_ERROR); throw ElytronToolMessages.msg.optionNotSpecified(ADD_ALIAS_PARAM); } if (secret == null) { secret = prompt(false, ElytronToolMessages.msg.secretToStorePrompt(), true, ElytronToolMessages.msg.secretToStorePromptConfirm()); if (secret == null) { setStatus(GENERAL_CONFIGURATION_ERROR); throw ElytronToolMessages.msg.optionNotSpecified(PASSWORD_CREDENTIAL_VALUE_PARAM); } } Map<String, Object> locationAttributes = readAttributesForPreservation(Paths.get(location)); credentialStore.store(alias, createCredential(secret, entryType)); credentialStore.flush(); if (entryType != null) { System.out.println(ElytronToolMessages.msg.aliasStored(alias, entryType)); } else { System.out.println(ElytronToolMessages.msg.aliasStored(alias)); } setStatus(ElytronTool.ElytronToolExitStatus_OK); setAttributesForPreservation(Paths.get(location), locationAttributes); } else if (cmdLine.hasOption(REMOVE_ALIAS_PARAM)) { String alias = cmdLine.getOptionValue(REMOVE_ALIAS_PARAM); if (credentialStore.exists(alias, entryTypeToCredential(entryType))) { credentialStore.remove(alias, entryTypeToCredential(entryType)); credentialStore.flush(); if (entryType != null) { System.out.println(ElytronToolMessages.msg.aliasRemoved(alias, entryType)); } else { System.out.println(ElytronToolMessages.msg.aliasRemoved(alias)); } setStatus(ElytronTool.ElytronToolExitStatus_OK); } else { if (entryType != null) { System.out.println(ElytronToolMessages.msg.aliasDoesNotExist(alias, entryType)); } else { System.out.println(ElytronToolMessages.msg.aliasDoesNotExist(alias)); } setStatus(ALIAS_NOT_FOUND); } } else if (cmdLine.hasOption(CHECK_ALIAS_PARAM)) { String alias = cmdLine.getOptionValue(CHECK_ALIAS_PARAM); if (credentialStore.exists(alias, entryTypeToCredential(entryType))) { setStatus(ElytronTool.ElytronToolExitStatus_OK); System.out.println(ElytronToolMessages.msg.aliasExists(alias)); } else { setStatus(ALIAS_NOT_FOUND); if (entryType != null) { System.out.println(ElytronToolMessages.msg.aliasDoesNotExist(alias, entryType)); } else { System.out.println(ElytronToolMessages.msg.aliasDoesNotExist(alias)); } } } else if (cmdLine.hasOption(ALIASES_PARAM)) { Set<String> aliases = credentialStore.getAliases(); if (aliases.size() != 0) { StringBuilder list = new StringBuilder(); for (String alias: aliases) { list.append(alias).append(" "); } System.out.println(ElytronToolMessages.msg.aliases(list.toString())); } else { System.out.println(ElytronToolMessages.msg.noAliases()); } setStatus(ElytronTool.ElytronToolExitStatus_OK); } else if (cmdLine.hasOption(GENERATE_KEY_PAIR_PARAM)) { String alias = cmdLine.getOptionValue(GENERATE_KEY_PAIR_PARAM); if (alias == null || alias.isEmpty()) { setStatus(GENERAL_CONFIGURATION_ERROR); throw ElytronToolMessages.msg.optionNotSpecified(GENERATE_KEY_PAIR_PARAM); } int size = getArgumentAsInt(cmdLine.getOptionValue(SIZE_PARAM)); String algorithm = cmdLine.getOptionValue(ALGORITHM_PARAM); if (algorithm == null) algorithm = RSA_ALGORITHM; credentialStore.store(alias, createKeyPairCredential(algorithm, size)); credentialStore.flush(); System.out.println(ElytronToolMessages.msg.aliasStored(alias, KeyPairCredential.class.getName())); setStatus(ElytronTool.ElytronToolExitStatus_OK); } else if (cmdLine.hasOption(EXPORT_KEY_PAIR_PUBLIC_KEY_PARAM)) { String alias = cmdLine.getOptionValue(EXPORT_KEY_PAIR_PUBLIC_KEY_PARAM); if (alias == null || alias.isEmpty()) { setStatus(GENERAL_CONFIGURATION_ERROR); throw ElytronToolMessages.msg.optionNotSpecified(EXPORT_KEY_PAIR_PUBLIC_KEY_PARAM); } if (credentialStore.exists(alias, KeyPairCredential.class)) { KeyPairCredential credential = credentialStore.retrieve(alias, KeyPairCredential.class); System.out.println(PublicKeyEntry.toString(credential.getKeyPair().getPublic())); setStatus(ElytronTool.ElytronToolExitStatus_OK); } else { setStatus(ALIAS_NOT_FOUND); if (entryType != null) { System.out.println(ElytronToolMessages.msg.aliasDoesNotExist(alias, entryType)); } else { System.out.println(ElytronToolMessages.msg.aliasDoesNotExist(alias)); } } } else if (cmdLine.hasOption(IMPORT_KEY_PAIR_PARAM)) { String alias = cmdLine.getOptionValue(IMPORT_KEY_PAIR_PARAM); if (alias == null || alias.isEmpty()) { setStatus(GENERAL_CONFIGURATION_ERROR); throw ElytronToolMessages.msg.optionNotSpecified(IMPORT_KEY_PAIR_PARAM); } String passphrase = cmdLine.getOptionValue(KEY_PASSPHRASE_PARAM); if (passphrase == null || passphrase.isEmpty()) { passphrase = prompt(false, ElytronToolMessages.msg.keyPassphrasePrompt(), true, ElytronToolMessages.msg.keyPassphrasePromptConfirm()); } ElytronFilePasswordProvider passwordProvider = new ElytronFilePasswordProvider(createCredential(passphrase, PasswordCredential.class.getName())); KeyPairCredential keyPairCredential; String privateKeyContent; String publicKeyContent = null; String privateKeyString = cmdLine.getOptionValue(PRIVATE_KEY_STRING_PARAM); String publicKeyString = cmdLine.getOptionValue(PUBLIC_KEY_STRING_PARAM); String privateKeyFile = cmdLine.getOptionValue(PRIVATE_KEY_LOCATION_PARAM); String publicKeyFile = cmdLine.getOptionValue(PUBLIC_KEY_LOCATION_PARAM); if (privateKeyFile != null) { if (!Files.exists(Paths.get(privateKeyFile))) { setStatus(GENERAL_CONFIGURATION_ERROR); throw ElytronToolMessages.msg.keyFileDoesNotExist(privateKeyFile); } File keyFile = new File(privateKeyFile); FileInputStream stream = new FileInputStream(keyFile); byte[] keyData = new byte[stream.available()]; try { stream.read(keyData, 0, stream.available()); } finally { safeClose(stream); } privateKeyContent = new String(keyData); } else if (privateKeyString != null) { privateKeyContent = privateKeyString; } else { setStatus(GENERAL_CONFIGURATION_ERROR); throw ElytronToolMessages.msg.noPrivateKeySpecified(); } if (privateKeyContent.isEmpty()) { setStatus(GENERAL_CONFIGURATION_ERROR); throw ElytronToolMessages.msg.noPrivateKeySpecified(); } if (publicKeyFile != null) { if (!Files.exists(Paths.get(publicKeyFile))) { setStatus(GENERAL_CONFIGURATION_ERROR); throw ElytronToolMessages.msg.keyFileDoesNotExist(publicKeyFile); } File keyFile = new File(publicKeyFile); FileInputStream stream = new FileInputStream(keyFile); byte[] keyData = new byte[stream.available()]; try { stream.read(keyData, 0, stream.available()); } finally { safeClose(stream); } publicKeyContent = new String(keyData); } else if (publicKeyString != null) { publicKeyContent = publicKeyString; } keyPairCredential = parseKeyPairCredential(privateKeyContent, publicKeyContent, passwordProvider); credentialStore.store(alias, keyPairCredential); credentialStore.flush(); System.out.println(ElytronToolMessages.msg.aliasStored(alias, KeyPairCredential.class.getName())); setStatus(ElytronTool.ElytronToolExitStatus_OK); } else if (cmdLine.hasOption(CREATE_CREDENTIAL_STORE_PARAM)) { credentialStore.flush(); System.out.println(ElytronToolMessages.msg.credentialStoreCreated()); setStatus(ElytronTool.ElytronToolExitStatus_OK); } else { setStatus(ACTION_NOT_DEFINED); throw ElytronToolMessages.msg.actionToPerformNotDefined(); } if (printSummary) { StringBuilder com = new StringBuilder(); if (cmdLine.hasOption(ADD_ALIAS_PARAM)) { if (implProps.get("create") != null && implProps.get("create").equals("true")) { getCreateSummary(implProps, com, password); com.append("\n"); } com.append("/subsystem=elytron/credential-store=test:add-alias(alias="); com.append(cmdLine.getOptionValue(ADD_ALIAS_PARAM)); if (entryType != null) { com.append(",entry-type=\"").append(entryType).append("\""); } com.append(",secret-value=\""); com.append(secret); com.append("\")"); } else if (cmdLine.hasOption(REMOVE_ALIAS_PARAM)) { com.append("/subsystem=elytron/credential-store=test:remove-alias(alias="); com.append(cmdLine.getOptionValue(REMOVE_ALIAS_PARAM)); com.append(")"); } else if (cmdLine.hasOption(ALIASES_PARAM) || cmdLine.hasOption(CHECK_ALIAS_PARAM) ) { com.append("/subsystem=elytron/credential-store=test:read-aliases()"); } else if (cmdLine.hasOption(CREATE_CREDENTIAL_STORE_PARAM)){ getCreateSummary(implProps, com, password); } System.out.println(ElytronToolMessages.msg.commandSummary(com.toString())); } } CredentialStoreCommand(); static Map<String, Object> readAttributesForPreservation(Path path); static void setAttributesForPreservation(Path path, Map<String, Object> attrs); @Override void execute(String[] args); @Override void help(); static int ACTION_NOT_DEFINED; static int ALIAS_NOT_FOUND; static int GENERAL_CONFIGURATION_ERROR; static final String RSA_ALGORITHM; static final String DSA_ALGORITHM; static final String EC_ALGORITHM; static final String CREDENTIAL_STORE_COMMAND; static final String STORE_LOCATION_PARAM; static final String IMPLEMENTATION_PROPERTIES_PARAM; static final String CREDENTIAL_STORE_PASSWORD_PARAM; static final String CREDENTIAL_STORE_TYPE_PARAM; static final String SALT_PARAM; static final String ITERATION_PARAM; static final String PASSWORD_CREDENTIAL_VALUE_PARAM; static final String ADD_ALIAS_PARAM; static final String CHECK_ALIAS_PARAM; static final String ALIASES_PARAM; static final String REMOVE_ALIAS_PARAM; static final String CREATE_CREDENTIAL_STORE_PARAM; static final String HELP_PARAM; static final String PRINT_SUMMARY_PARAM; static final String ENTRY_TYPE_PARAM; static final String OTHER_PROVIDERS_PARAM; static final String DEBUG_PARAM; static final String CUSTOM_CREDENTIAL_STORE_PROVIDER_PARAM; static final String GENERATE_KEY_PAIR_PARAM; static final String ALGORITHM_PARAM; static final String SIZE_PARAM; static final String EXPORT_KEY_PAIR_PUBLIC_KEY_PARAM; static final String IMPORT_KEY_PAIR_PARAM; static final String PRIVATE_KEY_LOCATION_PARAM; static final String PUBLIC_KEY_LOCATION_PARAM; static final String PRIVATE_KEY_STRING_PARAM; static final String PUBLIC_KEY_STRING_PARAM; static final String KEY_PASSPHRASE_PARAM; }