Search in sources :

Example 16 with Ssl

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

the class SslConnectorCustomizerTests method sslEnabledProtocolsConfiguration.

@Test
void sslEnabledProtocolsConfiguration() throws Exception {
    Ssl ssl = new Ssl();
    ssl.setKeyPassword("password");
    ssl.setKeyStore("src/test/resources/test.jks");
    ssl.setEnabledProtocols(new String[] { "TLSv1.2" });
    ssl.setCiphers(new String[] { "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256", "BRAVO" });
    SslConnectorCustomizer customizer = new SslConnectorCustomizer(ssl, null);
    Connector connector = this.tomcat.getConnector();
    customizer.customize(connector);
    this.tomcat.start();
    SSLHostConfig sslHostConfig = connector.getProtocolHandler().findSslHostConfigs()[0];
    assertThat(sslHostConfig.getSslProtocol()).isEqualTo("TLS");
    assertThat(sslHostConfig.getEnabledProtocols()).containsExactly("TLSv1.2");
}
Also used : Connector(org.apache.catalina.connector.Connector) Ssl(cn.taketoday.framework.web.server.Ssl) SSLHostConfig(org.apache.tomcat.util.net.SSLHostConfig) Test(org.junit.jupiter.api.Test)

Example 17 with Ssl

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

the class NettyReactiveWebServerFactoryTests method testSslWithAlias.

protected Mono<String> testSslWithAlias(String alias) {
    String keyStore = "classpath:test.jks";
    String keyPassword = "password";
    NettyReactiveWebServerFactory factory = getFactory();
    Ssl ssl = new Ssl();
    ssl.setKeyStore(keyStore);
    ssl.setKeyPassword(keyPassword);
    ssl.setKeyAlias(alias);
    factory.setSsl(ssl);
    this.webServer = factory.getWebServer(new EchoHandler());
    this.webServer.start();
    ReactorClientHttpConnector connector = buildTrustAllSslConnector();
    WebClient client = WebClient.builder().baseUrl("https://localhost:" + this.webServer.getPort()).clientConnector(connector).build();
    return client.post().uri("/test").contentType(MediaType.TEXT_PLAIN).body(BodyInserters.fromValue("Hello World")).retrieve().bodyToMono(String.class);
}
Also used : Ssl(cn.taketoday.framework.web.server.Ssl) WebClient(cn.taketoday.web.reactive.function.client.WebClient) ReactorClientHttpConnector(cn.taketoday.http.client.reactive.ReactorClientHttpConnector)

Example 18 with Ssl

use of cn.taketoday.framework.web.server.Ssl in project today-infrastructure 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 19 with Ssl

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

the class UndertowWebServerFactoryDelegate method createBuilder.

Builder createBuilder(AbstractConfigurableWebServerFactory factory) {
    Ssl ssl = factory.getSsl();
    InetAddress address = factory.getAddress();
    int port = factory.getPort();
    Builder builder = Undertow.builder();
    if (this.bufferSize != null) {
        builder.setBufferSize(this.bufferSize);
    }
    if (this.ioThreads != null) {
        builder.setIoThreads(this.ioThreads);
    }
    if (this.workerThreads != null) {
        builder.setWorkerThreads(this.workerThreads);
    }
    if (this.directBuffers != null) {
        builder.setDirectBuffers(this.directBuffers);
    }
    Http2 http2 = factory.getHttp2();
    if (http2 != null) {
        builder.setServerOption(UndertowOptions.ENABLE_HTTP2, http2.isEnabled());
    }
    if (ssl != null && ssl.isEnabled()) {
        new SslBuilderCustomizer(factory.getPort(), address, ssl, factory.getOrCreateSslStoreProvider()).customize(builder);
    } else {
        builder.addHttpListener(port, (address != null) ? address.getHostAddress() : "0.0.0.0");
    }
    builder.setServerOption(UndertowOptions.SHUTDOWN_TIMEOUT, 0);
    for (UndertowBuilderCustomizer customizer : this.builderCustomizers) {
        customizer.customize(builder);
    }
    return builder;
}
Also used : Builder(io.undertow.Undertow.Builder) Http2(cn.taketoday.framework.web.server.Http2) Ssl(cn.taketoday.framework.web.server.Ssl) InetAddress(java.net.InetAddress)

Example 20 with Ssl

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

the class SslBuilderCustomizerTests method keyStoreProviderIsUsedWhenCreatingKeyStore.

@Test
void keyStoreProviderIsUsedWhenCreatingKeyStore() throws Exception {
    Ssl ssl = new Ssl();
    ssl.setKeyPassword("password");
    ssl.setKeyStore("src/test/resources/test.jks");
    ssl.setKeyStoreProvider("com.example.KeyStoreProvider");
    SslBuilderCustomizer customizer = new SslBuilderCustomizer(8080, InetAddress.getLocalHost(), ssl, null);
    assertThatIllegalStateException().isThrownBy(() -> ReflectionTestUtils.invokeMethod(customizer, "getKeyManagers", 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