Search in sources :

Example 21 with Ssl

use of cn.taketoday.framework.web.server.Ssl in project today-framework by TAKETODAY.

the class SslBuilderCustomizerTests method getKeyManagersWhenAliasIsNullShouldNotDecorate.

@Test
void getKeyManagersWhenAliasIsNullShouldNotDecorate() throws Exception {
    Ssl ssl = new Ssl();
    ssl.setKeyPassword("password");
    ssl.setKeyStore("src/test/resources/test.jks");
    SslBuilderCustomizer customizer = new SslBuilderCustomizer(8080, InetAddress.getLocalHost(), ssl, null);
    KeyManager[] keyManagers = ReflectionTestUtils.invokeMethod(customizer, "getKeyManagers", ssl, null);
    Class<?> name = Class.forName("cn.taketoday.framework.web.embedded.undertow.SslBuilderCustomizer$ConfigurableAliasKeyManager");
    assertThat(keyManagers[0]).isNotInstanceOf(name);
}
Also used : Ssl(cn.taketoday.framework.web.server.Ssl) KeyManager(javax.net.ssl.KeyManager) Test(org.junit.jupiter.api.Test)

Example 22 with Ssl

use of cn.taketoday.framework.web.server.Ssl in project today-framework by TAKETODAY.

the class SslBuilderCustomizerTests method trustStoreProviderIsUsedWhenCreatingTrustStore.

@Test
void trustStoreProviderIsUsedWhenCreatingTrustStore() throws Exception {
    Ssl ssl = new Ssl();
    ssl.setTrustStorePassword("password");
    ssl.setTrustStore("src/test/resources/test.jks");
    ssl.setTrustStoreProvider("com.example.TrustStoreProvider");
    SslBuilderCustomizer customizer = new SslBuilderCustomizer(8080, InetAddress.getLocalHost(), ssl, null);
    assertThatIllegalStateException().isThrownBy(() -> ReflectionTestUtils.invokeMethod(customizer, "getTrustManagers", ssl, null)).withCauseInstanceOf(NoSuchProviderException.class).withMessageContaining("com.example.TrustStoreProvider");
}
Also used : NoSuchProviderException(java.security.NoSuchProviderException) Ssl(cn.taketoday.framework.web.server.Ssl) Test(org.junit.jupiter.api.Test)

Example 23 with Ssl

use of cn.taketoday.framework.web.server.Ssl in project today-framework by TAKETODAY.

the class AbstractReactiveWebServerFactoryTests method sslWantsClientAuthenticationSucceedsWithClientCertificate.

@Test
void sslWantsClientAuthenticationSucceedsWithClientCertificate() throws Exception {
    Ssl ssl = new Ssl();
    ssl.setClientAuth(Ssl.ClientAuth.WANT);
    ssl.setKeyStore("classpath:test.jks");
    ssl.setKeyPassword("password");
    ssl.setKeyStorePassword("secret");
    ssl.setTrustStore("classpath:test.jks");
    testClientAuthSuccess(ssl, buildTrustAllSslWithClientKeyConnector("test.jks", "password"));
}
Also used : Ssl(cn.taketoday.framework.web.server.Ssl) Test(org.junit.jupiter.api.Test)

Example 24 with Ssl

use of cn.taketoday.framework.web.server.Ssl in project today-framework by TAKETODAY.

the class AbstractReactiveWebServerFactoryTests method sslWithPemCertificates.

@Test
void sslWithPemCertificates() throws Exception {
    Ssl ssl = new Ssl();
    ssl.setClientAuth(Ssl.ClientAuth.NEED);
    ssl.setCertificate("classpath:test-cert.pem");
    ssl.setCertificatePrivateKey("classpath:test-key.pem");
    ssl.setTrustCertificate("classpath:test-cert.pem");
    ssl.setKeyStorePassword("secret");
    testClientAuthSuccess(ssl, buildTrustAllSslWithClientKeyConnector("test.p12", "secret"));
}
Also used : Ssl(cn.taketoday.framework.web.server.Ssl) Test(org.junit.jupiter.api.Test)

Example 25 with Ssl

use of cn.taketoday.framework.web.server.Ssl in project today-framework by TAKETODAY.

the class AbstractReactiveWebServerFactoryTests method sslNeedsClientAuthenticationSucceedsWithClientCertificate.

@Test
void sslNeedsClientAuthenticationSucceedsWithClientCertificate() throws Exception {
    Ssl ssl = new Ssl();
    ssl.setClientAuth(Ssl.ClientAuth.NEED);
    ssl.setKeyStore("classpath:test.jks");
    ssl.setKeyStorePassword("secret");
    ssl.setKeyPassword("password");
    ssl.setTrustStore("classpath:test.jks");
    testClientAuthSuccess(ssl, buildTrustAllSslWithClientKeyConnector("test.jks", "password"));
}
Also used : Ssl(cn.taketoday.framework.web.server.Ssl) Test(org.junit.jupiter.api.Test)

Aggregations

Ssl (cn.taketoday.framework.web.server.Ssl)72 Test (org.junit.jupiter.api.Test)58 Connector (org.apache.catalina.connector.Connector)12 SSLHostConfig (org.apache.tomcat.util.net.SSLHostConfig)10 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)10 SslStoreProvider (cn.taketoday.framework.web.server.SslStoreProvider)8 NoSuchProviderException (java.security.NoSuchProviderException)8 ServletRegistrationBean (cn.taketoday.framework.web.servlet.ServletRegistrationBean)6 HttpComponentsClientHttpRequestFactory (cn.taketoday.http.client.HttpComponentsClientHttpRequestFactory)6 ReactorClientHttpConnector (cn.taketoday.http.client.reactive.ReactorClientHttpConnector)6 ExampleServlet (cn.taketoday.test.web.servlet.ExampleServlet)6 WebClient (cn.taketoday.web.reactive.function.client.WebClient)6 KeyStore (java.security.KeyStore)6 HttpClient (org.apache.http.client.HttpClient)6 SSLConnectionSocketFactory (org.apache.http.conn.ssl.SSLConnectionSocketFactory)6 SSLContextBuilder (org.apache.http.ssl.SSLContextBuilder)6 WebServerException (cn.taketoday.framework.web.server.WebServerException)4 InetAddress (java.net.InetAddress)4 TrustSelfSignedStrategy (org.apache.http.conn.ssl.TrustSelfSignedStrategy)4 SSLHostConfigCertificate (org.apache.tomcat.util.net.SSLHostConfigCertificate)4