I have some draft, but code contain lot of dependencies to present or share entire the app implementation
Here is what I’m doing:
// 1. Init socket
let client = SocketClient::new();
client.set_protocol(SocketProtocol::Tcp);
client.set_tls_validation_flags(TlsCertificateFlags::INSECURE);
client.set_tls(true);
// 2. Create connection
client.connect_to_uri_async(
url.as_str(),
1965,
Some(&cancellable),
move |connect| match connect {
Ok(connection) => {
// 3. Wrap connection
let tls_connection = gtk::gio::TlsClientConnection::new(
&connection,
None::<&SocketConnectable>,
)
.unwrap();
// 4. Apply certificate
tls_connection.set_certificate(
>k::gio::TlsCertificate::from_file("test.pem")
.unwrap(),
);
// 5. Now trying to send request
tls_connection.output_stream().write_bytes_async(
&Bytes::from(gformat!("{url}\r\n").as_bytes()),
Priority::DEFAULT,
Some(&cancellable),
move |request| match request {
// ..
And get this error:
Error performing TLS handshake: An unexpected TLS packet was received
Not sure I understand how to work with self-signed certificates on Glib / Gio level, before successfully connected with PHP API, where just provided certificate with validation disabled (as self-signed) but here not sure how to work, and can’t find any examples in web… Maybe link to some application sources would help… maybe I just connecting incorrect (this construction above work without TlsClientConnection
)
Found also this issue, not sure that’s my luck (Fedora 41)
Doubts about this line also:
client.set_tls_validation_flags(TlsCertificateFlags::INSECURE);
this method marked as deprecated, but without this flag I have another error (as self-signed). Certificate file should be valid anyway, I’ve tested it in another app.
Just want some guide for beginner, or app example, everything found - implementation with non gio crates but I want make app gtk oriented where it is possible, without high-level wrappers, but seems my skills not enough at this point