我正在尝试使用命令行在rabbitmq-c 库(ssl-plumbing 分支)中运行 SSL 示例“amqps_listenq”
$./amqps_listenq [ServerIP] 5671 hello ./cacert.pem ./key.pem ./cert.pem
我收到以下错误
opening SSL/TLS connection
当我尝试调试代码时,它在 main 的以下块中失败
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 + "'");
}