Search in sources :

Example 11 with KeyException

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);
    }
}
Also used : SecretKey(javax.crypto.SecretKey) InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) UnrecoverableKeyException(java.security.UnrecoverableKeyException) NoSuchPaddingException(javax.crypto.NoSuchPaddingException) Cipher(javax.crypto.Cipher) GCMParameterSpec(javax.crypto.spec.GCMParameterSpec) KeyStoreException(java.security.KeyStoreException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) KeyException(java.security.KeyException) UnrecoverableKeyException(java.security.UnrecoverableKeyException)

Example 12 with KeyException

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);
    }
}
Also used : PermissionException(org.ow2.proactive.scheduler.common.exception.PermissionException) NotConnectedException(org.ow2.proactive.scheduler.common.exception.NotConnectedException) PermissionRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.PermissionRestException) Scheduler(org.ow2.proactive.scheduler.common.Scheduler) NotConnectedRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException) SchedulerRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.SchedulerRestException) KeyException(java.security.KeyException)

Example 13 with KeyException

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;
}
Also used : HelpFormatter(org.apache.commons.cli.HelpFormatter) Throwables.getStackTraceAsString(com.google.common.base.Throwables.getStackTraceAsString) KeyException(java.security.KeyException)

Example 14 with KeyException

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;
}
Also used : File(java.io.File) KeyException(java.security.KeyException) Credentials(org.ow2.proactive.authentication.crypto.Credentials) LoginException(javax.security.auth.login.LoginException) ActiveObjectCreationException(org.objectweb.proactive.ActiveObjectCreationException) KeyException(java.security.KeyException) NotConfiguredException(org.objectweb.proactive.extensions.dataspaces.exceptions.NotConfiguredException) NodeException(org.objectweb.proactive.core.node.NodeException) ParseException(org.apache.commons.cli.ParseException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) AddingNodesException(org.ow2.proactive.resourcemanager.exception.AddingNodesException) ProActiveRuntimeException(org.objectweb.proactive.core.ProActiveRuntimeException) NotConnectedException(org.ow2.proactive.resourcemanager.exception.NotConnectedException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) ProActiveException(org.objectweb.proactive.core.ProActiveException)

Example 15 with KeyException

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");
    }
}
Also used : OperatingSystem(org.ow2.proactive.resourcemanager.utils.OperatingSystem) KeyException(java.security.KeyException)

Aggregations

KeyException (java.security.KeyException)59 IOException (java.io.IOException)22 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)14 File (java.io.File)10 PublicKey (java.security.PublicKey)8 FileInputStream (java.io.FileInputStream)7 Cipher (javax.crypto.Cipher)6 Throwables.getStackTraceAsString (com.google.common.base.Throwables.getStackTraceAsString)5 InvalidKeySpecException (java.security.spec.InvalidKeySpecException)5 LoginException (javax.security.auth.login.LoginException)5 Credentials (org.ow2.proactive.authentication.crypto.Credentials)5 FileNotFoundException (java.io.FileNotFoundException)4 PrivateKey (java.security.PrivateKey)4 CredData (org.ow2.proactive.authentication.crypto.CredData)4 RMException (org.ow2.proactive.resourcemanager.exception.RMException)4 CommandLineBuilder (org.ow2.proactive.resourcemanager.utils.CommandLineBuilder)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 DataInputStream (java.io.DataInputStream)3 InputStream (java.io.InputStream)3 Key (java.security.Key)3