Coverage Report

Created: 2022-11-24 06:56

/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
#include <botan/kdf.h>
12
#include <botan/internal/tls_handshake_io.h>
13
#include <botan/internal/tls_handshake_state.h>
14
15
#if defined(BOTAN_HAS_TLS_13)
16
   #include <botan/internal/tls_cipher_state.h>
17
#endif
18
19
namespace Botan::TLS {
20
21
namespace {
22
23
/*
24
* Compute the verify_data for TLS 1.2
25
*/
26
std::vector<uint8_t> finished_compute_verify_12(const Handshake_State& state,
27
      Connection_Side side)
28
754
   {
29
754
   const uint8_t TLS_CLIENT_LABEL[] =
30
754
      {
31
754
      0x63, 0x6C, 0x69, 0x65, 0x6E, 0x74, 0x20, 0x66, 0x69, 0x6E, 0x69,
32
754
      0x73, 0x68, 0x65, 0x64
33
754
      };
34
35
754
   const uint8_t TLS_SERVER_LABEL[] =
36
754
      {
37
754
      0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x20, 0x66, 0x69, 0x6E, 0x69,
38
754
      0x73, 0x68, 0x65, 0x64
39
754
      };
40
41
754
   auto prf = state.protocol_specific_prf();
42
43
754
   std::vector<uint8_t> input;
44
754
   std::vector<uint8_t> label;
45
754
   label += (side == CLIENT)
46
754
            ? std::make_pair(TLS_CLIENT_LABEL, sizeof(TLS_CLIENT_LABEL))
47
754
            : std::make_pair(TLS_SERVER_LABEL, sizeof(TLS_SERVER_LABEL));
48
49
754
   input += state.hash().final(state.ciphersuite().prf_algo());
50
51
754
   return unlock(prf->derive_key(12, state.session_keys().master_secret(), input, label));
52
754
   }
53
54
} // namespace
55
56
std::vector<uint8_t> Finished::serialize() const
57
377
   {
58
377
   return m_verification_data;
59
377
   }
60
61
5.22k
Finished::Finished(const std::vector<uint8_t>& buf) : m_verification_data(buf) {}
62
63
std::vector<uint8_t> Finished::verify_data() const
64
0
   {
65
0
   return m_verification_data;
66
0
   }
67
68
Finished_12::Finished_12(Handshake_IO& io,
69
                      Handshake_State& state,
70
                      Connection_Side side)
71
377
   {
72
377
   m_verification_data = finished_compute_verify_12(state, side);
73
377
   state.hash().update(io.send(*this));
74
377
   }
75
76
bool Finished_12::verify(const Handshake_State& state,
77
                         Connection_Side side) const
78
377
   {
79
377
   std::vector<uint8_t> computed_verify = finished_compute_verify_12(state, side);
80
81
377
#if defined(BOTAN_UNSAFE_FUZZER_MODE)
82
377
   return true;
83
#else
84
   return (m_verification_data.size() == computed_verify.size()) &&
85
          constant_time_compare(m_verification_data.data(), computed_verify.data(), computed_verify.size());
86
#endif
87
377
   }
88
89
#if defined(BOTAN_HAS_TLS_13)
90
Finished_13::Finished_13(Cipher_State* cipher_state,
91
                         const Transcript_Hash& transcript_hash)
92
0
   {
93
0
   m_verification_data = cipher_state->finished_mac(transcript_hash);
94
0
   }
95
96
bool Finished_13::verify(Cipher_State* cipher_state, const Transcript_Hash& transcript_hash) const
97
0
   {
98
0
   return cipher_state->verify_peer_finished_mac(transcript_hash, m_verification_data);
99
0
   }
100
#endif
101
}