-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
networking: delete std.x; add std.crypto.tls and std.http.Client #13980
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
Merged
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 cd0d514
remove the experimental std.x namespace
andrewrk ba44513
std.http reorg; introduce std.crypto.Tls
andrewrk d2f5d0b
std.crypto.Tls: parse the ServerHello handshake
andrewrk 920e5bc
std.crypto.Tls: discard ChangeCipherSpec messages
andrewrk 595fff7
std.crypto.Tls: decrypting handshake messages
andrewrk 40a8550
std.crypto.Tls: add read/write methods
andrewrk b97fc43
std.crypto.Tls: client is working against some servers
andrewrk 462b3ed
std.crypto.Tls: handshake fixes
andrewrk 02c33d0
std.crypto.Tls: parse encrypted extensions
andrewrk 93ab8be
extract std.crypto.tls.Client into separate namespace
andrewrk 942b5b4
std.crypto.tls: implement the rest of the cipher suites
andrewrk 8ef4dcd
std.crypto.tls: add some benchmark data points
andrewrk f6c3a86
std.crypto.tls.Client: remove unnecessary coercion
andrewrk 41f4461
std.crypto.tls.Client: verify the server's Finished message
andrewrk e2efba7
std.crypto.tls: refactor to remove mutations
andrewrk 7a23778
std.crypto.tls: send a legacy session id
andrewrk f460c21
std.crypto.tls.Client: avoid hard-coded bytes in key_share
andrewrk e2c16d0
std.crypto.tls.Client: support secp256r1 for handshake
andrewrk 5d7eca6
std.crypto.tls.Client: fix verify_data for batched handshakes
andrewrk 3237000
std.crypto.tls: rudimentary certificate parsing
andrewrk bbc0742
introduce std.crypto.CertificateBundle
andrewrk 504070e
std.crypto.CertificateBundle: ignore duplicate certificates
andrewrk 244a97e
std.crypto.tls: certificate signature validation
andrewrk 7ed7bd2
std.crypto.tls: verify the common name matches
andrewrk 22db1e1
std.crypto.CertificateBundle: disable test on WASI
andrewrk 4f9f457
std.crypto.tls: rename HandshakeCipher
andrewrk 29475b4
std.crypto.tls: validate previous certificate
andrewrk 16f936b
std.crypto.tls: handle the certificate_verify message
andrewrk 862ecf2
std.crypto.tls.Client: handle extra data after handshake
andrewrk 7cb535d
std.crypto.tls.Certificate: verify time validity
andrewrk 642a8b0
std.crypto.tls.Certificate: explicit error set for verify
andrewrk c71c562
remove std.crypto.der
andrewrk 5b8b5f2
add url parsing to the std lib
andrewrk a1f6a08
std.crypto.Certificate.Bundle: fix 32-bit build
andrewrk b24f178
std.crypto.tls.Certificate: fix parsing missing subsequent fields
andrewrk b1cbfa0
std.crypto.Certificate: remove subject_alt_name parsing
andrewrk 5bbedb6
std.crypto.Certificate: support verifying secp384r1 pub keys
andrewrk ceb211e
std.crypto.tls.Client: handle key_update message
andrewrk 477864d
std.crypto.tls.Client: fix truncation attack vulnerability
andrewrk 21ab991
std.crypto.tls.Client: use enums more
andrewrk 940d368
std.crypto.tls.Client: fix the read function
andrewrk 16af628
std.crypto.tls.Client: support SignatureScheme.ecdsa_secp384r1_sha384
andrewrk 1d20ada
std.crypto.tls.Client: refactor to reduce namespace bloat
andrewrk 7391df2
std.crypto: make proper use of `undefined`
andrewrk e4a9b19
std.crypto.tls.Client: rework the read function
andrewrk 22e2aaa
crypto.tls: support rsa_pss_rsae_sha256 and fixes
andrewrk 05fee3b
std.crypto.tls.Client: fix eof logic
andrewrk 2d090f6
add std.http.Headers
andrewrk 79b41db
std.crypto.tls: avoid heap allocation
andrewrk 341e68f
std.crypto.tls.Client: remove debug prints
andrewrk 0fb78b1
std.crypto.tls: use a Decoder abstraction
andrewrk 66b07fd
std.crypto.Certificate: bump RSA needed memory
andrewrk b3c8c38
std.os: add missing handling of ECONNRESET in readv
andrewrk 611a1fd
std.crypto.tls: add API for sending close_notify
andrewrk 3127bd7
std.http.Client: don't send TLS close_notify
andrewrk 97acdee
std.crypto.tls: verify via Subject Alt Name
andrewrk 9ca6d67
std.crypto.tls.Certificate: make the current time a parameter
andrewrk 7178451
std.crypto.tls.Client: make close_notify optional
andrewrk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| /// 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); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.