8000 Merge pull request #235 from rabbitmq/rabbitmq-java-client-230 · xingly/rabbitmq-java-client@2540946 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2540946

Browse files
Merge pull request rabbitmq#235 from rabbitmq/rabbitmq-java-client-230
Emit a warning in NullTrustManager, introduce TrustEverythingTrustManager
2 parents 11f3668 + cf46a69 commit 2540946

File tree

3 files changed

+80
-1
lines changed

3 files changed

+80
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,7 @@ public void useSslProtocol()
576576
public void useSslProtocol(String protocol)
577577
throws NoSuchAlgorithmException, KeyManagementException
578578
{
579-
useSslProtocol(protocol, new NullTrustManager());
579+
useSslProtocol(protocol, new TrustEverythingTrustManager());
580580
}
581581

582582
/**

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,31 @@
1616

1717
package com.rabbitmq.client;
1818

19+
import org.slf4j.LoggerFactory;
20+
1921
import java.security.cert.X509Certificate;
2022

2123
import javax.net.ssl.X509TrustManager;
2224

2325
/**
2426
* Convenience class providing a default implementation of javax.net.ssl.X509TrustManager.
2527
* Trusts every single certificate presented to it.
28+
*
29+
* Deprecated, use {@link TrustEverythingTrustManager} instead.
30+
* Will be removed in next major release.
31+
*
8000 32+
* @deprecated
2633
*/
2734
public class NullTrustManager implements X509TrustManager {
35+
36+
public NullTrustManager() {
37+
LoggerFactory.getLogger(NullTrustManager.class).warn(
38+
"This trust manager trusts every certificate, effectively disabling peer verification. " +
39+
"This is convenient for local development but prone to man-in-the-middle attacks. " +
40+
"Please see http://www.rabbitmq.com/ssl.html#validating-cerficates to learn more about peer certificate validation."
41+
);
42+
}
43+
2844
/**
2945
* Doesn't even bother looking at its arguments, simply returns,
3046
* which makes the check succeed.
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// Copyright (c) 2007-Present Pivotal Software, Inc. All rights reserved.
2+
//
3+
// This software, the RabbitMQ Java client library, is triple-licensed under the
4+
// Mozilla Public License 1.1 ("MPL"), the GNU General Public License version 2
5+
// ("GPL") and the Apache License version 2 ("ASL"). For the MPL, please see
6+
// LICENSE-MPL-RabbitMQ. For the GPL, please see LICENSE-GPL2. For the ASL,
7+
// please see LICENSE-APACHE2.
8+
//
9+
// This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND,
10+
// either express or implied. See the LICENSE file for specific language governing
11+
// rights and limitations of this software.
12+
//
13+
// If you have any questions regarding licensing, please contact us at
14+
// info@rabbitmq.com.
15+
16+
17+
package com.rabbitmq.client;
18+
19+
import org.slf4j.LoggerFactory;
20+
21+
import javax.net.ssl.X509TrustManager;
22+
import java.security.cert.X509Certificate;
23+
24+
/**
25+
* Convenience class providing a default implementation of javax.net.ssl.X509TrustManager.
26+
* Trusts every single certificate presented to it.
27+
*/
28+
public class TrustEverythingTrustManager implements X509TrustManager {
29+
30+
public TrustEverythingTrustManager() {
31+
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."
35+
);
36+
}
37+
38+
/**
39+
* Doesn't even bother looking at its arguments, simply returns,
40+
* which makes the check succeed.
41+
*/
42+
@Override
43+
public void checkClientTrusted(X509Certificate[] chain, String authType) {
44+
// Do nothing.
45+
}
46+
47+
/**
48+
* Doesn't even bother looking at its arguments, simply returns,
49+
* which makes the check succeed.
50+
*/
51+
@Override
52+
public void checkServerTrusted(X509Certificate[] chain, String authType) {
53+
// Do nothing.
54+
}
55+
56+
/**
57+
* Always returns an empty array of X509Certificates.
58+
*/
59+
@Override
60+
public X509Certificate[] getAcceptedIssuers() {
61+
return new X509Certificate[0];
62+
}
63+
}

0 commit comments

Comments
 (0)
0