private static KeyStore getKeyStore(Certificate[] chain, PrivateKey pk) { try { KeyStore ks = KeyStore.getInstance(KEYSTORE_TYPE); try { ks.load(null, null); } // empty catch (Exception ignore) { } //@SuppressWarnings("unused") KeyStore.Entry ke = new KeyStore.PrivateKeyEntry(pk, chain); ks.setKeyEntry(CERT_ALIAS, pk, THE_PASSWORD, chain); log.debug("added certificate chain to keystore: " + CERT_ALIAS + "," + pk + "," + THE_PASSWORD + "," + chain); return ks; } catch (KeyStoreException ex) { if (ex.getCause() != null && ex.getCause() instanceof java.security.NoSuchAlgorithmException) { throw new IllegalArgumentException( "Sorry, this implementation of Java, issued by " + System.getProperty("java.vendor") + ", does not support CADC Certificates."); } throw new RuntimeException("failed to find/load KeyStore of type " + KEYSTORE_TYPE, ex); } }
private KeyStore initKeystore(KeystoreData keystoreData, String storeid, CallbackHandler handler) throws WrongKeystoreCredentialException, MissingKeystoreAlgorithmException, MissingKeystoreProviderException, MissingKeyAlgorithmException, CertificateException, IOException { try { return KeyStoreService.loadKeyStore(keystoreData.getKeystore().toByteArray(), storeid, keystoreData.getType(), handler); } catch (UnrecoverableKeyException e) { throw new WrongKeystoreCredentialException(e); } catch (KeyStoreException e) { if(e.getCause()!=null){ Throwable cause = e.getCause(); if(cause instanceof NoSuchAlgorithmException){ throw new MissingKeystoreAlgorithmException(cause.getMessage(), cause); } if(cause instanceof NoSuchProviderException){ throw new MissingKeystoreProviderException(cause.getMessage(), cause); } } throw new IllegalStateException("Unidentified keystore exception", e); } catch (NoSuchAlgorithmException e) { throw new MissingKeyAlgorithmException(e.getMessage(), e); } }
public KeyStore keyStore() { try { KeyStore keyStore = KeyStore.getInstance(this.keyStoreType.name()); keyStore.load(this.keyStoreInputStream, null == keyStorePwd ? new char[0] : keyStorePwd.toCharArray()); return keyStore; } catch (KeyStoreException e) { if (e.getCause() instanceof NoSuchAlgorithmException || e.getCause() instanceof NoSuchProviderException) { throw new ApnsException(new InvalidKeyStoreTypeException("(" + this.keyStoreType + ")", e)); } else { throw new ApnsException(new InvalidKeyStoreTypeException(e)); } } catch (CertificateException e) { throw new ApnsException(new InvalidKeyStoreFormatException("cant load keystore", e)); } catch (NoSuchAlgorithmException e) { throw new ApnsException(new InvalidKeyStoreFormatException("cant load keystore", e)); } catch (IOException e) { if (e.getCause() instanceof BadPaddingException) { throw new ApnsException(new InvalidKeyStorePasswordException("(" + this.keyStorePwd + ")", e)); } else { throw new ApnsException(new InvalidKeyStoreFormatException(e)); } } }