mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 19:47:34 +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
|
@ -24,36 +24,26 @@ void TLSv12WebSocketConnectionImpl::connect(ConnectionInfo const& connection)
|
|||
VERIFY(on_connected);
|
||||
VERIFY(on_connection_error);
|
||||
VERIFY(on_ready_to_read);
|
||||
m_socket = TLS::TLSv12::construct(this);
|
||||
m_socket = TLS::TLSv12::connect(connection.url().host(), connection.url().port_or_default()).release_value_but_fixme_should_propagate_errors();
|
||||
|
||||
m_socket->set_root_certificates(DefaultRootCACertificates::the().certificates());
|
||||
m_socket->on_tls_error = [this](TLS::AlertDescription) {
|
||||
on_connection_error();
|
||||
};
|
||||
m_socket->on_tls_ready_to_read = [this](auto&) {
|
||||
m_socket->on_ready_to_read = [this] {
|
||||
on_ready_to_read();
|
||||
};
|
||||
m_socket->set_on_tls_ready_to_write([this](auto& tls) {
|
||||
tls.set_on_tls_ready_to_write(nullptr);
|
||||
on_connected();
|
||||
});
|
||||
m_socket->on_tls_finished = [this] {
|
||||
on_connection_error();
|
||||
};
|
||||
m_socket->on_tls_certificate_request = [](auto&) {
|
||||
// FIXME : Once we handle TLS certificate requests, handle it here as well.
|
||||
};
|
||||
bool success = m_socket->connect(connection.url().host(), connection.url().port_or_default());
|
||||
if (!success) {
|
||||
deferred_invoke([this] {
|
||||
on_connection_error();
|
||||
});
|
||||
}
|
||||
on_connected();
|
||||
}
|
||||
|
||||
bool TLSv12WebSocketConnectionImpl::send(ReadonlyBytes data)
|
||||
{
|
||||
return m_socket->write(data);
|
||||
return m_socket->write_or_error(data);
|
||||
}
|
||||
|
||||
bool TLSv12WebSocketConnectionImpl::can_read_line()
|
||||
|
@ -73,24 +63,24 @@ bool TLSv12WebSocketConnectionImpl::can_read()
|
|||
|
||||
ByteBuffer TLSv12WebSocketConnectionImpl::read(int max_size)
|
||||
{
|
||||
return m_socket->read(max_size);
|
||||
auto buffer = ByteBuffer::create_uninitialized(max_size).release_value_but_fixme_should_propagate_errors();
|
||||
auto nread = m_socket->read(buffer).release_value_but_fixme_should_propagate_errors();
|
||||
return buffer.slice(0, nread);
|
||||
}
|
||||
|
||||
bool TLSv12WebSocketConnectionImpl::eof()
|
||||
{
|
||||
return m_socket->eof();
|
||||
return m_socket->is_eof();
|
||||
}
|
||||
|
||||
void TLSv12WebSocketConnectionImpl::discard_connection()
|
||||
{
|
||||
if (!m_socket)
|
||||
return;
|
||||
m_socket->on_tls_connected = nullptr;
|
||||
m_socket->on_tls_error = nullptr;
|
||||
m_socket->on_tls_finished = nullptr;
|
||||
m_socket->on_tls_certificate_request = nullptr;
|
||||
m_socket->on_ready_to_read = nullptr;
|
||||
remove_child(*m_socket);
|
||||
m_socket = nullptr;
|
||||
}
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ public:
|
|||
private:
|
||||
explicit TLSv12WebSocketConnectionImpl(Core::Object* parent = nullptr);
|
||||
|
||||
RefPtr<TLS::TLSv12> m_socket;
|
||||
OwnPtr<TLS::TLSv12> m_socket;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue