1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 package org.apache.hc.core5.http2.ssl;
29
30 import javax.net.ssl.SSLEngine;
31 import javax.net.ssl.SSLException;
32 import javax.net.ssl.SSLParameters;
33
34 import org.apache.hc.core5.http.ssl.TLS;
35 import org.apache.hc.core5.http.ssl.TlsCiphers;
36 import org.apache.hc.core5.net.NamedEndpoint;
37 import org.apache.hc.core5.reactor.ssl.SSLSessionInitializer;
38 import org.apache.hc.core5.reactor.ssl.SSLSessionVerifier;
39 import org.apache.hc.core5.reactor.ssl.TlsDetails;
40 import org.conscrypt.Conscrypt;
41
42
43
44
45
46
47 public final class ConscryptSupport {
48
49 public static SSLSessionInitializer initialize(
50 final Object attachment,
51 final SSLSessionInitializer initializer) {
52 return new SSLSessionInitializer() {
53
54 @Override
55 public void initialize(final NamedEndpoint endpoint, final SSLEngine sslEngine) {
56 final SSLParameters sslParameters = sslEngine.getSSLParameters();
57 sslParameters.setProtocols(TLS.excludeWeak(sslParameters.getProtocols()));
58 sslParameters.setCipherSuites(TlsCiphers.excludeH2Blacklisted(sslParameters.getCipherSuites()));
59 H2TlsSupport.setEnableRetransmissions(sslParameters, false);
60 final String[] appProtocols = H2TlsSupport.selectApplicationProtocols(attachment);
61 if (Conscrypt.isConscrypt(sslEngine)) {
62 sslEngine.setSSLParameters(sslParameters);
63 Conscrypt.setApplicationProtocols(sslEngine, appProtocols);
64 } else {
65 H2TlsSupport.setApplicationProtocols(sslParameters, appProtocols);
66 sslEngine.setSSLParameters(sslParameters);
67 }
68 if (initializer != null) {
69 initializer.initialize(endpoint, sslEngine);
70 }
71 }
72
73 };
74 }
75
76 public static SSLSessionVerifier verify(final SSLSessionVerifier verifier) {
77 return new SSLSessionVerifier() {
78
79 @Override
80 public TlsDetails verify(final NamedEndpoint endpoint, final SSLEngine sslEngine) throws SSLException {
81 TlsDetails tlsDetails = verifier != null ? verifier.verify(endpoint, sslEngine) : null;
82 if (tlsDetails == null && Conscrypt.isConscrypt(sslEngine)) {
83 tlsDetails = new TlsDetails(sslEngine.getSession(), Conscrypt.getApplicationProtocol(sslEngine));
84 }
85 return tlsDetails;
86 }
87
88 };
89 }
90
91 }