Skip to content

Commit 5a9b7d2

Browse files
authored
Make SSLSocketTest agnostic about whether TLSv1 is supported. (#1043)
Calculates the set of supported protocols where needed and for various negotiation tests avoids the use of TLSv1. Tested: Removed TLSv1 from the set of supported protocols and ran all tests.
1 parent 761de8f commit 5a9b7d2

1 file changed

Lines changed: 13 additions & 10 deletions

File tree

common/src/test/java/org/conscrypt/javax/net/ssl/SSLSocketTest.java

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -426,9 +426,9 @@ public void test_SSLSocket_noncontiguousProtocols_useLower() throws Exception {
426426
SSLContext clientContext = c.clientContext;
427427
SSLSocket client = (SSLSocket)
428428
clientContext.getSocketFactory().createSocket(c.host, c.port);
429-
client.setEnabledProtocols(new String[] {"TLSv1.2", "TLSv1"});
429+
client.setEnabledProtocols(new String[] {"TLSv1.3", "TLSv1.1"});
430430
final SSLSocket server = (SSLSocket) c.serverSocket.accept();
431-
server.setEnabledProtocols(new String[] {"TLSv1.2", "TLSv1.1", "TLSv1"});
431+
server.setEnabledProtocols(new String[] {"TLSv1.3", "TLSv1.2", "TLSv1.1"});
432432
ExecutorService executor = Executors.newSingleThreadExecutor();
433433
Future<Void> future = executor.submit(new Callable<Void>() {
434434
@Override public Void call() throws Exception {
@@ -439,7 +439,7 @@ public void test_SSLSocket_noncontiguousProtocols_useLower() throws Exception {
439439
executor.shutdown();
440440
client.startHandshake();
441441

442-
assertEquals("TLSv1", client.getSession().getProtocol());
442+
assertEquals("TLSv1.1", client.getSession().getProtocol());
443443

444444
future.get();
445445
client.close();
@@ -457,9 +457,9 @@ public void test_SSLSocket_noncontiguousProtocols_canNegotiate() throws Exceptio
457457
SSLContext clientContext = c.clientContext;
458458
SSLSocket client = (SSLSocket)
459459
clientContext.getSocketFactory().createSocket(c.host, c.port);
460-
client.setEnabledProtocols(new String[] {"TLSv1.2", "TLSv1"});
460+
client.setEnabledProtocols(new String[] {"TLSv1.3", "TLSv1.1"});
461461
final SSLSocket server = (SSLSocket) c.serverSocket.accept();
462-
server.setEnabledProtocols(new String[] {"TLSv1.1", "TLSv1"});
462+
server.setEnabledProtocols(new String[] {"TLSv1.2", "TLSv1.1"});
463463
ExecutorService executor = Executors.newSingleThreadExecutor();
464464
Future<Void> future = executor.submit(new Callable<Void>() {
465465
@Override public Void call() throws Exception {
@@ -470,7 +470,7 @@ public void test_SSLSocket_noncontiguousProtocols_canNegotiate() throws Exceptio
470470
executor.shutdown();
471471
client.startHandshake();
472472

473-
assertEquals("TLSv1", client.getSession().getProtocol());
473+
assertEquals("TLSv1.1", client.getSession().getProtocol());
474474

475475
future.get();
476476
client.close();
@@ -1060,7 +1060,7 @@ public void test_SSLSocket_sendsTlsFallbackScsv_InappropriateFallback_Failure()
10601060
Future<Void> s = runAsync(new Callable<Void>() {
10611061
@Override
10621062
public Void call() throws Exception {
1063-
server.setEnabledProtocols(new String[] {"TLSv1.1", "TLSv1"});
1063+
server.setEnabledProtocols(new String[] {"TLSv1.2", "TLSv1.1"});
10641064
server.setEnabledCipherSuites(serverCipherSuites);
10651065
try {
10661066
server.startHandshake();
@@ -1076,7 +1076,7 @@ public Void call() throws Exception {
10761076
Future<Void> c = runAsync(new Callable<Void>() {
10771077
@Override
10781078
public Void call() throws Exception {
1079-
client.setEnabledProtocols(new String[]{"TLSv1"});
1079+
client.setEnabledProtocols(new String[]{"TLSv1.1"});
10801080
client.setEnabledCipherSuites(clientCipherSuites);
10811081
try {
10821082
client.startHandshake();
@@ -1098,8 +1098,11 @@ public Void call() throws Exception {
10981098

10991099
@Test
11001100
public void test_SSLSocket_tlsFallback_byVersion() throws Exception {
1101-
for (final String protocol : new String[] { "TLSv1", "TLSv1.1", "TLSv1.2", "TLSv1.3" }) {
1102-
SSLSocketFactory factory = new DelegatingSSLSocketFactory((SSLSocketFactory) SSLSocketFactory.getDefault()) {
1101+
String[] supportedProtocols =
1102+
SSLContext.getDefault().getDefaultSSLParameters().getProtocols();
1103+
for (final String protocol : supportedProtocols) {
1104+
SSLSocketFactory factory = new DelegatingSSLSocketFactory(
1105+
(SSLSocketFactory) SSLSocketFactory.getDefault()) {
11031106
@Override protected SSLSocket configureSocket(SSLSocket socket) {
11041107
socket.setEnabledProtocols(new String[] {protocol});
11051108
String[] enabled = socket.getEnabledCipherSuites();

0 commit comments

Comments
 (0)