authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2024-11-01 00:11:44-04:00
committergravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2024-11-07 20:25:26-05:00
loge184b15a6639f28e47d4a43d59136726d686b3b1
tree6722a153aaa6ab2df781148d030a3c30e1b7f3c6
parentc2a779ae79facc0c6a102825723ae707fdbf8c19

std.crypto.tls: fix fetching https://nginx.org

Note that the removed `error.TlsIllegalParameter` case is still caught below when it is compared to a fixed-length string, but after checking the proper protocol version requirement first.

1 files changed, 3 insertions(+), 3 deletions(-)

lib/std/crypto/tls/Client.zig+3-3
...@@ -257,7 +257,7 @@ pub fn init(stream: anytype, ca_bundle: Certificate.Bundle, host: []const u8) In...@@ -257,7 +257,7 @@ pub fn init(stream: anytype, ca_bundle: Certificate.Bundle, host: []const u8) In
257 if (handshake_type != .server_hello) return error.TlsUnexpectedMessage;257 if (handshake_type != .server_hello) return error.TlsUnexpectedMessage;
258 const length = ptd.decode(u24);258 const length = ptd.decode(u24);
259 var hsd = try ptd.sub(length);259 var hsd = try ptd.sub(length);
260 try hsd.ensure(2 + 32 + 1 + 32 + 2 + 1);260 try hsd.ensure(2 + 32 + 1);
261 const legacy_version = hsd.decode(u16);261 const legacy_version = hsd.decode(u16);
262 @memcpy(&server_hello_rand, hsd.array(32));262 @memcpy(&server_hello_rand, hsd.array(32));
263 if (mem.eql(u8, &server_hello_rand, &tls.hello_retry_request_sequence)) {263 if (mem.eql(u8, &server_hello_rand, &tls.hello_retry_request_sequence)) {
...@@ -266,8 +266,8 @@ pub fn init(stream: anytype, ca_bundle: Certificate.Bundle, host: []const u8) In...@@ -266,8 +266,8 @@ pub fn init(stream: anytype, ca_bundle: Certificate.Bundle, host: []const u8) In
266 return error.TlsUnexpectedMessage;266 return error.TlsUnexpectedMessage;
267 }267 }
268 const legacy_session_id_echo_len = hsd.decode(u8);268 const legacy_session_id_echo_len = hsd.decode(u8);
269 if (legacy_session_id_echo_len != 32) return error.TlsIllegalParameter;269 try hsd.ensure(legacy_session_id_echo_len + 2 + 1);
270 const legacy_session_id_echo = hsd.array(32);270 const legacy_session_id_echo = hsd.slice(legacy_session_id_echo_len);
271 cipher_suite_tag = hsd.decode(tls.CipherSuite);271 cipher_suite_tag = hsd.decode(tls.CipherSuite);
272 hsd.skip(1); // legacy_compression_method272 hsd.skip(1); // legacy_compression_method
273 var supported_version: ?u16 = null;273 var supported_version: ?u16 = null;