-
Notifications
You must be signed in to change notification settings - Fork 2
/
tls_context.hpp
79 lines (63 loc) · 2.18 KB
/
tls_context.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#ifndef _TLS_HANDSHAKE_TLS_CONTEXT
#define _TLS_HANDSHAKE_TLS_CONTEXT
#include <cstdint>
#include <optional>
#include <string>
#include <vector>
#include "./bytes.hpp"
class Keys {
public:
bytes_t client_write_mac_key;
bytes_t server_write_mac_key;
bytes_t client_write_key;
bytes_t server_write_key;
bytes_t client_write_iv;
bytes_t server_write_iv;
Keys(
const bytes_t& client_write_mac_key,
const bytes_t& server_write_mac_key,
const bytes_t& client_write_key,
const bytes_t& server_write_key,
const bytes_t& client_write_iv,
const bytes_t& server_write_iv
)
: client_write_mac_key(client_write_mac_key)
, server_write_mac_key(server_write_mac_key)
, client_write_key(client_write_key)
, server_write_key(server_write_key)
, client_write_iv(client_write_iv)
, server_write_iv(server_write_iv)
{}
};
class TLSContext {
public:
bytes_t client_random;
bytes_t server_random;
std::optional<bytes_t> premaster_secret;
bytes_t master_secret;
std::optional<Keys> keys;
std::optional<bytes_t> server_public_key;
bool client_hello_handshake_added;
bool premaster_secret_packet_handshake_added;
std::vector<bytes_t> handshake_packets;
std::uint64_t i_seq;
TLSContext();
std::optional<std::string> hostname;
virtual void set_hostname(const std::string& hn) { hostname = hn; }
virtual bytes_t get_client_hello();
virtual void eat_server_hello(const bytes_t&);
virtual void eat_server_certificates(const bytes_t&);
virtual void eat_server_hello_done(const bytes_t&);
virtual bytes_t get_client_key_exchange_packet();
virtual bytes_t get_change_cipher_spec_packet();
virtual bytes_t get_verify_data_packet();
void eat_server_verify_data(const bytes_t&);
virtual bytes_t encrypt_packet(std::uint8_t, const bytes_t&);
virtual bytes_t encrypt_packet(const bytes_t&);
virtual bytes_t decrypt_server_packet(const bytes_t&);
virtual bytes_t get_close_packet();
protected:
virtual void set_master_secret();
virtual void set_keys();
};
#endif