define SocketConnectable to resolve SNI requirement

This commit is contained in:
yggverse 2024-11-21 21:48:58 +02:00
parent 69142fa60f
commit 3ca06362ed

View File

@ -21,8 +21,8 @@ use crate::Profile;
use gtk::{ use gtk::{
gdk_pixbuf::Pixbuf, gdk_pixbuf::Pixbuf,
gio::{ gio::{
Cancellable, IOStream, SocketClient, SocketClientEvent, SocketConnectable, SocketProtocol, Cancellable, IOStream, NetworkAddress, SocketClient, SocketClientEvent, SocketConnectable,
TlsCertificate, TlsClientConnection, SocketProtocol, TlsCertificate, TlsClientConnection,
}, },
glib::{ glib::{
gformat, Bytes, GString, Priority, Regex, RegexCompileFlags, RegexMatchFlags, Uri, gformat, Bytes, GString, Priority, Regex, RegexCompileFlags, RegexMatchFlags, Uri,
@ -428,11 +428,12 @@ impl Page {
// Stream wrapper for TLS connections // Stream wrapper for TLS connections
fn auth( fn auth(
connection: impl IsA<IOStream>, connection: impl IsA<IOStream>,
connectable: impl IsA<SocketConnectable>,
certificate: Option<TlsCertificate>, certificate: Option<TlsCertificate>,
) -> impl IsA<IOStream> { ) -> impl IsA<IOStream> {
if let Some(certificate) = certificate { if let Some(certificate) = certificate {
let tls_connection = 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.set_certificate(&certificate);
tls_connection.connect_accept_certificate(move |_, _, _| true); // @TODO manual validation tls_connection.connect_accept_certificate(move |_, _, _| true); // @TODO manual validation
tls_connection.upcast::<IOStream>() tls_connection.upcast::<IOStream>()
@ -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 // Create connection
client.clone().connect_to_uri_async( client.clone().connect_async(
url.clone().as_str(), &connectable.clone(),
1965,
Some(&cancellable.clone()), Some(&cancellable.clone()),
move |connect| match connect { move |connect| match connect {
Ok(connection) => { Ok(connection) => {
// Encrypt stream using authorization TLS // Encrypt stream using authorization TLS
let stream = auth(connection, certificate); let stream = auth(connection, connectable, certificate);
// Send request // Send request
stream.output_stream().write_bytes_async( stream.output_stream().write_bytes_async(