gpt4 book ai didi

ssl - mosquitto 中的 tls 连接失败

转载 作者:太空宇宙 更新时间:2023-11-03 13:53:02 26 4
gpt4 key购买 nike

我已经生成证书并能够使用以下命令成功连接

mosquitto_sub -t "hello/world" -v --cafile ../certs/ca.crt --cert ../certs/client.crt --key ../certs/client.key

虽然我尝试使用相同的证书对我的代码执行相同的操作,但我遇到了以下错误

客户端

LIBMOSQUITTO 1004005
8: Unable to connect: A TLS error occurred.
Success

服务器端

1452241406: New connection from 127.0.0.1 on port 1883.
1452241406: OpenSSL Error: error:140780E5:SSL routines:SSL23_READ:ssl handshake failure
1452241406: Socket error on client <unknown>, disconnecting.

这是我的代码

int main(){
printf("LIBMOSQUITTO %d\n", LIBMOSQUITTO_VERSION_NUMBER);

if ((m = mosquitto_new("rtr", 1, NULL)) == NULL) {
fprintf(stderr, "Out of memory.\n");
exit(1);
}

int rc = mosquitto_tls_set(m,
"path/to/ca.crt", /* cafile */
NULL, /* capath */
"/path/to/client.crt", /* certfile */
"/path/to/client.key", /* keyfile */
NULL /* pw_callback() */
);

if (rc != MOSQ_ERR_SUCCESS) {
fprintf(stderr, "Cannot set TLS CA: %s (check path names)\n",
mosquitto_strerror(rc));
exit(3);
}
#if 0
mosquitto_tls_opts_set(m,
SSL_VERIFY_PEER,
NULL, /* tls_version: "tlsv1.2", "tlsv1" */
NULL /* ciphers */
);
mosquitto_tls_insecure_set(m, 1);
#endif
if ((rc = mosquitto_connect(m, "localhost", 1883, 20)) != MOSQ_ERR_SUCCESS) {
fprintf(stderr, "%d: Unable to connect: %s\n", rc,
mosquitto_strerror(rc));
perror("");
exit(2);
}
}

更新:还针对端口 8884 进行了测试

最佳答案

您还没有调用 mosquitto_lib_init()

关于ssl - mosquitto 中的 tls 连接失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34672531/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com