为什么我的rabbitMQ客户端无法连接?

时间:2017-12-05 10:47:04

标签: java rabbitmq amqp

我尝试使用TLSv1.2创建与服务器的RabbitMQ连接,但我有java.net.SocketException:连接重置或javax.net.ssl.SSLHandshakeException:收到致命警报:handshake_failure(看起来像这样异常随机变化。

当我使用TLSv1.0时它工作,但是当服务器更改协议时它停止工作(即使我使用相同的密码,端口等)。

如果vhost / other连接参数不正确,是否可以获得此异常?

在连接之前,我设置了:

System.setProperty("https.protocols", "TLSv1.2");

这是我的配置:

public ConnectionFactory get() throws IOException, KeyStoreException, NoSuchAlgorithmException,
        CertificateException, UnrecoverableKeyException, KeyManagementException, URISyntaxException {
    final ConnectionFactory cf = new ConnectionFactory();

    final SSLContext sslContext = getSSLContext();

    cf.useSslProtocol(sslContext);

    final ConnectionSettings connectionSettings = getConnectionSettings(sslContext.getSocketFactory());

    cf.setHost(connectionSettings.getHost());
    cf.setPort(connectionSettings.getPort());
    cf.setVirtualHost(connectionSettings.getVirtualHost());
    //using cf.setUsername and cs.setPassword doesn't work

    cf.setSaslConfig(DefaultSaslConfig.EXTERNAL);
    cf.setAutomaticRecoveryEnabled(false);
    cf.setTopologyRecoveryEnabled(false);

    return cf;
}

getSSLContext()方法:

private SSLContext getSSLContext(){
    //SECURE_PROTOCOLE = "TLSv1.2"
    final SSLContext sslContext = SSLContext.getInstance(SECURE_PROTOCOLE);

    KeyStore keystore = KeyStore.getInstance("Windows-MY");
    keystore.load(null, null); 

    final KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
    kmf.init(keystore, null);


    TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {

        public X509Certificate[] getAcceptedIssuers() {
            return null;
        }

        @Override
        public void checkClientTrusted(X509Certificate[] arg0, String arg1) throws CertificateException {
            // Not implemented
        }

        @Override
        public void checkServerTrusted(X509Certificate[] arg0, String arg1) throws CertificateException {
            // Not implemented
        }
    } };

    sslContext.init(keyManagerWrapper(kmf),
            trustAllCerts, new SecureRandom());
    return sslContext;   
    }

当我尝试创建新连接时发生异常:

this.connectionFactory = new ConnectionFactoryProvider().get();
this.connection = this.connectionFactory.newConnection();

1 个答案:

答案 0 :(得分:0)

RabbitMQ团队监控this mailing list,有时只回答StackOverflow上的问题。

使用有限的信息诊断TLS错误非常困难。您没有提供以下有用的信息:

  • RabbitMQ版
  • Erlang版
  • RabbitMQ服务器和客户端的操作系统平台和版本
  • Java版本和Java客户端版本

这行代码暗示您在Windows上运行客户端应用程序:

KeyStore.getInstance("Windows-MY")

如果您可以提供上述信息以及一整套TLS / SSL证书,以重现理想的问题。

RabbitMQ文档还包括comprehensive TLS/SSL troubleshooting guide