Skip to content

Commit

Permalink
WebContent+WebWorker: Use custom certificate paths with Qt networking
Browse files Browse the repository at this point in the history
This change adds a `--certificate` option to both WebContent and
WebWorker, which allows one or more custom root certificate paths to be
specified. Certificates are then loaded from these paths when Qt
networking is used.

This allows WPT tests that require a https connecion to be run locally
with Qt networking.
  • Loading branch information
tcl3 committed Jul 10, 2024
1 parent 772d64a commit 4d4b401
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
11 changes: 10 additions & 1 deletion Ladybird/Qt/RequestManagerQt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,24 @@
*/

#include "RequestManagerQt.h"
#include "StringUtils.h"
#include "WebSocketImplQt.h"
#include "WebSocketQt.h"
#include <QNetworkCookie>

namespace Ladybird {

RequestManagerQt::RequestManagerQt()
RequestManagerQt::RequestManagerQt(Vector<ByteString> const& certificate_paths)
{
m_qnam = new QNetworkAccessManager(this);
auto ssl_configuration = QSslConfiguration::defaultConfiguration();
ssl_configuration.setPeerVerifyMode(QSslSocket::VerifyNone);
for (auto const& certificate_path : certificate_paths) {
auto certificates = QSslCertificate::fromPath(qstring_from_ak_string(certificate_path));
for (auto const& certificate : certificates)
ssl_configuration.addCaCertificate(certificate);
}
QSslConfiguration::setDefaultConfiguration(ssl_configuration);

QObject::connect(m_qnam, &QNetworkAccessManager::finished, this, &RequestManagerQt::reply_finished);
}
Expand Down
6 changes: 3 additions & 3 deletions Ladybird/Qt/RequestManagerQt.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ class RequestManagerQt
, public Web::ResourceLoaderConnector {
Q_OBJECT
public:
static NonnullRefPtr<RequestManagerQt> create()
static NonnullRefPtr<RequestManagerQt> create(Vector<ByteString> const& certificate_paths)
{
return adopt_ref(*new RequestManagerQt());
return adopt_ref(*new RequestManagerQt(certificate_paths));
}

virtual ~RequestManagerQt() override { }
Expand All @@ -34,7 +34,7 @@ private slots:
void reply_finished(QNetworkReply*);

private:
RequestManagerQt();
explicit RequestManagerQt(Vector<ByteString> const& certificate_paths);

class Request
: public Web::ResourceLoaderConnectorRequest {
Expand Down
3 changes: 2 additions & 1 deletion Ladybird/WebContent/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
args_parser.add_option(is_layout_test_mode, "Is layout test mode", "layout-test-mode");
args_parser.add_option(expose_internals_object, "Expose internals object", "expose-internals-object");
args_parser.add_option(use_lagom_networking, "Enable Lagom servers for networking", "use-lagom-networking");
args_parser.add_option(certificates, "Path to a certificate file", "certificate", 'C', "certificate");
args_parser.add_option(use_skia_painter, "Enable Skia painter", "use-skia-painting");
args_parser.add_option(wait_for_debugger, "Wait for debugger", "wait-for-debugger");
args_parser.add_option(mach_server_name, "Mach server name", "mach-server-name", 0, "mach_server_name");
Expand Down Expand Up @@ -150,7 +151,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)

#if defined(HAVE_QT)
if (!use_lagom_networking)
Web::ResourceLoader::initialize(Ladybird::RequestManagerQt::create());
Web::ResourceLoader::initialize(Ladybird::RequestManagerQt::create(certificates));
else
#endif
TRY(initialize_lagom_networking(request_server_socket));
Expand Down
4 changes: 3 additions & 1 deletion Ladybird/WebWorker/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,14 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)

int request_server_socket { -1 };
StringView serenity_resource_root;
Vector<ByteString> certificates;
bool use_lagom_networking { false };

Core::ArgsParser args_parser;
args_parser.add_option(request_server_socket, "File descriptor of the request server socket", "request-server-socket", 's', "request-server-socket");
args_parser.add_option(serenity_resource_root, "Absolute path to directory for serenity resources", "serenity-resource-root", 'r', "serenity-resource-root");
args_parser.add_option(use_lagom_networking, "Enable Lagom servers for networking", "use-lagom-networking");
args_parser.add_option(certificates, "Path to a certificate file", "certificate", 'C', "certificate");
args_parser.parse(arguments);

#if defined(HAVE_QT)
Expand All @@ -61,7 +63,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)

#if defined(HAVE_QT)
if (!use_lagom_networking)
Web::ResourceLoader::initialize(Ladybird::RequestManagerQt::create());
Web::ResourceLoader::initialize(Ladybird::RequestManagerQt::create(certificates));
else
#endif
TRY(initialize_lagom_networking(request_server_socket));
Expand Down

0 comments on commit 4d4b401

Please sign in to comment.