2020-01-18 11:38:21 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
*
|
2021-04-22 11:24:48 +03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 11:38:21 +03:00
|
|
|
*/
|
|
|
|
|
2021-08-31 11:19:20 +03:00
|
|
|
#include <AK/OwnPtr.h>
|
2020-02-06 17:04:03 +03:00
|
|
|
#include <LibCore/EventLoop.h>
|
|
|
|
#include <LibCore/LocalServer.h>
|
2021-11-23 12:59:50 +03:00
|
|
|
#include <LibCore/System.h>
|
2021-12-06 20:11:05 +03:00
|
|
|
#include <LibIPC/SingleServer.h>
|
2021-11-23 12:41:57 +03:00
|
|
|
#include <LibMain/Main.h>
|
2020-10-30 11:27:32 +03:00
|
|
|
#include <LibTLS/Certificate.h>
|
2022-02-25 13:18:30 +03:00
|
|
|
#include <RequestServer/ConnectionFromClient.h>
|
2021-04-23 23:45:52 +03:00
|
|
|
#include <RequestServer/GeminiProtocol.h>
|
|
|
|
#include <RequestServer/HttpProtocol.h>
|
|
|
|
#include <RequestServer/HttpsProtocol.h>
|
2021-10-23 22:42:07 +03:00
|
|
|
#include <signal.h>
|
2019-11-23 23:45:33 +03:00
|
|
|
|
2021-11-23 12:41:57 +03:00
|
|
|
ErrorOr<int> serenity_main(Main::Arguments)
|
2019-11-23 23:45:33 +03:00
|
|
|
{
|
2022-02-09 22:42:56 +03:00
|
|
|
if constexpr (TLS_SSL_KEYLOG_DEBUG)
|
|
|
|
TRY(Core::System::pledge("stdio inet accept unix cpath wpath rpath sendfd recvfd sigaction"));
|
|
|
|
else
|
|
|
|
TRY(Core::System::pledge("stdio inet accept unix rpath sendfd recvfd sigaction"));
|
|
|
|
|
2022-07-04 19:04:00 +03:00
|
|
|
#ifdef SIGINFO
|
2021-10-01 20:59:51 +03:00
|
|
|
signal(SIGINFO, [](int) { RequestServer::ConnectionCache::dump_jobs(); });
|
2022-07-04 19:04:00 +03:00
|
|
|
#endif
|
2022-02-09 22:42:56 +03:00
|
|
|
|
|
|
|
if constexpr (TLS_SSL_KEYLOG_DEBUG)
|
|
|
|
TRY(Core::System::pledge("stdio inet accept unix cpath wpath rpath sendfd recvfd"));
|
|
|
|
else
|
|
|
|
TRY(Core::System::pledge("stdio inet accept unix rpath sendfd recvfd"));
|
2021-10-01 20:59:51 +03:00
|
|
|
|
2020-10-30 11:27:32 +03:00
|
|
|
// Ensure the certificates are read out here.
|
2024-02-05 19:34:51 +03:00
|
|
|
// FIXME: Allow specifying extra certificates on the command line, or in other configuration.
|
2020-12-21 02:09:48 +03:00
|
|
|
[[maybe_unused]] auto& certs = DefaultRootCACertificates::the();
|
2020-10-30 11:27:32 +03:00
|
|
|
|
2020-02-02 14:34:39 +03:00
|
|
|
Core::EventLoop event_loop;
|
2020-01-17 13:12:06 +03:00
|
|
|
// FIXME: Establish a connection to LookupServer and then drop "unix"?
|
2021-11-23 12:59:50 +03:00
|
|
|
TRY(Core::System::unveil("/tmp/portal/lookup", "rw"));
|
2022-01-23 20:01:59 +03:00
|
|
|
TRY(Core::System::unveil("/etc/timezone", "r"));
|
2022-02-09 22:42:56 +03:00
|
|
|
if constexpr (TLS_SSL_KEYLOG_DEBUG)
|
|
|
|
TRY(Core::System::unveil("/home/anon", "rwc"));
|
2021-11-23 12:59:50 +03:00
|
|
|
TRY(Core::System::unveil(nullptr, nullptr));
|
2020-05-04 19:48:20 +03:00
|
|
|
|
2021-08-31 11:19:20 +03:00
|
|
|
[[maybe_unused]] auto gemini = make<RequestServer::GeminiProtocol>();
|
|
|
|
[[maybe_unused]] auto http = make<RequestServer::HttpProtocol>();
|
|
|
|
[[maybe_unused]] auto https = make<RequestServer::HttpsProtocol>();
|
2020-07-06 14:27:25 +03:00
|
|
|
|
2022-02-25 13:18:30 +03:00
|
|
|
auto client = TRY(IPC::take_over_accepted_client_from_system_server<RequestServer::ConnectionFromClient>());
|
2021-12-06 20:11:05 +03:00
|
|
|
|
2021-09-05 20:31:39 +03:00
|
|
|
auto result = event_loop.exec();
|
|
|
|
|
|
|
|
// FIXME: We exit instead of returning, so that protocol destructors don't get called.
|
|
|
|
// The Protocol base class should probably do proper de-registration instead of
|
|
|
|
// just VERIFY_NOT_REACHED().
|
|
|
|
exit(result);
|
2019-11-23 23:45:33 +03:00
|
|
|
}
|