1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 19:17:44 +00:00

ProtocolServer+LibTLS: Pipe certificate requests from LibTLS to clients

This makes gemini.circumlunar.space (and some more gemini pages) work
again :^)
This commit is contained in:
AnotherTest 2020-08-02 05:27:42 +04:30 committed by Andreas Kling
parent 9d3ffa096a
commit 97256ad977
22 changed files with 161 additions and 3 deletions

View file

@ -68,6 +68,13 @@ bool Client::stop_download(Badge<Download>, Download& download)
return send_sync<Messages::ProtocolServer::StopDownload>(download.id())->success();
}
bool Client::set_certificate(Badge<Download>, Download& download, String certificate, String key)
{
if (!m_downloads.contains(download.id()))
return false;
return send_sync<Messages::ProtocolServer::SetCertificate>(download.id(), move(certificate), move(key))->success();
}
void Client::handle(const Messages::ProtocolClient::DownloadFinished& message)
{
RefPtr<Download> download;
@ -85,4 +92,13 @@ void Client::handle(const Messages::ProtocolClient::DownloadProgress& message)
}
}
OwnPtr<Messages::ProtocolClient::CertificateRequestedResponse> Client::handle(const Messages::ProtocolClient::CertificateRequested& message)
{
if (auto download = const_cast<Download*>(m_downloads.get(message.download_id()).value_or(nullptr))) {
download->did_request_certificates({});
}
return make<Messages::ProtocolClient::CertificateRequestedResponse>();
}
}

View file

@ -46,14 +46,15 @@ public:
bool is_supported_protocol(const String&);
RefPtr<Download> start_download(const String& url, const HashMap<String, String>& request_headers = {});
bool stop_download(Badge<Download>, Download&);
bool set_certificate(Badge<Download>, Download&, String, String);
private:
Client();
virtual void handle(const Messages::ProtocolClient::DownloadProgress&) override;
virtual void handle(const Messages::ProtocolClient::DownloadFinished&) override;
virtual OwnPtr<Messages::ProtocolClient::CertificateRequestedResponse> handle(const Messages::ProtocolClient::CertificateRequested&) override;
HashMap<i32, RefPtr<Download>> m_downloads;
};

View file

@ -67,4 +67,14 @@ void Download::did_progress(Badge<Client>, Optional<u32> total_size, u32 downloa
if (on_progress)
on_progress(total_size, downloaded_size);
}
void Download::did_request_certificates(Badge<Client>)
{
if (on_certificate_requested) {
auto result = on_certificate_requested();
if (!m_client->set_certificate({}, *this, result.certificate, result.key)) {
dbg() << "Download: set_certificate failed";
}
}
}
}

View file

@ -40,6 +40,11 @@ class Client;
class Download : public RefCounted<Download> {
public:
struct CertificateAndKey {
String certificate;
String key;
};
static NonnullRefPtr<Download> create_from_id(Badge<Client>, Client& client, i32 download_id)
{
return adopt(*new Download(client, download_id));
@ -50,9 +55,11 @@ public:
Function<void(bool success, const ByteBuffer& payload, RefPtr<SharedBuffer> payload_storage, const HashMap<String, String, CaseInsensitiveStringTraits>& response_headers, Optional<u32> status_code)> on_finish;
Function<void(Optional<u32> total_size, u32 downloaded_size)> on_progress;
Function<CertificateAndKey()> on_certificate_requested;
void did_finish(Badge<Client>, bool success, Optional<u32> status_code, u32 total_size, i32 shbuf_id, const IPC::Dictionary& response_headers);
void did_progress(Badge<Client>, Optional<u32> total_size, u32 downloaded_size);
void did_request_certificates(Badge<Client>);
private:
explicit Download(Client&, i32 download_id);