| ... | @@ -11,7 +11,7 @@ const ApplicationCipher = tls.ApplicationCipher; | ... | @@ -11,7 +11,7 @@ const ApplicationCipher = tls.ApplicationCipher; |
| 11 | const CipherSuite = tls.CipherSuite; | 11 | const CipherSuite = tls.CipherSuite; |
| 12 | const ContentType = tls.ContentType; | 12 | const ContentType = tls.ContentType; |
| 13 | const HandshakeType = tls.HandshakeType; | 13 | const HandshakeType = tls.HandshakeType; |
| 14 | const CipherParams = tls.CipherParams; | 14 | const HandshakeCipher = tls.HandshakeCipher; |
| 15 | const max_ciphertext_len = tls.max_ciphertext_len; | 15 | const max_ciphertext_len = tls.max_ciphertext_len; |
| 16 | const hkdfExpandLabel = tls.hkdfExpandLabel; | 16 | const hkdfExpandLabel = tls.hkdfExpandLabel; |
| 17 | const int2 = tls.int2; | 17 | const int2 = tls.int2; |
| ... | @@ -117,7 +117,7 @@ pub fn init(stream: net.Stream, ca_bundle: crypto.CertificateBundle, host: []con | ... | @@ -117,7 +117,7 @@ pub fn init(stream: net.Stream, ca_bundle: crypto.CertificateBundle, host: []con |
| 117 | | 117 | |
| 118 | const client_hello_bytes1 = plaintext_header[5..]; | 118 | const client_hello_bytes1 = plaintext_header[5..]; |
| 119 | | 119 | |
| 120 | var cipher_params: CipherParams = undefined; | 120 | var handshake_cipher: HandshakeCipher = undefined; |
| 121 | | 121 | |
| 122 | var handshake_buf: [8000]u8 = undefined; | 122 | var handshake_buf: [8000]u8 = undefined; |
| 123 | var len: usize = 0; | 123 | var len: usize = 0; |
| ... | @@ -243,8 +243,8 @@ pub fn init(stream: net.Stream, ca_bundle: crypto.CertificateBundle, host: []con | ... | @@ -243,8 +243,8 @@ pub fn init(stream: net.Stream, ca_bundle: crypto.CertificateBundle, host: []con |
| 243 | .AEGIS_256_SHA384, | 243 | .AEGIS_256_SHA384, |
| 244 | .AEGIS_128L_SHA256, | 244 | .AEGIS_128L_SHA256, |
| 245 | => |tag| { | 245 | => |tag| { |
| 246 | const P = std.meta.TagPayloadByName(CipherParams, @tagName(tag)); | 246 | const P = std.meta.TagPayloadByName(HandshakeCipher, @tagName(tag)); |
| 247 | cipher_params = @unionInit(CipherParams, @tagName(tag), .{ | 247 | handshake_cipher = @unionInit(HandshakeCipher, @tagName(tag), .{ |
| 248 | .handshake_secret = undefined, | 248 | .handshake_secret = undefined, |
| 249 | .master_secret = undefined, | 249 | .master_secret = undefined, |
| 250 | .client_handshake_key = undefined, | 250 | .client_handshake_key = undefined, |
| ... | @@ -255,7 +255,7 @@ pub fn init(stream: net.Stream, ca_bundle: crypto.CertificateBundle, host: []con | ... | @@ -255,7 +255,7 @@ pub fn init(stream: net.Stream, ca_bundle: crypto.CertificateBundle, host: []con |
| 255 | .server_handshake_iv = undefined, | 255 | .server_handshake_iv = undefined, |
| 256 | .transcript_hash = P.Hash.init(.{}), | 256 | .transcript_hash = P.Hash.init(.{}), |
| 257 | }); | 257 | }); |
| 258 | const p = &@field(cipher_params, @tagName(tag)); | 258 | const p = &@field(handshake_cipher, @tagName(tag)); |
| 259 | p.transcript_hash.update(client_hello_bytes1); // Client Hello part 1 | 259 | p.transcript_hash.update(client_hello_bytes1); // Client Hello part 1 |
| 260 | p.transcript_hash.update(host); // Client Hello part 2 | 260 | p.transcript_hash.update(host); // Client Hello part 2 |
| 261 | p.transcript_hash.update(frag); // Server Hello | 261 | p.transcript_hash.update(frag); // Server Hello |
| ... | @@ -329,7 +329,7 @@ pub fn init(stream: net.Stream, ca_bundle: crypto.CertificateBundle, host: []con | ... | @@ -329,7 +329,7 @@ pub fn init(stream: net.Stream, ca_bundle: crypto.CertificateBundle, host: []con |
| 329 | }, | 329 | }, |
| 330 | .application_data => { | 330 | .application_data => { |
| 331 | var cleartext_buf: [8000]u8 = undefined; | 331 | var cleartext_buf: [8000]u8 = undefined; |
| 332 | const cleartext = switch (cipher_params) { | 332 | const cleartext = switch (handshake_cipher) { |
| 333 | inline else => |*p| c: { | 333 | inline else => |*p| c: { |
| 334 | const P = @TypeOf(p.*); | 334 | const P = @TypeOf(p.*); |
| 335 | const ciphertext_len = record_size - P.AEAD.tag_length; | 335 | const ciphertext_len = record_size - P.AEAD.tag_length; |
| ... | @@ -366,7 +366,7 @@ pub fn init(stream: net.Stream, ca_bundle: crypto.CertificateBundle, host: []con | ... | @@ -366,7 +366,7 @@ pub fn init(stream: net.Stream, ca_bundle: crypto.CertificateBundle, host: []con |
| 366 | const handshake = cleartext[ct_i..next_handshake_i]; | 366 | const handshake = cleartext[ct_i..next_handshake_i]; |
| 367 | switch (handshake_type) { | 367 | switch (handshake_type) { |
| 368 | @enumToInt(HandshakeType.encrypted_extensions) => { | 368 | @enumToInt(HandshakeType.encrypted_extensions) => { |
| 369 | switch (cipher_params) { | 369 | switch (handshake_cipher) { |
| 370 | inline else => |*p| p.transcript_hash.update(wrapped_handshake), | 370 | inline else => |*p| p.transcript_hash.update(wrapped_handshake), |
| 371 | } | 371 | } |
| 372 | const total_ext_size = mem.readIntBig(u16, handshake[0..2]); | 372 | const total_ext_size = mem.readIntBig(u16, handshake[0..2]); |
| ... | @@ -390,7 +390,7 @@ pub fn init(stream: net.Stream, ca_bundle: crypto.CertificateBundle, host: []con | ... | @@ -390,7 +390,7 @@ pub fn init(stream: net.Stream, ca_bundle: crypto.CertificateBundle, host: []con |
| 390 | } | 390 | } |
| 391 | }, | 391 | }, |
| 392 | @enumToInt(HandshakeType.certificate) => cert: { | 392 | @enumToInt(HandshakeType.certificate) => cert: { |
| 393 | switch (cipher_params) { | 393 | switch (handshake_cipher) { |
| 394 | inline else => |*p| p.transcript_hash.update(wrapped_handshake), | 394 | inline else => |*p| p.transcript_hash.update(wrapped_handshake), |
| 395 | } | 395 | } |
| 396 | if (validated_cert) break :cert; | 396 | if (validated_cert) break :cert; |
| ... | @@ -445,7 +445,7 @@ pub fn init(stream: net.Stream, ca_bundle: crypto.CertificateBundle, host: []con | ... | @@ -445,7 +445,7 @@ pub fn init(stream: net.Stream, ca_bundle: crypto.CertificateBundle, host: []con |
| 445 | } | 445 | } |
| 446 | }, | 446 | }, |
| 447 | @enumToInt(HandshakeType.certificate_verify) => { | 447 | @enumToInt(HandshakeType.certificate_verify) => { |
| 448 | switch (cipher_params) { | 448 | switch (handshake_cipher) { |
| 449 | inline else => |*p| p.transcript_hash.update(wrapped_handshake), | 449 | inline else => |*p| p.transcript_hash.update(wrapped_handshake), |
| 450 | } | 450 | } |
| 451 | std.debug.print("ignoring certificate_verify\n", .{}); | 451 | std.debug.print("ignoring certificate_verify\n", .{}); |
| ... | @@ -458,7 +458,7 @@ pub fn init(stream: net.Stream, ca_bundle: crypto.CertificateBundle, host: []con | ... | @@ -458,7 +458,7 @@ pub fn init(stream: net.Stream, ca_bundle: crypto.CertificateBundle, host: []con |
| 458 | 0x00, 0x01, // length | 458 | 0x00, 0x01, // length |
| 459 | 0x01, | 459 | 0x01, |
| 460 | }; | 460 | }; |
| 461 | const app_cipher = switch (cipher_params) { | 461 | const app_cipher = switch (handshake_cipher) { |
| 462 | inline else => |*p, tag| c: { | 462 | inline else => |*p, tag| c: { |
| 463 | const P = @TypeOf(p.*); | 463 | const P = @TypeOf(p.*); |
| 464 | const finished_digest = p.transcript_hash.peek(); | 464 | const finished_digest = p.transcript_hash.peek(); |