Search in sources :

Example 1 with InvalidSSLConfig

use of com.notnoop.exceptions.InvalidSSLConfig in project java-apns by notnoop.

the class SSLContextBuilder method withTrustKeyStore.

public SSLContextBuilder withTrustKeyStore(KeyStore keyStore, String keyStorePassword) throws InvalidSSLConfig {
    try {
        TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(algorithm);
        trustManagerFactory.init(keyStore);
        trustManagers = trustManagerFactory.getTrustManagers();
        return this;
    } catch (GeneralSecurityException e) {
        throw new InvalidSSLConfig(e);
    }
}
Also used : TrustManagerFactory(javax.net.ssl.TrustManagerFactory) GeneralSecurityException(java.security.GeneralSecurityException) InvalidSSLConfig(com.notnoop.exceptions.InvalidSSLConfig)

Example 2 with InvalidSSLConfig

use of com.notnoop.exceptions.InvalidSSLConfig in project java-apns by notnoop.

the class SSLContextBuilder method withCertificateKeyStore.

public SSLContextBuilder withCertificateKeyStore(KeyStore keyStore, String keyStorePassword) throws InvalidSSLConfig {
    try {
        keyManagerFactory = KeyManagerFactory.getInstance(algorithm);
        keyManagerFactory.init(keyStore, keyStorePassword.toCharArray());
        return this;
    } catch (GeneralSecurityException e) {
        throw new InvalidSSLConfig(e);
    }
}
Also used : GeneralSecurityException(java.security.GeneralSecurityException) InvalidSSLConfig(com.notnoop.exceptions.InvalidSSLConfig)

Example 3 with InvalidSSLConfig

use of com.notnoop.exceptions.InvalidSSLConfig in project java-apns by notnoop.

the class SSLContextBuilder method build.

public SSLContext build() throws InvalidSSLConfig {
    if (keyManagerFactory == null) {
        throw new InvalidSSLConfig("Missing KeyManagerFactory");
    }
    if (trustManagers == null) {
        throw new InvalidSSLConfig("Missing TrustManagers");
    }
    try {
        final SSLContext sslContext = SSLContext.getInstance("TLS");
        sslContext.init(keyManagerFactory.getKeyManagers(), trustManagers, null);
        return sslContext;
    } catch (GeneralSecurityException e) {
        throw new InvalidSSLConfig(e);
    }
}
Also used : GeneralSecurityException(java.security.GeneralSecurityException) InvalidSSLConfig(com.notnoop.exceptions.InvalidSSLConfig) SSLContext(javax.net.ssl.SSLContext)

Example 4 with InvalidSSLConfig

use of com.notnoop.exceptions.InvalidSSLConfig in project java-apns by notnoop.

the class SSLContextBuilder method withDefaultTrustKeyStore.

public SSLContextBuilder withDefaultTrustKeyStore() throws InvalidSSLConfig {
    try {
        TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(algorithm);
        trustManagerFactory.init((KeyStore) null);
        trustManagers = trustManagerFactory.getTrustManagers();
        return this;
    } catch (GeneralSecurityException e) {
        throw new InvalidSSLConfig(e);
    }
}
Also used : TrustManagerFactory(javax.net.ssl.TrustManagerFactory) GeneralSecurityException(java.security.GeneralSecurityException) InvalidSSLConfig(com.notnoop.exceptions.InvalidSSLConfig)

Example 5 with InvalidSSLConfig

use of com.notnoop.exceptions.InvalidSSLConfig in project java-apns by notnoop.

the class SSLContextBuilder method withCertificateKeyStore.

public SSLContextBuilder withCertificateKeyStore(InputStream keyStoreStream, String keyStorePassword, String keyStoreType, String keyAlias) throws InvalidSSLConfig {
    try {
        final KeyStore ks = KeyStore.getInstance(keyStoreType);
        ks.load(keyStoreStream, keyStorePassword.toCharArray());
        return withCertificateKeyStore(ks, keyStorePassword, keyAlias);
    } catch (GeneralSecurityException e) {
        throw new InvalidSSLConfig(e);
    } catch (IOException e) {
        throw new InvalidSSLConfig(e);
    }
}
Also used : GeneralSecurityException(java.security.GeneralSecurityException) InvalidSSLConfig(com.notnoop.exceptions.InvalidSSLConfig) IOException(java.io.IOException) KeyStore(java.security.KeyStore)

Aggregations

InvalidSSLConfig (com.notnoop.exceptions.InvalidSSLConfig)6 GeneralSecurityException (java.security.GeneralSecurityException)6 IOException (java.io.IOException)2 KeyStore (java.security.KeyStore)2 TrustManagerFactory (javax.net.ssl.TrustManagerFactory)2 SSLContext (javax.net.ssl.SSLContext)1