Павел Дорофеев
May 29, 2022, 9:28 p.m.

How to implement TLSv1.2 on Qt 4.8.1

Initially, QSsl in Qt 4.8.1 (released about 13 years ago) used only the maximum of TLS v1.0.

Today is 2022 and Tls v1.0 and v1.1 are being blocked by almost every decent site on the internet.

Qt in QSsl uses the open library openssl.


TLS v1.2 appears in openssl version 1.0.2.

Building the openssl 1.0.2 libraries is not a problem both dynamically and statically (ssleay32.dll/lib, libeay32.dll/lib).

But how to use them in Qt 4.8.1 so that the connection occurs via Tlsv1.2 is not a trivial task (at first glance).

What to do? You need to study the openssl source code to understand how Tls1.2 is called first.

And it turns out that everything is actually not difficult, since the openssl developers did not change the general logic of the sources. Just in the right place in the qsslsocket_openssl.cpp file, you need to create a context for connecting through the appropriate function variant:

  1. switch (configuration.protocol) {
  2. case QSsl::SslV2:
  3. #ifndef OPENSSL_NO_SSL2
  4. ctx = SSL_CTX_new(client ? SSLv2_client_method() : SSLv2_server_method());
  5. #else
  6. ctx = 0; // SSL 2 not supported by the system, but chosen deliberately -> error
  7. #endif
  8. break;
  9. case QSsl::SslV3:
  10.  
  11. #ifndef OPENSSL_NO_SSL3 //++
  12. ctx = SSL_CTX_new(client ? SSLv3_client_method() : SSLv3_server_method());
  13. #else
  14. ctx = 0; // SSL 3 not supported by the system, but chosen deliberately -> error
  15. #endif
  16. break;
  17.  
  18. case QSsl::SecureProtocols: // SslV2 will be disabled below
  19. case QSsl::TlsV1SslV3: // SslV2 will be disabled below
  20. case QSsl::AnyProtocol:
  21. default:
  22. //--ctx = q_SSL_CTX_new(client ? q_SSLv23_client_method() : q_SSLv23_server_method());
  23. //--ctx = SSL_CTX_new(client ? SSLv23_client_method() : SSLv23_server_method());
  24. ctx = SSL_CTX_new(client ? TLSv1_2_client_method() : TLSv1_2_server_method());
  25. break; //++
  26.  
  27. case QSsl::TlsV1:
  28. ctx = SSL_CTX_new(client ? TLSv1_client_method() : TLSv1_server_method());
  29. break;
  30. }

In general, and all that is needed.

By article asked0question(s)

1

Comments

Only authorized users can post comments.
Please, Log in or Sign up
  • Last comments
  • Evgenii Legotckoi
    March 9, 2025, 9:02 p.m.
    К сожалению, я этого подсказать не могу, поскольку у меня нет необходимости в обходе блокировок и т.д. Поэтому я и не задавался решением этой проблемы. Ну выглядит так, что вам действитель…
  • VP
    March 9, 2025, 4:14 p.m.
    Здравствуйте! Я устанавливал Qt6 из исходников а также Qt Creator по отдельности. Все компоненты, связанные с разработкой для Android, установлены. Кроме одного... Когда пытаюсь скомпилиров…
  • ИМ
    Nov. 22, 2024, 9:51 p.m.
    Добрый вечер Евгений! Я сделал себе авторизацию аналогичную вашей, все работает, кроме возврата к предидущей странице. Редеректит всегда на главную, хотя в логах сервера вижу запросы на правильн…
  • Evgenii Legotckoi
    Oct. 31, 2024, 11:37 p.m.
    Добрый день. Да, можно. Либо через такие же плагины, либо с постобработкой через python библиотеку Beautiful Soup
  • A
    Oct. 19, 2024, 5:19 p.m.
    Подскажите как это запустить? Я не шарю в программировании и кодинге. Скачал и установаил Qt, но куча ошибок выдается и не запустить. А очень надо fb3 переконвертировать в html