Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tls 1.2 decode error for https://cdn.kernel.org #21952

Open
Allar opened this issue Nov 10, 2024 · 0 comments
Open

tls 1.2 decode error for https://cdn.kernel.org #21952

Allar opened this issue Nov 10, 2024 · 0 comments
Labels
bug Observed behavior contradicts documented or intended behavior

Comments

@Allar
Copy link

Allar commented Nov 10, 2024

Zig Version

0.14.0-dev.2198+e5f5229fd

Steps to Reproduce and Observed Behavior

I'm using this function to download files, which is probably not ideal but it seems to work for the most part.

https://github.com/torvalds/linux/archive/refs/tags/v6.11.tar.gz works successfully
https://cdn.kernel.org/pub/linux/kernel/v6.x/linux-6.11.7.tar.xz results in a tls decode error

It would be nice to be able to support downloading from cdn.kernel.org imo.

Opening a specific issue for this url as per #14172 (comment)

pub fn downloadFile(allocator: std.mem.Allocator, uri: std.Uri, destSubPath: []const u8) !void {
    var client: std.http.Client = .{ .allocator = allocator };
    defer client.deinit();

    try client.ca_bundle.rescan(allocator);

    var serverHeaderBuffer: [8192]u8 = undefined;

    var req = try client.open(.GET, uri, .{
        .server_header_buffer = &serverHeaderBuffer,
    });
    defer req.deinit();

    try req.send();
    try req.finish();

    std.log.info("downloading {}", .{uri});

    try req.wait();

    switch (req.response.status) {
        .ok => {},
        else => {
            return FetchError.BadResponse;
        },
    }

    const bodyBufferSize = 4096;

    // create br with bodyBufferSize?
    var br = std.io.bufferedReader(req.reader());
    const r = br.reader();

    var bodyBuf: [bodyBufferSize]u8 = undefined;

    var readBytes = try r.read(&bodyBuf);

    if (readBytes <= 0) {
        return FetchError.NoData;
    }

    const file = try std.fs.cwd().createFile(destSubPath, .{});
    defer file.close();

    var bw = std.io.bufferedWriter(file.writer());

    while (readBytes > 0) {
        _ = try bw.write(bodyBuf[0..readBytes]);
        readBytes = try r.read(&bodyBuf);
    }

    try bw.flush();
}

Expected Behavior

For the http client to negotiate and download the file using the kernel.org url as it does for the github url.

@Allar Allar added the bug Observed behavior contradicts documented or intended behavior label Nov 10, 2024
@Allar Allar changed the title zls 1.2 decode error for https://cdn.kernel.org tls 1.2 decode error for https://cdn.kernel.org Nov 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Observed behavior contradicts documented or intended behavior
Projects
None yet
Development

No branches or pull requests

1 participant