Search in sources :

Example 6 with SSLHostConfig

use of org.apache.tomcat.util.net.SSLHostConfig in project spring-boot by spring-projects.

the class TomcatServletWebServerFactoryTests method sslCiphersConfiguration.

@Test
public void sslCiphersConfiguration() throws Exception {
    Ssl ssl = new Ssl();
    ssl.setKeyStore("test.jks");
    ssl.setKeyStorePassword("secret");
    ssl.setCiphers(new String[] { "ALPHA", "BRAVO", "CHARLIE" });
    TomcatServletWebServerFactory factory = getFactory();
    factory.setSsl(ssl);
    Tomcat tomcat = getTomcat(factory);
    Connector connector = ((TomcatWebServer) this.webServer).getServiceConnectors().get(tomcat.getService())[0];
    SSLHostConfig[] sslHostConfigs = connector.getProtocolHandler().findSslHostConfigs();
    assertThat(sslHostConfigs[0].getCiphers()).isEqualTo("ALPHA:BRAVO:CHARLIE");
}
Also used : Connector(org.apache.catalina.connector.Connector) Tomcat(org.apache.catalina.startup.Tomcat) Ssl(org.springframework.boot.web.server.Ssl) SSLHostConfig(org.apache.tomcat.util.net.SSLHostConfig) Test(org.junit.Test)

Example 7 with SSLHostConfig

use of org.apache.tomcat.util.net.SSLHostConfig in project tomcat by apache.

the class SSLHostConfigSF method storeChildren.

/**
     * Store nested SSLHostConfigCertificate elements.
     * {@inheritDoc}
     */
@Override
public void storeChildren(PrintWriter aWriter, int indent, Object aSSLHostConfig, StoreDescription parentDesc) throws Exception {
    if (aSSLHostConfig instanceof SSLHostConfig) {
        SSLHostConfig sslHostConfig = (SSLHostConfig) aSSLHostConfig;
        // Store nested <SSLHostConfigCertificate> elements
        SSLHostConfigCertificate[] hostConfigsCertificates = sslHostConfig.getCertificates().toArray(new SSLHostConfigCertificate[0]);
        storeElementArray(aWriter, indent, hostConfigsCertificates);
    }
}
Also used : SSLHostConfigCertificate(org.apache.tomcat.util.net.SSLHostConfigCertificate) SSLHostConfig(org.apache.tomcat.util.net.SSLHostConfig)

Example 8 with SSLHostConfig

use of org.apache.tomcat.util.net.SSLHostConfig in project spring-boot by spring-projects.

the class TomcatServletWebServerFactoryTests method sslEnabledProtocolsConfiguration.

@Test
public void sslEnabledProtocolsConfiguration() throws Exception {
    Ssl ssl = getSsl(null, "password", "src/test/resources/test.jks");
    ssl.setEnabledProtocols(new String[] { "TLSv1.2" });
    ssl.setCiphers(new String[] { "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256", "BRAVO" });
    TomcatServletWebServerFactory factory = getFactory();
    factory.setSsl(ssl);
    this.webServer = factory.getWebServer(sessionServletRegistration());
    Tomcat tomcat = ((TomcatWebServer) this.webServer).getTomcat();
    this.webServer.start();
    Connector connector = tomcat.getConnector();
    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) Tomcat(org.apache.catalina.startup.Tomcat) Ssl(org.springframework.boot.web.server.Ssl) SSLHostConfig(org.apache.tomcat.util.net.SSLHostConfig) Test(org.junit.Test)

Example 9 with SSLHostConfig

use of org.apache.tomcat.util.net.SSLHostConfig in project spring-boot by spring-projects.

the class TomcatServletWebServerFactoryTests method sslEnabledMultipleProtocolsConfiguration.

@Test
public void sslEnabledMultipleProtocolsConfiguration() throws Exception {
    Ssl ssl = getSsl(null, "password", "src/test/resources/test.jks");
    ssl.setEnabledProtocols(new String[] { "TLSv1.1", "TLSv1.2" });
    ssl.setCiphers(new String[] { "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256", "BRAVO" });
    TomcatServletWebServerFactory factory = getFactory();
    factory.setSsl(ssl);
    this.webServer = factory.getWebServer(sessionServletRegistration());
    this.webServer.start();
    Tomcat tomcat = ((TomcatWebServer) this.webServer).getTomcat();
    Connector connector = tomcat.getConnector();
    SSLHostConfig sslHostConfig = connector.getProtocolHandler().findSslHostConfigs()[0];
    assertThat(sslHostConfig.getSslProtocol()).isEqualTo("TLS");
    assertThat(sslHostConfig.getEnabledProtocols()).containsExactlyInAnyOrder("TLSv1.1", "TLSv1.2");
}
Also used : Connector(org.apache.catalina.connector.Connector) Tomcat(org.apache.catalina.startup.Tomcat) Ssl(org.springframework.boot.web.server.Ssl) SSLHostConfig(org.apache.tomcat.util.net.SSLHostConfig) Test(org.junit.Test)

Aggregations

SSLHostConfig (org.apache.tomcat.util.net.SSLHostConfig)9 Connector (org.apache.catalina.connector.Connector)5 Tomcat (org.apache.catalina.startup.Tomcat)3 Test (org.junit.Test)3 Ssl (org.springframework.boot.web.server.Ssl)3 SSLHostConfigCertificate (org.apache.tomcat.util.net.SSLHostConfigCertificate)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 Engine (org.apache.catalina.Engine)1 LifecycleListener (org.apache.catalina.LifecycleListener)1 Service (org.apache.catalina.Service)1 TomcatURLStreamHandlerFactory (org.apache.catalina.webresources.TomcatURLStreamHandlerFactory)1 UpgradeProtocol (org.apache.coyote.UpgradeProtocol)1 Type (org.apache.tomcat.util.net.SSLHostConfigCertificate.Type)1