Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. How to make Qt use OpenSsl on Windows
QtWS25 Last Chance

How to make Qt use OpenSsl on Windows

Scheduled Pinned Locked Moved Unsolved Qt Creator and other tools
5 Posts 3 Posters 2.0k 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.
  • A Offline
    A Offline
    ArtiFAS
    wrote on last edited by
    #1

    Hi,

    I'm making a desktop app on Linux and Windows with Qt.
    I've tried over and over again to make Qt on Windows use OpenSsl (I absolutely need to import a pkcs12) without success.
    It works without any problem on Linux, but for some reason, it doesn't on Windows...

    Here's a code sample of the problem:

    qDebug() << "QSslSocket support ssl?" << QSslSocket::supportsSsl();
        qDebug() << "QSslSocket::sslLibraryBuildVersion: " << QSslSocket::sslLibraryBuildVersionString();
    
    	_socket = new QSslSocket(this);
    
    	QSslConfiguration config;
    	QFile pkcs(path + "/ca.pfx");
    
    	pkcs.open(QFile::ReadOnly);
    	QSslKey key;
    	QSslCertificate caCert;
    
    	static bool import = QSslCertificate::importPkcs12(&pkcs, &key, &caCert);
    

    This code gives these outputs:

    QSslSocket support ssl? true
    QSslSocket::sslLibraryBuildVersion:  "Secure Channel (NTDDI: 0xA00000B)"
    qt.network.ssl: The backend "schannel" cannot read PKCS12 format
    qt.network.ssl: Available TLS backend does not support PKCS12
    

    I've tried to configure my CMakeLists.txt to force OpenSsl with these lines:

    find_package(OpenSSL REQUIRED)
    
    ...
    
    target_link_libraries(MyApp OpenSSL::SSL OpenSSL::Crypto)
    target_include_directories(MyApp PRIVATE ${OPENSSL_INCLUDE_DIR})
    

    Nothing works, I still have the same outputs.

    I also tried the configure script with -I and -L option, but couldn't make it run (always had cmake and MinGW errors).

    I must say that I use CLion to develop my app, so I don't have a .pro file.

    Is there any way to force OpenSsl in Qt on a Windows machine?

    Thanks!

    sierdzioS 1 Reply Last reply
    0
    • A ArtiFAS

      Hi,

      I'm making a desktop app on Linux and Windows with Qt.
      I've tried over and over again to make Qt on Windows use OpenSsl (I absolutely need to import a pkcs12) without success.
      It works without any problem on Linux, but for some reason, it doesn't on Windows...

      Here's a code sample of the problem:

      qDebug() << "QSslSocket support ssl?" << QSslSocket::supportsSsl();
          qDebug() << "QSslSocket::sslLibraryBuildVersion: " << QSslSocket::sslLibraryBuildVersionString();
      
      	_socket = new QSslSocket(this);
      
      	QSslConfiguration config;
      	QFile pkcs(path + "/ca.pfx");
      
      	pkcs.open(QFile::ReadOnly);
      	QSslKey key;
      	QSslCertificate caCert;
      
      	static bool import = QSslCertificate::importPkcs12(&pkcs, &key, &caCert);
      

      This code gives these outputs:

      QSslSocket support ssl? true
      QSslSocket::sslLibraryBuildVersion:  "Secure Channel (NTDDI: 0xA00000B)"
      qt.network.ssl: The backend "schannel" cannot read PKCS12 format
      qt.network.ssl: Available TLS backend does not support PKCS12
      

      I've tried to configure my CMakeLists.txt to force OpenSsl with these lines:

      find_package(OpenSSL REQUIRED)
      
      ...
      
      target_link_libraries(MyApp OpenSSL::SSL OpenSSL::Crypto)
      target_include_directories(MyApp PRIVATE ${OPENSSL_INCLUDE_DIR})
      

      Nothing works, I still have the same outputs.

      I also tried the configure script with -I and -L option, but couldn't make it run (always had cmake and MinGW errors).

      I must say that I use CLion to develop my app, so I don't have a .pro file.

      Is there any way to force OpenSsl in Qt on a Windows machine?

      Thanks!

      sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      @ArtiFAS Secure channel is the built-in alternative on Windows. To make OpenSSL work (I assume you are using prebuilt Qt right?), you need to put OpenSSL libraries next to the .exe file of your application. That's it. Qt even ships with some OpenSSL libs, if you opted to install them they are in <qt installation dir>/tools/OpenSSL.

      If Qt will still favour secure channel, you can compile Qt yourself and force OpenSSL through configure flags. But that, I'd say, is last resort.

      (Z(:^

      A 1 Reply Last reply
      2
      • sierdzioS sierdzio

        @ArtiFAS Secure channel is the built-in alternative on Windows. To make OpenSSL work (I assume you are using prebuilt Qt right?), you need to put OpenSSL libraries next to the .exe file of your application. That's it. Qt even ships with some OpenSSL libs, if you opted to install them they are in <qt installation dir>/tools/OpenSSL.

        If Qt will still favour secure channel, you can compile Qt yourself and force OpenSSL through configure flags. But that, I'd say, is last resort.

        A Offline
        A Offline
        ArtiFAS
        wrote on last edited by
        #3

        @sierdzio Thanks for your reply and sorry about the delay.

        I've tried putting the libssl-xxx.dll and libcrypto-xxx.dll file in the build directory (with the .exe), but it does not seem to work.

        864a7a34-d753-4d2e-b992-36ed8022fb71-image.png

        I still get the same error.

        The CMakeLists.txt is still the same.

        Do you have an idea of something else I could be doing wrong?

        Thanks for the help!

        jsulmJ 1 Reply Last reply
        0
        • A ArtiFAS

          @sierdzio Thanks for your reply and sorry about the delay.

          I've tried putting the libssl-xxx.dll and libcrypto-xxx.dll file in the build directory (with the .exe), but it does not seem to work.

          864a7a34-d753-4d2e-b992-36ed8022fb71-image.png

          I still get the same error.

          The CMakeLists.txt is still the same.

          Do you have an idea of something else I could be doing wrong?

          Thanks for the help!

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @ArtiFAS Are these OpenSSL libs for the same architecture (x86/x86_64)?

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          A 1 Reply Last reply
          0
          • jsulmJ jsulm

            @ArtiFAS Are these OpenSSL libs for the same architecture (x86/x86_64)?

            A Offline
            A Offline
            ArtiFAS
            wrote on last edited by ArtiFAS
            #5

            @jsulm Yes, I run my app on a x64 Windows VM (VirtualBox) and the dlls are for x64 architectures.

            Could it be caused by the Virtual environnement though? I never really explored this branch of the problem...

            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