From 068539c85a473750977b810dbe128f9c213e5fd9 Mon Sep 17 00:00:00 2001 From: Vadim Troshchinskiy Shmelev Date: Tue, 11 Feb 2025 13:27:16 +0100 Subject: [PATCH] Add ability to ignore SSL errors --- qtermwidget/CMakeLists.txt | 2 +- src/main.cpp | 10 ++++++++++ src/mainwindow.cpp | 16 ++++++++++++++++ src/mainwindow.h | 2 ++ src/ogcommandline.h | 6 ++++++ 5 files changed, 35 insertions(+), 1 deletion(-) diff --git a/qtermwidget/CMakeLists.txt b/qtermwidget/CMakeLists.txt index 09a1e35..c325923 100644 --- a/qtermwidget/CMakeLists.txt +++ b/qtermwidget/CMakeLists.txt @@ -53,7 +53,7 @@ else() find_package(Qt5LinguistTools "${QT_MINIMUM_VERSION}" REQUIRED) endif() -find_package(lxqt-build-tools ${LXQTBT_MINIMUM_VERSION} REQUIRED) +find_package(lxqt2-build-tools ${LXQTBT_MINIMUM_VERSION} REQUIRED) if(USE_UTF8PROC) find_package(Utf8Proc REQUIRED) diff --git a/src/main.cpp b/src/main.cpp index 5bde173..f606106 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -53,6 +53,12 @@ int main(int argc, char *argv[]) QCommandLineOption disableWebSecurityOption("disable-web-security", "Disable web security and allow custom URL schemes"); parser.addOption(disableWebSecurityOption); + QCommandLineOption noSandboxOption("no-sandbox", "Disable Chromium sandbox to allow running as root"); + parser.addOption(noSandboxOption); + + QCommandLineOption ignoreSslErrors("ignore-ssl-errors", "Ignore SSL certificate errors"); + parser.addOption(ignoreSslErrors); + QCommandLineOption helpOption = parser.addHelpOption(); OGCommandLineOptions &options = OGCommandLineOptions::getInstance(); @@ -76,6 +82,10 @@ int main(int argc, char *argv[]) options.setNewTabBehavior(OGCommandLineOptions::NewTabBehavior::Ignore); } + if (parser.isSet(ignoreSslErrors)) { + options.setIgnoreSslErrors(true); + } + QStringList positional = parser.positionalArguments(); if ( positional.length() > 0) { options.setUrl( positional[0 ] ); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 6f825e3..c54824f 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -127,6 +127,7 @@ MainWindow::MainWindow(QWidget *parent) connect(m_web,SIGNAL(loadFinished(bool)),this,SLOT(slotWebLoadFinished(bool))); connect(m_web,SIGNAL(loadProgress(int)),this,SLOT(slotWebLoadProgress(int))); connect(m_web,SIGNAL(urlChanged(const QUrl&)),this,SLOT(slotUrlChanged(const QUrl&))); + // Ignore SSL errors. @@ -180,6 +181,9 @@ MainWindow::MainWindow(QWidget *parent) //QStringList arguments=QCoreApplication::arguments(); m_web->setPage( new OGWebPage(this)); + connect(m_web->page(), &QWebEnginePage::certificateError, this, &MainWindow::slotCertificateErrors); + + OGCommandLineOptions &options = OGCommandLineOptions::getInstance(); QUrl url = QUrl(options.getUrl()); @@ -341,6 +345,18 @@ void MainWindow::slotSslErrors(QNetworkReply* reply) reply->ignoreSslErrors(); } +void MainWindow::slotCertificateErrors(const QWebEngineCertificateError &certificateError) { + qWarning() << "SSL error:" << certificateError.description(); + + OGCommandLineOptions &options = OGCommandLineOptions::getInstance(); + if (options.getIgnoreSslErrors()) { + qInfo() << "Ignoring SSL errors"; + + auto mutableError = const_cast(certificateError); + mutableError.acceptCertificate(); + } +} + void MainWindow::slotProcessStarted() { startProgressBar(); diff --git a/src/mainwindow.h b/src/mainwindow.h index 995d1b6..6bc6937 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -58,6 +58,8 @@ class MainWindow : public QMainWindow void slotWebLoadFinished(bool ok); void slotWebLoadProgress(int progress); void slotSslErrors(QNetworkReply* reply); + void slotCertificateErrors(const QWebEngineCertificateError &certificateError); + // Funciones que manejan cada vez que el proceso hace algo void slotProcessStarted(); diff --git a/src/ogcommandline.h b/src/ogcommandline.h index 4a6c992..c68e194 100644 --- a/src/ogcommandline.h +++ b/src/ogcommandline.h @@ -35,6 +35,10 @@ class OGCommandLineOptions { NewTabBehavior getNewTabBehavior() const { return _newTabBehavior; } void setNewTabBehavior(NewTabBehavior nt) { _newTabBehavior = nt; } + bool getIgnoreSslErrors() const { return _ignoreSslErrors; } + void setIgnoreSslErrors(bool value) { _ignoreSslErrors = value; } + + private: OGCommandLineOptions() { @@ -42,4 +46,6 @@ private: QString _url; NewTabBehavior _newTabBehavior{ReplacePage}; + + bool _ignoreSslErrors = false; }; \ No newline at end of file