【发布时间】:2021-03-15 23:16:30
【问题描述】:
我正在创建一个使用 mosquitto 库和 mosquittopp.h 的 C++ MQTT 客户端:
https://github.com/iosphere/mosquitto/blob/master/lib/cpp/mosquittopp.h.
我希望连接的 MQTT 代理使用 TLS 1.2,只有用于握手的服务器/代理证书(不需要客户端证书)。
如何验证代码中服务器证书的有效性?
我在 mosquittopp.h 文件中看到以下与 TLS 相关的函数:
int tls_set(const char *cafile, const char *capath=NULL, const char *certfile=NULL, const char *keyfile=NULL, int (*pw_callback)(char *buf, int size, int rwflag, void *userdata)=NULL);
int tls_opts_set(int cert_reqs, const char *tls_version=NULL, const char *ciphers=NULL);
int tls_insecure_set(bool value);
int tls_psk_set(const char *psk, const char *identity, const char *ciphers=NULL);
tls_set 似乎已经在客户端上寻找证书,但证书只会来自服务器/代理?我对此有点迷茫。提前致谢。
【问题讨论】: