Skip to content
Permalink
Browse files
Use jep244 (ALPN support) was back-ported to java 8u251
  • Loading branch information
ok2c committed Jun 1, 2021
1 parent b0effc4 commit 706cacf2cd684b3fc699a1b02d0edfdc08f360a6
Show file tree
Hide file tree
Showing 11 changed files with 9 additions and 112 deletions.
@@ -21,9 +21,7 @@ services:
- docker

jdk:
- oraclejdk8
- openjdk11
- oraclejdk11
- oraclejdk16
- openjdk-ea

@@ -56,7 +56,7 @@ public static SSLSessionInitializer initialize(
sslEngine.setSSLParameters(sslParameters);
Conscrypt.setApplicationProtocols(sslEngine, appProtocols);
} else {
H2TlsSupport.setApplicationProtocols(sslParameters, appProtocols);
sslParameters.setApplicationProtocols(appProtocols);
sslEngine.setSSLParameters(sslParameters);
}
if (initializer != null) {
@@ -46,6 +46,10 @@ public static void setEnableRetransmissions(final SSLParameters sslParameters, f
ReflectionUtils.callSetter(sslParameters, "EnableRetransmissions", Boolean.TYPE, value);
}

/**
* @deprecated Use {@link SSLParameters#setApplicationProtocols(String[])}.
*/
@Deprecated
public static void setApplicationProtocols(final SSLParameters sslParameters, final String[] values) {
ReflectionUtils.callSetter(sslParameters, "ApplicationProtocols", String[].class, values);
}
@@ -71,7 +75,7 @@ public static SSLSessionInitializer enforceRequirements(
sslParameters.setProtocols(TLS.excludeWeak(sslParameters.getProtocols()));
sslParameters.setCipherSuites(TlsCiphers.excludeH2Blacklisted(sslParameters.getCipherSuites()));
setEnableRetransmissions(sslParameters, false);
setApplicationProtocols(sslParameters, selectApplicationProtocols(attachment));
sslParameters.setApplicationProtocols(selectApplicationProtocols(attachment));
sslEngine.setSSLParameters(sslParameters);
if (initializer != null) {
initializer.initialize(endpoint, sslEngine);
@@ -60,13 +60,9 @@
import org.apache.hc.core5.reactor.IOReactorConfig;
import org.apache.hc.core5.reactor.ListenerEndpoint;
import org.apache.hc.core5.testing.SSLTestContexts;
import org.apache.hc.core5.util.ReflectionUtils;
import org.apache.hc.core5.util.Timeout;
import org.hamcrest.CoreMatchers;
import org.hamcrest.MatcherAssert;
import org.junit.Assume;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExternalResource;
@@ -165,18 +161,6 @@ protected void after() {

};

private static int JAVA_VER;

@BeforeClass
public static void determineJavaVersion() {
JAVA_VER = ReflectionUtils.determineJRELevel();
}

@Before
public void checkVersion() {
Assume.assumeTrue("Java version must be 9 or greater and less than 16", JAVA_VER >= 9 && JAVA_VER < 16);
}

@Test
public void testALPN() throws Exception {
server.start();
@@ -29,8 +29,6 @@

import java.net.InetSocketAddress;
import java.util.concurrent.Future;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.hc.core5.http.ContentType;
import org.apache.hc.core5.http.HttpHost;
@@ -57,13 +55,9 @@
import org.apache.hc.core5.reactor.ListenerEndpoint;
import org.apache.hc.core5.testing.SSLTestContexts;
import org.apache.hc.core5.testing.classic.LoggingConnPoolListener;
import org.apache.hc.core5.util.ReflectionUtils;
import org.apache.hc.core5.util.Timeout;
import org.hamcrest.CoreMatchers;
import org.hamcrest.MatcherAssert;
import org.junit.Assume;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExternalResource;
@@ -145,18 +139,6 @@ protected void after() {

};

private static int JAVA_VER;

@BeforeClass
public static void determineJavaVersion() {
JAVA_VER = ReflectionUtils.determineJRELevel();
}

@Before
public void checkVersion() {
Assume.assumeTrue("Java version must be 1.8 or greater", JAVA_VER >= 8);
}

@Test
public void testForceHttp1() throws Exception {
server.start();
@@ -223,27 +205,7 @@ public void testNegotiateProtocol() throws Exception {
MatcherAssert.assertThat(message1, CoreMatchers.notNullValue());
final HttpResponse response1 = message1.getHead();
MatcherAssert.assertThat(response1.getCode(), CoreMatchers.equalTo(HttpStatus.SC_OK));

if (isAlpnSupported()) {
MatcherAssert.assertThat(response1.getVersion(), CoreMatchers.equalTo(HttpVersion.HTTP_2));
} else {
MatcherAssert.assertThat(response1.getVersion(), CoreMatchers.equalTo(HttpVersion.HTTP_1_1));
}
}

private boolean isAlpnSupported() {
if (JAVA_VER == 8) {
// The 'java.version' property values are structured "1.8.0_[BUILD NUMBER]" in java 8 releases.
final Matcher matcher = Pattern.compile("^1\\.8\\.0_(\\d+)$")
.matcher(System.getProperty("java.version"));
if (matcher.matches()) {
final int java8Build = Integer.parseInt(matcher.group(1));
// jep244 (alpn) was backported to java 8u251.
// https://bugs.java.com/bugdatabase/view_bug.do?bug_id=8230977
return java8Build >= 251;
}
}
return JAVA_VER > 8 && JAVA_VER < 16;
MatcherAssert.assertThat(response1.getVersion(), CoreMatchers.equalTo(HttpVersion.HTTP_2));
}

}
@@ -61,14 +61,10 @@
import org.apache.hc.core5.reactor.IOReactorConfig;
import org.apache.hc.core5.reactor.ListenerEndpoint;
import org.apache.hc.core5.testing.SSLTestContexts;
import org.apache.hc.core5.util.ReflectionUtils;
import org.apache.hc.core5.util.TimeValue;
import org.apache.hc.core5.util.Timeout;
import org.hamcrest.CoreMatchers;
import org.hamcrest.MatcherAssert;
import org.junit.Assume;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExternalResource;
@@ -160,20 +156,6 @@ protected void after() {

};

private static int javaVersion;

@BeforeClass
public static void determineJavaVersion() {
javaVersion = ReflectionUtils.determineJRELevel();
}

@Before
public void checkVersion() {
if (scheme == URIScheme.HTTPS) {
Assume.assumeTrue("Java version must be 1.8 or greater", javaVersion > 7);
}
}

@Test
public void testSequentialRequests() throws Exception {
server.start();
@@ -59,13 +59,9 @@
import org.apache.hc.core5.reactor.ListenerEndpoint;
import org.apache.hc.core5.testing.SSLTestContexts;
import org.apache.hc.core5.testing.classic.LoggingConnPoolListener;
import org.apache.hc.core5.util.ReflectionUtils;
import org.apache.hc.core5.util.Timeout;
import org.hamcrest.CoreMatchers;
import org.hamcrest.MatcherAssert;
import org.junit.Assume;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExternalResource;
@@ -163,20 +159,6 @@ protected void after() {

};

private static int javaVersion;

@BeforeClass
public static void determineJavaVersion() {
javaVersion = ReflectionUtils.determineJRELevel();
}

@Before
public void checkVersion() {
if (scheme == URIScheme.HTTPS) {
Assume.assumeTrue("Java version must be 1.8 or greater", javaVersion > 7);
}
}

@Test
public void testSequentialRequests() throws Exception {
server.start();
@@ -52,13 +52,11 @@
import org.apache.hc.core5.http.protocol.RequestValidateHost;
import org.apache.hc.core5.reactor.IOReactorConfig;
import org.apache.hc.core5.ssl.SSLContextBuilder;
import org.apache.hc.core5.util.ReflectionUtils;
import org.apache.hc.core5.util.TimeValue;
import org.apache.hc.core5.util.Timeout;
import org.conscrypt.Conscrypt;
import org.junit.Assert;
import org.junit.Assume;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExternalResource;
@@ -99,11 +97,6 @@ public JSSEProviderIntegrationTest(final String securityProviderName, final Stri
private Http1TestServer server;
private Http1TestClient client;

@BeforeClass
public static void determineJavaVersion() {
Assume.assumeTrue("Java version must be 8 or greater", ReflectionUtils.determineJRELevel() >= 8);
}

@Rule
public TestRule resourceRules = RuleChain.outerRule(new ExternalResource() {

@@ -57,7 +57,6 @@
import org.apache.hc.core5.reactor.IOSession;
import org.apache.hc.core5.util.Args;
import org.apache.hc.core5.util.Asserts;
import org.apache.hc.core5.util.ReflectionUtils;
import org.apache.hc.core5.util.Timeout;

/**
@@ -381,7 +380,7 @@ private void doHandshake(final IOSession protocolSession) throws IOException {
}
if (this.tlsDetails == null) {
final SSLSession sslSession = this.sslEngine.getSession();
final String applicationProtocol = ReflectionUtils.callGetter(this.sslEngine, "ApplicationProtocol", String.class);
final String applicationProtocol = this.sslEngine.getApplicationProtocol();
this.tlsDetails = new TlsDetails(sslSession, applicationProtocol);
}

@@ -59,12 +59,9 @@
import javax.net.ssl.SSLSocket;
import javax.net.ssl.TrustManagerFactory;

import org.apache.hc.core5.util.ReflectionUtils;
import org.apache.hc.core5.util.Timeout;
import org.junit.After;
import org.junit.Assert;
import org.junit.Assume;
import org.junit.BeforeClass;
import org.junit.Test;

/**
@@ -78,11 +75,6 @@ private static boolean isWindows() {
return System.getProperty("os.name").contains("Windows");
}

@BeforeClass
public static void determineJavaVersion() {
Assume.assumeTrue("Java version must be 8 or greater", ReflectionUtils.determineJRELevel() >= 8);
}

private static final Timeout TIMEOUT = Timeout.ofSeconds(5);
private ExecutorService executorService;

@@ -78,6 +78,7 @@
<log4j.version>2.8.2</log4j.version>
<rxjava.version>2.2.8</rxjava.version>
<api.comparison.version>5.1</api.comparison.version>
<hc.animal-sniffer.signature.ignores>javax.net.ssl.SSLEngine,javax.net.ssl.SSLParameters</hc.animal-sniffer.signature.ignores>
</properties>

<dependencyManagement>

0 comments on commit 706cacf

Please sign in to comment.