mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 07:07:45 +00:00
Userland: Convert TLS::TLSv12 to a Core::Stream::Socket
This commit converts TLS::TLSv12 to a Core::Stream object, and in the process allows TLS to now wrap other Core::Stream::Socket objects. As a large part of LibHTTP and LibGemini depend on LibTLS's interface, this also converts those to support Core::Stream, which leads to a simplification of LibHTTP (as there's no need to care about the underlying socket type anymore). Note that RequestServer now controls the TLS socket options, which is a better place anyway, as RS is the first receiver of the user-requested options (though this is currently not particularly useful).
This commit is contained in:
parent
7a95c451a3
commit
aafc451016
47 changed files with 841 additions and 1157 deletions
|
@ -127,40 +127,15 @@ void ClientConnection::ensure_connection(URL const& url, ::RequestServer::CacheL
|
|||
|
||||
struct {
|
||||
URL const& m_url;
|
||||
void start(NonnullRefPtr<Core::Socket> socket)
|
||||
void start(Core::Stream::Socket& socket)
|
||||
{
|
||||
auto is_tls = is<TLS::TLSv12>(*socket);
|
||||
auto* tls_instance = is_tls ? static_cast<TLS::TLSv12*>(socket.ptr()) : nullptr;
|
||||
|
||||
auto is_connected = false;
|
||||
if (is_tls && tls_instance->is_established())
|
||||
is_connected = true;
|
||||
if (!is_tls && socket->is_connected())
|
||||
is_connected = true;
|
||||
|
||||
VERIFY(!is_connected);
|
||||
|
||||
bool did_connect;
|
||||
if (is_tls) {
|
||||
tls_instance->set_root_certificates(DefaultRootCACertificates::the().certificates());
|
||||
tls_instance->on_tls_connected = [socket = socket.ptr(), url = m_url, tls_instance] {
|
||||
tls_instance->set_on_tls_ready_to_write([socket, url](auto&) {
|
||||
ConnectionCache::request_did_finish(url, socket);
|
||||
});
|
||||
};
|
||||
tls_instance->on_tls_error = [socket = socket.ptr(), url = m_url](auto) {
|
||||
ConnectionCache::request_did_finish(url, socket);
|
||||
};
|
||||
did_connect = tls_instance->connect(m_url.host(), m_url.port_or_default());
|
||||
} else {
|
||||
socket->on_connected = [socket = socket.ptr(), url = m_url]() mutable {
|
||||
ConnectionCache::request_did_finish(url, socket);
|
||||
};
|
||||
did_connect = socket->connect(m_url.host(), m_url.port_or_default());
|
||||
}
|
||||
|
||||
if (!did_connect)
|
||||
ConnectionCache::request_did_finish(m_url, socket);
|
||||
auto is_connected = socket.is_open();
|
||||
VERIFY(is_connected);
|
||||
ConnectionCache::request_did_finish(m_url, &socket);
|
||||
}
|
||||
void fail(Core::NetworkJob::Error error)
|
||||
{
|
||||
dbgln("Pre-connect to {} failed: {}", m_url, Core::to_string(error));
|
||||
}
|
||||
} job { url };
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue