Skip to content

HTTPS doesn't work on WindowsΒ #24911

@squeek502

Description

@squeek502

Zig Version

0.15.0, 0.16.0-dev.2+07e7cfa35

Steps to Reproduce and Observed Behavior

Follow up to #24732. The regression originally reported here seems to have evaded all the fixes.

This means that any package manager usage with https URLs will fail on Windows hosts. Trying to build zls, for example:

C:\Users\Ryan\Programming\Zig\zls\build.zig.zon:16:20: error: unable to connect to server: TlsInitializationFailed
            .url = "https://github.com/ziglibs/known-folders/archive/92defaee76b07487769ca352fd0ba95bc8b42a2f.tar.gz",
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:\Users\Ryan\Programming\Zig\zls\build.zig.zon:20:20: error: unable to connect to server: TlsInitializationFailed
            .url = "https://github.com/ziglibs/diffz/archive/a20dd1f11b10819a6f570f98b42e1c91e3704357.tar.gz",
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:\Users\Ryan\Programming\Zig\zls\build.zig.zon:24:20: error: unable to connect to server: TlsInitializationFailed
            .url = "https://github.com/zigtools/lsp-kit/archive/4835b9d3d3cf732fe1830189d81f331c68fb3e77.tar.gz",
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

A way to reproduce it without involving the package manager:

const std = @import("std");

pub fn main() !void {
    var debug_allocator: std.heap.DebugAllocator(.{}) = .{};
    defer std.debug.assert(debug_allocator.deinit() == .ok);
    const gpa = debug_allocator.allocator();

    var client: std.http.Client = .{ .allocator = gpa };
    defer client.deinit();

    var body: std.Io.Writer.Allocating = .init(gpa);
    defer body.deinit();

    const res = try client.fetch(.{
        .location = .{ .url = "https://www.ryanliptak.com/misc/notin.html" },
        .method = .GET,
        .response_writer = &body.writer,
    });

    std.debug.print("{}\n", .{res.status});
}
error: TlsInitializationFailed
C:\Users\Ryan\Programming\Zig\zig\lib\std\crypto\aes_gcm.zig:108:17: 0x7ff7489a5656 in decrypt (httpclient_zcu.obj)
                return error.AuthenticationFailed;
                ^
C:\Users\Ryan\Programming\Zig\zig\lib\std\crypto\tls\Client.zig:370:29: 0x7ff7489754fc in init (httpclient_zcu.obj)
                            return error.TlsBadRecordMac;
                            ^
C:\Users\Ryan\Programming\Zig\zig\lib\std\http\Client.zig:342:25: 0x7ff7488de1cf in create (httpclient_zcu.obj)
                ) catch return error.TlsInitializationFailed,
                        ^
C:\Users\Ryan\Programming\Zig\zig\lib\std\http\Client.zig:1450:24: 0x7ff7488cea3f in connectTcpOptions (httpclient_zcu.obj)
            const tc = try Connection.Tls.create(client, proxied_host, proxied_port, stream);
                       ^
C:\Users\Ryan\Programming\Zig\zig\lib\std\http\Client.zig:1408:5: 0x7ff7488cec3b in connectTcp (httpclient_zcu.obj)
    return connectTcpOptions(client, .{ .host = host, .port = port, .protocol = protocol });
    ^
C:\Users\Ryan\Programming\Zig\zig\lib\std\http\Client.zig:1583:14: 0x7ff7488c7aa0 in connect (httpclient_zcu.obj)
    } orelse return client.connectTcp(host, port, protocol);
             ^
C:\Users\Ryan\Programming\Zig\zig\lib\std\http\Client.zig:1699:18: 0x7ff7488c27d7 in request (httpclient_zcu.obj)
        break :c try client.connect(host_name, uriPort(uri, protocol), protocol);
                 ^
C:\Users\Ryan\Programming\Zig\zig\lib\std\http\Client.zig:1789:15: 0x7ff7488beab9 in fetch (httpclient_zcu.obj)
    var req = try request(client, method, uri, .{
              ^
C:\Users\Ryan\Programming\Zig\tmp\httpclient.zig:14:17: 0x7ff7488be5df in main (httpclient_zcu.obj)
    const res = try client.fetch(.{
                ^

Expected Behavior

HTTPS works on Windows hosts

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behavioros-windowsregressionIt worked in a previous version of Zig, but stopped working.standard libraryThis issue involves writing Zig code for the standard library.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions