/src/botan/src/lib/tls/msg_finished.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Finished Message |
3 | | * (C) 2004-2006,2012 Jack Lloyd |
4 | | * 2021 Elektrobit Automotive GmbH |
5 | | * 2022 René Meusel, Hannes Rantzsch - neXenio GmbH |
6 | | * |
7 | | * Botan is released under the Simplified BSD License (see license.txt) |
8 | | */ |
9 | | |
10 | | #include <botan/tls_messages.h> |
11 | | |
12 | | #include <botan/kdf.h> |
13 | | #include <botan/internal/ct_utils.h> |
14 | | #include <botan/internal/target_info.h> |
15 | | #include <botan/internal/tls_handshake_io.h> |
16 | | #include <botan/internal/tls_handshake_state.h> |
17 | | |
18 | | #if defined(BOTAN_HAS_TLS_13) |
19 | | #include <botan/internal/tls_cipher_state.h> |
20 | | #endif |
21 | | |
22 | | namespace Botan::TLS { |
23 | | |
24 | | namespace { |
25 | | |
26 | | /* |
27 | | * Compute the verify_data for TLS 1.2 |
28 | | */ |
29 | 488 | std::vector<uint8_t> finished_compute_verify_12(const Handshake_State& state, Connection_Side side) { |
30 | 488 | const uint8_t TLS_CLIENT_LABEL[] = { |
31 | 488 | 0x63, 0x6C, 0x69, 0x65, 0x6E, 0x74, 0x20, 0x66, 0x69, 0x6E, 0x69, 0x73, 0x68, 0x65, 0x64}; |
32 | | |
33 | 488 | const uint8_t TLS_SERVER_LABEL[] = { |
34 | 488 | 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x20, 0x66, 0x69, 0x6E, 0x69, 0x73, 0x68, 0x65, 0x64}; |
35 | | |
36 | 488 | auto prf = state.protocol_specific_prf(); |
37 | | |
38 | 488 | std::vector<uint8_t> input; |
39 | 488 | std::vector<uint8_t> label; |
40 | 488 | label += (side == Connection_Side::Client) ? std::make_pair(TLS_CLIENT_LABEL, sizeof(TLS_CLIENT_LABEL)) |
41 | 488 | : std::make_pair(TLS_SERVER_LABEL, sizeof(TLS_SERVER_LABEL)); |
42 | | |
43 | 488 | input += state.hash().final(state.ciphersuite().prf_algo()); |
44 | | |
45 | 488 | return unlock(prf->derive_key(12, state.session_keys().master_secret(), input, label)); |
46 | 488 | } |
47 | | |
48 | | } // namespace |
49 | | |
50 | 244 | std::vector<uint8_t> Finished::serialize() const { |
51 | 244 | return m_verification_data; |
52 | 244 | } |
53 | | |
54 | 5.34k | Finished::Finished(const std::vector<uint8_t>& buf) : m_verification_data(buf) {} |
55 | | |
56 | 0 | std::vector<uint8_t> Finished::verify_data() const { |
57 | 0 | return m_verification_data; |
58 | 0 | } |
59 | | |
60 | 244 | Finished_12::Finished_12(Handshake_IO& io, Handshake_State& state, Connection_Side side) { |
61 | 244 | m_verification_data = finished_compute_verify_12(state, side); |
62 | 244 | state.hash().update(io.send(*this)); |
63 | 244 | } |
64 | | |
65 | 244 | bool Finished_12::verify(const Handshake_State& state, Connection_Side side) const { |
66 | 244 | std::vector<uint8_t> computed_verify = finished_compute_verify_12(state, side); |
67 | | |
68 | 244 | #if defined(BOTAN_UNSAFE_FUZZER_MODE) |
69 | 244 | return true; |
70 | | #else |
71 | | // first check the size: |
72 | | if(m_verification_data.size() != computed_verify.size()) { |
73 | | return false; |
74 | | } |
75 | | |
76 | | return CT::is_equal(m_verification_data.data(), computed_verify.data(), computed_verify.size()).as_bool(); |
77 | | #endif |
78 | 244 | } |
79 | | |
80 | | #if defined(BOTAN_HAS_TLS_13) |
81 | 0 | Finished_13::Finished_13(Cipher_State* cipher_state, const Transcript_Hash& transcript_hash) { |
82 | 0 | m_verification_data = cipher_state->finished_mac(transcript_hash); |
83 | 0 | } |
84 | | |
85 | 0 | bool Finished_13::verify(Cipher_State* cipher_state, const Transcript_Hash& transcript_hash) const { |
86 | 0 | return cipher_state->verify_peer_finished_mac(transcript_hash, m_verification_data); |
87 | 0 | } |
88 | | #endif |
89 | | } // namespace Botan::TLS |