use of java.security.KeyException in project TinyKeePass by sorz.
the class SecureStringStorage method getCipher.
private Cipher getCipher(int mode, byte[] iv) throws SystemException, KeyException {
try {
SecretKey key = (SecretKey) keyStore.getKey(KEY_ALIAS, null);
Cipher cipher = Cipher.getInstance("AES/GCM/NoPadding");
if (iv != null) {
GCMParameterSpec params = new GCMParameterSpec(128, iv);
cipher.init(mode, key, params);
} else {
cipher.init(mode, key);
}
return cipher;
} catch (KeyException e) {
throw e;
} catch (KeyStoreException | NoSuchAlgorithmException | UnrecoverableKeyException | NoSuchPaddingException | InvalidAlgorithmParameterException e) {
throw new SystemException(e);
}
}
use of java.security.KeyException in project scheduling by ow2-proactive.
the class SchedulerStateRest method putThirdPartyCredential.
@Override
public void putThirdPartyCredential(String sessionId, String key, String value) throws NotConnectedRestException, PermissionRestException, SchedulerRestException {
try {
Scheduler s = checkAccess(sessionId);
s.putThirdPartyCredential(key, value);
} catch (PermissionException e) {
throw new PermissionRestException(e);
} catch (NotConnectedException e) {
throw new NotConnectedRestException(e);
} catch (KeyException e) {
throw new SchedulerRestException(e);
}
}
use of java.security.KeyException in project scheduling by ow2-proactive.
the class RMNodeStarter method fillParameters.
protected String fillParameters(final CommandLine cl, final Options options) {
boolean printHelp = false;
try {
// Optional rmURL option
if (cl.hasOption(OPTION_RM_URL)) {
rmURL = cl.getOptionValue(OPTION_RM_URL);
}
// The path to the file that contains the credential
if (cl.hasOption(OPTION_CREDENTIAL_FILE)) {
try {
credentials = Credentials.getCredentials(cl.getOptionValue(OPTION_CREDENTIAL_FILE));
} catch (KeyException ke) {
logger.error(ExitStatus.CRED_UNREADABLE.description, ke);
System.exit(ExitStatus.CRED_UNREADABLE.exitCode);
}
// The name of the env variable that contains
} else if (cl.hasOption(OPTION_CREDENTIAL_ENV)) {
final String variableName = cl.getOptionValue(OPTION_CREDENTIAL_ENV);
final String value = System.getenv(variableName);
if (value == null) {
logger.error(ExitStatus.CRED_ENVIRONMENT.description);
System.exit(ExitStatus.CRED_ENVIRONMENT.exitCode);
}
try {
credentials = Credentials.getCredentialsBase64(value.getBytes());
} catch (KeyException ke) {
logger.error(ExitStatus.CRED_DECODE.description, ke);
System.exit(ExitStatus.CRED_DECODE.exitCode);
}
// Read the credentials directly from the command-line argument
} else if (cl.hasOption(OPTION_CREDENTIAL_VAL)) {
final String str = cl.getOptionValue(OPTION_CREDENTIAL_VAL);
try {
credentials = Credentials.getCredentialsBase64(str.getBytes());
} catch (KeyException ke) {
logger.error(ExitStatus.CRED_DECODE.description, ke);
System.exit(ExitStatus.CRED_DECODE.exitCode);
}
} else {
credentials = getDefaultCredentials();
}
String nodeName;
// Optional node name
if (cl.hasOption(OPTION_NODE_NAME)) {
nodeName = cl.getOptionValue(OPTION_NODE_NAME);
} else {
nodeName = getDefaultNodeName();
}
// Optional node source name
if (cl.hasOption(OPTION_SOURCE_NAME)) {
nodeSourceName = cl.getOptionValue(OPTION_SOURCE_NAME);
}
// Optional wait on join option
if (cl.hasOption(OPTION_WAIT_AND_JOIN_TIMEOUT)) {
RMNodeStarter.WAIT_ON_JOIN_TIMEOUT_IN_MS = Integer.valueOf(cl.getOptionValue(OPTION_WAIT_AND_JOIN_TIMEOUT));
RMNodeStarter.WAIT_ON_JOIN_TIMEOUT_IN_MS_USER_SUPPLIED = true;
}
// Optional ping delay
if (cl.hasOption(OPTION_PING_DELAY)) {
RMNodeStarter.PING_DELAY_IN_MS = Integer.valueOf(cl.getOptionValue(OPTION_PING_DELAY));
RMNodeStarter.PING_DELAY_IN_MS_USER_SUPPLIED = true;
}
// Optional number of add node attempts before quitting
if (cl.hasOption(OPTION_ADD_NODE_ATTEMPTS)) {
RMNodeStarter.NB_OF_ADD_NODE_ATTEMPTS = Integer.valueOf(cl.getOptionValue(OPTION_ADD_NODE_ATTEMPTS));
RMNodeStarter.NB_OF_ADD_NODE_ATTEMPTS_USER_SUPPLIED = true;
}
// Optional delay between add node attempts
if (cl.hasOption(OPTION_ADD_NODE_ATTEMPTS_DELAY)) {
RMNodeStarter.ADD_NODE_ATTEMPTS_DELAY_IN_MS = Integer.valueOf(cl.getOptionValue(OPTION_ADD_NODE_ATTEMPTS_DELAY));
RMNodeStarter.ADD_NODE_ATTEMPTS_DELAY_IN_MS_USER_SUPPLIED = true;
}
setNodeAvailabilityReportTimeoutDelay(cl);
// Discovery
if (cl.hasOption(OPTION_DISCOVERY_PORT)) {
discoveryPort = Integer.valueOf(cl.getOptionValue(OPTION_DISCOVERY_PORT));
} else if (System.getProperty(DISCOVERY_PORT_NAME) != null) {
discoveryPort = Integer.valueOf(System.getProperty(DISCOVERY_PORT_NAME));
}
if (cl.hasOption(OPTION_DISCOVERY_TIMEOUT)) {
discoveryTimeoutInMs = Integer.valueOf(cl.getOptionValue(OPTION_DISCOVERY_TIMEOUT));
} else if (System.getProperty(DISCOVERY_TIMEOUT_IN_MS_NAME) != null) {
discoveryPort = Integer.valueOf(System.getProperty(DISCOVERY_TIMEOUT_IN_MS_NAME));
}
readWorkersOption(cl);
// Optional help option
if (cl.hasOption(OPTION_HELP)) {
printHelp = true;
}
// Optional help option
if (cl.hasOption(OPTION_DISABLE_MONITORING)) {
disabledMonitoring = true;
}
return nodeName;
} catch (Throwable t) {
printHelp = true;
logger.info(t.getMessage());
t.printStackTrace(System.err);
System.exit(ExitStatus.FAILED_TO_LAUNCH.exitCode);
} finally {
if (printHelp) {
// Automatically generate the help statement
HelpFormatter formatter = new HelpFormatter();
// Prints usage
formatter.printHelp("java " + RMNodeStarter.class.getName(), options);
System.exit(ExitStatus.OK.exitCode);
}
}
return null;
}
use of java.security.KeyException in project scheduling by ow2-proactive.
the class RMNodeStarter method getDefaultCredentials.
private Credentials getDefaultCredentials() {
try {
return Credentials.getCredentials();
} catch (KeyException fromDiskKeyException) {
try {
Credentials credentialsFromRMHome = Credentials.getCredentials(new File(PAResourceManagerProperties.RM_HOME.getValueAsStringOrNull(), "config/authentication/rm.cred").getAbsolutePath());
logger.info("Using default credentials from ProActive home, authenticating as user rm");
return credentialsFromRMHome;
} catch (KeyException fromRMHomeKeyException) {
try {
Credentials credentialsFromJar = Credentials.getCredentials(RMNodeStarter.class.getResourceAsStream("/config/authentication/rm.cred"));
logger.info("Using default credentials from ProActive jars, authenticating as user rm");
return credentialsFromJar;
} catch (Exception fromJarKeyException) {
logger.error("Failed to read credentials, from location obtained using system property, RM home or ProActive jars", fromJarKeyException);
System.exit(ExitStatus.CRED_UNREADABLE.exitCode);
}
}
}
return null;
}
use of java.security.KeyException in project scheduling by ow2-proactive.
the class SSHInfrastructure method configure.
/**
* Configures the Infrastructure
*
* @param parameters
* parameters[4] : ssh Options, see {@link SSHClient}
* parameters[5] : java path on the remote machines parameters[6]
* : Scheduling path on remote machines parameters[7] : target
* OS' type (Linux, Windows or Cygwin) parameters[8] : extra java
* options parameters[9] : rm cred
* @throws IllegalArgumentException
* configuration failed
*/
@Override
public void configure(Object... parameters) {
super.configure(parameters);
int index = 4;
if (parameters != null && parameters.length >= 10) {
this.sshOptions = parameters[index++].toString();
this.javaPath = parameters[index++].toString();
if (this.javaPath == null || this.javaPath.equals("")) {
throw new IllegalArgumentException("A valid Java path must be supplied.");
}
this.schedulingPath = parameters[index++].toString();
// target OS
if (parameters[index] != null) {
OperatingSystem configuredTargetOs = OperatingSystem.getOperatingSystem(parameters[index++].toString());
if (configuredTargetOs == null) {
throw new IllegalArgumentException("Only 'Linux', 'Windows' and 'Cygwin' are valid values for Target OS Property.");
}
persistedInfraVariables.put(TARGET_OS_OBJ_KEY, configuredTargetOs);
} else {
throw new IllegalArgumentException("Target OS parameter cannot be null");
}
this.javaOptions = parameters[index++].toString();
// credentials
if (parameters[index] == null) {
throw new IllegalArgumentException("Credentials must be specified");
}
try {
persistedInfraVariables.put(CREDENTIALS_KEY, Credentials.getCredentialsBase64((byte[]) parameters[index++]));
} catch (KeyException e) {
throw new IllegalArgumentException("Could not retrieve base64 credentials", e);
}
} else {
throw new IllegalArgumentException("Invalid parameters for infrastructure creation");
}
}
Aggregations