Search in sources :

Example 36 with KeyException

use of java.security.KeyException in project robovm by robovm.

the class KeyExceptionTest method testKeyException05.

/**
     * Test for <code>KeyException(Throwable)</code> constructor Assertion:
     * constructs KeyException when <code>cause</code> is not null
     */
public void testKeyException05() {
    KeyException tE = new KeyException(tCause);
    if (tE.getMessage() != null) {
        String toS = tCause.toString();
        String getM = tE.getMessage();
        assertTrue("getMessage() should contain ".concat(toS), (getM.indexOf(toS) != -1));
    }
    assertNotNull("getCause() must not return null", tE.getCause());
    assertEquals("getCause() must return ".concat(tCause.toString()), tE.getCause(), tCause);
}
Also used : KeyException(java.security.KeyException)

Example 37 with KeyException

use of java.security.KeyException in project robovm by robovm.

the class KeyExceptionTest method testKeyException04.

/**
     * Test for <code>KeyException(Throwable)</code> constructor Assertion:
     * constructs KeyException when <code>cause</code> is null
     */
public void testKeyException04() {
    Throwable cause = null;
    KeyException tE = new KeyException(cause);
    assertNull("getMessage() must return null.", tE.getMessage());
    assertNull("getCause() must return null", tE.getCause());
}
Also used : KeyException(java.security.KeyException)

Example 38 with KeyException

use of java.security.KeyException in project cxf by apache.

the class RequestParser method parseKeyInfoElement.

/**
 * Parse the KeyInfo Element to return a ReceivedKey object containing the found certificate or
 * public key.
 */
private static ReceivedKey parseKeyInfoElement(Element keyInfoElement) throws STSException {
    KeyInfoFactory keyInfoFactory = null;
    try {
        keyInfoFactory = KeyInfoFactory.getInstance("DOM", "ApacheXMLDSig");
    } catch (NoSuchProviderException ex) {
        keyInfoFactory = KeyInfoFactory.getInstance("DOM");
    }
    try {
        KeyInfo keyInfo = keyInfoFactory.unmarshalKeyInfo(new DOMStructure(keyInfoElement));
        List<?> list = keyInfo.getContent();
        for (int i = 0; i < list.size(); i++) {
            if (list.get(i) instanceof KeyValue) {
                KeyValue keyValue = (KeyValue) list.get(i);
                ReceivedKey receivedKey = new ReceivedKey();
                receivedKey.setPublicKey(keyValue.getPublicKey());
                return receivedKey;
            } else if (list.get(i) instanceof X509Certificate) {
                ReceivedKey receivedKey = new ReceivedKey();
                receivedKey.setX509Cert((X509Certificate) list.get(i));
                return receivedKey;
            } else if (list.get(i) instanceof X509Data) {
                X509Data x509Data = (X509Data) list.get(i);
                for (int j = 0; j < x509Data.getContent().size(); j++) {
                    if (x509Data.getContent().get(j) instanceof X509Certificate) {
                        ReceivedKey receivedKey = new ReceivedKey();
                        receivedKey.setX509Cert((X509Certificate) x509Data.getContent().get(j));
                        return receivedKey;
                    }
                }
            }
        }
    } catch (MarshalException e) {
        LOG.log(Level.WARNING, "", e);
        throw new STSException(e.getMessage(), e, STSException.INVALID_REQUEST);
    } catch (KeyException e) {
        LOG.log(Level.WARNING, "", e);
        throw new STSException(e.getMessage(), e, STSException.INVALID_REQUEST);
    }
    return null;
}
Also used : MarshalException(javax.xml.crypto.MarshalException) KeyValue(javax.xml.crypto.dsig.keyinfo.KeyValue) STSException(org.apache.cxf.ws.security.sts.provider.STSException) X509Data(javax.xml.crypto.dsig.keyinfo.X509Data) X509Certificate(java.security.cert.X509Certificate) KeyException(java.security.KeyException) KeyInfoFactory(javax.xml.crypto.dsig.keyinfo.KeyInfoFactory) KeyInfo(javax.xml.crypto.dsig.keyinfo.KeyInfo) DOMStructure(javax.xml.crypto.dom.DOMStructure) NoSuchProviderException(java.security.NoSuchProviderException)

Example 39 with KeyException

use of java.security.KeyException in project TinyKeePass by sorz.

the class BaseActivity method getKey.

private void getKey() {
    int authMethod = preferences.getInt(PREF_KEY_AUTH_METHOD, AUTH_METHOD_UNDEFINED);
    switch(authMethod) {
        case AUTH_METHOD_UNDEFINED:
            onKeyAuthFailed.accept(getString(R.string.broken_keys));
            break;
        case AUTH_METHOD_NONE:
        case AUTH_METHOD_SCREEN_LOCK:
            try {
                Cipher cipher = secureStringStorage.getDecryptCipher();
                decryptKey(cipher);
            } catch (UserNotAuthenticatedException e) {
                // should do authentication
                Intent intent = keyguardManager.createConfirmDeviceCredentialIntent(getString(R.string.auth_key_title), getString(R.string.auth_key_description));
                startActivityForResult(intent, REQUEST_CONFIRM_DEVICE_CREDENTIAL);
            } catch (KeyException e) {
                onKeyException(e);
            } catch (SecureStringStorage.SystemException e) {
                throw new RuntimeException(e);
            }
            break;
        case DatabaseSetupActivity.AUTH_METHOD_FINGERPRINT:
            getFragmentManager().beginTransaction().add(FingerprintDialogFragment.newInstance(Cipher.DECRYPT_MODE), "fingerprint").commit();
            break;
    }
}
Also used : SecureStringStorage(org.sorz.lab.tinykeepass.auth.SecureStringStorage) UserNotAuthenticatedException(android.security.keystore.UserNotAuthenticatedException) Intent(android.content.Intent) Cipher(javax.crypto.Cipher) KeyException(java.security.KeyException)

Example 40 with KeyException

use of java.security.KeyException in project scheduling by ow2-proactive.

the class SchedulerAuthenticationGUIHelper method login.

/**
 * This method will log a client to the scheduler by requesting his URL, username and password from a
 * graphical interface.
 *
 * @param schedulerURL The default URL of the scheduler to connect
 * @return The connection to the scheduler as a {@link Scheduler} if logging successful.
 * 			If the username is empty or if the user cancel the authentication, this method will return null.
 * @throws LoginException If a problem occurs while logging the user.
 * @throws SchedulerException If a problem occurs at scheduler level.
 */
public static Scheduler login(String schedulerURL) throws LoginException, SchedulerException {
    AuthResultContainer auth = connect(schedulerURL);
    if (auth == null) {
        return null;
    } else {
        SchedulerAuthenticationInterface schedAuth = auth.getAuth();
        Credentials cred = null;
        try {
            cred = Credentials.createCredentials(new CredData(CredData.parseLogin(auth.getUsername()), CredData.parseDomain(auth.getUsername()), auth.getPassword()), schedAuth.getPublicKey());
        } catch (LoginException e) {
            throw new LoginException("Could not retrieve public key from Scheduler " + schedulerURL + ", contact the administrator" + e);
        } catch (KeyException e) {
            throw new LoginException("Could not encrypt credentials " + e);
        }
        return schedAuth.login(cred);
    }
}
Also used : CredData(org.ow2.proactive.authentication.crypto.CredData) LoginException(javax.security.auth.login.LoginException) Credentials(org.ow2.proactive.authentication.crypto.Credentials) 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