Skip to content

Commit 149b6c7

Browse files
Stronger language around ConnectionFactory methods that enable TLS with a permissive TrustManager
Make it clear which methods are offered for convenience in development environments.
1 parent 0d0ea41 commit 149b6c7

File tree

2 files changed

+38
-22
lines changed

2 files changed

+38
-22
lines changed

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

+31-17
Original file line numberDiff line numberDiff line change
@@ -653,12 +653,14 @@ public boolean isSSL(){
653653
}
654654

655655
/**
656-
* Convenience method for setting up a SSL socket factory/engine, using
657-
* the DEFAULT_SSL_PROTOCOL and a trusting TrustManager.
658-
* Note the trust manager will trust every server certificate presented
656+
* Convenience method for configuring TLS using
657+
* the default set of TLS protocols and a trusting TrustManager.
658+
* This setup is <strong>only suitable for development
659+
* and QA environments</strong>.
660+
* The trust manager will <strong>trust every server certificate presented</strong>
659661
* to it, this is convenient for local development but
660-
* not recommended to use in production as it provides no protection
661-
* against man-in-the-middle attacks.
662+
* <strong>not recommended to use in production</strong> as it provides no protection
663+
* against man-in-the-middle attacks. Prefer {@link #useSslProtocol(SSLContext)}.
662664
*/
663665
public void useSslProtocol()
664666
throws NoSuchAlgorithmException, KeyManagementException
@@ -667,15 +669,19 @@ public void useSslProtocol()
667669
}
668670

669671
/**
670-
* Convenience method for setting up a SSL socket factory/engine, using
671-
* the supplied protocol and a very trusting TrustManager.
672-
* Note the trust manager will trust every server certificate presented
672+
* Convenience method for configuring TLS using
673+
* the supplied protocol and a very trusting TrustManager. This setup is <strong>only suitable for development
674+
* and QA environments</strong>.
675+
* The trust manager <strong>will trust every server certificate presented</strong>
673676
* to it, this is convenient for local development but
674-
* not recommended to use in production as it provides no protection
675-
* against man-in-the-middle attacks.
677+
* not recommended to use in production as it <strong>provides no protection
678+
* against man-in-the-middle attacks</strong>.
679+
*
680+
* Use {@link #useSslProtocol(SSLContext)} in production environments.
676681
* The produced {@link SSLContext} instance will be shared by all
677-
* the connections created by this connection factory. Use
678-
* {@link #setSslContextFactory(SslContextFactory)} for more flexibility.
682+
* the connections created by this connection factory.
683+
*
684+
* Use {@link #setSslContextFactory(SslContextFactory)} for more flexibility.
679685
* @see #setSslContextFactory(SslContextFactory)
680686
*/
681687
public void useSslProtocol(String protocol)
@@ -685,13 +691,18 @@ public void useSslProtocol(String protocol)
685691
}
686692

687693
/**
688-
* Convenience method for setting up an SSL socket factory/engine.
689-
* Pass in the SSL protocol to use, e.g. "TLSv1" or "TLSv1.2".
694+
* Convenience method for configuring TLS.
695+
* Pass in the TLS protocol version to use, e.g. "TLSv1.2" or "TLSv1.1", and
696+
* a desired {@link TrustManager}.
697+
*
698+
*
690699
* The produced {@link SSLContext} instance will be shared with all
691700
* the connections created by this connection factory. Use
692701
* {@link #setSslContextFactory(SslContextFactory)} for more flexibility.
693-
* @param protocol SSL protocol to use.
702+
* @param protocol the TLS protocol to use.
703+
* @param trustManager the {@link TrustManager} implementation to use.
694704
* @see #setSslContextFactory(SslContextFactory)
705+
* @see #useSslProtocol(SSLContext)
695706
*/
696707
public void useSslProtocol(String protocol, TrustManager trustManager)
697708
throws NoSuchAlgorithmException, KeyManagementException
@@ -702,8 +713,11 @@ public void useSslProtocol(String protocol, TrustManager trustManager)
702713
}
703714

704715
/**
705-
* Convenience method for setting up an SSL socket socketFactory/engine.
706-
* Pass in an initialized SSLContext.
716+
* Sets up TLS with an initialized {@link SSLContext}. The caller is responsible
717+
* for setting up the context with a {@link TrustManager} with suitable security guarantees,
718+
* e.g. peer verification.
719+
*
720+
*
707721
* The {@link SSLContext} instance will be shared with all
708722
* the connections created by this connection factory. Use
709723
* {@link #setSslContextFactory(SslContextFactory)} for more flexibility.

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)