无法使用SSL支持连接到RabbitMq-c

时间:2013-03-14 08:44:42

标签: c ssl openssl rabbitmq

我正在尝试使用命令行在rabbitmq-c library(ssl-plumbing分支)中运行SSL示例“amqps_listenq”

$./amqps_listenq [ServerIP]  5671 hello ./cacert.pem ./key.pem ./cert.pem

我收到以下错误

opening SSL/TLS connection

当我尝试调试代码时,它在主

中的以下块中失败
status = amqp_socket_open(socket, hostname, port);
if (status) {
    die("opening SSL/TLS connection");
}

当我调试到“amqp_socket_open”方法时,我发现它在amqp_openssl.c中的以下块中失败

if (self->verify) {
    int status = amqp_ssl_socket_verify(self, host);
    if (status) {
        return -1;
    }
}

我跟踪了amqp_ssl_socket_verify中的错误,发现我在以下块中失败

#ifdef _MSC_VER
#define strcasecmp _stricmp
#endif
    if (strcasecmp(host, (char *)utf8_value)) {
        goto error; //<-- it fails here
    }
#ifdef _MSC_VER
#undef strcasecmp
#endif
exit:
    OPENSSL_free(utf8_value);
    return status;
error:
    status = -1;
    goto exit;

状态等于-1 任何想法问题在哪里??

请注意,即使我没有使用以下代码设置证书,我也可以使用java在同一台服务器上使用SSL轻松连接到RabbitMq

ConnectionFactory factory = new ConnectionFactory();
factory.setHost("[ServerIP]");
factory.setPort(5671);
factory.useSslProtocol();
factory.setUsername("guest");
factory.setPassword("guest");
Connection connection = factory.newConnection();
Channel channel = connection.createChannel();

channel.queueDeclare("hello_ssl", false, false, false, null);
System.out.println(" [*] Waiting for messages. To exit press CTRL+C");

QueueingConsumer consumer = new QueueingConsumer(channel);
channel.basicConsume(QUEUE_NAME, true, consumer);

while (true){
  QueueingConsumer.Delivery delivery = consumer.nextDelivery();
  String message = new String(delivery.getBody());
  System.out.println(" [" + i + "] Received '" + message + "'");
}

2 个答案:

答案 0 :(得分:1)

我一直在调试librabbitmq,我看到完全相同的行为。 utf8_value变量包含“amqp”,而主机变量包含amqp服务器主机名。

我有一个解决方法:

-  if (strcasecmp(host, (char *)utf8_value)) {
-    goto error;
+
+  if(strcasecmp((char *)utf8_value, "amqp")) {
+    if (strcasecmp(host, (char *)utf8_value) ) {
+      goto error;
+    }
   }

我在这里分叉并打了补丁:https://github.com/drainware/rabbitmq-c

答案 1 :(得分:0)

问题是证书,验证域是否与证书详细信息匹配。