Skip to content

Commit b2f5cf5

Browse files
michaelklishinacogoluegnes
authored andcommitted
Stronger language around ConnectionFactory methods that enable TLS with a permissive TrustManager
Make it clear which methods are offered for convenience in development environments. (cherry picked from commit 149b6c7) Conflicts: src/main/java/com/rabbitmq/client/ConnectionFactory.java
1 parent 44ab5b6 commit b2f5cf5

File tree

2 files changed

+40
-14
lines changed

2 files changed

+40
-14
lines changed

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

+33-9
Original file line numberDiff line numberDiff line change
@@ -640,8 +640,14 @@ public boolean isSSL(){
640640
}
641641

642642
/**
643-
* Convenience method for setting up a SSL socket factory/engine, using
644-
* the DEFAULT_SSL_PROTOCOL and a trusting TrustManager.
643+
* Convenience method for configuring TLS using
644+
* the default set of TLS protocols and a trusting TrustManager.
645+
* This setup is <strong>only suitable for development
646+
* and QA environments</strong>.
647+
* The trust manager will <strong>trust every server certificate presented</strong>
648+
* to it, this is convenient for local development but
649+
* <strong>not recommended to use in production</strong> as it provides no protection
650+
* against man-in-the-middle attacks. Prefer {@link #useSslProtocol(SSLContext)}.
645651
*/
646652
public void useSslProtocol()
647653
throws NoSuchAlgorithmException, KeyManagementException
@@ -650,8 +656,17 @@ public void useSslProtocol()
650656
}
651657

652658
/**
653-
* Convenience method for setting up a SSL socket factory/engine, using
654-
* the supplied protocol and a very trusting TrustManager.
659+
* Convenience method for configuring TLS using
660+
* the supplied protocol and a very trusting TrustManager. This setup is <strong>only suitable for development
661+
* and QA environments</strong>.
662+
* The trust manager <strong>will trust every server certificate presented</strong>
663+
* to it, this is convenient for local development but
664+
* not recommended to use in production as it <strong>provides no protection
665+
* against man-in-the-middle attacks</strong>.
666+
*
667+
* Use {@link #useSslProtocol(SSLContext)} in production environments.
668+
* The produced {@link SSLContext} instance will be shared by all
669+
* the connections created by this connection factory.
655670
*/
656671
public void useSslProtocol(String protocol)
657672
throws NoSuchAlgorithmException, KeyManagementException
@@ -660,10 +675,16 @@ public void useSslProtocol(String protocol)
660675
}
661676

662677
/**
663-
* Convenience method for setting up an SSL socket factory/engine.
664-
* Pass in the SSL protocol to use, e.g. "TLSv1" or "TLSv1.2".
678+
* Convenience method for configuring TLS.
679+
* Pass in the TLS protocol version to use, e.g. "TLSv1.2" or "TLSv1.1", and
680+
* a desired {@link TrustManager}.
681+
*
665682
*
666-
* @param protocol SSL protocol to use.
683+
* The produced {@link SSLContext} instance will be shared with all
684+
* the connections created by this connection factory.
685+
* @param protocol the TLS protocol to use.
686+
* @param trustManager the {@link TrustManager} implementation to use.
687+
* @see #useSslProtocol(SSLContext)
667688
*/
668689
public void useSslProtocol(String protocol, TrustManager trustManager)
669690
throws NoSuchAlgorithmException, KeyManagementException
@@ -674,9 +695,12 @@ public void useSslProtocol(String protocol, TrustManager trustManager)
674695
}
675696

676697
/**
677-
* Convenience method for setting up an SSL socket factory/engine.
678-
* Pass in an initialized SSLContext.
698+
* Sets up TLS with an initialized {@link SSLContext}. The caller is responsible
699+
* for setting up the context with a {@link TrustManager} with suitable security guarantees,
700+
* e.g. peer verification.
679701
*
702+
* The {@link SSLContext} instance will be shared with all
703+
* the connections created by this connection factory.
680704
* @param context An initialized SSLContext
681705
*/
682706
public void useSslProtocol(SSLContext context) {

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

+7-5
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,18 @@
2222
import java.security.cert.X509Certificate;
2323

2424
/**
25-
* Convenience class providing a default implementation of javax.net.ssl.X509TrustManager.
26-
* Trusts every single certificate presented to it.
25+
* Convenience class providing a default implementation of {@link javax.net.ssl.X509TrustManager}.
26+
* Trusts every single certificate presented to it. This implementation does not perform peer
27+
* verification and <strong>provides no protection against Man-in-the-Middle (MITM) attacks</strong> and therefore
28+
* <strong>only suitable for some development and QA environments</strong>.
2729
*/
2830
public class TrustEverythingTrustManager implements X509TrustManager {
2931

3032
public TrustEverythingTrustManager() {
3133
LoggerFactory.getLogger(TrustEverythingTrustManager.class).warn(
32-
"This trust manager trusts every certificate, effectively disabling peer verification. " +
33-
"This is convenient for local development but prone to man-in-the-middle attacks. " +
34-
"Please see http://www.rabbitmq.com/ssl.html#validating-cerficates to learn more about peer certificate validation."
34+
"SECURITY ALERT: this trust manager trusts every certificate, effectively disabling peer verification. " +
35+
"This is convenient for local development but offers no protection against man-in-the-middle attacks. " +
36+
"Please see https://www.rabbitmq.com/ssl.html#validating-cerficates to learn more about peer certificate verification."
3537
);
3638
}
3739

0 commit comments

Comments
 (0)