Search in sources :

Example 1 with UnrecoverableKeyException

use of java.security.UnrecoverableKeyException in project hadoop by apache.

the class JavaKeyStoreProvider method getMetadata.

@Override
public Metadata getMetadata(String name) throws IOException {
    readLock.lock();
    try {
        if (cache.containsKey(name)) {
            return cache.get(name);
        }
        try {
            if (!keyStore.containsAlias(name)) {
                return null;
            }
            Metadata meta = ((KeyMetadata) keyStore.getKey(name, password)).metadata;
            cache.put(name, meta);
            return meta;
        } catch (ClassCastException e) {
            throw new IOException("Can't cast key for " + name + " in keystore " + path + " to a KeyMetadata. Key may have been added using " + " keytool or some other non-Hadoop method.", e);
        } catch (KeyStoreException e) {
            throw new IOException("Can't get metadata for " + name + " from keystore " + path, e);
        } catch (NoSuchAlgorithmException e) {
            throw new IOException("Can't get algorithm for " + name + " from keystore " + path, e);
        } catch (UnrecoverableKeyException e) {
            throw new IOException("Can't recover key for " + name + " from keystore " + path, e);
        }
    } finally {
        readLock.unlock();
    }
}
Also used : UnrecoverableKeyException(java.security.UnrecoverableKeyException) IOException(java.io.IOException) KeyStoreException(java.security.KeyStoreException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException)

Example 2 with UnrecoverableKeyException

use of java.security.UnrecoverableKeyException in project LolliPin by OrangeGangsters.

the class FingerprintUiHelper method initCipher.

/**
     * Initialize the {@link Cipher} instance with the created key in the {@link #createKey()}
     * method.
     *
     * @return {@code true} if initialization is successful, {@code false} if the lock screen has
     * been disabled or reset after the key was generated, or if a fingerprint got enrolled after
     * the key was generated.
     */
private boolean initCipher() {
    try {
        if (mKeyStore == null) {
            mKeyStore = KeyStore.getInstance("AndroidKeyStore");
        }
        createKey();
        mKeyStore.load(null);
        SecretKey key = (SecretKey) mKeyStore.getKey(KEY_NAME, null);
        mCipher = Cipher.getInstance("AES/CBC/PKCS7Padding");
        mCipher.init(Cipher.ENCRYPT_MODE, key);
        return true;
    } catch (NoSuchPaddingException | KeyStoreException | CertificateException | UnrecoverableKeyException | IOException | NoSuchAlgorithmException | InvalidKeyException e) {
        return false;
    }
}
Also used : SecretKey(javax.crypto.SecretKey) UnrecoverableKeyException(java.security.UnrecoverableKeyException) NoSuchPaddingException(javax.crypto.NoSuchPaddingException) CertificateException(java.security.cert.CertificateException) KeyStoreException(java.security.KeyStoreException) IOException(java.io.IOException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) InvalidKeyException(java.security.InvalidKeyException)

Example 3 with UnrecoverableKeyException

use of java.security.UnrecoverableKeyException in project ribbon by Netflix.

the class AbstractSslContextFactory method createKeyManagers.

/**
     * Creates the key managers to be used by the factory from the associated key store and password.
     *
     * @return the newly created array of key managers
     * @throws ClientSslSocketFactoryException if an exception is detected in loading the key store
     */
private KeyManager[] createKeyManagers() throws ClientSslSocketFactoryException {
    final KeyManagerFactory factory;
    try {
        factory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
        factory.init(this.keyStore, this.keyStorePassword.toCharArray());
    } catch (NoSuchAlgorithmException e) {
        throw new ClientSslSocketFactoryException(String.format("Failed to create the key store because the algorithm %s is not supported. ", KeyManagerFactory.getDefaultAlgorithm()), e);
    } catch (UnrecoverableKeyException e) {
        throw new ClientSslSocketFactoryException("Unrecoverable Key Exception initializing key manager factory; this is probably fatal", e);
    } catch (KeyStoreException e) {
        throw new ClientSslSocketFactoryException("KeyStore exception initializing key manager factory; this is probably fatal", e);
    }
    KeyManager[] managers = factory.getKeyManagers();
    LOGGER.debug("Key managers are initialized. Total {} managers. ", managers.length);
    return managers;
}
Also used : UnrecoverableKeyException(java.security.UnrecoverableKeyException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) KeyStoreException(java.security.KeyStoreException) KeyManager(javax.net.ssl.KeyManager) KeyManagerFactory(javax.net.ssl.KeyManagerFactory)

Example 4 with UnrecoverableKeyException

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

the class TestKeyStore method dump.

/**
     * Dump a key store for debugging.
     */
public static void dump(String context, KeyStore keyStore, char[] keyPassword) throws KeyStoreException, NoSuchAlgorithmException {
    PrintStream out = System.out;
    out.println("context=" + context);
    out.println("\tkeyStore=" + keyStore);
    out.println("\tkeyStore.type=" + keyStore.getType());
    out.println("\tkeyStore.provider=" + keyStore.getProvider());
    out.println("\tkeyPassword=" + ((keyPassword == null) ? null : new String(keyPassword)));
    out.println("\tsize=" + keyStore.size());
    for (String alias : Collections.list(keyStore.aliases())) {
        out.println("alias=" + alias);
        out.println("\tcreationDate=" + keyStore.getCreationDate(alias));
        if (keyStore.isCertificateEntry(alias)) {
            out.println("\tcertificate:");
            out.println("==========================================");
            out.println(keyStore.getCertificate(alias));
            out.println("==========================================");
            continue;
        }
        if (keyStore.isKeyEntry(alias)) {
            out.println("\tkey:");
            out.println("==========================================");
            String key;
            try {
                key = ("Key retrieved using password\n" + keyStore.getKey(alias, keyPassword));
            } catch (UnrecoverableKeyException e1) {
                try {
                    key = ("Key retrieved without password\n" + keyStore.getKey(alias, null));
                } catch (UnrecoverableKeyException e2) {
                    key = "Key could not be retrieved";
                }
            }
            out.println(key);
            out.println("==========================================");
            Certificate[] chain = keyStore.getCertificateChain(alias);
            if (chain == null) {
                out.println("No certificate chain associated with key");
                out.println("==========================================");
            } else {
                for (int i = 0; i < chain.length; i++) {
                    out.println("Certificate chain element #" + i);
                    out.println(chain[i]);
                    out.println("==========================================");
                }
            }
            continue;
        }
        out.println("\tunknown entry type");
    }
}
Also used : PrintStream(java.io.PrintStream) UnrecoverableKeyException(java.security.UnrecoverableKeyException) DEROctetString(com.android.org.bouncycastle.asn1.DEROctetString) X509Certificate(java.security.cert.X509Certificate) Certificate(java.security.cert.Certificate)

Example 5 with UnrecoverableKeyException

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

the class UnrecoverableKeyExceptionTest method testUnrecoverableKeyException03.

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

Aggregations

UnrecoverableKeyException (java.security.UnrecoverableKeyException)99 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)77 KeyStoreException (java.security.KeyStoreException)76 IOException (java.io.IOException)60 CertificateException (java.security.cert.CertificateException)49 InvalidKeyException (java.security.InvalidKeyException)28 NoSuchPaddingException (javax.crypto.NoSuchPaddingException)27 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)26 BadPaddingException (javax.crypto.BadPaddingException)26 IllegalBlockSizeException (javax.crypto.IllegalBlockSizeException)26 KeyStore (java.security.KeyStore)24 KeyManagementException (java.security.KeyManagementException)19 RemoteException (android.os.RemoteException)15 SecretKey (javax.crypto.SecretKey)15 KeyManagerFactory (javax.net.ssl.KeyManagerFactory)15 SSLContext (javax.net.ssl.SSLContext)14 FileNotFoundException (java.io.FileNotFoundException)13 Key (java.security.Key)12 NoSuchProviderException (java.security.NoSuchProviderException)11 PrivateKey (java.security.PrivateKey)11