Skip to content

Commit abec859

Browse files
garyrussellartembilan
authored andcommitted
Always default to TLSv1.2
Resolves #1169 Previously, the default was TLSv1.2 if the context was created by the amqp-client, but 1.1 if the context was created by the factory bean.
1 parent 6d2809d commit abec859

File tree

4 files changed

+31
-5
lines changed

4 files changed

+31
-5
lines changed

spring-rabbit/src/main/java/org/springframework/amqp/rabbit/connection/RabbitConnectionFactoryBean.java

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -93,7 +93,24 @@ public class RabbitConnectionFactoryBean extends AbstractFactoryBean<ConnectionF
9393

9494
private static final String TRUST_STORE_TYPE = "trustStore.type";
9595

96-
private static final String TLS_V1_1 = "TLSv1.1";
96+
private static final String DEFAULT_PROTOCOL;
97+
98+
static {
99+
String protocol = "TLSv1.1";
100+
try {
101+
String[] protocols = SSLContext.getDefault().getSupportedSSLParameters().getProtocols();
102+
for (String prot : protocols) {
103+
if ("TLSv1.2".equals(prot)) {
104+
protocol = "TLSv1.2";
105+
break;
106+
}
107+
}
108+
}
109+
catch (NoSuchAlgorithmException e) {
110+
// nothing
111+
}
112+
DEFAULT_PROTOCOL = protocol;
113+
}
97114

98115
private static final String KEY_STORE_DEFAULT_TYPE = "PKCS12";
99116

@@ -125,7 +142,7 @@ public class RabbitConnectionFactoryBean extends AbstractFactoryBean<ConnectionF
125142

126143
private String trustStoreType;
127144

128-
private String sslAlgorithm = TLS_V1_1;
145+
private String sslAlgorithm = DEFAULT_PROTOCOL;
129146

130147
private boolean sslAlgorithmSet;
131148

spring-rabbit/src/test/java/org/springframework/amqp/rabbit/connection/SSLConnectionTests.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ public void testUseSslProtocolShouldNotBeCalled() throws Exception {
102102
fb.afterPropertiesSet();
103103
fb.getObject();
104104
verify(rabbitCf, never()).useSslProtocol();
105+
ArgumentCaptor<SSLContext> captor = ArgumentCaptor.forClass(SSLContext.class);
106+
verify(rabbitCf).useSslProtocol(captor.capture());
107+
assertThat(captor.getValue().getProtocol()).isEqualTo("TLSv1.2");
105108
}
106109

107110
@Test
@@ -123,11 +126,11 @@ public void testSkipServerCertificateWithAlgorithm() throws Exception {
123126
ConnectionFactory rabbitCf = spy(TestUtils.getPropertyValue(fb, "connectionFactory", ConnectionFactory.class));
124127
new DirectFieldAccessor(fb).setPropertyValue("connectionFactory", rabbitCf);
125128
fb.setUseSSL(true);
126-
fb.setSslAlgorithm("TLSv1.2");
129+
fb.setSslAlgorithm("TLSv1.1");
127130
fb.setSkipServerCertificateValidation(true);
128131
fb.afterPropertiesSet();
129132
fb.getObject();
130-
verify(rabbitCf).useSslProtocol("TLSv1.2");
133+
verify(rabbitCf).useSslProtocol("TLSv1.1");
131134
}
132135

133136

src/reference/asciidoc/amqp.adoc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,9 @@ If you wish to skip this validation for some reason, set the factory bean's `ski
523523
Starting with version 2.1, the `RabbitConnectionFactoryBean` now calls `enableHostnameVerification()` by default.
524524
To revert to the previous behavior, set the `enableHostnameVerification` property to `false`.
525525

526+
IMPORTANT: Starting with version 2.2.5, the factory bean will always use TLS v1.2 by default; previously, it used v1.1 in some cases and v1.2 in others (depending on other properties).
527+
If you need to use v1.1 for some reason, set the `sslAlgorithm` property: `setSslAlgorithm("TLSv1.1")`.
528+
526529
[[cluster]]
527530
===== Connecting to a Cluster
528531

src/reference/asciidoc/whats-new.adoc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ See <<template-confirms>> for more information.
9999

100100
Also, the publisher confirm type is now specified with the `ConfirmType` enum instead of the two mutually exclusive setter methods.
101101

102+
The `RabbitConnectionFactoryBean` now uses TLS 1.2 by default when SSL is enabled.
103+
See <<rabbitconnectionfactorybean-configuring-ssl>> for more information.
104+
102105
==== New MessagePostProcessor Classes
103106

104107
Classes `DeflaterPostProcessor` and `InflaterPostProcessor` were added to support compression and decompression, respectively, when the message content-encoding is set to `deflate`.

0 commit comments

Comments
 (0)