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();
}
}
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;
}
}
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;
}
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");
}
}
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());
}
Aggregations