/src/botan/build/include/botan/internal/tls_handshake_layer_13.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * TLS handshake layer 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 | | #ifndef BOTAN_TLS_HANDSHAKE_LAYER_13_H_ |
10 | | #define BOTAN_TLS_HANDSHAKE_LAYER_13_H_ |
11 | | |
12 | | #include <optional> |
13 | | #include <vector> |
14 | | |
15 | | #include <botan/tls_magic.h> |
16 | | #include <botan/tls_messages.h> |
17 | | |
18 | | namespace Botan::TLS { |
19 | | |
20 | | class Transcript_Hash_State; |
21 | | |
22 | | /** |
23 | | * Implementation of the TLS 1.3 handshake protocol layer |
24 | | * |
25 | | * This component transforms payload bytes received in TLS records |
26 | | * from the peer into parsed handshake messages and vice versa. |
27 | | */ |
28 | | class BOTAN_TEST_API Handshake_Layer |
29 | | { |
30 | | public: |
31 | 6.41k | Handshake_Layer(Connection_Side whoami) : m_peer(whoami == SERVER ? CLIENT : SERVER) {} |
32 | | |
33 | | /** |
34 | | * Reads data that was received in handshake records and stores it internally for further |
35 | | * processing during the invocation of `next_message()`. |
36 | | * |
37 | | * @param data_from_peer The data to be parsed. |
38 | | */ |
39 | | void copy_data(const secure_vector<uint8_t>& data_from_peer); |
40 | | |
41 | | /** |
42 | | * Parses one handshake message off the internal buffer that is being filled using `copy_data`. |
43 | | * |
44 | | * @param policy the TLS policy |
45 | | * @param transcript_hash the transcript hash state to be updated |
46 | | * |
47 | | * @return the parsed handshake message, or nullopt if more data is needed to complete the message |
48 | | */ |
49 | | std::optional<Handshake_Message_13> next_message(const Policy& policy, Transcript_Hash_State& transcript_hash); |
50 | | |
51 | | /** |
52 | | * Parses one post-handshake message off the internal buffer that is being filled using `copy_data`. |
53 | | * |
54 | | * @param policy the TLS policy |
55 | | * |
56 | | * @return the parsed post-handshake message, or nullopt if more data is needed to complete the message |
57 | | */ |
58 | | std::optional<Post_Handshake_Message_13> next_post_handshake_message(const Policy& policy); |
59 | | |
60 | | /** |
61 | | * Marshalls one handshake message for sending in an (encrypted) record and updates the |
62 | | * provided transcript hash state accordingly. |
63 | | * |
64 | | * @param message the handshake message to be marshalled |
65 | | * @param transcript_hash the transcript hash state to be updated |
66 | | * |
67 | | * @return the marshalled handshake message |
68 | | */ |
69 | | static std::vector<uint8_t> prepare_message(const Handshake_Message_13_Ref message, Transcript_Hash_State& transcript_hash); |
70 | | |
71 | | /** |
72 | | * Marshalls one post-handshake message for sending in an (encrypted) record. |
73 | | * |
74 | | * @param message the post handshake message to be marshalled |
75 | | * |
76 | | * @return the marshalled post-handshake message |
77 | | */ |
78 | | static std::vector<uint8_t> prepare_post_handshake_message(const Post_Handshake_Message_13& message); |
79 | | |
80 | | /** |
81 | | * Check if the Handshake_Layer has stored a partial message in its internal buffer. |
82 | | * This can happen if a handshake message spans multiple records. |
83 | | */ |
84 | 0 | bool has_pending_data() const { return !m_read_buffer.empty(); } |
85 | | |
86 | | private: |
87 | | std::vector<uint8_t> m_read_buffer; |
88 | | Connection_Side m_peer; |
89 | | }; |
90 | | |
91 | | } |
92 | | |
93 | | #endif |