Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. qml websocket (wss) self signed certificate
Forum Updated to NodeBB v4.3 + New Features

qml websocket (wss) self signed certificate

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
6 Posts 3 Posters 910 Views 3 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.
  • P Offline
    P Offline
    poucz
    wrote on 31 Jul 2020, 13:10 last edited by
    #1

    Hello,
    I would like to test my APP which using websocket in qml .
    For test I created self signed certificate and now I need to load this cert to qml.
    How to make it easily? Some C++ wraper ? (all my code is write in pure qml).

    Thank you

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 31 Jul 2020, 15:48 last edited by
      #2

      Hi,

      IIRC, you would need to use QSslConfiguration. That part should be done in your main.cpp.

      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
      • P Offline
        P Offline
        poucz
        wrote on 3 Aug 2020, 07:48 last edited by
        #3

        Thank you for answer.

        I tryed this

        	QList<QSslCertificate> certs;
        	QSslCertificate cert(readFile("/tmp/cer/cert.pem"));
        	certs.append(cert);
        
        	QSslConfiguration config;
        	config.setCaCertificates(certs);
        	config.setLocalCertificateChain(certs);
        
        	QSslConfiguration::setDefaultConfiguration(config);
        	
        

        without success.
        Keys are generetad by :

        openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365 -nodes
        

        Server is python script, and it seems it working (testing with python client).

        P 1 Reply Last reply 6 Aug 2020, 12:31
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 3 Aug 2020, 19:13 last edited by
          #4

          @poucz said in qml websocket (wss) self signed certificate:

          QSslCertificate cert(readFile("/tmp/cer/cert.pem"));

          Are you sure readFile returns the correct content ?

          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
          • P Offline
            P Offline
            poucz
            wrote on 6 Aug 2020, 11:50 last edited by
            #5

            Yes I'm sure, In debugger I can see all bytes and variable 'cert' and 'cert2' contains valid field : "notValidAfter" and "notValidBefore"

            I don't know if I generate cert correctly.

            But with python client it works.

            Server is Python script:

            ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
            ssl_context.load_cert_chain("/tmp/cer/cert.pem", "/tmp/cer/key.pem")
            start_server = websockets.serve(server_handler, port=6789, ssl=ssl_context)
            asyncio.get_event_loop().run_until_complete(start_server)
            asyncio.get_event_loop().run_forever()
            

            and with python's client I can connect:

                 ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2)
                 ssl_context.load_verify_locations("/tmp/cer/cert.pem")
                 async with websockets.connect(uri, ssl=ssl_context) as websocket:
            
            1 Reply Last reply
            0
            • P poucz
              3 Aug 2020, 07:48

              Thank you for answer.

              I tryed this

              	QList<QSslCertificate> certs;
              	QSslCertificate cert(readFile("/tmp/cer/cert.pem"));
              	certs.append(cert);
              
              	QSslConfiguration config;
              	config.setCaCertificates(certs);
              	config.setLocalCertificateChain(certs);
              
              	QSslConfiguration::setDefaultConfiguration(config);
              	
              

              without success.
              Keys are generetad by :

              openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365 -nodes
              

              Server is python script, and it seems it working (testing with python client).

              P Offline
              P Offline
              Pablo J. Rogina
              wrote on 6 Aug 2020, 12:31 last edited by Pablo J. Rogina 8 Jun 2020, 12:31
              #6

              @poucz said in qml websocket (wss) self signed certificate:

              I tryed this

              What if you try the ICS approach?

              This is, creating a QSslCertificate and then adding that certificate to all SSL connections with QSslSocket::addDefaultCaCertificate()

              Remember that WebSocket QML Type internally uses a QWebSocket after all, and it in turn uses a QTcpSocket.

              Upvote the answer(s) that helped you solve the issue
              Use "Topic Tools" button to mark your post as Solved
              Add screenshots via postimage.org
              Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

              1 Reply Last reply
              0

              4/6

              3 Aug 2020, 19:13

              • Login

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