Repository: eclipse-mosquitto/mosquitto

Issue #1283: Mosquitto broker and client default to TLS_AES_256_GCM_SHA384 with tls1.3
Created: 2019-05-17T08:11:18Z
Good morning,
when trying to connect with tls1.3 both the broker and the client (mosquitto_pub) are ignoring the "ciphers" keyword and always using TLS_AES_256_GCM_SHA384 even if other ciphers (or any random string such as "test") are specified.
Component: mosquitto 1.6.2 (latest) and mosquitto_pub 1.6.2 (latest)
OS: Linux (Ubuntu 18.10)
openssl version(broker): 1.1.1  (11 Sep 2018)
openssl verision(client): 1.1.1b (26 Feb 2019)
Client string:
-> mosquitto_pub -h 127.0.0.1 -t "test" -p 8883 -i "Client1" -u Client1 -m "message" --cafile ca.pem --cert client.crt --key client.key --tls-version tlsv1.3 --ciphers example --insecure
###########################
listener 8883
allow_anonymous false
cafile cert/ca.pem
certfile cert/server.crt
keyfile cert/server.key
tls_version tlsv1.3
ciphers test
log_type all
log_dest stdout
############################

Duplicate issue #1825: Mosquitto has no option to configure TLS 1.3 cipher suites.
Created: 2020-09-15T18:23:39Z
When the broker or client library are set to use TLS 1.3, it seems the ciphers option doesn't affect which TLS 1.3 cipher suites are used at all, and in fact throws an error if a string like "TLS_AES_128_GCM_SHA256" is given.
Looking through the code (src/net.c in particular), I can see the library makes the call to SSL_CTX_set_cipher_list(). According to the OpenSSL manual (https://www.openssl.org/docs/man1.1.1/man3/SSL_CTX_set_ciphersuites.html), this call is only meant for TLS 1.2 and below. For TLS 1.3, the correct call would be SSL_CTX_set_ciphersuites().
As a proposed fix, listener -> tls_version can be used to check if TLS 1.3 is used, and if so, SSL_CTX_set_ciphersuites() can be called instead of SSL_CTX_set_cipher_list().

Closing comment (2020-12-17T16:37:28Z): @ralight This fix should also solve #1283. Unfortunatly, I tried but I was still not able to enforce a specific TLS 1.3 cipher.
Steps to test with respect to test.mosquitto.org:


Access the eclipse-mosquitto:2-openssl Docker container with docker exec -it <container-id> sh and download the mosquitto.org.crt CA file with wget https://test.mosquitto.org/ssl/mosquitto.org.crt


Use the Alpine packet manager to update the packets list, upgrade installed packets, install openssl and use it to get a list of locally supported TLS 1.3 ciphers:

apk update && apk upgrade && apk add openssl
openssl ciphers -s -tls1_3



Working command: mosquitto_pub -h test.mosquitto.org -p 8883 --cafile mosquitto.org.crt  -t "Ciphers_TEST" -m "Message" --tls-version tlsv1.3 (verified with Wireshark the use of TLS_AES_256_GCM_SHA384)


Not working command:  mosquitto_pub -h test.mosquitto.org -p 8883 --cafile mosquitto.org.crt  -t "Ciphers_TEST" -m "Message" --tls-version tlsv1.3 --ciphers TLS_AES_128_GCM_SHA256 (returns Unable to connect (A TLS error occurred.).)


An error ('No cipher can be selected.',) is also provided if I specify a TLS 1.3 cipher (e.g., TLS_AES_128_GCM_SHA256) with paho-mqtt as follows - but works with TLS 1.2 ciphers.
client.tls_set('mosquitto.org.crt',
       None,
       None,
       cert_reqs=ssl.CERT_REQUIRED,
       tls_version=ssl.PROTOCOL_TLS,
       ciphers="TLS_AES_128_GCM_SHA256")

According to Testssl, test.mosquitto.org should support the following TLS 1.3 ciphers: TLS_AES_256_GCM_SHA384, TLS_CHACHA20_POLY1305_SHA256 and TLS_AES_128_GCM_SHA256.
I tried also locally (eclipse-mosquitto:2-openssl Docker container and self-signed certificates and keys) with the following Mosquitto configuration. If i force the TLS 1.3 cipher, paho-mqtt provides always the same error, while if I remove the ciphers param from tls_set and verify with Wireshark, the selected CipherSuite is TLS_AES_256_GCM_SHA384 (as reported in #1283).
listener 8883
tls_version tlsv1.3
ciphers_tls1.3 TLS_CHACHA20_POLY1305_SHA256:TLS_AES_128_GCM_SHA256
allow_anonymous true

cafile certs/ca.crt
certfile certs/server.crt
keyfile certs/server.key

require_certificate true