use of java.io.Console in project wildfly by wildfly.
the class VaultInteraction method start.
public void start() {
Console console = System.console();
if (console == null) {
System.err.println(SecurityLogger.ROOT_LOGGER.noConsole());
System.exit(1);
}
Scanner in = new Scanner(System.in);
while (true) {
String commandStr = SecurityLogger.ROOT_LOGGER.interactionCommandOptions();
System.out.println(commandStr);
int choice = in.nextInt();
switch(choice) {
case 0:
System.out.println(SecurityLogger.ROOT_LOGGER.taskStoreSecuredAttribute());
char[] attributeValue = VaultInteractiveSession.getSensitiveValue(SecurityLogger.ROOT_LOGGER.interactivePromptSecureAttributeValue(), SecurityLogger.ROOT_LOGGER.interactivePromptSecureAttributeValueAgain());
String vaultBlock = null;
while (vaultBlock == null || vaultBlock.length() == 0) {
vaultBlock = console.readLine(SecurityLogger.ROOT_LOGGER.interactivePromptVaultBlock());
}
String attributeName = null;
while (attributeName == null || attributeName.length() == 0) {
attributeName = console.readLine(SecurityLogger.ROOT_LOGGER.interactivePromptAttributeName());
}
try {
vaultNISession.addSecuredAttributeWithDisplay(vaultBlock, attributeName, attributeValue);
} catch (Exception e) {
System.out.println(SecurityLogger.ROOT_LOGGER.problemOcurred() + "\n" + e.getLocalizedMessage());
}
break;
case 1:
System.out.println(SecurityLogger.ROOT_LOGGER.taskVerifySecuredAttributeExists());
try {
vaultBlock = null;
while (vaultBlock == null || vaultBlock.length() == 0) {
vaultBlock = console.readLine(SecurityLogger.ROOT_LOGGER.interactivePromptVaultBlock());
}
attributeName = null;
while (attributeName == null || attributeName.length() == 0) {
attributeName = console.readLine(SecurityLogger.ROOT_LOGGER.interactivePromptAttributeName());
}
if (!vaultNISession.checkSecuredAttribute(vaultBlock, attributeName)) {
System.out.println(SecurityLogger.ROOT_LOGGER.interactiveMessageNoValueStored(VaultSession.blockAttributeDisplayFormat(vaultBlock, attributeName)));
} else {
System.out.println(SecurityLogger.ROOT_LOGGER.interactiveMessageValueStored(VaultSession.blockAttributeDisplayFormat(vaultBlock, attributeName)));
}
} catch (Exception e) {
System.out.println(SecurityLogger.ROOT_LOGGER.problemOcurred() + "\n" + e.getLocalizedMessage());
}
break;
case 2:
System.out.println(SecurityLogger.ROOT_LOGGER.taskRemoveSecuredAttribute());
try {
vaultBlock = null;
while (vaultBlock == null || vaultBlock.length() == 0) {
vaultBlock = console.readLine(SecurityLogger.ROOT_LOGGER.interactivePromptVaultBlock());
}
attributeName = null;
while (attributeName == null || attributeName.length() == 0) {
attributeName = console.readLine(SecurityLogger.ROOT_LOGGER.interactivePromptAttributeName());
}
if (!vaultNISession.removeSecuredAttribute(vaultBlock, attributeName)) {
System.out.println(SecurityLogger.ROOT_LOGGER.messageAttributeNotRemoved(VaultSession.blockAttributeDisplayFormat(vaultBlock, attributeName)));
} else {
System.out.println(SecurityLogger.ROOT_LOGGER.messageAttributeRemovedSuccessfuly(VaultSession.blockAttributeDisplayFormat(vaultBlock, attributeName)));
}
} catch (Exception e) {
System.out.println(SecurityLogger.ROOT_LOGGER.problemOcurred() + "\n" + e.getLocalizedMessage());
}
break;
default:
in.close();
System.exit(0);
}
}
}
use of java.io.Console in project wildfly by wildfly.
the class VaultInteractiveSession method start.
public void start() {
Console console = System.console();
if (console == null) {
System.err.println(SecurityLogger.ROOT_LOGGER.noConsole());
System.exit(1);
}
while (encDir == null || encDir.length() == 0) {
encDir = console.readLine(SecurityLogger.ROOT_LOGGER.enterEncryptionDirectory() + " ");
}
while (keystoreURL == null || keystoreURL.length() == 0) {
keystoreURL = console.readLine(SecurityLogger.ROOT_LOGGER.enterKeyStoreURL() + " ");
}
char[] keystorePasswd = getSensitiveValue(SecurityLogger.ROOT_LOGGER.enterKeyStorePassword(), SecurityLogger.ROOT_LOGGER.enterKeyStorePasswordAgain());
try {
while (salt == null || salt.length() != 8) {
salt = console.readLine(SecurityLogger.ROOT_LOGGER.enterSalt() + " ");
}
String ic = console.readLine(SecurityLogger.ROOT_LOGGER.enterIterationCount() + " ");
iterationCount = Integer.parseInt(ic);
vaultNISession = new VaultSession(keystoreURL, new String(keystorePasswd), encDir, salt, iterationCount, true);
while (keystoreAlias == null || keystoreAlias.length() == 0) {
keystoreAlias = console.readLine(SecurityLogger.ROOT_LOGGER.enterKeyStoreAlias() + " ");
}
System.out.println(SecurityLogger.ROOT_LOGGER.initializingVault());
vaultNISession.startVaultSession(keystoreAlias);
vaultNISession.vaultConfigurationDisplay();
System.out.println(SecurityLogger.ROOT_LOGGER.vaultInitialized());
System.out.println(SecurityLogger.ROOT_LOGGER.handshakeComplete());
VaultInteraction vaultInteraction = new VaultInteraction(vaultNISession);
vaultInteraction.start();
} catch (Exception e) {
System.out.println(SecurityLogger.ROOT_LOGGER.exceptionEncountered() + e.getLocalizedMessage());
}
}
use of java.io.Console in project wildfly by wildfly.
the class VaultInteractiveSession method getSensitiveValue.
public static char[] getSensitiveValue(String passwordPrompt, String confirmationPrompt) {
while (true) {
if (passwordPrompt == null)
passwordPrompt = SecurityLogger.ROOT_LOGGER.enterYourPassword();
if (confirmationPrompt == null) {
confirmationPrompt = SecurityLogger.ROOT_LOGGER.enterYourPasswordAgain();
}
Console console = System.console();
char[] passwd = console.readPassword(passwordPrompt + " ");
char[] passwd1 = console.readPassword(confirmationPrompt + " ");
boolean noMatch = !Arrays.equals(passwd, passwd1);
if (noMatch)
System.out.println(SecurityLogger.ROOT_LOGGER.passwordsDoNotMatch());
else {
System.out.println(SecurityLogger.ROOT_LOGGER.passwordsMatch());
return passwd;
}
}
}
use of java.io.Console in project wildfly by wildfly.
the class VaultTool method main.
public static void main(String[] args) {
VaultTool tool = null;
if (args != null && args.length > 0) {
int returnVal = 0;
try {
tool = new VaultTool(args);
returnVal = tool.execute();
} catch (Exception e) {
System.err.println(SecurityLogger.ROOT_LOGGER.problemOcurred());
e.printStackTrace(System.err);
System.exit(1);
}
System.exit(returnVal);
} else {
tool = new VaultTool();
System.out.println("**********************************");
System.out.println("**** JBoss Vault ***************");
System.out.println("**********************************");
Console console = System.console();
if (console == null) {
System.err.println(SecurityLogger.ROOT_LOGGER.noConsole());
System.exit(1);
}
Scanner in = new Scanner(System.in);
while (true) {
System.out.println(SecurityLogger.ROOT_LOGGER.interactiveCommandString());
try {
int choice = in.nextInt();
switch(choice) {
case 0:
System.out.println(SecurityLogger.ROOT_LOGGER.startingInteractiveSession());
VaultInteractiveSession vsession = new VaultInteractiveSession();
tool.setSession(vsession);
vsession.start();
break;
case 1:
System.out.println(SecurityLogger.ROOT_LOGGER.removingInteractiveSession());
tool.setSession(null);
break;
default:
in.close();
System.exit(0);
}
} catch (InputMismatchException e) {
in.close();
System.exit(0);
}
}
}
}
use of java.io.Console in project bnd by bndtools.
the class NexusCommand method _sign.
public void _sign(SignOptions options) throws Exception {
String password = null;
if (options.password() == null) {
Console console = System.console();
if (console == null) {
error("No -p/--password set for PGP key and no console to ask");
} else {
char[] pw = console.readPassword("Passsword: ");
if (pw == null || pw.length == 0) {
error("Password not entered");
}
password = new String(pw);
}
} else
password = options.password();
Signer signer = new Signer(new String(password), options.command(getProperty("gpg", System.getenv("GPG"))));
if (signer == null || password == null || !isOk())
return;
List<String> args = options._arguments();
if (args.isEmpty()) {
List<URI> files = nexus.files();
for (URI uri : files) {
try {
logger.debug("signing {}", relative(uri));
File f = nexus.download(uri);
byte[] signature = signer.sign(f);
if (options.show())
show(signature);
else
nexus.upload(new URI(uri + ".asc"), signature);
} catch (Exception e) {
exception(e, "could not download/sign/upload %s", relative(uri));
}
}
} else {
for (String arg : args) {
File f = getFile(arg);
if (!f.isFile()) {
error("Can't find file %s", f);
} else {
byte[] signature = signer.sign(f);
if (options.show())
show(signature);
else {
File out = new File(f.getParentFile(), f.getName() + ".asc");
IO.store(signature, out);
}
}
}
}
}
Aggregations