Skip to content

Commit 820bc92

Browse files
committed
Add support for Apache HTTP client 5 in X-Pack SSL
1 parent f79dc89 commit 820bc92

File tree

30 files changed

+880
-113
lines changed

30 files changed

+880
-113
lines changed

gradle/verification-metadata.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2927,6 +2927,11 @@
29272927
<sha256 value="a121f4b14ec525e54e29b9f5db7b93f4a97e088774e81c7143b5198f67d81bec" origin="Generated by Gradle"/>
29282928
</artifact>
29292929
</component>
2930+
<component group="org.apache.httpcomponents.core5" name="httpcore5-h2" version="5.3.4">
2931+
<artifact name="httpcore5-h2-5.3.4.jar">
2932+
<sha256 value="1fb4f34e4b612e7c127ad693335583587850b17ce9b1c366f9de1ca49fe2c781" origin="Generated by Gradle"/>
2933+
</artifact>
2934+
</component>
29302935
<component group="org.apache.james" name="apache-mime4j-core" version="0.8.13">
29312936
<artifact name="apache-mime4j-core-0.8.13.jar">
29322937
<sha256 value="00496c123926395d59e5dfdfc8342c607600c6c9e6e6dcab981a673b62481cdf" origin="Generated by Gradle"/>
@@ -4945,6 +4950,11 @@
49454950
<sha256 value="2f2a92d410b268139d7d63b75ed25e21995cfe4100c19bf23577cfdbc8077bda" origin="Generated by Gradle"/>
49464951
</artifact>
49474952
</component>
4953+
<component group="org.slf4j" name="slf4j-ext" version="2.0.6">
4954+
<artifact name="slf4j-ext-2.0.6.jar">
4955+
<sha256 value="0f6ef03bc0291899f3fb324baba0dee02fa8c6c1adc7b465f5b923ac70379efd" origin="Generated by Gradle"/>
4956+
</artifact>
4957+
</component>
49484958
<component group="org.slf4j" name="slf4j-log4j12" version="1.7.10">
49494959
<artifact name="slf4j-log4j12-1.7.10.jar">
49504960
<sha256 value="2e4eebc6e346c92c417aa4e662738802645ef21c5eb4435132dc78d631f2eebb" origin="Generated by Gradle"/>

x-pack/plugin/core/build.gradle

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ esplugin {
3232
tasks.named("dependencyLicenses").configure {
3333
mapping from: /http.*/, to: 'httpclient' // pulled in by rest client
3434
mapping from: /commons-.*/, to: 'commons' // pulled in by rest client
35+
mapping from: /slf4j-.*/, to: 'slf4j'
3536
}
3637

3738
configurations {
@@ -43,15 +44,23 @@ dependencies {
4344
compileOnly project(":server")
4445
api project(':libs:grok')
4546
api project(":libs:ssl-config")
47+
4648
api "org.apache.httpcomponents:httpclient:${versions.httpclient}"
4749
api "org.apache.httpcomponents:httpcore:${versions.httpcore}"
4850
api "org.apache.httpcomponents:httpcore-nio:${versions.httpcore}"
4951
api "org.apache.httpcomponents:httpasyncclient:${versions.httpasyncclient}"
52+
5053
api "org.apache.httpcomponents.client5:httpclient5:${versions.httpclient5}"
5154
api "org.apache.httpcomponents.core5:httpcore5:${versions.httpcore5}"
55+
api "org.apache.httpcomponents.core5:httpcore5-h2:${versions.httpcore5}"
56+
runtimeOnly "org.slf4j:slf4j-api:${versions.slf4j}"
57+
runtimeOnly "org.apache.logging.log4j:log4j-slf4j-impl:${versions.log4j}"
58+
5259
api "commons-logging:commons-logging:${versions.commonslogging}"
5360
api "org.apache.logging.log4j:log4j-1.2-api:${versions.log4j}"
61+
5462
api "commons-codec:commons-codec:${versions.commonscodec}"
63+
5564
testImplementation project(path: ':modules:aggregations')
5665
testImplementation project(path: ':modules:data-streams')
5766
testImplementation project(':modules:mapper-extras')
@@ -141,7 +150,11 @@ tasks.named("thirdPartyAudit").configure {
141150
//commons-logging provided dependencies
142151
'javax.servlet.ServletContextEvent',
143152
'javax.servlet.ServletContextListener',
144-
'javax.jms.Message'
153+
'javax.jms.Message',
154+
// HttpClient5 can use Conscrypt (TLS using BoringSSL), but we don't want that
155+
'org.conscrypt.Conscrypt',
156+
// SLF4j via HttpClient5
157+
'org.slf4j.ext.EventData'
145158
)
146159
}
147160

x-pack/plugin/core/src/main/java/module-info.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
requires unboundid.ldapsdk;
2424
requires org.elasticsearch.tdigest;
2525
requires org.elasticsearch.xcore.templates;
26+
requires org.apache.httpcomponents.client5.httpclient5;
27+
requires org.apache.httpcomponents.core5.httpcore5;
2628

2729
exports org.elasticsearch.index.engine.frozen;
2830
exports org.elasticsearch.license;
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
package org.elasticsearch.xpack.core.ssl;
9+
10+
import org.apache.http.conn.ssl.NoopHostnameVerifier;
11+
import org.apache.http.nio.conn.ssl.SSLIOSessionStrategy;
12+
import org.elasticsearch.common.Strings;
13+
import org.elasticsearch.common.ssl.SslConfiguration;
14+
15+
import java.util.List;
16+
17+
import javax.net.ssl.HostnameVerifier;
18+
import javax.net.ssl.SSLContext;
19+
import javax.net.ssl.SSLParameters;
20+
21+
public abstract class AbstractSslBuilder<T> {
22+
23+
public T build(SslConfiguration config, SSLContext sslContext) {
24+
String[] ciphers = supportedCiphers(sslParameters(sslContext).getCipherSuites(), config.getCipherSuites(), false);
25+
String[] supportedProtocols = config.supportedProtocols().toArray(Strings.EMPTY_ARRAY);
26+
HostnameVerifier verifier;
27+
28+
if (config.verificationMode().isHostnameVerificationEnabled()) {
29+
verifier = SSLIOSessionStrategy.getDefaultHostnameVerifier();
30+
} else {
31+
verifier = NoopHostnameVerifier.INSTANCE;
32+
}
33+
34+
return build(sslContext, supportedProtocols, ciphers, verifier);
35+
}
36+
37+
/**
38+
* This method exists to simplify testing
39+
*/
40+
String[] supportedCiphers(String[] supportedCiphers, List<String> requestedCiphers, boolean log) {
41+
return SSLService.supportedCiphers(supportedCiphers, requestedCiphers, log);
42+
}
43+
44+
/**
45+
* The {@link SSLParameters} that are associated with the {@code sslContext}.
46+
* <p>
47+
* This method exists to simplify testing since {@link SSLContext#getSupportedSSLParameters()} is {@code final}.
48+
*
49+
* @param sslContext The SSL context for the current SSL settings
50+
* @return Never {@code null}.
51+
*/
52+
SSLParameters sslParameters(SSLContext sslContext) {
53+
return sslContext.getSupportedSSLParameters();
54+
}
55+
56+
abstract T build(SSLContext sslContext, String[] protocols, String[] ciphers, HostnameVerifier verifier);
57+
}

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ssl/SSLIOSessionStrategyBuilder.java

Lines changed: 3 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -8,68 +8,32 @@
88
package org.elasticsearch.xpack.core.ssl;
99

1010
import org.apache.http.HttpHost;
11-
import org.apache.http.conn.ssl.NoopHostnameVerifier;
1211
import org.apache.http.nio.conn.ssl.SSLIOSessionStrategy;
1312
import org.apache.http.nio.reactor.IOSession;
1413
import org.elasticsearch.common.Strings;
1514
import org.elasticsearch.common.logging.LoggerMessageFormat;
16-
import org.elasticsearch.common.ssl.SslConfiguration;
1715
import org.elasticsearch.common.ssl.SslDiagnostics;
1816

1917
import java.security.cert.Certificate;
2018
import java.security.cert.X509Certificate;
21-
import java.util.List;
2219

2320
import javax.net.ssl.HostnameVerifier;
2421
import javax.net.ssl.SSLContext;
2522
import javax.net.ssl.SSLException;
26-
import javax.net.ssl.SSLParameters;
2723
import javax.net.ssl.SSLPeerUnverifiedException;
2824
import javax.net.ssl.SSLSession;
2925
import javax.security.auth.x500.X500Principal;
3026

31-
public class SSLIOSessionStrategyBuilder {
27+
class SSLIOSessionStrategyBuilder extends AbstractSslBuilder<SSLIOSessionStrategy> {
3228

3329
public static final SSLIOSessionStrategyBuilder INSTANCE = new SSLIOSessionStrategyBuilder();
3430

35-
public SSLIOSessionStrategy sslIOSessionStrategy(SslConfiguration config, SSLContext sslContext) {
36-
String[] ciphers = supportedCiphers(sslParameters(sslContext).getCipherSuites(), config.getCipherSuites(), false);
37-
String[] supportedProtocols = config.supportedProtocols().toArray(Strings.EMPTY_ARRAY);
38-
HostnameVerifier verifier;
39-
40-
if (config.verificationMode().isHostnameVerificationEnabled()) {
41-
verifier = SSLIOSessionStrategy.getDefaultHostnameVerifier();
42-
} else {
43-
verifier = NoopHostnameVerifier.INSTANCE;
44-
}
45-
46-
return sslIOSessionStrategy(sslContext, supportedProtocols, ciphers, verifier);
47-
}
48-
49-
/**
50-
* This method exists to simplify testing
51-
*/
52-
String[] supportedCiphers(String[] supportedCiphers, List<String> requestedCiphers, boolean log) {
53-
return SSLService.supportedCiphers(supportedCiphers, requestedCiphers, log);
54-
}
55-
56-
/**
57-
* The {@link SSLParameters} that are associated with the {@code sslContext}.
58-
* <p>
59-
* This method exists to simplify testing since {@link SSLContext#getSupportedSSLParameters()} is {@code final}.
60-
*
61-
* @param sslContext The SSL context for the current SSL settings
62-
* @return Never {@code null}.
63-
*/
64-
SSLParameters sslParameters(SSLContext sslContext) {
65-
return sslContext.getSupportedSSLParameters();
66-
}
67-
6831
/**
6932
* This method only exists to simplify testing because {@link SSLIOSessionStrategy} does
7033
* not expose any of the parameters that you give it.
7134
*/
72-
SSLIOSessionStrategy sslIOSessionStrategy(SSLContext sslContext, String[] protocols, String[] ciphers, HostnameVerifier verifier) {
35+
@Override
36+
SSLIOSessionStrategy build(SSLContext sslContext, String[] protocols, String[] ciphers, HostnameVerifier verifier) {
7337
return new SSLIOSessionStrategy(sslContext, protocols, ciphers, verifier) {
7438
@Override
7539
protected void verifySession(HttpHost host, IOSession iosession, SSLSession session) throws SSLException {

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ssl/SSLService.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*/
77
package org.elasticsearch.xpack.core.ssl;
88

9+
import org.apache.hc.core5.http.nio.ssl.TlsStrategy;
910
import org.apache.http.conn.ssl.DefaultHostnameVerifier;
1011
import org.apache.http.conn.ssl.NoopHostnameVerifier;
1112
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
@@ -237,7 +238,7 @@ public SslProfile profile(String profileName) {
237238
@Deprecated
238239
public SSLIOSessionStrategy sslIOSessionStrategy(Settings settingsToUse) {
239240
SslConfiguration config = sslConfiguration(settingsToUse);
240-
return SSLIOSessionStrategyBuilder.INSTANCE.sslIOSessionStrategy(config, sslContext(config));
241+
return SSLIOSessionStrategyBuilder.INSTANCE.build(config, sslContext(config));
241242
}
242243

243244
/**
@@ -735,7 +736,12 @@ public SSLConnectionSocketFactory connectionSocketFactory() {
735736

736737
@Override
737738
public SSLIOSessionStrategy ioSessionStrategy4() {
738-
return SSLIOSessionStrategyBuilder.INSTANCE.sslIOSessionStrategy(this.sslConfiguration, context);
739+
return SSLIOSessionStrategyBuilder.INSTANCE.build(this.sslConfiguration, context);
740+
}
741+
742+
@Override
743+
public TlsStrategy clientTlsStrategy() {
744+
return TlsStrategyBuilder.INSTANCE.build(this.sslConfiguration, context);
739745
}
740746

741747
@Override

0 commit comments

Comments
 (0)