Skip to content

Commit e116e8d

Browse files
committed
AMQP-830 Enable Hostname Verification by default
JIRA: https://jira.spring.io/browse/AMQP-830
1 parent 8c4c1a7 commit e116e8d

File tree

3 files changed

+40
-12
lines changed

3 files changed

+40
-12
lines changed

build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ subprojects { subproject ->
8282
log4jVersion = '2.11.0'
8383
logbackVersion = '1.2.3'
8484
mockitoVersion = '2.18.0'
85-
rabbitmqVersion = project.hasProperty('rabbitmqVersion') ? project.rabbitmqVersion : '5.3.0'
85+
rabbitmqVersion = project.hasProperty('rabbitmqVersion') ? project.rabbitmqVersion : '5.4.0.RC2'
8686
rabbitmqHttpClientVersion = '2.1.0.RELEASE'
8787

8888
springVersion = project.hasProperty('springVersion') ? project.springVersion : '5.1.0.RC2'

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

+35-11
Original file line numberDiff line numberDiff line change
@@ -103,30 +103,32 @@ public class RabbitConnectionFactoryBean extends AbstractFactoryBean<ConnectionF
103103

104104
private Resource sslPropertiesLocation;
105105

106-
private volatile String keyStore;
106+
private String keyStore;
107107

108-
private volatile String trustStore;
108+
private String trustStore;
109109

110-
private volatile Resource keyStoreResource;
110+
private Resource keyStoreResource;
111111

112-
private volatile Resource trustStoreResource;
112+
private Resource trustStoreResource;
113113

114-
private volatile String keyStorePassphrase;
114+
private String keyStorePassphrase;
115115

116-
private volatile String trustStorePassphrase;
116+
private String trustStorePassphrase;
117117

118-
private volatile String keyStoreType;
118+
private String keyStoreType;
119119

120-
private volatile String trustStoreType;
120+
private String trustStoreType;
121121

122-
private volatile String sslAlgorithm = TLS_V1_1;
122+
private String sslAlgorithm = TLS_V1_1;
123123

124-
private volatile boolean sslAlgorithmSet;
124+
private boolean sslAlgorithmSet;
125125

126-
private volatile SecureRandom secureRandom;
126+
private SecureRandom secureRandom;
127127

128128
private boolean skipServerCertificateValidation;
129129

130+
private boolean enableHostnameVerification = true;
131+
130132
public RabbitConnectionFactoryBean() {
131133
this.connectionFactory.setAutomaticRecoveryEnabled(false);
132134
}
@@ -604,6 +606,22 @@ public void setChannelRpcTimeout(int channelRpcTimeout) {
604606
this.connectionFactory.setChannelRpcTimeout(channelRpcTimeout);
605607
}
606608

609+
/**
610+
* Enable server hostname verification for TLS connections.
611+
* <p>
612+
* This enables hostname verification regardless of the IO mode used (blocking or
613+
* non-blocking IO).
614+
* <p>
615+
* This can be called typically after setting the {@link SSLContext} with one of the
616+
* <code>useSslProtocol</code> methods. Requires amqp-client 5.4.0 or later.
617+
* @param enable false to disable.
618+
* @since 2.0.6
619+
* @see ConnectionFactory#enableHostnameVerification()
620+
*/
621+
public void setEnableHostnameVerification(boolean enable) {
622+
this.enableHostnameVerification = enable;
623+
}
624+
607625
@Override
608626
public Class<?> getObjectType() {
609627
return ConnectionFactory.class;
@@ -686,6 +704,9 @@ protected void setUpSSL() throws Exception {
686704
SSLContext context = createSSLContext();
687705
context.init(keyManagers, trustManagers, this.secureRandom);
688706
this.connectionFactory.useSslProtocol(context);
707+
if (this.enableHostnameVerification) {
708+
this.connectionFactory.enableHostnameVerification();
709+
}
689710
}
690711
}
691712

@@ -709,6 +730,9 @@ private void useDefaultTrustStoreMechanism()
709730
trustManagerFactory.init((KeyStore) null);
710731
sslContext.init(null, trustManagerFactory.getTrustManagers(), null);
711732
this.connectionFactory.useSslProtocol(sslContext);
733+
if (this.enableHostnameVerification) {
734+
this.connectionFactory.enableHostnameVerification();
735+
}
712736
}
713737

714738
}

src/reference/asciidoc/whats-new.adoc

+4
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,7 @@ See <<management-rest-api>> for more information.
6565

6666
The listener container factory can now be configured with a `RetryTemplate` and, optionally, a `RecoveryCallback` used when sending replies.
6767
See <<async-annotation-driven-enable>> for more information.
68+
69+
===== Connection Factory Bean Changes
70+
71+
The `RabbitConnectionFactoryBean` now calls `enableHostnameVerification()` by default; to revert to the previous behavior, set the `enabaleHostnameVerification` property to `false`.

0 commit comments

Comments
 (0)