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. QNetworkAccessManager to a HTTPS troubles
Forum Updated to NodeBB v4.3 + New Features

QNetworkAccessManager to a HTTPS troubles

Scheduled Pinned Locked Moved Solved General and Desktop
22 Posts 4 Posters 6.2k 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.
  • R Offline
    R Offline
    reonZ
    wrote on last edited by
    #1

    I am trying to connect to a secure website and am having trouble understanding the steps to get there, i think i am supposed to use QSslSocket, which i try to do, but then i get this error when i use QSslSocket::connectToHostEncrypted:

    qt.network.ssl: QSslSocket::connectToHostEncrypted: TLS initialization failed

    What am i missing ?

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

      Hi,

      What version of Qt are you using ?
      On what platform ?
      With what version of OpenSSL ?

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

      R 1 Reply Last reply
      1
      • SGaistS SGaist

        Hi,

        What version of Qt are you using ?
        On what platform ?
        With what version of OpenSSL ?

        R Offline
        R Offline
        reonZ
        wrote on last edited by
        #3

        @SGaist Qt 5.12 on windows 10 64bit, and i don't know anything about OpenSSL so that will be most likely what i am missing, Could you elaborate on how to use it ?

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

          Here you have the starting point.

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

          R 1 Reply Last reply
          2
          • SGaistS SGaist

            Here you have the starting point.

            R Offline
            R Offline
            reonZ
            wrote on last edited by
            #5

            @SGaist I am not sure i understand, do i need to build my own Qt ? i have never done that.

            JKSHJ 1 Reply Last reply
            0
            • R reonZ

              @SGaist I am not sure i understand, do i need to build my own Qt ? i have never done that.

              JKSHJ Offline
              JKSHJ Offline
              JKSH
              Moderators
              wrote on last edited by
              #6

              @reonZ said in QNetworkAccessManager to a HTTPS troubles:

              do i need to build my own Qt ?,

              No need to build Qt; you just need to install OpenSSL and add it to your PATH.

              The bitness of OpenSSL must match the bitness of your Qt libraries (so if you use 32-bit Qt, install 32-bit OpenSSL). Qt 5.12 uses OpenSSL 1.1.0.

              Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

              R 1 Reply Last reply
              4
              • JKSHJ JKSH

                @reonZ said in QNetworkAccessManager to a HTTPS troubles:

                do i need to build my own Qt ?,

                No need to build Qt; you just need to install OpenSSL and add it to your PATH.

                The bitness of OpenSSL must match the bitness of your Qt libraries (so if you use 32-bit Qt, install 32-bit OpenSSL). Qt 5.12 uses OpenSSL 1.1.0.

                R Offline
                R Offline
                reonZ
                wrote on last edited by
                #7

                @JKSH I am really sorry to be asking that but this is far beyond my expertise, i just installed OpenSSL 1.1.0j and added INCLUDEPATH += C:/OpenSSL-Win64/include in my .pro, but now what ? i have no idea how i am supposed to use it.

                JKSHJ 1 Reply Last reply
                0
                • R reonZ

                  @JKSH I am really sorry to be asking that but this is far beyond my expertise, i just installed OpenSSL 1.1.0j and added INCLUDEPATH += C:/OpenSSL-Win64/include in my .pro, but now what ? i have no idea how i am supposed to use it.

                  JKSHJ Offline
                  JKSHJ Offline
                  JKSH
                  Moderators
                  wrote on last edited by
                  #8

                  Hi @reonZ, no apology required :)

                  @reonZ said in QNetworkAccessManager to a HTTPS troubles:

                  i just installed OpenSSL 1.1.0j

                  Good.

                  and added INCLUDEPATH += C:/OpenSSL-Win64/include in my .pro, but now what ? i have no idea how i am supposed to use it.

                  I meant your PATH environment variable, not your project INCLUDEPATH. See https://helpdeskgeek.com/windows-10/add-windows-path-environment-variable/ and add the folder that contains the OpenSSL DLLs (not the include folder).

                  You don't need to do anything else. Just run your Qt program. It will search for the OpenSSL DLL in your PATH and load it automatically.

                  Anyway, I notice that you've installed 64-bit OpenSSL, which will only work with 64-bit apps. Are you using 64-bit Qt or 32-bit Qt?

                  Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                  R 1 Reply Last reply
                  2
                  • JKSHJ JKSH

                    Hi @reonZ, no apology required :)

                    @reonZ said in QNetworkAccessManager to a HTTPS troubles:

                    i just installed OpenSSL 1.1.0j

                    Good.

                    and added INCLUDEPATH += C:/OpenSSL-Win64/include in my .pro, but now what ? i have no idea how i am supposed to use it.

                    I meant your PATH environment variable, not your project INCLUDEPATH. See https://helpdeskgeek.com/windows-10/add-windows-path-environment-variable/ and add the folder that contains the OpenSSL DLLs (not the include folder).

                    You don't need to do anything else. Just run your Qt program. It will search for the OpenSSL DLL in your PATH and load it automatically.

                    Anyway, I notice that you've installed 64-bit OpenSSL, which will only work with 64-bit apps. Are you using 64-bit Qt or 32-bit Qt?

                    R Offline
                    R Offline
                    reonZ
                    wrote on last edited by
                    #9

                    @JKSH I did put it in my windows PATH, tried both the C:\OpenSSL-Win32\bin and C:\OpenSSL-Win64\bin version just in case and i still have the same error (i restarted Qt each time).

                    JKSHJ 1 Reply Last reply
                    0
                    • R reonZ

                      @JKSH I did put it in my windows PATH, tried both the C:\OpenSSL-Win32\bin and C:\OpenSSL-Win64\bin version just in case and i still have the same error (i restarted Qt each time).

                      JKSHJ Offline
                      JKSHJ Offline
                      JKSH
                      Moderators
                      wrote on last edited by
                      #10

                      @reonZ said in QNetworkAccessManager to a HTTPS troubles:

                      I did put it in my windows PATH, tried both the C:\OpenSSL-Win32\bin and C:\OpenSSL-Win64\bin version just in case and i still have the same error

                      1. Are you using 32-bit or 64-bit Qt?
                      2. Where did you download OpenSSL from?
                      3. What does QSslSocket::sslLibraryBuildVersionString() return?
                      4. What does QSslSocket::sslLibraryVersionString() return?

                      (i restarted Qt each time).

                      I'm not 100% sure, but you'll also need to make sure that Windows has recorded the changes. Did you close all the Windows dialogs after changing the settings?

                      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                      R 1 Reply Last reply
                      1
                      • R reonZ

                        I am trying to connect to a secure website and am having trouble understanding the steps to get there, i think i am supposed to use QSslSocket, which i try to do, but then i get this error when i use QSslSocket::connectToHostEncrypted:

                        qt.network.ssl: QSslSocket::connectToHostEncrypted: TLS initialization failed

                        What am i missing ?

                        kshegunovK Offline
                        kshegunovK Offline
                        kshegunov
                        Moderators
                        wrote on last edited by
                        #11

                        Relevant bugreports:
                        https://bugreports.qt.io/browse/QTBUG-72015
                        https://bugreports.qt.io/browse/QTBUG-72016

                        Basically you can get that if you have misconfigured the socket - no private key, or local certificate. The error is nondescriptive, so you need to make sure (if you use any of those two) that both exist and are valid, and you do that manually. Could you provide the snippet you use to connect to said server?

                        Read and abide by the Qt Code of Conduct

                        R 1 Reply Last reply
                        0
                        • JKSHJ JKSH

                          @reonZ said in QNetworkAccessManager to a HTTPS troubles:

                          I did put it in my windows PATH, tried both the C:\OpenSSL-Win32\bin and C:\OpenSSL-Win64\bin version just in case and i still have the same error

                          1. Are you using 32-bit or 64-bit Qt?
                          2. Where did you download OpenSSL from?
                          3. What does QSslSocket::sslLibraryBuildVersionString() return?
                          4. What does QSslSocket::sslLibraryVersionString() return?

                          (i restarted Qt each time).

                          I'm not 100% sure, but you'll also need to make sure that Windows has recorded the changes. Did you close all the Windows dialogs after changing the settings?

                          R Offline
                          R Offline
                          reonZ
                          wrote on last edited by
                          #12

                          @JKSH

                          1/ In Qt creator it says Based on Qt 5.12.0 (MVSC 2015, 32 bit)
                          2/ From here http://slproweb.com/products/Win32OpenSSL.html
                          3/ QSslSocket::sslLibraryBuildVersionString() returns OpenSSL 1.0.2p 14 Aug 2018
                          4/ QSslSocket::sslLibraryVersionString() returns empty

                          And yes, i made sure to close all the dialog windows before restarting Qt.

                          JKSHJ 1 Reply Last reply
                          0
                          • kshegunovK kshegunov

                            Relevant bugreports:
                            https://bugreports.qt.io/browse/QTBUG-72015
                            https://bugreports.qt.io/browse/QTBUG-72016

                            Basically you can get that if you have misconfigured the socket - no private key, or local certificate. The error is nondescriptive, so you need to make sure (if you use any of those two) that both exist and are valid, and you do that manually. Could you provide the snippet you use to connect to said server?

                            R Offline
                            R Offline
                            reonZ
                            wrote on last edited by
                            #13

                            @kshegunov My test code is pretty bare right now, i just wanted to see how it worked first, it is just a simple QNetworkAccessManager::get on https://www.google.com.

                            kshegunovK 1 Reply Last reply
                            0
                            • R reonZ

                              @kshegunov My test code is pretty bare right now, i just wanted to see how it worked first, it is just a simple QNetworkAccessManager::get on https://www.google.com.

                              kshegunovK Offline
                              kshegunovK Offline
                              kshegunov
                              Moderators
                              wrote on last edited by
                              #14

                              It works yes, if it's configured properly. However: QSslSocket::sslLibraryVersionString() shouldn't return empty. I'd guess Qt can't find to load your openssl library.

                              Read and abide by the Qt Code of Conduct

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

                                Hi,

                                Following item 3, Qt was built using OpenSSL 1.0.2 so you have to download the most recent version of the 1.0 series of OpenSSL. You can't use 1.1 in this case because they broke API and ABI compatibility.

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

                                R 1 Reply Last reply
                                3
                                • SGaistS SGaist

                                  Hi,

                                  Following item 3, Qt was built using OpenSSL 1.0.2 so you have to download the most recent version of the 1.0 series of OpenSSL. You can't use 1.1 in this case because they broke API and ABI compatibility.

                                  R Offline
                                  R Offline
                                  reonZ
                                  wrote on last edited by reonZ
                                  #16

                                  @SGaist Installed 1.0.2q and still the same, QSslSocket::sslLibraryVersionString() returns empty. I am loosing hope :(

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

                                    Go to the Run part of the Project panel and modify the PATH environment variable there to also contain the path to your 1.0 version of OpenSSL dlls.

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

                                    R 1 Reply Last reply
                                    0
                                    • SGaistS SGaist

                                      Go to the Run part of the Project panel and modify the PATH environment variable there to also contain the path to your 1.0 version of OpenSSL dlls.

                                      R Offline
                                      R Offline
                                      reonZ
                                      wrote on last edited by
                                      #18

                                      @SGaist Sadly it is already there, even twice for some reason.

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

                                        Then I would ensure that this folder is the first to appear in the list and also that there are no other versions of OpenSSL on the system, for example in the Windows specific folders.

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

                                        R 1 Reply Last reply
                                        2
                                        • SGaistS SGaist

                                          Then I would ensure that this folder is the first to appear in the list and also that there are no other versions of OpenSSL on the system, for example in the Windows specific folders.

                                          R Offline
                                          R Offline
                                          reonZ
                                          wrote on last edited by
                                          #20

                                          @SGaist Alright it is working now, i indeed needed to install the 64bit version and not the 32 bit:

                                          QSslSocket::sslLibraryBuildVersionString()   "OpenSSL 1.0.2p  14 Aug 2018"
                                          QSslSocket::sslLibraryVersionString()        "OpenSSL 1.0.2q  20 Nov 2018"
                                          

                                          I also received the result from QNetworkAccessManager::get

                                          Thanks a lot for all the help, you guys are awesome.

                                          Edit: i still always have this in the output console though QNetworkReplyHttpImplPrivate::_q_startOperation was called more than once but it is not related to this because i had it on non secure get too.

                                          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