@@ -23,14 +23,17 @@ namespace ssl = boost::asio::ssl;
2323using tcp = boost::asio::ip::tcp;
2424
2525std::string get_ssl_certificate (const std::string& host) {
26+ bool status = true ;
27+ std::string cert_buffer;
2628 boost::asio::io_context io_context;
2729
2830 // Use SSLv23 context (it's compatible with all versions of SSL/TLS)
2931 ssl::context ssl_context (ssl::context::sslv23);
3032
31- // Restrict supported protocols to TLSv1.3 and TLSv1.2, these are no no
33+ // Restrict supported protocol to TLSv1.3
3234 ssl_context.set_options (ssl::context::no_sslv2 | ssl::context::no_sslv3);
3335 ssl_context.set_options (ssl::context::no_tlsv1 | ssl::context::no_tlsv1_1);
36+ ssl_context.set_options (ssl::context::no_tlsv1_2);
3437
3538 // Resolver for HTTPS (default port 443)
3639 tcp::resolver resolver (io_context);
@@ -44,33 +47,34 @@ std::string get_ssl_certificate(const std::string& host) {
4447 stream.handshake (ssl::stream_base::client);
4548 } catch (const boost::system::system_error& e) {
4649 std::cerr << " SSL handshake failed: " << e.what () << std::endl;
47- return " " ;
50+ status = false ;
4851 }
4952
50- // Get certificate
51- X509* cert = SSL_get_peer_certificate (stream.native_handle ());
52- if (!cert) {
53- std::cerr << " No certificate found." << std::endl;
54- return " " ;
55- }
56-
57- // Verify the certificate matches the host
58- if (X509_check_host (cert, host.c_str (), host.length (), 0 , nullptr ) != 1 ) {
59- std::cerr << " Hostname verification failed." << std::endl;
53+ if (status) {
54+ // Get certificate
55+ X509* cert = SSL_get_peer_certificate (stream.native_handle ());
56+ if (!cert) {
57+ std::cerr << " No certificate found." << std::endl;
58+ status = false ;
59+ }
60+ if (status) {
61+ // Verify the certificate matches the host
62+ if (X509_check_host (
63+ cert, host.c_str (), host.length (), 0 , nullptr ) != 1 ) {
64+ std::cerr << " Hostname verification failed." << std::endl;
65+ status = false ;
66+ }
67+ if (status) {
68+ BIO* bio = BIO_new (BIO_s_mem ());
69+ PEM_write_bio_X509 (bio, cert);
70+ char * cert_str = nullptr ;
71+ qint64 cert_len = BIO_get_mem_data (bio, &cert_str);
72+ cert_buffer = std::string (cert_str, cert_len);
73+ BIO_free (bio);
74+ }
75+ }
6076 X509_free (cert);
61- return " " ;
6277 }
63-
64- BIO* bio = BIO_new (BIO_s_mem ());
65- PEM_write_bio_X509 (bio, cert);
66- char * cert_str = nullptr ;
67- qint64 cert_len = BIO_get_mem_data (bio, &cert_str);
68- std::string cert_buffer (cert_str, cert_len);
69-
70- // Clean up
71- BIO_free (bio);
72- X509_free (cert);
73-
7478 return cert_buffer;
7579}
7680
@@ -96,25 +100,6 @@ int Downloader::getStatus() {
96100 return m_status;
97101}
98102
99- void Downloader::saveToFile (const QByteArray& data, const QString& filePath) {
100- QFileInfo fileInfo (filePath);
101-
102- if (fileInfo.exists () && !fileInfo.isFile ()) {
103- qDebug () << " Error: The zip path is not a regular file." << filePath;
104- return ;
105- }
106-
107- QFile file (filePath);
108-
109- if (file.open (QIODevice::WriteOnly) == true ) { // flawfinder: ignore
110- file.write (data);
111- file.close ();
112- qDebug () << " Data saved to file:" << filePath;
113- } else {
114- qDebug () << " Error saving data to file:" << file.errorString ();
115- }
116- }
117-
118103void Downloader::run () {
119104 if (m_url.isEmpty () || m_file.isEmpty () || m_levelDir.isEmpty ()) {
120105 m_status = 3 ; // object error
0 commit comments