Search in sources :

Example 26 with Ssl

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

the class AbstractReactiveWebServerFactoryTests method sslWantsClientAuthenticationSucceedsWithoutClientCertificate.

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

Example 27 with Ssl

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

the class AbstractServletWebServerFactoryTests method sslWithInvalidAliasFailsDuringStartup.

@Test
void sslWithInvalidAliasFailsDuringStartup() {
    AbstractServletWebServerFactory factory = getFactory();
    Ssl ssl = getSsl(null, "password", "test-alias-404", "src/test/resources/test.jks");
    factory.setSsl(ssl);
    ServletRegistrationBean<ExampleServlet> registration = new ServletRegistrationBean<>(new ExampleServlet(true, false), "/hello");
    ThrowingCallable call = () -> factory.getWebServer(registration).start();
    assertThatSslWithInvalidAliasCallFails(call);
}
Also used : ServletRegistrationBean(cn.taketoday.framework.web.servlet.ServletRegistrationBean) ThrowingCallable(org.assertj.core.api.ThrowableAssert.ThrowingCallable) Ssl(cn.taketoday.framework.web.server.Ssl) ExampleServlet(cn.taketoday.test.web.servlet.ExampleServlet) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Example 28 with Ssl

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

the class AbstractServletWebServerFactoryTests method getSsl.

private Ssl getSsl(String cert, String privateKey) {
    Ssl ssl = new Ssl();
    ssl.setClientAuth(ClientAuth.NEED);
    ssl.setCertificate(cert);
    ssl.setCertificatePrivateKey(privateKey);
    ssl.setTrustCertificate(cert);
    ssl.setKeyStorePassword("secret");
    return ssl;
}
Also used : Ssl(cn.taketoday.framework.web.server.Ssl)

Example 29 with Ssl

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

the class SslServerCustomizerTests method configureSslWhenSslIsEnabledWithNoKeyStoreThrowsWebServerException.

@Test
void configureSslWhenSslIsEnabledWithNoKeyStoreThrowsWebServerException() {
    Ssl ssl = new Ssl();
    SslServerCustomizer customizer = new SslServerCustomizer(null, ssl, null, null);
    assertThatExceptionOfType(Exception.class).isThrownBy(() -> customizer.configureSsl(new SslContextFactory.Server(), ssl, null)).satisfies((ex) -> {
        assertThat(ex).isInstanceOf(WebServerException.class);
        assertThat(ex).hasMessageContaining("Could not load key store 'null'");
    });
}
Also used : SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) Ssl(cn.taketoday.framework.web.server.Ssl) Test(org.junit.jupiter.api.Test)

Example 30 with Ssl

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

the class SslServerCustomizerTests method keyStoreProviderIsUsedWhenCreatingKeyStore.

@Test
void keyStoreProviderIsUsedWhenCreatingKeyStore() {
    Ssl ssl = new Ssl();
    ssl.setKeyPassword("password");
    ssl.setKeyStore("src/test/resources/test.jks");
    ssl.setKeyStoreProvider("com.example.KeyStoreProvider");
    SslServerCustomizer customizer = new SslServerCustomizer(ssl, null, null);
    assertThatIllegalStateException().isThrownBy(() -> customizer.getKeyManagerFactory(ssl, null)).withCauseInstanceOf(NoSuchProviderException.class).withMessageContaining("com.example.KeyStoreProvider");
}
Also used : NoSuchProviderException(java.security.NoSuchProviderException) 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