Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. MQTT TLS find cipher and protocol used

MQTT TLS find cipher and protocol used

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 1 Posters 161 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    Gary Metalle
    wrote on 7 Nov 2023, 14:45 last edited by
    #1

    I have been playing with the MQTT simpleclient example and have been able to get a secure connection to a remote MQTT broker. It would be nice to find out the cipher and protocol version (1.2 or 1.3) that was decided during the handshake but I can't see any way of getting it?

    I have tried getting this after a connect:

        QSslConfiguration c = QSslConfiguration::defaultConfiguration();
        qDebug() << "Protocol:" << c.protocol();
        qDebug() << "Session Cipher:" << c.sessionCipher();
        qDebug() << "Session Protocol:" << c.sessionProtocol();
    

    But it's all empty. QSslSocket seems to have some interesting properties but I can't see a way to get the instance of this that the QMqttClient is using. QSslConfiguration doesn't seem to be correct.

    I'm guessing this is something to do with the underlying SSL backend (OpenSSL in my case) doing all this during the handshake?

    It might also be nice to get some information about the downloaded SSL certificate that the broker provided such as expiry date etc.

    1 Reply Last reply
    0
    • G Offline
      G Offline
      Gary Metalle
      wrote on 7 Nov 2023, 15:06 last edited by
      #2

      OK it wasn't too difficult in the end, you can use the transport() function from QMqttClient and cast it to a QSslSocket pointer as long as the transport type is SecureSocket.

          QIODevice* d = m_client->transport();
          if (d)
          {
              QSslSocket* s = dynamic_cast<QSslSocket*>(d);
              if (s)
              {
                  qDebug() << "Protocol:" << s->protocol();
                  qDebug() << "Session Cipher:" << s->sessionCipher();
                  qDebug() << "Session Protocol:" << s->sessionProtocol();
              }
          }
      
      1 Reply Last reply
      0
      • S SGaist has marked this topic as solved on 7 Nov 2023, 20:51

      1/2

      7 Nov 2023, 14:45

      • Login

      • Login or register to search.
      1 out of 2
      • First post
        1/2
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved