Search in sources :

Example 1 with SSLFactory

use of nl.altindag.ssl.SSLFactory in project mutual-tls-ssl by Hakky54.

the class SSLFactoryTestHelper method createSSLFactory.

public static SSLFactory createSSLFactory(boolean oneWayAuthenticationEnabled, boolean twoWayAuthenticationEnabled) {
    String keyStorePath = "keystores-for-unit-tests/identity.jks";
    String keyStorePassword = "secret";
    String trustStorePath = "keystores-for-unit-tests/truststore.jks";
    String trustStorePassword = "secret";
    SSLFactory.Builder sslFactoryBuilder = SSLFactory.builder();
    if (oneWayAuthenticationEnabled) {
        sslFactoryBuilder.withTrustMaterial(trustStorePath, trustStorePassword.toCharArray()).withHostnameVerifier(new DefaultHostnameVerifier());
    }
    if (twoWayAuthenticationEnabled) {
        sslFactoryBuilder.withIdentityMaterial(keyStorePath, keyStorePassword.toCharArray()).withTrustMaterial(trustStorePath, trustStorePassword.toCharArray()).withHostnameVerifier(new DefaultHostnameVerifier());
    }
    return Mockito.spy(sslFactoryBuilder.build());
}
Also used : SSLFactory(nl.altindag.ssl.SSLFactory) DefaultHostnameVerifier(org.apache.http.conn.ssl.DefaultHostnameVerifier)

Example 2 with SSLFactory

use of nl.altindag.ssl.SSLFactory in project mutual-tls-ssl by Hakky54.

the class OldJdkHttpClientServiceShould method throwClientExceptionWhenProvidedUrlDoesNotContainHttpOrHttps.

@Test
void throwClientExceptionWhenProvidedUrlDoesNotContainHttpOrHttps() {
    SSLFactory sslFactory = mock(SSLFactory.class);
    OldJdkHttpClientService victim = spy(new OldJdkHttpClientService(sslFactory));
    assertThatThrownBy(() -> victim.executeRequest("www.google.com")).isInstanceOf(ClientException.class).hasMessage("Could not create a http client for one of these reasons: invalid url, security is enable while using an url with http or security is disable while using an url with https");
}
Also used : SSLFactory(nl.altindag.ssl.SSLFactory) ClientException(nl.altindag.client.ClientException) Test(org.junit.jupiter.api.Test)

Example 3 with SSLFactory

use of nl.altindag.ssl.SSLFactory in project mutual-tls-ssl by Hakky54.

the class ClientConfigShould method createApache5HttpClient.

@Test
void createApache5HttpClient() {
    SSLFactory sslFactory = createSSLFactory(false, true);
    org.apache.hc.client5.http.impl.classic.CloseableHttpClient httpClient = victim.apache5HttpClient(sslFactory);
    assertThat(httpClient).isNotNull();
    verify(sslFactory, times(1)).getSslContext();
    verify(sslFactory, times(1)).getHostnameVerifier();
    verify(sslFactory, times(2)).getSslParameters();
}
Also used : SSLFactory(nl.altindag.ssl.SSLFactory) SSLFactoryTestHelper.createSSLFactory(nl.altindag.client.util.SSLFactoryTestHelper.createSSLFactory) Test(org.junit.jupiter.api.Test)

Example 4 with SSLFactory

use of nl.altindag.ssl.SSLFactory in project mutual-tls-ssl by Hakky54.

the class ClientConfigShould method createApacheHttpClient.

@Test
void createApacheHttpClient() {
    SSLFactory sslFactory = createSSLFactory(false, true);
    CloseableHttpClient httpClient = victim.apacheHttpClient(sslFactory);
    assertThat(httpClient).isNotNull();
    verify(sslFactory, times(1)).getSslContext();
    verify(sslFactory, times(1)).getHostnameVerifier();
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) SSLFactory(nl.altindag.ssl.SSLFactory) SSLFactoryTestHelper.createSSLFactory(nl.altindag.client.util.SSLFactoryTestHelper.createSSLFactory) Test(org.junit.jupiter.api.Test)

Example 5 with SSLFactory

use of nl.altindag.ssl.SSLFactory in project mutual-tls-ssl by Hakky54.

the class ClientConfigShould method createGoogleHttpClient.

@Test
void createGoogleHttpClient() throws IOException {
    SSLFactory sslFactory = createSSLFactory(false, true);
    HttpTransport httpTransport = victim.googleHttpClient(sslFactory);
    assertThat(httpTransport).isNotNull();
    verify(sslFactory, times(1)).getSslSocketFactory();
    verify(sslFactory, times(1)).getHostnameVerifier();
    httpTransport.shutdown();
}
Also used : HttpTransport(com.google.api.client.http.HttpTransport) SSLFactory(nl.altindag.ssl.SSLFactory) SSLFactoryTestHelper.createSSLFactory(nl.altindag.client.util.SSLFactoryTestHelper.createSSLFactory) Test(org.junit.jupiter.api.Test)

Aggregations

SSLFactory (nl.altindag.ssl.SSLFactory)73 Test (org.junit.jupiter.api.Test)62 SSLFactoryTestHelper.createSSLFactory (nl.altindag.client.util.SSLFactoryTestHelper.createSSLFactory)22 KeyStore (java.security.KeyStore)21 SSLContext (javax.net.ssl.SSLContext)13 SSLSessionContext (javax.net.ssl.SSLSessionContext)11 SSLSession (javax.net.ssl.SSLSession)9 SslContext (io.netty.handler.ssl.SslContext)7 HttpClient (java.net.http.HttpClient)5 SslContextFactory (org.eclipse.jetty.util.ssl.SslContextFactory)5 HttpRequest (java.net.http.HttpRequest)3 X509Certificate (java.security.cert.X509Certificate)3 List (java.util.List)3 HttpsServer (com.sun.net.httpserver.HttpsServer)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 InputStream (java.io.InputStream)2 Certificate (java.security.cert.Certificate)2 ExecutorService (java.util.concurrent.ExecutorService)2 OkHttpClient (okhttp3.OkHttpClient)2 LayeredConnectionSocketFactory (org.apache.hc.client5.http.socket.LayeredConnectionSocketFactory)2