Problem description
The following errors occurred in the TLS/SSL of mosquitto during the test today, indicating that the error occurred in the TLS version:
I know that the default tls version of mosquitto_pub and mosquitto_sub is tlsv1.2, however, the version of openssl in my virtual machine is 1.1.1, and the tls_version tlsv1.1 is configured in mosquitto.conf (one-way authentication is configured here, two-way authentication is also (here the configuration is one-way authentication, two-way authentication is also applicable), so there will be tls version error.
Solution:
For C programs of mosquitto library
Use the API mosquitto_tls_set() before attaching mosquitto_tls_opts_set(), this API can set the corresponding tls version of the client, note that the tls version defaults to tlsv1.2.
The code is as follows:
int rc = -1;
rc = mosquitto_tls_opts_set(mosq, 1, "tlsv1.1", NULL);
if( rc != MOSQ_ERR_SUCCESS )
{
printf("mosquitto_tls_opts_set failure.\n");
exit(1);
}
rc = mosquitto_tls_set(mosq, CAFILE, CAPATH, CERTFILE, KEYFILE, NULL);
if( rc != MOSQ_ERR_SUCCESS )
{
printf("mosquitto_tls_set failure.\n");
exit(1);
}
On the mosquitto command line
The following is the test of one-way authentication (in case of two-way authentication, add the certificate and key by yourself)
mosquitto_ pub -h 192.168.222.130 -p 8884 -t “hello” -m “hi sub” –tls-version tlsv1. 1 –cafile ./ ca/ca.crt
mosquitto_ sub -h 192.168.222.130 -p 8884 -t “hello” –tls-version tlsv1. 1 –cafile ./ ca/ca.crt
If the problem is solved successfully, it can be connected normally:
Read More:
- Nginx Error: SSL: error:140AB18F:SSL routines:SSL_CTX_use_certificate:ee key too small
- [Solved] svn: OPTIONS of ‘https://xxx/svn/xxx’: SSL handshake failed: SSL error: Key usage violation in certificate has been detected.
- [Solved] Git Error: OpenSSL SSL_connect: SSL_ERROR_SYSCALL in connection to github.com:443
- Nginx Error: nginx: [emerg] the “ssl“ parameter requires ngx_http_ssl_module in /project/api/nginx.conf:
- [Solved] Git Error: OpenSSL SSL_read: Connection was reset, errno 10054和Failed to connect to github.com port 443
- [How to Solve] Apache cannot be restarted with Windows Server + Open SSL
- Apache Cannot Start: SSL Library Error: -8181 Certificate has expired
- Deepin svn Error: svn: E120171: Error running context: An error occurred during SSL communication
- Github Clone Failed SSL_ERROR_SYSCALL in connection to github.com:443
- PM2 user defined Log, PID and other Log File Locations
- [Solved] Git Clone Failed Error: 4069 bytes of body are still expected
- [Solved] KingbaseES V8R3 Error: cluster.log ERROR: md5 authentication failed
- Read and write BMP image with Pure C language
- Ubuntu: pdserving deployment output log.txt Error
- [Solved] nova-compute.log Error: Instance failed block device setup
- Linux Nagios failed to log in to internal server error (Fixed)
- Hadoop 3.2.0 idea development environment construction and HDFS read write API operation
- [Solved] Syntax Error: TypeError: Cannot read property ‘parseComponent‘ of undefined (vue报错)
- Git Clone RPC failed;curl 18 transfer closed with outstanding read data remaining
- [Solved] Log Error: kernel: blk_update_request: I/O error, dev fd0, sector 0