Botan 3.11.0
Crypto and TLS for C&
msg_finished_12.cpp
Go to the documentation of this file.
1/*
2* Finished Message
3* (C) 2004-2006,2012 Jack Lloyd
4*
5* Botan is released under the Simplified BSD License (see license.txt)
6*/
7
8#include <botan/tls_messages_12.h>
9
10#include <botan/kdf.h>
11#include <botan/internal/ct_utils.h>
12#include <botan/internal/target_info.h>
13#include <botan/internal/tls_handshake_io.h>
14#include <botan/internal/tls_handshake_state.h>
15
16namespace Botan::TLS {
17
18namespace {
19
20/*
21* Compute the verify_data for TLS 1.2
22*/
23std::vector<uint8_t> finished_compute_verify_12(const Handshake_State& state, Connection_Side side) {
24 const uint8_t TLS_CLIENT_LABEL[] = {
25 0x63, 0x6C, 0x69, 0x65, 0x6E, 0x74, 0x20, 0x66, 0x69, 0x6E, 0x69, 0x73, 0x68, 0x65, 0x64};
26
27 const uint8_t TLS_SERVER_LABEL[] = {
28 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x20, 0x66, 0x69, 0x6E, 0x69, 0x73, 0x68, 0x65, 0x64};
29
30 auto prf = state.protocol_specific_prf();
31
32 std::vector<uint8_t> input;
33 std::vector<uint8_t> label;
34 label += (side == Connection_Side::Client) ? std::make_pair(TLS_CLIENT_LABEL, sizeof(TLS_CLIENT_LABEL))
35 : std::make_pair(TLS_SERVER_LABEL, sizeof(TLS_SERVER_LABEL));
36
37 input += state.hash().final(state.ciphersuite().prf_algo());
38
39 return unlock(prf->derive_key(12, state.session_keys().master_secret(), input, label));
40}
41
42} // namespace
43
45 m_verification_data = finished_compute_verify_12(state, side);
46 state.hash().update(io.send(*this));
47}
48
49bool Finished_12::verify(const Handshake_State& state, Connection_Side side) const {
50 std::vector<uint8_t> computed_verify = finished_compute_verify_12(state, side);
51
52#if defined(BOTAN_UNSAFE_FUZZER_MODE)
53 return true;
54#else
55 return CT::is_equal<uint8_t>(m_verification_data, computed_verify).as_bool();
56#endif
57}
58
59} // namespace Botan::TLS
bool verify(const Handshake_State &state, Connection_Side side) const
Finished_12(Handshake_IO &io, Handshake_State &state, Connection_Side side)
std::vector< uint8_t > m_verification_data
void update(const uint8_t in[], size_t length)
virtual std::vector< uint8_t > send(const Handshake_Message &msg)=0
constexpr CT::Mask< T > is_equal(const T x[], const T y[], size_t len)
Definition ct_utils.h:798
std::vector< T > unlock(const secure_vector< T > &in)
Definition secmem.h:85