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. QtCOAP PSK put request to IKEA Tradfri Bridge doesn't work. -> Strange SSL Errors
Forum Updated to NodeBB v4.3 + New Features

QtCOAP PSK put request to IKEA Tradfri Bridge doesn't work. -> Strange SSL Errors

Scheduled Pinned Locked Moved Solved General and Desktop
14 Posts 2 Posters 1.0k Views 1 Watching
  • 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.
  • F Offline
    F Offline
    Frime
    wrote on last edited by Frime
    #1

    Hi!

    I want to write a simple app which controls my IKEA Tradfri light bulbs - Just for fun. The protocol works perfectly as described here: https://freesoft.dev/program/121979476

    The following command works as expected when I run it in Terminal:

    coap-client -m post -u "Client_identity" -k "$GATEWAYCODE" -e '{"9090":"$USERNAME"}' "coaps://$GATEWAYIP:5684/15011/9063"
    

    Now I try to solve this with QtCOAP. This is my code:

     m_coapClient = new QCoapClient(QtCoap::SecurityMode::PreSharedKey, this);
        
        QCoapSecurityConfiguration configuration;
        configuration.setPreSharedKeyIdentity("Client_identity");
        configuration.setPreSharedKey("xxxxxxxxxxxxxxxx");
        m_configuration = configuration;
        m_coapClient->setSecurityConfiguration(m_configuration);
        QCoapRequest request;
        QUrl url;
        url.setHost("192.168.10.94");
        url.setPort(5684);
        url.setPath("/15011/9063");
        request.setUrl(url);
        request.setPayload("{\"9090\":\"frime\"}");
        m_coapClient->post(request);
    

    But I only get the following error message:

    qt.coap.connection: Handshake error:  "Im Ablauf des SSL-Protokolls ist ein Fehler aufgetreten: error:14102410:SSL routines:dtls1_read_bytes:sslv3 alert handshake failure"
    

    What am I doing wrong?

    Thanks in advance!
    Friedemann

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      What OS are you on ?
      What version of Qt are you running ?
      What version of OpenSSL do you have ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • F Offline
        F Offline
        Frime
        wrote on last edited by
        #3

        Thanks for fast reply!

        What OS are you on ?

        Ubuntu 20.04 LTS running in a VirtualBox

        What version of Qt are you running ?

        5.14.2

        What version of OpenSSL do you have ?

        OpenSSL 1.1.1f 31 Mar 2020

        Thanks in advance!

        Best,
        Friedemann

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Did you check the network activity with a tool like Wireshark ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          F 1 Reply Last reply
          1
          • F Offline
            F Offline
            Frime
            wrote on last edited by Frime
            #5
            This post is deleted!
            1 Reply Last reply
            0
            • SGaistS SGaist

              Did you check the network activity with a tool like Wireshark ?

              F Offline
              F Offline
              Frime
              wrote on last edited by Frime
              #6

              I don't really see where the problem is. Unofortunately it is not possible to upload the Wireshark file.

              Screenshot 2020-05-17 at 11.43.28.png

              F 1 Reply Last reply
              0
              • F Frime

                I don't really see where the problem is. Unofortunately it is not possible to upload the Wireshark file.

                Screenshot 2020-05-17 at 11.43.28.png

                F Offline
                F Offline
                Frime
                wrote on last edited by Frime
                #7

                Screenshot 2020-05-17 at 11.43.14.png

                F 1 Reply Last reply
                0
                • F Frime

                  Screenshot 2020-05-17 at 11.43.14.png

                  F Offline
                  F Offline
                  Frime
                  wrote on last edited by Frime
                  #8

                  I found this discussion via google. I think the DTLS version is the problem..

                  https://www.qt.io/blog/2019/06/06/introducing-qtcoap

                  Screenshot 2020-05-17 at 15.30.44.png

                  1 Reply Last reply
                  0
                  • F Offline
                    F Offline
                    Frime
                    wrote on last edited by Frime
                    #9

                    But Qt uses the latest version of OpenSSL...

                    QSslSocket::sslLibraryBuildVersionString()
                    

                    also returns

                    OpenSSL 1.1.1f 31 Mar 2020
                    

                    Maybe a Qt Bug?

                    1 Reply Last reply
                    0
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      Did you check the bug report system ?

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      1 Reply Last reply
                      0
                      • F Offline
                        F Offline
                        Frime
                        wrote on last edited by
                        #11

                        Yep. I have already created a bug report...
                        https://bugreports.qt.io/browse/QTBUG-84273?filter=-2

                        1 Reply Last reply
                        0
                        • SGaistS Offline
                          SGaistS Offline
                          SGaist
                          Lifetime Qt Champion
                          wrote on last edited by
                          #12

                          Thanks !

                          Interested in AI ? www.idiap.ch
                          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                          1 Reply Last reply
                          0
                          • F Offline
                            F Offline
                            Frime
                            wrote on last edited by
                            #13

                            Thanks to the help of Sona Kurazyan in the Qt Bug Tracker everything works now:

                            From your capture I can see that your client has not used the mandatory ciphers TLS_PSK_WITH_AES_128_CCM* required by CoAP. Some libraries (e.g. libcoap, which is what IKEA Tradfri LightBulb seems to be using) are working only with those ciphers. The problem is, that OpenSSL does not use CCM ciphers by default, and you need to "force" their usage by setting the cipher string to QCoapSecurityConfiguration in the following way:

                            configuration.setDefaultCipherString("AESCCM");
                            

                            After adding this line the handshake has worked. But I got a "BadRequest" error now.
                            It turned out that there was a small Qt bug at another place after all:

                            Just found that the payload set to the request is being ignored when calling post() without data, so the request is sent with an empty payload. I'm assuming that's the difference.
                            I'll prepare a fix for this.

                            A workaround is to change this line

                            request.setPayload("{\"9090\":\"frime\"}");
                            m_coapClient->post(request);
                            

                            to

                            m_coapClient->post(request, "{\"9090\":\"frime\"}");
                            
                            1 Reply Last reply
                            2
                            • SGaistS Offline
                              SGaistS Offline
                              SGaist
                              Lifetime Qt Champion
                              wrote on last edited by
                              #14

                              Thanks for the follow up !

                              Interested in AI ? www.idiap.ch
                              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                              1 Reply Last reply
                              0

                              • Login

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