我已经生成了证书,并且能够使用下面的命令成功地连接
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
发布于 2016-01-08 09:15:21
你没有给mosquitto_lib_init()打电话。
发布于 2016-01-08 09:05:03
您的代码正在连接到端口1883,它通常不是TLS端口;根据您在mosquitto.conf中配置的内容,我认为您需要端口8883,假设您在8883上配置了一个TLS侦听器。
我还指出,您使用的是/path/to和path/to,它们可能是复制/粘贴错误,也可能不是。
https://stackoverflow.com/questions/34672531
复制相似问题