| ... | ... | @@ -662,21 +662,20 @@ pub fn init(stream: anytype, ca_bundle: Certificate.Bundle, host: []const u8) In |
| 662 | 662 | &.{ "key expansion", &server_hello_rand, &client_hello_rand }, |
| 663 | 663 | @sizeOf(P.Tls_1_2), |
| 664 | 664 | ); |
| 665 | | const verify_data_len = 12; |
| 666 | 665 | const client_verify_cleartext = .{@intFromEnum(tls.HandshakeType.finished)} ++ |
| 667 | 666 | array(u24, u8, hmacExpandLabel( |
| 668 | 667 | P.Hmac, |
| 669 | 668 | &master_secret, |
| 670 | 669 | &.{ "client finished", &p.transcript_hash.peek() }, |
| 671 | | verify_data_len, |
| 670 | P.verify_data_length, |
| 672 | 671 | )); |
| 673 | 672 | p.transcript_hash.update(&client_verify_cleartext); |
| 674 | 673 | p.version = .{ .tls_1_2 = .{ |
| 675 | | .server_verify_data = hmacExpandLabel( |
| 674 | .expected_server_verify_data = hmacExpandLabel( |
| 676 | 675 | P.Hmac, |
| 677 | 676 | &master_secret, |
| 678 | 677 | &.{ "server finished", &p.transcript_hash.finalResult() }, |
| 679 | | verify_data_len, |
| 678 | P.verify_data_length, |
| 680 | 679 | ), |
| 681 | 680 | .app_cipher = std.mem.bytesToValue(P.Tls_1_2, &key_block), |
| 682 | 681 | } }; |
| ... | ... | @@ -747,10 +746,11 @@ pub fn init(stream: anytype, ca_bundle: Certificate.Bundle, host: []const u8) In |
| 747 | 746 | .tls_1_3 => { |
| 748 | 747 | const pv = &p.version.tls_1_3; |
| 749 | 748 | const P = @TypeOf(p.*).A; |
| 749 | try hsd.ensure(P.Hmac.mac_length); |
| 750 | 750 | const finished_digest = p.transcript_hash.peek(); |
| 751 | 751 | p.transcript_hash.update(wrapped_handshake); |
| 752 | 752 | const expected_server_verify_data = tls.hmac(P.Hmac, &finished_digest, pv.server_finished_key); |
| 753 | | if (!mem.eql(u8, &expected_server_verify_data, hsd.buf)) return error.TlsDecryptError; |
| 753 | if (!std.crypto.timing_safe.eql([P.Hmac.mac_length]u8, expected_server_verify_data, hsd.array(P.Hmac.mac_length).*)) return error.TlsDecryptError; |
| 754 | 754 | const handshake_hash = p.transcript_hash.finalResult(); |
| 755 | 755 | const verify_data = tls.hmac(P.Hmac, &handshake_hash, pv.client_finished_key); |
| 756 | 756 | const out_cleartext = .{@intFromEnum(tls.HandshakeType.finished)} ++ |
| ... | ... | @@ -788,8 +788,9 @@ pub fn init(stream: anytype, ca_bundle: Certificate.Bundle, host: []const u8) In |
| 788 | 788 | }, |
| 789 | 789 | .tls_1_2 => { |
| 790 | 790 | const pv = &p.version.tls_1_2; |
| 791 | | try hsd.ensure(12); |
| 792 | | if (!std.mem.eql(u8, hsd.array(12), &pv.server_verify_data)) return error.TlsDecryptError; |
| 791 | const P = @TypeOf(p.*).A; |
| 792 | try hsd.ensure(P.verify_data_length); |
| 793 | if (!std.crypto.timing_safe.eql([P.verify_data_length]u8, pv.expected_server_verify_data, hsd.array(P.verify_data_length).*)) return error.TlsDecryptError; |
| 793 | 794 | break :app_cipher @unionInit(tls.ApplicationCipher, @tagName(tag), .{ .tls_1_2 = pv.app_cipher }); |
| 794 | 795 | }, |
| 795 | 796 | else => unreachable, |