Botan 3.13.0
Crypto and TLS for C&
tls_handshake_state_13.cpp
Go to the documentation of this file.
1/*
2* TLS handshake state (machine) implementation for TLS 1.3
3* (C) 2022 Jack Lloyd
4* 2022 Hannes Rantzsch, René Meusel - neXenio GmbH
5*
6* Botan is released under the Simplified BSD License (see license.txt)
7*/
8
9#include <botan/internal/tls_handshake_state_13.h>
10
11#include <botan/assert.h>
12
13namespace Botan::TLS::Internal {
14
16 if(m_client_hello) {
17 // Make sure that the updated Client Hello is compatible to the initial one.
19 m_client_hello->validate_updates(client_hello);
20 }
21
22 m_client_hello = std::move(client_hello);
23 return m_client_hello.value();
24}
25
27 BOTAN_STATE_CHECK(!m_client_hello_12.has_value());
28 m_client_hello_12 = std::move(client_hello);
29 return m_client_hello_12.value();
30}
31
33 BOTAN_STATE_CHECK(!m_server_hello.has_value());
34 m_server_hello = std::move(server_hello);
35 return m_server_hello.value();
36}
37
39 BOTAN_STATE_CHECK(!m_server_hello_12.has_value());
40 m_server_hello_12 = std::move(server_hello);
41 return m_server_hello_12.value();
42}
43
45 // RFC 8446 4.1.4
46 // If a client receives a second HelloRetryRequest in the same connection
47 // [...], it MUST abort the handshake with an "unexpected_message" alert.
48 BOTAN_STATE_CHECK(!m_hello_retry_request.has_value());
49 m_hello_retry_request = std::move(hello_retry_request);
50 return m_hello_retry_request.value();
51}
52
54 const bool /*from_peer*/) {
55 BOTAN_STATE_CHECK(!m_encrypted_extensions.has_value());
56 m_encrypted_extensions = std::move(encrypted_extensions);
57 return m_encrypted_extensions.value();
58}
59
61 const bool /*from_peer*/) {
62 BOTAN_STATE_CHECK(!m_certificate_request.has_value());
63 m_certificate_request = std::move(certificate_request);
64 return m_certificate_request.value();
65}
66
68 auto& target = ((m_side == Connection_Side::Client) == from_peer) ? m_server_certificate : m_client_certificate;
69 BOTAN_STATE_CHECK(!target.has_value());
70 target = std::move(certificate);
71 return target.value();
72}
73
75 auto& target =
76 ((m_side == Connection_Side::Client) == from_peer) ? m_server_certificate_verify : m_client_certificate_verify;
77 BOTAN_STATE_CHECK(!target.has_value());
78 target = std::move(certificate_verify);
79 return target.value();
80}
81
82Finished_13& Handshake_State_13_Base::store(Finished_13 finished, const bool from_peer) {
83 auto& target = ((m_side == Connection_Side::Client) == from_peer) ? m_server_finished : m_client_finished;
84 BOTAN_STATE_CHECK(!target.has_value());
85 target = std::move(finished);
86 return target.value();
87}
88
89} // namespace Botan::TLS::Internal
#define BOTAN_STATE_CHECK(expr)
Definition assert.h:49
Client_Hello_13 & store(Client_Hello_13 client_hello, bool from_peer)
const Hello_Retry_Request & hello_retry_request() const
const Certificate_Request_13 & certificate_request() const
const Encrypted_Extensions & encrypted_extensions() const