8000 Bump default TLS version to v1.2 with a fallback for older JDKs · Donaldhan/rabbitmq-java-client@e5e5ccb · GitHub
[go: up one dir, main page]

Skip to content

Commit e5e5ccb

Browse files
Bump default TLS version to v1.2 with a fallback for older JDKs
Namely JDK 6.
1 parent d366ea7 commit e5e5ccb

File tree

3 files changed

+46
-4
lines changed

3 files changed

+46
-4
lines changed

src/main/java/com/rabbitmq/client/ConnectionFactory.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,9 @@ public class ConnectionFactory implements Cloneable {
8181
* zero means wait indefinitely */
8282
public static final int DEFAULT_SHUTDOWN_TIMEOUT = 10000;
8383

84-
/** The default SSL protocol */
85-
private static final String DEFAULT_SSL_PROTOCOL = "TLSv1";
84+
private static final String PREFERED_TLS_PROTOCOL = "TLSv1.2";
85+
86+
private static final String FALLBACK_TLS_PROTOCOL = "TLSv1";
8687

8788
private String username = DEFAULT_USER;
8889
private String password = DEFAULT_PASS;
@@ -552,7 +553,7 @@ public boolean isSSL(){
552553
public void useSslProtocol()
553554
throws NoSuchAlgorithmException, KeyManagementException
554555
{
555-
useSslProtocol(DEFAULT_SSL_PROTOCOL);
556+
useSslProtocol(computeDefaultTlsProcotol(SSLContext.getDefault().getSupportedSSLParameters().getProtocols()));
556557
}
557558

558559
/**
@@ -589,6 +590,17 @@ public void useSslProtocol(SSLContext context) {
589590
setSocketFactory(context.getSocketFactory());
590591
}
591592

593+
public String computeDefaultTlsProcotol(String [] supportedProtocols) {
594+
if(supportedProtocols != null) {
595+
for (String supportedProtocol : supportedProtocols) {
596+
if(PREFERED_TLS_PROTOCOL.equalsIgnoreCase(supportedProtocol)) {
597+
return supportedProtocol;
598+
}
599+
}
600+
}
601+
return FALLBACK_TLS_PROTOCOL;
602+
}
603+
592604
/**
593605
* Returns true if <a href="http://www.rabbitmq.com/api-guide.html#recovery">automatic connection recovery</a>
594606
* is enabled, false otherwise
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.rabbitmq.client.test.ssl;
2+
3+
import com.rabbitmq.client.ConnectionFactory;
4+
import junit.framework.TestCase;
5+
import org.junit.Assert;
6+
7+
public class ConnectionFactoryDefaultTlsVersion extends TestCase {
8+
9+
private ConnectionFactory connectionFactory = new ConnectionFactory();
10+
11+
public void testDefaultTlsVersionJdk16ShouldTakeFallback() {
12+
String [] supportedProtocols = {"SSLv2Hello", "SSLv3", "TLSv1"};
13+
String tlsProtocol = connectionFactory.computeDefaultTlsProcotol(supportedProtocols);
14+
Assert.assertEquals("TLSv1",tlsProtocol);
15+
}
16+
17+
public void testDefaultTlsVersionJdk17ShouldTakePrefered() {
18+
String [] supportedProtocols = {"SSLv2Hello", "SSLv3", "TLSv1", "TLSv1.1", "TLSv1.2"};
19+
String tlsProtocol = connectionFactory.computeDefaultTlsProcotol(supportedProtocols);
20+
Assert.assertEquals("TLSv1.2",tlsProtocol);
21+
}
22+
23+
public void testDefaultTlsVersionJdk18ShouldTakePrefered() {
24+
String [] supportedProtocols = {"SSLv2Hello", "SSLv3", "TLSv1", "TLSv1.1", "TLSv1.2"};
25+
String tlsProtocol = connectionFactory.computeDefaultTlsProcotol(supportedProtocols);
26+
Assert.assertEquals("TLSv1.2",tlsProtocol);
27+
}
28+
29+
}

src/test/java/com/rabbitmq/client/test/ssl/SSLTests.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
public class SSLTests extends AbstractRMQTestSuite {
2525
public static TestSuite suite() {
2626
TestSuite suite = new TestSuite("ssl");
27-
//Skip the tests if not under umbrella and not SSL available
27+
suite.addTestSuite(ConnectionFactoryDefaultTlsVersion.class);
28+
// Skip the tests if not under umbrella and no TLS setup available
2829
if (!requiredProperties()) return suite;
2930
if (!(isUnderUmbrella() && isSSLAvailable())) return suite;
3031
suite.addTestSuite(UnverifiedConnection.class);

0 commit comments

Comments
 (0)
0