From 3ca06362edba1454619e24ff6617ba7d6e998848 Mon Sep 17 00:00:00 2001 From: yggverse Date: Thu, 21 Nov 2024 21:48:58 +0200 Subject: [PATCH] define SocketConnectable to resolve SNI requirement --- src/app/browser/window/tab/item/page.rs | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/app/browser/window/tab/item/page.rs b/src/app/browser/window/tab/item/page.rs index 0aed7fdb..f49db94b 100644 --- a/src/app/browser/window/tab/item/page.rs +++ b/src/app/browser/window/tab/item/page.rs @@ -21,8 +21,8 @@ use crate::Profile; use gtk::{ gdk_pixbuf::Pixbuf, gio::{ - Cancellable, IOStream, SocketClient, SocketClientEvent, SocketConnectable, SocketProtocol, - TlsCertificate, TlsClientConnection, + Cancellable, IOStream, NetworkAddress, SocketClient, SocketClientEvent, SocketConnectable, + SocketProtocol, TlsCertificate, TlsClientConnection, }, glib::{ gformat, Bytes, GString, Priority, Regex, RegexCompileFlags, RegexMatchFlags, Uri, @@ -428,11 +428,12 @@ impl Page { // Stream wrapper for TLS connections fn auth( connection: impl IsA, + connectable: impl IsA, certificate: Option, ) -> impl IsA { if let Some(certificate) = certificate { let tls_connection = - TlsClientConnection::new(&connection, None::<&SocketConnectable>).unwrap(); // @TODO handle + TlsClientConnection::new(&connection, Some(&connectable)).unwrap(); // @TODO handle tls_connection.set_certificate(&certificate); tls_connection.connect_accept_certificate(move |_, _, _| true); // @TODO manual validation tls_connection.upcast::() @@ -504,15 +505,18 @@ impl Page { } }); + // https://geminiprotocol.net/docs/protocol-specification.gmi#server-name-indication + let connectable = NetworkAddress::new(&uri.host().unwrap(), 1965); + // Create connection - client.clone().connect_to_uri_async( - url.clone().as_str(), - 1965, + client.clone().connect_async( + &connectable.clone(), Some(&cancellable.clone()), move |connect| match connect { Ok(connection) => { + // Encrypt stream using authorization TLS - let stream = auth(connection, certificate); + let stream = auth(connection, connectable, certificate); // Send request stream.output_stream().write_bytes_async(