Skip to content

Commit 7a96f86

Browse files
committed
temporary workaround, see AsyncHttpClient#1511
1 parent de3f984 commit 7a96f86

File tree

2 files changed

+38
-21
lines changed

2 files changed

+38
-21
lines changed

client/src/main/java/org/asynchttpclient/netty/ssl/DefaultSslEngineFactory.java

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,33 +20,14 @@
2020
import io.netty.handler.ssl.util.InsecureTrustManagerFactory;
2121
import org.asynchttpclient.AsyncHttpClientConfig;
2222

23-
import javax.net.ssl.SSLContext;
2423
import javax.net.ssl.SSLEngine;
2524
import javax.net.ssl.SSLException;
2625
import java.util.Arrays;
27-
import java.util.List;
2826

2927
import static org.asynchttpclient.util.MiscUtils.isNonEmpty;
3028

3129
public class DefaultSslEngineFactory extends SslEngineFactoryBase {
3230

33-
// TODO replace with a custom CipherSuiteFilter once https://github.com/netty/netty/issues/7673 is fixed
34-
private static final List<String> JDK_SUPPORTED_CIPHER_SUITES;
35-
36-
static {
37-
SSLContext context;
38-
try {
39-
context = SSLContext.getInstance("TLS");
40-
context.init(null, null, null);
41-
} catch (Exception e) {
42-
throw new Error("Failed to initialize the default SSL context", e);
43-
}
44-
45-
SSLEngine engine = context.createSSLEngine();
46-
47-
JDK_SUPPORTED_CIPHER_SUITES = Arrays.asList(engine.getSupportedCipherSuites());
48-
}
49-
5031
private volatile SslContext sslContext;
5132

5233
private SslContext buildSslContext(AsyncHttpClientConfig config) throws SSLException {
@@ -65,8 +46,8 @@ private SslContext buildSslContext(AsyncHttpClientConfig config) throws SSLExcep
6546

6647
if (isNonEmpty(config.getEnabledCipherSuites())) {
6748
sslContextBuilder.ciphers(Arrays.asList(config.getEnabledCipherSuites()));
68-
} else if (!config.isFilterInsecureCipherSuites() && !config.isUseOpenSsl()) {
69-
sslContextBuilder.ciphers(JDK_SUPPORTED_CIPHER_SUITES);
49+
} else if (!config.isFilterInsecureCipherSuites()) {
50+
sslContextBuilder.ciphers(null, IdentityCipherSuiteFilterWorkaround.INSTANCE);
7051
}
7152

7253
if (config.isUseInsecureTrustManager()) {
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright (c) 2018 AsyncHttpClient Project. All rights reserved.
3+
*
4+
* This program is licensed to you under the Apache License Version 2.0,
5+
* and you may not use this file except in compliance with the Apache License Version 2.0.
6+
* You may obtain a copy of the Apache License Version 2.0 at
7+
* http://www.apache.org/licenses/LICENSE-2.0.
8+
*
9+
* Unless required by applicable law or agreed to in writing,
10+
* software distributed under the Apache License Version 2.0 is distributed on an
11+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
13+
*/
14+
package org.asynchttpclient.netty.ssl;
15+
16+
import io.netty.handler.ssl.CipherSuiteFilter;
17+
18+
import java.util.List;
19+
import java.util.Set;
20+
21+
// workaround for https://github.com/netty/netty/pull/7691
22+
class IdentityCipherSuiteFilterWorkaround implements CipherSuiteFilter {
23+
static final IdentityCipherSuiteFilterWorkaround INSTANCE = new IdentityCipherSuiteFilterWorkaround();
24+
25+
private IdentityCipherSuiteFilterWorkaround() { }
26+
27+
@Override
28+
public String[] filterCipherSuites(Iterable<String> ciphers, List<String> defaultCiphers,
29+
Set<String> supportedCiphers) {
30+
if (ciphers == null) {
31+
return supportedCiphers.toArray(new String[supportedCiphers.size()]);
32+
} else {
33+
throw new UnsupportedOperationException();
34+
}
35+
}
36+
}

0 commit comments

Comments
 (0)