Kelvin Bouma
Kelvin Bouma

Reputation: 326

"TLS support is not available" error when making HTTPS request

So yes, the "TLS support is not available" error. This is to be found at this thread as well. However, the solution mentioned is to install glib-networking. I installed this via msys2. While this does work when working in msys2, it does not work when you're just working in Windows 10.

What I mean by this is if I just double-click the program, it will give off this error. When I run it via msys2, it works. When I run it on Ubuntu it also works. The fault lies with Windows and I would suspect having to either add some DLLs or installing glib-networking in some other way.

Anyway, here is the code where the error occurred (I set C# highlighting b/c it's pretty much the same and Vala highlighting doesn't exist on here):

private static void HTTPSReq(string host, string href, string vars) {
    const uint16 PORT = 443;
        
    try {
        Resolver resolver = Resolver.get_default();
        List<InetAddress> addresses = resolver.lookup_by_name(host, null);
        InetAddress address = addresses.nth_data(0);

        SocketClient client = new SocketClient();
        client.tls = true;
        client.set_tls_validation_flags(TlsCertificateFlags.EXPIRED);
        SocketConnection conn = client.connect(new InetSocketAddress(address, PORT));

        int vars_length = vars.length;

        string message = @"POST $href HTTP/1.1\r\nHost: $host\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: $vars_length\r\n\r\n$vars";
        conn.output_stream.write(message.data);

        DataInputStream response = new DataInputStream(conn.input_stream);
        string line, lastLine = "";

        while ((line = response.read_line().strip()) != null) {
            lastLine = line;
        }

        label.set_text(lastLine);
    } catch (Error e) {
        label.set_text(e.message);
    }
}

e.message is the variable which contains "TLS support is not available"

So how do I make this work?

Upvotes: 2

Views: 1092

Answers (1)

heinrich5991
heinrich5991

Reputation: 2983

You somehow have to make sure that glib-networking is loaded into the process. It's the one providing TLS support to glib.

The error message comes from the dummy TLS module built into glib itself: https://gitlab.gnome.org/GNOME/glib/-/blob/f7d2a58be64282dd5525ee3c92678b8309e9cc62/gio/gdummytlsbackend.c#L196-197

  g_set_error_literal (error, G_TLS_ERROR, G_TLS_ERROR_UNAVAILABLE,
                       _("TLS support is not available"));

Upvotes: 0

Related Questions