Botan 2.1.0 Crypto and TLS for C++11

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

tls_handshake_state.h
Go to the documentation of this file.
1 /*
2 * TLS Handshake State
3 * (C) 2004-2006,2011,2012 Jack Lloyd
4 *
5 * Botan is released under the Simplified BSD License (see license.txt)
6 */
7
8 #ifndef BOTAN_TLS_HANDSHAKE_STATE_H__
9 #define BOTAN_TLS_HANDSHAKE_STATE_H__
10
11 #include <botan/internal/tls_handshake_hash.h>
12 #include <botan/internal/tls_handshake_io.h>
13 #include <botan/internal/tls_session_key.h>
14 #include <botan/tls_ciphersuite.h>
15 #include <botan/tls_exceptn.h>
16 #include <botan/tls_handshake_msg.h>
17 #include <botan/pk_keys.h>
18 #include <botan/pubkey.h>
19 #include <functional>
20
21 namespace Botan {
22
23 class KDF;
24
25 namespace TLS {
26
27 class Callbacks;
28 class Policy;
29
30 class Hello_Verify_Request;
31 class Client_Hello;
32 class Server_Hello;
33 class Certificate;
34 class Certificate_Status;
35 class Server_Key_Exchange;
36 class Certificate_Req;
37 class Server_Hello_Done;
38 class Certificate;
39 class Client_Key_Exchange;
40 class Certificate_Verify;
41 class New_Session_Ticket;
42 class Finished;
43
44 /**
45 * SSL/TLS Handshake State
46 */
47 class Handshake_State
48 {
49 public:
50 Handshake_State(Handshake_IO* io, Callbacks& callbacks);
51
52 virtual ~Handshake_State() = default;
53
54 Handshake_State(const Handshake_State&) = delete;
55 Handshake_State& operator=(const Handshake_State&) = delete;
56
57 Handshake_IO& handshake_io() { return *m_handshake_io; }
58
59 /**
60 * Return true iff we have received a particular message already
61 * @param msg_type the message type
62 */
63 bool received_handshake_msg(Handshake_Type msg_type) const;
64
65 /**
66 * Confirm that we were expecting this message type
67 * @param msg_type the message type
68 */
69 void confirm_transition_to(Handshake_Type msg_type);
70
71 /**
72 * Record that we are expecting a particular message type next
73 * @param msg_type the message type
74 */
75 void set_expected_next(Handshake_Type msg_type);
76
77 std::pair<Handshake_Type, std::vector<uint8_t>>
78 get_next_handshake_msg();
79
80 std::vector<uint8_t> session_ticket() const;
81
82 std::pair<std::string, Signature_Format>
83 parse_sig_format(const Public_Key& key,
84 const std::string& hash_algo,
85 const std::string& sig_algo,
86 bool for_client_auth,
87 const Policy& policy) const;
88
89 std::pair<std::string, Signature_Format>
90 choose_sig_format(const Private_Key& key,
91 std::string& hash_algo,
92 std::string& sig_algo,
93 bool for_client_auth,
94 const Policy& policy) const;
95
96 std::string srp_identifier() const;
97
98 KDF* protocol_specific_prf() const;
99
100 Protocol_Version version() const { return m_version; }
101
102 void set_version(const Protocol_Version& version);
103
104 void hello_verify_request(const Hello_Verify_Request& hello_verify);
105
106 void client_hello(Client_Hello* client_hello);
107 void server_hello(Server_Hello* server_hello);
108 void server_certs(Certificate* server_certs);
109 void server_cert_status(Certificate_Status* server_cert_status);
110 void server_kex(Server_Key_Exchange* server_kex);
111 void cert_req(Certificate_Req* cert_req);
112 void server_hello_done(Server_Hello_Done* server_hello_done);
113 void client_certs(Certificate* client_certs);
114 void client_kex(Client_Key_Exchange* client_kex);
115 void client_verify(Certificate_Verify* client_verify);
116 void new_session_ticket(New_Session_Ticket* new_session_ticket);
117 void server_finished(Finished* server_finished);
118 void client_finished(Finished* client_finished);
119
120 const Client_Hello* client_hello() const
121 { return m_client_hello.get(); }
122
123 const Server_Hello* server_hello() const
124 { return m_server_hello.get(); }
125
126 const Certificate* server_certs() const
127 { return m_server_certs.get(); }
128
129 const Server_Key_Exchange* server_kex() const
130 { return m_server_kex.get(); }
131
132 const Certificate_Req* cert_req() const
133 { return m_cert_req.get(); }
134
135 const Server_Hello_Done* server_hello_done() const
136 { return m_server_hello_done.get(); }
137
138 const Certificate* client_certs() const
139 { return m_client_certs.get(); }
140
141 const Client_Key_Exchange* client_kex() const
142 { return m_client_kex.get(); }
143
144 const Certificate_Verify* client_verify() const
145 { return m_client_verify.get(); }
146
147 const Certificate_Status* server_cert_status() const
148 { return m_server_cert_status.get(); }
149
150 const New_Session_Ticket* new_session_ticket() const
151 { return m_new_session_ticket.get(); }
152
153 const Finished* server_finished() const
154 { return m_server_finished.get(); }
155
156 const Finished* client_finished() const
157 { return m_client_finished.get(); }
158
159 const Ciphersuite& ciphersuite() const { return m_ciphersuite; }
160
161 const Session_Keys& session_keys() const { return m_session_keys; }
162
163 void compute_session_keys();
164
165 void compute_session_keys(const secure_vector<uint8_t>& resume_master_secret);
166
167 Handshake_Hash& hash() { return m_handshake_hash; }
168
169 const Handshake_Hash& hash() const { return m_handshake_hash; }
170
171 void note_message(const Handshake_Message& msg);
172 private:
173
174 Callbacks& m_callbacks;
175
176 std::unique_ptr<Handshake_IO> m_handshake_io;
177
178 uint32_t m_hand_expecting_mask = 0;
179 uint32_t m_hand_received_mask = 0;
180 Protocol_Version m_version;
181 Ciphersuite m_ciphersuite;
182 Session_Keys m_session_keys;
183 Handshake_Hash m_handshake_hash;
184
185 std::unique_ptr<Client_Hello> m_client_hello;
186 std::unique_ptr<Server_Hello> m_server_hello;
187 std::unique_ptr<Certificate> m_server_certs;
188 std::unique_ptr<Certificate_Status> m_server_cert_status;
189 std::unique_ptr<Server_Key_Exchange> m_server_kex;
190 std::unique_ptr<Certificate_Req> m_cert_req;
191 std::unique_ptr<Server_Hello_Done> m_server_hello_done;
192 std::unique_ptr<Certificate> m_client_certs;
193 std::unique_ptr<Client_Key_Exchange> m_client_kex;
194 std::unique_ptr<Certificate_Verify> m_client_verify;
195 std::unique_ptr<New_Session_Ticket> m_new_session_ticket;
196 std::unique_ptr<Finished> m_server_finished;
197 std::unique_ptr<Finished> m_client_finished;
198 };
199
200 }
201
202 }
203
204 #endif
Botan::TLS::Certificate_Req
Definition: tls_messages.h:475
Botan::TLS::Server_Hello
Definition: tls_messages.h:255
Botan::TLS::Handshake_State::parse_sig_format
std::pair< std::string, Signature_Format > parse_sig_format(const Public_Key &key, const std::string &hash_algo, const std::string &sig_algo, bool for_client_auth, const Policy &policy) const
Definition: tls_handshake_state.cpp:483
Botan::TLS::Handshake_State::operator=
Handshake_State & operator=(const Handshake_State &)=delete
Botan::TLS::Handshake_State::~Handshake_State
virtual ~Handshake_State()=default
Botan::TLS::Handshake_State::server_hello_done
const Server_Hello_Done * server_hello_done() const
Definition: tls_handshake_state.h:135
Botan::TLS::Hello_Verify_Request
Definition: tls_messages.h:47
Botan::TLS::Handshake_State::client_finished
const Finished * client_finished() const
Definition: tls_handshake_state.h:156
Botan::TLS::Handshake_State::session_keys
const Session_Keys & session_keys() const
Definition: tls_handshake_state.h:161
Botan::TLS::Handshake_State::server_hello
const Server_Hello * server_hello() const
Definition: tls_handshake_state.h:123
Botan::Private_Key
Definition: pk_keys.h:166
Botan::TLS::Certificate_Verify
Definition: tls_messages.h:508
Botan::TLS::Handshake_State::server_finished
const Finished * server_finished() const
Definition: tls_handshake_state.h:153
Botan::TLS::Finished
Definition: tls_messages.h:542
Botan::TLS::Handshake_State::server_certs
const Certificate * server_certs() const
Definition: tls_handshake_state.h:126
Botan::TLS::Handshake_Hash
Definition: tls_handshake_hash.h:22
Botan::TLS::Handshake_State::Handshake_State
Handshake_State(Handshake_IO *io, Callbacks &callbacks)
Definition: tls_handshake_state.cpp:178
Botan::TLS::Handshake_State::server_cert_status
const Certificate_Status * server_cert_status() const
Definition: tls_handshake_state.h:147
Botan::TLS::Protocol_Version
Definition: tls_version.h:21
Botan::TLS::Server_Key_Exchange
Definition: tls_messages.h:581
Botan::TLS::Session_Keys
Definition: tls_session_key.h:22
Botan::TLS::Handshake_State::protocol_specific_prf
KDF * protocol_specific_prf() const
Definition: tls_handshake_state.cpp:356
Botan::TLS::Ciphersuite
Definition: tls_ciphersuite.h:22
Botan::TLS::Server_Hello_Done
Definition: tls_messages.h:649
Botan::TLS::Callbacks
Definition: tls_callbacks.h:35
Botan::TLS::Handshake_State::compute_session_keys
void compute_session_keys()
Definition: tls_handshake_state.cpp:284
Botan::TLS::Handshake_State::hash
Handshake_Hash & hash()
Definition: tls_handshake_state.h:167
Botan::TLS::Handshake_State::set_version
void set_version(const Protocol_Version &version)
Definition: tls_handshake_state.cpp:279
Botan::TLS::Handshake_State::server_kex
const Server_Key_Exchange * server_kex() const
Definition: tls_handshake_state.h:129
Botan::TLS::Client_Key_Exchange
Definition: tls_messages.h:397
Botan::secure_vector
std::vector< T, secure_allocator< T >> secure_vector
Definition: secmem.h:121
Botan::TLS::Handshake_State::get_next_handshake_msg
std::pair< Handshake_Type, std::vector< uint8_t > > get_next_handshake_msg()
Definition: tls_handshake_state.cpp:328
Botan::TLS::Handshake_State::client_verify
const Certificate_Verify * client_verify() const
Definition: tls_handshake_state.h:144
Botan::TLS::Handshake_Message
Definition: tls_handshake_msg.h:26
Botan::TLS::Handshake_State::hash
const Handshake_Hash & hash() const
Definition: tls_handshake_state.h:169
Botan::TLS::Handshake_IO
Definition: tls_handshake_io.h:30
Botan
Definition: alg_id.cpp:13
Botan::TLS::Handshake_State::confirm_transition_to
void confirm_transition_to(Handshake_Type msg_type)
Definition: tls_handshake_state.cpp:294
Botan::TLS::Certificate
Definition: tls_messages.h:431
Botan::TLS::Handshake_State::session_ticket
std::vector< uint8_t > session_ticket() const
Definition: tls_handshake_state.cpp:348
resume_master_secret
secure_vector< uint8_t > resume_master_secret
Definition: tls_client.cpp:38
Botan::Public_Key
Definition: pk_keys.h:24
Botan::TLS::Handshake_State::note_message
void note_message(const Handshake_Message &msg)
Definition: tls_handshake_state.cpp:185
Botan::KDF
Definition: kdf.h:20
Botan::TLS::Policy
Definition: tls_policy.h:26
Botan::PKCS11::ObjectClass::Certificate
Botan::TLS::Handshake_State::handshake_io
Handshake_IO & handshake_io()
Definition: tls_handshake_state.h:57
Botan::TLS::Handshake_State::hello_verify_request
void hello_verify_request(const Hello_Verify_Request &hello_verify)
Definition: tls_handshake_state.cpp:190
Botan::TLS::New_Session_Ticket
Definition: tls_messages.h:663
Botan::TLS::Handshake_State
Definition: tls_handshake_state.h:47
Botan::TLS::Handshake_State::srp_identifier
std::string srp_identifier() const
Definition: tls_handshake_state.cpp:336
Botan::TLS::Handshake_State::choose_sig_format
std::pair< std::string, Signature_Format > choose_sig_format(const Private_Key &key, std::string &hash_algo, std::string &sig_algo, bool for_client_auth, const Policy &policy) const
Definition: tls_handshake_state.cpp:424
Botan::TLS::Handshake_State::new_session_ticket
const New_Session_Ticket * new_session_ticket() const
Definition: tls_handshake_state.h:150
Botan::TLS::Handshake_State::ciphersuite
const Ciphersuite & ciphersuite() const
Definition: tls_handshake_state.h:159
Botan::TLS::Handshake_State::received_handshake_msg
bool received_handshake_msg(Handshake_Type msg_type) const
Definition: tls_handshake_state.cpp:320
Botan::TLS::Handshake_State::client_certs
const Certificate * client_certs() const
Definition: tls_handshake_state.h:138
Botan::TLS::Handshake_State::set_expected_next
void set_expected_next(Handshake_Type msg_type)
Definition: tls_handshake_state.cpp:315
Botan::TLS::Handshake_State::cert_req
const Certificate_Req * cert_req() const
Definition: tls_handshake_state.h:132
Botan::TLS::Certificate_Status
Definition: tls_messages.h:454
Botan::TLS::Handshake_State::version
Protocol_Version version() const
Definition: tls_handshake_state.h:100
Botan::TLS::Handshake_State::client_hello
const Client_Hello * client_hello() const
Definition: tls_handshake_state.h:120
Botan::TLS::Handshake_State::client_kex
const Client_Key_Exchange * client_kex() const
Definition: tls_handshake_state.h:141
Botan::TLS::Handshake_Type
Handshake_Type
Definition: tls_magic.h:38
Botan::TLS::Client_Hello
Definition: tls_messages.h:67