Search in sources :

Example 11 with Ssl

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

the class JettyServletWebServerFactoryTests method getSslSettings.

private Ssl getSslSettings(String... enabledProtocols) {
    Ssl ssl = new Ssl();
    ssl.setKeyStore("src/test/resources/test.jks");
    ssl.setKeyStorePassword("secret");
    ssl.setKeyPassword("password");
    ssl.setCiphers(new String[] { "ALPHA", "BRAVO", "CHARLIE" });
    ssl.setEnabledProtocols(enabledProtocols);
    return ssl;
}
Also used : Ssl(cn.taketoday.framework.web.server.Ssl)

Example 12 with Ssl

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

the class JettyServletWebServerFactoryTests method sslCiphersConfiguration.

@Test
void sslCiphersConfiguration() {
    Ssl ssl = new Ssl();
    ssl.setKeyStore("src/test/resources/test.jks");
    ssl.setKeyStorePassword("secret");
    ssl.setKeyPassword("password");
    ssl.setCiphers(new String[] { "ALPHA", "BRAVO", "CHARLIE" });
    JettyServletWebServerFactory factory = getFactory();
    factory.setSsl(ssl);
    this.webServer = factory.getWebServer();
    this.webServer.start();
    JettyWebServer jettyWebServer = (JettyWebServer) this.webServer;
    ServerConnector connector = (ServerConnector) jettyWebServer.getServer().getConnectors()[0];
    SslConnectionFactory connectionFactory = connector.getConnectionFactory(SslConnectionFactory.class);
    SslContextFactory sslContextFactory = extractSslContextFactory(connectionFactory);
    Assertions.assertThat(sslContextFactory.getIncludeCipherSuites()).containsExactly("ALPHA", "BRAVO", "CHARLIE");
    Assertions.assertThat(sslContextFactory.getExcludeCipherSuites()).isEmpty();
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) SslConnectionFactory(org.eclipse.jetty.server.SslConnectionFactory) Ssl(cn.taketoday.framework.web.server.Ssl) Test(org.junit.jupiter.api.Test)

Example 13 with Ssl

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

Example 14 with Ssl

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

the class SslServerCustomizerTests method getKeyManagerFactoryWhenSslIsEnabledWithNoKeyStoreThrowsWebServerException.

@Test
void getKeyManagerFactoryWhenSslIsEnabledWithNoKeyStoreThrowsWebServerException() {
    Ssl ssl = new Ssl();
    SslServerCustomizer customizer = new SslServerCustomizer(ssl, null, null);
    assertThatIllegalStateException().isThrownBy(() -> customizer.getKeyManagerFactory(ssl, null)).withCauseInstanceOf(WebServerException.class).withMessageContaining("Could not load key store 'null'");
}
Also used : WebServerException(cn.taketoday.framework.web.server.WebServerException) Ssl(cn.taketoday.framework.web.server.Ssl) Test(org.junit.jupiter.api.Test)

Example 15 with Ssl

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

the class SslConnectorCustomizerTests method customizeWhenSslStoreProviderPresentShouldIgnorePasswordFromSsl.

@Test
void customizeWhenSslStoreProviderPresentShouldIgnorePasswordFromSsl(CapturedOutput output) throws Exception {
    System.setProperty("javax.net.ssl.trustStorePassword", "trustStoreSecret");
    Ssl ssl = new Ssl();
    ssl.setKeyPassword("password");
    ssl.setKeyStorePassword("secret");
    SslStoreProvider sslStoreProvider = mock(SslStoreProvider.class);
    given(sslStoreProvider.getTrustStore()).willReturn(loadStore());
    given(sslStoreProvider.getKeyStore()).willReturn(loadStore());
    SslConnectorCustomizer customizer = new SslConnectorCustomizer(ssl, sslStoreProvider);
    Connector connector = this.tomcat.getConnector();
    customizer.customize(connector);
    this.tomcat.start();
    assertThat(connector.getState()).isEqualTo(LifecycleState.STARTED);
    assertThat(output).doesNotContain("Password verification failed");
}
Also used : Connector(org.apache.catalina.connector.Connector) SslStoreProvider(cn.taketoday.framework.web.server.SslStoreProvider) 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