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

networking: delete std.x; add std.crypto.tls and std.http.Client #13980

Merged
merged 59 commits into from
Jan 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
ebcfc86
Compilation: better error message for file not found
andrewrk Dec 11, 2022
cd0d514
remove the experimental std.x namespace
andrewrk Dec 11, 2022
ba44513
std.http reorg; introduce std.crypto.Tls
andrewrk Dec 13, 2022
d2f5d0b
std.crypto.Tls: parse the ServerHello handshake
andrewrk Dec 14, 2022
920e5bc
std.crypto.Tls: discard ChangeCipherSpec messages
andrewrk Dec 14, 2022
595fff7
std.crypto.Tls: decrypting handshake messages
andrewrk Dec 15, 2022
40a8550
std.crypto.Tls: add read/write methods
andrewrk Dec 16, 2022
b97fc43
std.crypto.Tls: client is working against some servers
andrewrk Dec 16, 2022
462b3ed
std.crypto.Tls: handshake fixes
andrewrk Dec 16, 2022
02c33d0
std.crypto.Tls: parse encrypted extensions
andrewrk Dec 16, 2022
93ab8be
extract std.crypto.tls.Client into separate namespace
andrewrk Dec 16, 2022
942b5b4
std.crypto.tls: implement the rest of the cipher suites
andrewrk Dec 17, 2022
8ef4dcd
std.crypto.tls: add some benchmark data points
andrewrk Dec 17, 2022
f6c3a86
std.crypto.tls.Client: remove unnecessary coercion
andrewrk Dec 18, 2022
41f4461
std.crypto.tls.Client: verify the server's Finished message
andrewrk Dec 18, 2022
e2efba7
std.crypto.tls: refactor to remove mutations
andrewrk Dec 19, 2022
7a23778
std.crypto.tls: send a legacy session id
andrewrk Dec 19, 2022
f460c21
std.crypto.tls.Client: avoid hard-coded bytes in key_share
andrewrk Dec 19, 2022
e2c16d0
std.crypto.tls.Client: support secp256r1 for handshake
andrewrk Dec 19, 2022
5d7eca6
std.crypto.tls.Client: fix verify_data for batched handshakes
andrewrk Dec 19, 2022
3237000
std.crypto.tls: rudimentary certificate parsing
andrewrk Dec 19, 2022
bbc0742
introduce std.crypto.CertificateBundle
andrewrk Dec 20, 2022
504070e
std.crypto.CertificateBundle: ignore duplicate certificates
andrewrk Dec 20, 2022
244a97e
std.crypto.tls: certificate signature validation
andrewrk Dec 21, 2022
7ed7bd2
std.crypto.tls: verify the common name matches
andrewrk Dec 21, 2022
22db1e1
std.crypto.CertificateBundle: disable test on WASI
andrewrk Dec 21, 2022
4f9f457
std.crypto.tls: rename HandshakeCipher
andrewrk Dec 21, 2022
29475b4
std.crypto.tls: validate previous certificate
andrewrk Dec 22, 2022
16f936b
std.crypto.tls: handle the certificate_verify message
andrewrk Dec 22, 2022
862ecf2
std.crypto.tls.Client: handle extra data after handshake
andrewrk Dec 22, 2022
7cb535d
std.crypto.tls.Certificate: verify time validity
andrewrk Dec 23, 2022
642a8b0
std.crypto.tls.Certificate: explicit error set for verify
andrewrk Dec 23, 2022
c71c562
remove std.crypto.der
andrewrk Dec 23, 2022
5b8b5f2
add url parsing to the std lib
andrewrk Dec 26, 2022
a1f6a08
std.crypto.Certificate.Bundle: fix 32-bit build
andrewrk Dec 26, 2022
b24f178
std.crypto.tls.Certificate: fix parsing missing subsequent fields
andrewrk Dec 28, 2022
b1cbfa0
std.crypto.Certificate: remove subject_alt_name parsing
andrewrk Dec 28, 2022
5bbedb6
std.crypto.Certificate: support verifying secp384r1 pub keys
andrewrk Dec 28, 2022
ceb211e
std.crypto.tls.Client: handle key_update message
andrewrk Dec 28, 2022
477864d
std.crypto.tls.Client: fix truncation attack vulnerability
andrewrk Dec 28, 2022
21ab991
std.crypto.tls.Client: use enums more
andrewrk Dec 28, 2022
940d368
std.crypto.tls.Client: fix the read function
andrewrk Dec 28, 2022
16af628
std.crypto.tls.Client: support SignatureScheme.ecdsa_secp384r1_sha384
andrewrk Dec 29, 2022
1d20ada
std.crypto.tls.Client: refactor to reduce namespace bloat
andrewrk Dec 29, 2022
7391df2
std.crypto: make proper use of `undefined`
andrewrk Dec 29, 2022
e4a9b19
std.crypto.tls.Client: rework the read function
andrewrk Dec 29, 2022
22e2aaa
crypto.tls: support rsa_pss_rsae_sha256 and fixes
andrewrk Dec 30, 2022
05fee3b
std.crypto.tls.Client: fix eof logic
andrewrk Dec 30, 2022
2d090f6
add std.http.Headers
andrewrk Dec 30, 2022
79b41db
std.crypto.tls: avoid heap allocation
andrewrk Dec 30, 2022
341e68f
std.crypto.tls.Client: remove debug prints
andrewrk Dec 30, 2022
0fb78b1
std.crypto.tls: use a Decoder abstraction
andrewrk Dec 31, 2022
66b07fd
std.crypto.Certificate: bump RSA needed memory
andrewrk Dec 31, 2022
b3c8c38
std.os: add missing handling of ECONNRESET in readv
andrewrk Dec 31, 2022
611a1fd
std.crypto.tls: add API for sending close_notify
andrewrk Dec 31, 2022
3127bd7
std.http.Client: don't send TLS close_notify
andrewrk Dec 31, 2022
97acdee
std.crypto.tls: verify via Subject Alt Name
andrewrk Jan 2, 2023
9ca6d67
std.crypto.tls.Certificate: make the current time a parameter
andrewrk Jan 2, 2023
7178451
std.crypto.tls.Client: make close_notify optional
andrewrk Jan 3, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 98 additions & 0 deletions lib/std/Url.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
scheme: []const u8,
host: []const u8,
path: []const u8,
port: ?u16,

/// TODO: redo this implementation according to RFC 1738. This code is only a
andrewrk marked this conversation as resolved.
Show resolved Hide resolved
/// placeholder for now.
pub fn parse(s: []const u8) !Url {
var scheme_end: usize = 0;
var host_start: usize = 0;
var host_end: usize = 0;
var path_start: usize = 0;
var port_start: usize = 0;
var port_end: usize = 0;
var state: enum {
scheme,
scheme_slash1,
scheme_slash2,
host,
port,
path,
} = .scheme;

for (s) |b, i| switch (state) {
.scheme => switch (b) {
':' => {
state = .scheme_slash1;
scheme_end = i;
},
else => {},
},
.scheme_slash1 => switch (b) {
'/' => {
state = .scheme_slash2;
},
else => return error.InvalidUrl,
},
.scheme_slash2 => switch (b) {
'/' => {
state = .host;
host_start = i + 1;
},
else => return error.InvalidUrl,
},
.host => switch (b) {
':' => {
state = .port;
host_end = i;
port_start = i + 1;
},
'/' => {
state = .path;
host_end = i;
path_start = i;
},
else => {},
},
.port => switch (b) {
'/' => {
port_end = i;
state = .path;
path_start = i;
},
else => {},
},
.path => {},
};

const port_slice = s[port_start..port_end];
const port = if (port_slice.len == 0) null else try std.fmt.parseInt(u16, port_slice, 10);

return .{
.scheme = s[0..scheme_end],
.host = s[host_start..host_end],
.path = s[path_start..],
.port = port,
};
}

const Url = @This();
const std = @import("std.zig");
const testing = std.testing;

test "basic" {
const parsed = try parse("https://ziglang.org/download");
try testing.expectEqualStrings("https", parsed.scheme);
try testing.expectEqualStrings("ziglang.org", parsed.host);
try testing.expectEqualStrings("/download", parsed.path);
try testing.expectEqual(@as(?u16, null), parsed.port);
}

test "with port" {
const parsed = try parse("http://example:1337/");
try testing.expectEqualStrings("http", parsed.scheme);
try testing.expectEqualStrings("example", parsed.host);
try testing.expectEqualStrings("/", parsed.path);
try testing.expectEqual(@as(?u16, 1337), parsed.port);
}
4 changes: 2 additions & 2 deletions lib/std/c.zig
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ pub extern "c" fn sendto(
dest_addr: ?*const c.sockaddr,
addrlen: c.socklen_t,
) isize;
pub extern "c" fn sendmsg(sockfd: c.fd_t, msg: *const std.x.os.Socket.Message, flags: c_int) isize;
pub extern "c" fn sendmsg(sockfd: c.fd_t, msg: *const c.msghdr_const, flags: u32) isize;

pub extern "c" fn recv(sockfd: c.fd_t, arg1: ?*anyopaque, arg2: usize, arg3: c_int) isize;
pub extern "c" fn recvfrom(
Expand All @@ -217,7 +217,7 @@ pub extern "c" fn recvfrom(
noalias src_addr: ?*c.sockaddr,
noalias addrlen: ?*c.socklen_t,
) isize;
pub extern "c" fn recvmsg(sockfd: c.fd_t, msg: *std.x.os.Socket.Message, flags: c_int) isize;
pub extern "c" fn recvmsg(sockfd: c.fd_t, msg: *c.msghdr, flags: u32) isize;

pub extern "c" fn kill(pid: c.pid_t, sig: c_int) c_int;
pub extern "c" fn getdirentries(fd: c.fd_t, buf_ptr: [*]u8, nbytes: usize, basep: *i64) isize;
Expand Down
11 changes: 10 additions & 1 deletion lib/std/c/darwin.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1007,7 +1007,16 @@ pub const sockaddr = extern struct {
data: [14]u8,

pub const SS_MAXSIZE = 128;
pub const storage = std.x.os.Socket.Address.Native.Storage;
pub const storage = extern struct {
andrewrk marked this conversation as resolved.
Show resolved Hide resolved
len: u8 align(8),
family: sa_family_t,
padding: [126]u8 = undefined,

comptime {
assert(@sizeOf(storage) == SS_MAXSIZE);
assert(@alignOf(storage) == 8);
}
};
pub const in = extern struct {
len: u8 = @sizeOf(in),
family: sa_family_t = AF.INET,
Expand Down
14 changes: 12 additions & 2 deletions lib/std/c/dragonfly.zig
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const builtin = @import("builtin");
const std = @import("../std.zig");
const assert = std.debug.assert;
const maxInt = std.math.maxInt;
const iovec = std.os.iovec;

Expand Down Expand Up @@ -476,11 +477,20 @@ pub const CLOCK = struct {

pub const sockaddr = extern struct {
len: u8,
family: u8,
family: sa_family_t,
data: [14]u8,

pub const SS_MAXSIZE = 128;
pub const storage = std.x.os.Socket.Address.Native.Storage;
pub const storage = extern struct {
len: u8 align(8),
family: sa_family_t,
padding: [126]u8 = undefined,

comptime {
assert(@sizeOf(storage) == SS_MAXSIZE);
assert(@alignOf(storage) == 8);
}
};

pub const in = extern struct {
len: u8 = @sizeOf(in),
Expand Down
12 changes: 11 additions & 1 deletion lib/std/c/freebsd.zig
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const std = @import("../std.zig");
const assert = std.debug.assert;
const builtin = @import("builtin");
const maxInt = std.math.maxInt;
const iovec = std.os.iovec;
Expand Down Expand Up @@ -401,7 +402,16 @@ pub const sockaddr = extern struct {
data: [14]u8,

pub const SS_MAXSIZE = 128;
pub const storage = std.x.os.Socket.Address.Native.Storage;
pub const storage = extern struct {
len: u8 align(8),
family: sa_family_t,
padding: [126]u8 = undefined,

comptime {
assert(@sizeOf(storage) == SS_MAXSIZE);
assert(@alignOf(storage) == 8);
}
};

pub const in = extern struct {
len: u8 = @sizeOf(in),
Expand Down
12 changes: 11 additions & 1 deletion lib/std/c/haiku.zig
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const std = @import("../std.zig");
const assert = std.debug.assert;
const builtin = @import("builtin");
const maxInt = std.math.maxInt;
const iovec = std.os.iovec;
Expand Down Expand Up @@ -339,7 +340,16 @@ pub const sockaddr = extern struct {
data: [14]u8,

pub const SS_MAXSIZE = 128;
pub const storage = std.x.os.Socket.Address.Native.Storage;
pub const storage = extern struct {
len: u8 align(8),
family: sa_family_t,
padding: [126]u8 = undefined,

comptime {
assert(@sizeOf(storage) == SS_MAXSIZE);
assert(@alignOf(storage) == 8);
}
};

pub const in = extern struct {
len: u8 = @sizeOf(in),
Expand Down
12 changes: 11 additions & 1 deletion lib/std/c/netbsd.zig
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const std = @import("../std.zig");
const assert = std.debug.assert;
const builtin = @import("builtin");
const maxInt = std.math.maxInt;
const iovec = std.os.iovec;
Expand Down Expand Up @@ -481,7 +482,16 @@ pub const sockaddr = extern struct {
data: [14]u8,

pub const SS_MAXSIZE = 128;
pub const storage = std.x.os.Socket.Address.Native.Storage;
pub const storage = extern struct {
len: u8 align(8),
family: sa_family_t,
padding: [126]u8 = undefined,

comptime {
assert(@sizeOf(storage) == SS_MAXSIZE);
assert(@alignOf(storage) == 8);
}
};

pub const in = extern struct {
len: u8 = @sizeOf(in),
Expand Down
12 changes: 11 additions & 1 deletion lib/std/c/openbsd.zig
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const std = @import("../std.zig");
const assert = std.debug.assert;
const maxInt = std.math.maxInt;
const builtin = @import("builtin");
const iovec = std.os.iovec;
Expand Down Expand Up @@ -372,7 +373,16 @@ pub const sockaddr = extern struct {
data: [14]u8,

pub const SS_MAXSIZE = 256;
pub const storage = std.x.os.Socket.Address.Native.Storage;
pub const storage = extern struct {
len: u8 align(8),
family: sa_family_t,
padding: [254]u8 = undefined,

comptime {
assert(@sizeOf(storage) == SS_MAXSIZE);
assert(@alignOf(storage) == 8);
}
};

pub const in = extern struct {
len: u8 = @sizeOf(in),
Expand Down
11 changes: 10 additions & 1 deletion lib/std/c/solaris.zig
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const std = @import("../std.zig");
const assert = std.debug.assert;
const builtin = @import("builtin");
const maxInt = std.math.maxInt;
const iovec = std.os.iovec;
Expand Down Expand Up @@ -435,7 +436,15 @@ pub const sockaddr = extern struct {
data: [14]u8,

pub const SS_MAXSIZE = 256;
pub const storage = std.x.os.Socket.Address.Native.Storage;
pub const storage = extern struct {
family: sa_family_t align(8),
padding: [254]u8 = undefined,

comptime {
assert(@sizeOf(storage) == SS_MAXSIZE);
assert(@alignOf(storage) == 8);
}
};

pub const in = extern struct {
family: sa_family_t = AF.INET,
Expand Down
5 changes: 5 additions & 0 deletions lib/std/crypto.zig
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,9 @@ const std = @import("std.zig");

pub const errors = @import("crypto/errors.zig");

pub const tls = @import("crypto/tls.zig");
pub const Certificate = @import("crypto/Certificate.zig");

test {
_ = aead.aegis.Aegis128L;
_ = aead.aegis.Aegis256;
Expand Down Expand Up @@ -264,6 +267,8 @@ test {
_ = utils;
_ = random;
_ = errors;
_ = tls;
_ = Certificate;
}

test "CSPRNG" {
Expand Down
Loading