private static KeyStore createKeyStore ( final URL storeFile , final String password ) throws ClientSslSocketFactoryException { if ( storeFile == null ) { return null ; } Preconditions . checkArgument ( StringUtils . isNotEmpty ( password ) , "Null keystore should have empty password, defined keystore must have password" ) ; KeyStore keyStore = null ; try { keyStore = KeyStore . getInstance ( "jks" ) ; InputStream is = storeFile . openStream ( ) ; try { keyStore . load ( is , password . toCharArray ( ) ) ; } catch ( NoSuchAlgorithmException e ) { throw new ClientSslSocketFactoryException ( String . format ( "Failed to create a keystore that supports algorithm %s: %s" , SOCKET_ALGORITHM , e . getMessage ( ) ) , e ) ; } catch ( CertificateException e ) { throw new ClientSslSocketFactoryException ( String . format ( "Failed to create keystore with algorithm %s due to certificate exception: %s" , SOCKET_ALGORITHM , e . getMessage ( ) ) , e ) ; } finally { try { is . close ( ) ; } catch ( IOException ignore ) { // NOPMD } } } catch ( KeyStoreException e ) { throw new ClientSslSocketFactoryException ( String . format ( "KeyStore exception creating keystore: %s" , e . getMessage ( ) ) , e ) ; } catch ( IOException e ) { throw new ClientSslSocketFactoryException ( String . format ( "IO exception creating keystore: %s" , e . getMessage ( ) ) , e ) ; } return keyStore ; }
Opens the specified key or trust store using the given password .