2023-09-15 18:01:23 -06:00
|
|
|
/*
|
2024-10-04 13:19:50 +02:00
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <andreas@ladybird.org>
|
2023-09-15 18:01:23 -06:00
|
|
|
* Copyright (c) 2023, Andrew Kaster <akaster@serenityos.org>
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
*/
|
|
|
|
|
|
2024-08-07 20:55:27 +02:00
|
|
|
#include "LadybirdServiceBase.h"
|
2023-09-15 18:01:23 -06:00
|
|
|
#include <AK/LexicalPath.h>
|
|
|
|
|
#include <AK/OwnPtr.h>
|
|
|
|
|
#include <LibCore/ArgsParser.h>
|
|
|
|
|
#include <LibCore/EventLoop.h>
|
|
|
|
|
#include <LibCore/LocalServer.h>
|
|
|
|
|
#include <LibCore/System.h>
|
|
|
|
|
#include <LibFileSystem/FileSystem.h>
|
|
|
|
|
#include <LibIPC/SingleServer.h>
|
|
|
|
|
#include <LibTLS/Certificate.h>
|
|
|
|
|
#include <RequestServer/ConnectionFromClient.h>
|
|
|
|
|
#include <RequestServer/HttpProtocol.h>
|
|
|
|
|
#include <RequestServer/HttpsProtocol.h>
|
2024-11-09 12:50:33 -05:00
|
|
|
#include <UI/Utilities.h>
|
2023-09-15 18:01:23 -06:00
|
|
|
|
|
|
|
|
// FIXME: Share b/w RequestServer and WebSocket
|
2024-08-07 20:55:27 +02:00
|
|
|
static ErrorOr<ByteString> find_certificates(StringView serenity_resource_root)
|
2023-09-15 18:01:23 -06:00
|
|
|
{
|
2024-05-04 06:08:53 -06:00
|
|
|
auto cert_path = ByteString::formatted("{}/res/ladybird/cacert.pem", serenity_resource_root);
|
2024-02-23 13:40:16 -07:00
|
|
|
if (!FileSystem::exists(cert_path))
|
2024-09-05 15:06:15 +04:00
|
|
|
return Error::from_string_literal("Don't know how to load certs!");
|
2023-09-15 18:01:23 -06:00
|
|
|
return cert_path;
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-04 06:08:53 -06:00
|
|
|
ErrorOr<int> service_main(int ipc_socket)
|
2023-09-15 18:01:23 -06:00
|
|
|
{
|
|
|
|
|
// Ensure the certificates are read out here.
|
2024-07-21 16:50:14 +02:00
|
|
|
DefaultRootCACertificates::set_default_certificate_paths(Vector { TRY(find_certificates(s_ladybird_resource_root)) });
|
2024-07-06 23:12:39 +02:00
|
|
|
[[maybe_unused]] auto& certs = DefaultRootCACertificates::the();
|
2023-09-15 18:01:23 -06:00
|
|
|
|
|
|
|
|
Core::EventLoop event_loop;
|
|
|
|
|
|
2024-03-05 15:15:41 -07:00
|
|
|
RequestServer::HttpProtocol::install();
|
|
|
|
|
RequestServer::HttpsProtocol::install();
|
2023-09-15 18:01:23 -06:00
|
|
|
|
|
|
|
|
auto socket = TRY(Core::LocalSocket::adopt_fd(ipc_socket));
|
|
|
|
|
auto client = TRY(RequestServer::ConnectionFromClient::try_create(move(socket)));
|
|
|
|
|
|
|
|
|
|
return event_loop.exec();
|
|
|
|
|
}
|