Botan: src/ssl/tls_messages.h Source File

Botan 1.10.16

tls_messages.h
Go to the documentation of this file.
1 /*
2 * TLS Messages
3 * (C) 2004-2010 Jack Lloyd
4 *
5 * Released under the terms of the Botan license
6 */
7
8 #ifndef BOTAN_TLS_MESSAGES_H__
9 #define BOTAN_TLS_MESSAGES_H__
10
11 #include <botan/tls_record.h>
12 #include <botan/internal/tls_handshake_hash.h>
13 #include <botan/tls_policy.h>
14 #include <botan/bigint.h>
15 #include <botan/pkcs8.h>
16 #include <botan/x509cert.h>
17 #include <vector>
18
19 namespace Botan {
20
21 /**
22 * TLS Handshake Message Base Class
23 */
24 class HandshakeMessage
25 {
26 public:
27 void send(Record_Writer&, HandshakeHash&) const;
28
29 virtual Handshake_Type type() const = 0;
30
31 virtual ~HandshakeMessage() {}
32 private:
33 HandshakeMessage& operator=(const HandshakeMessage&) { return (*this); }
34 virtual SecureVector<byte> serialize() const = 0;
35 virtual void deserialize(const MemoryRegion<byte>&) = 0;
36 };
37
38 /**
39 * Client Hello Message
40 */
41 class Client_Hello : public HandshakeMessage
42 {
43 public:
44 Handshake_Type type() const { return CLIENT_HELLO; }
45 Version_Code version() const { return c_version; }
46 const SecureVector<byte>& session_id() const { return sess_id; }
47 std::vector<u16bit> ciphersuites() const { return suites; }
48 std::vector<byte> compression_algos() const { return comp_algos; }
49
50 const SecureVector<byte>& random() const { return c_random; }
51
52 std::string hostname() const { return requested_hostname; }
53
54 std::string srp_identifier() const { return requested_srp_id; }
55
56 bool offered_suite(u16bit) const;
57
58 Client_Hello(RandomNumberGenerator& rng,
59 Record_Writer&, const TLS_Policy&, HandshakeHash&);
60
61 Client_Hello(const MemoryRegion<byte>& buf,
62 Handshake_Type type)
63 {
64 if(type == CLIENT_HELLO)
65 deserialize(buf);
66 else
67 deserialize_sslv2(buf);
68 }
69
70 private:
71 SecureVector<byte> serialize() const;
72 void deserialize(const MemoryRegion<byte>&);
73 void deserialize_sslv2(const MemoryRegion<byte>&);
74
75 Version_Code c_version;
76 SecureVector<byte> sess_id, c_random;
77 std::vector<u16bit> suites;
78 std::vector<byte> comp_algos;
79 std::string requested_hostname;
80 std::string requested_srp_id;
81 };
82
83 /**
84 * Client Key Exchange Message
85 */
86 class Client_Key_Exchange : public HandshakeMessage
87 {
88 public:
89 Handshake_Type type() const { return CLIENT_KEX; }
90
91 SecureVector<byte> pre_master_secret() const;
92
93 SecureVector<byte> pre_master_secret(RandomNumberGenerator& rng,
94 const Private_Key* key,
95 Version_Code version);
96
97 Client_Key_Exchange(RandomNumberGenerator& rng,
98 Record_Writer& output,
99 HandshakeHash& hash,
100 const Public_Key* my_key,
101 Version_Code using_version,
102 Version_Code pref_version);
103
104 Client_Key_Exchange(const MemoryRegion<byte>& buf,
105 const CipherSuite& suite,
106 Version_Code using_version);
107 private:
108 SecureVector<byte> serialize() const;
109 void deserialize(const MemoryRegion<byte>&);
110
111 SecureVector<byte> key_material, pre_master;
112 bool include_length;
113 };
114
115 /**
116 * Certificate Message
117 */
118 class Certificate : public HandshakeMessage
119 {
120 public:
121 Handshake_Type type() const { return CERTIFICATE; }
122 std::vector<X509_Certificate> cert_chain() const { return certs; }
123
124 Certificate(Record_Writer&, const std::vector<X509_Certificate>&,
125 HandshakeHash&);
126 Certificate(const MemoryRegion<byte>& buf) { deserialize(buf); }
127 private:
128 SecureVector<byte> serialize() const;
129 void deserialize(const MemoryRegion<byte>&);
130 std::vector<X509_Certificate> certs;
131 };
132
133 /**
134 * Certificate Request Message
135 */
136 class Certificate_Req : public HandshakeMessage
137 {
138 public:
139 Handshake_Type type() const { return CERTIFICATE_REQUEST; }
140
141 std::vector<Certificate_Type> acceptable_types() const { return types; }
142 std::vector<X509_DN> acceptable_CAs() const { return names; }
143
144 /* TODO
145 Certificate_Req(Record_Writer&, HandshakeHash&,
146 const X509_Certificate&);
147 */
148 Certificate_Req(Record_Writer&, HandshakeHash&,
149 const std::vector<X509_Certificate>&);
150
151 Certificate_Req(const MemoryRegion<byte>& buf) { deserialize(buf); }
152 private:
153 SecureVector<byte> serialize() const;
154 void deserialize(const MemoryRegion<byte>&);
155
156 std::vector<X509_DN> names;
157 std::vector<Certificate_Type> types;
158 };
159
160 /**
161 * Certificate Verify Message
162 */
163 class Certificate_Verify : public HandshakeMessage
164 {
165 public:
166 Handshake_Type type() const { return CERTIFICATE_VERIFY; }
167
168 bool verify(const X509_Certificate&, HandshakeHash&);
169
170 Certificate_Verify(RandomNumberGenerator& rng,
171 Record_Writer&, HandshakeHash&,
172 const Private_Key*);
173
174 Certificate_Verify(const MemoryRegion<byte>& buf) { deserialize(buf); }
175 private:
176 SecureVector<byte> serialize() const;
177 void deserialize(const MemoryRegion<byte>&);
178
179 SecureVector<byte> signature;
180 };
181
182 /**
183 * Finished Message
184 */
185 class Finished : public HandshakeMessage
186 {
187 public:
188 Handshake_Type type() const { return FINISHED; }
189
190 bool verify(const MemoryRegion<byte>&, Version_Code,
191 const HandshakeHash&, Connection_Side);
192
193 Finished(Record_Writer&, Version_Code, Connection_Side,
194 const MemoryRegion<byte>&, HandshakeHash&);
195 Finished(const MemoryRegion<byte>& buf) { deserialize(buf); }
196 private:
197 SecureVector<byte> serialize() const;
198 void deserialize(const MemoryRegion<byte>&);
199
200 SecureVector<byte> compute_verify(const MemoryRegion<byte>&,
201 HandshakeHash, Connection_Side,
202 Version_Code);
203
204 Connection_Side side;
205 SecureVector<byte> verification_data;
206 };
207
208 /**
209 * Hello Request Message
210 */
211 class Hello_Request : public HandshakeMessage
212 {
213 public:
214 Handshake_Type type() const { return HELLO_REQUEST; }
215
216 Hello_Request(Record_Writer&);
217 Hello_Request(const MemoryRegion<byte>& buf) { deserialize(buf); }
218 private:
219 SecureVector<byte> serialize() const;
220 void deserialize(const MemoryRegion<byte>&);
221 };
222
223 /**
224 * Server Hello Message
225 */
226 class Server_Hello : public HandshakeMessage
227 {
228 public:
229 Handshake_Type type() const { return SERVER_HELLO; }
230 Version_Code version() { return s_version; }
231 const SecureVector<byte>& session_id() const { return sess_id; }
232 u16bit ciphersuite() const { return suite; }
233 byte compression_algo() const { return comp_algo; }
234
235 const SecureVector<byte>& random() const { return s_random; }
236
237 Server_Hello(RandomNumberGenerator& rng,
238 Record_Writer&, const TLS_Policy&,
239 const std::vector<X509_Certificate>&,
240 const Client_Hello&, Version_Code, HandshakeHash&);
241
242 Server_Hello(const MemoryRegion<byte>& buf) { deserialize(buf); }
243 private:
244 SecureVector<byte> serialize() const;
245 void deserialize(const MemoryRegion<byte>&);
246
247 Version_Code s_version;
248 SecureVector<byte> sess_id, s_random;
249 u16bit suite;
250 byte comp_algo;
251 };
252
253 /**
254 * Server Key Exchange Message
255 */
256 class Server_Key_Exchange : public HandshakeMessage
257 {
258 public:
259 Handshake_Type type() const { return SERVER_KEX; }
260 Public_Key* key() const;
261
262 bool verify(const X509_Certificate&, const MemoryRegion<byte>&,
263 const MemoryRegion<byte>&) const;
264
265 Server_Key_Exchange(RandomNumberGenerator& rng,
266 Record_Writer&, const Public_Key*,
267 const Private_Key*, const MemoryRegion<byte>&,
268 const MemoryRegion<byte>&, HandshakeHash&);
269
270 Server_Key_Exchange(const MemoryRegion<byte>& buf) { deserialize(buf); }
271 private:
272 SecureVector<byte> serialize() const;
273 SecureVector<byte> serialize_params() const;
274 void deserialize(const MemoryRegion<byte>&);
275
276 std::vector<BigInt> params;
277 SecureVector<byte> signature;
278 };
279
280 /**
281 * Server Hello Done Message
282 */
283 class Server_Hello_Done : public HandshakeMessage
284 {
285 public:
286 Handshake_Type type() const { return SERVER_HELLO_DONE; }
287
288 Server_Hello_Done(Record_Writer&, HandshakeHash&);
289 Server_Hello_Done(const MemoryRegion<byte>& buf) { deserialize(buf); }
290 private:
291 SecureVector<byte> serialize() const;
292 void deserialize(const MemoryRegion<byte>&);
293 };
294
295 }
296
297 #endif
Botan::HandshakeMessage::~HandshakeMessage
virtual ~HandshakeMessage()
Definition: tls_messages.h:31
Botan::Certificate_Req::type
Handshake_Type type() const
Definition: tls_messages.h:139
Botan::Server_Hello::Server_Hello
Server_Hello(const MemoryRegion< byte > &buf)
Definition: tls_messages.h:242
Botan::Certificate_Verify::type
Handshake_Type type() const
Definition: tls_messages.h:166
Botan::Client_Key_Exchange
Definition: tls_messages.h:86
Botan::Client_Hello::compression_algos
std::vector< byte > compression_algos() const
Definition: tls_messages.h:48
Botan::HandshakeMessage::send
void send(Record_Writer &, HandshakeHash &) const
Definition: hello.cpp:16
Botan::HandshakeMessage
Definition: tls_messages.h:24
Botan::Hello_Request::type
Handshake_Type type() const
Definition: tls_messages.h:214
Botan::Finished::type
Handshake_Type type() const
Definition: tls_messages.h:188
Botan::RandomNumberGenerator
Definition: rng.h:20
Botan::Client_Hello::session_id
const SecureVector< byte > & session_id() const
Definition: tls_messages.h:46
Botan::Private_Key
Definition: pk_keys.h:86
Botan::FINISHED
Definition: tls_magic.h:51
Botan::CERTIFICATE_REQUEST
Definition: tls_magic.h:47
Botan::Server_Hello::type
Handshake_Type type() const
Definition: tls_messages.h:229
Botan::Certificate::type
Handshake_Type type() const
Definition: tls_messages.h:121
Botan::SERVER_KEX
Definition: tls_magic.h:46
Botan::HandshakeMessage::type
virtual Handshake_Type type() const =0
Botan::Handshake_Type
Handshake_Type
Definition: tls_magic.h:40
Botan::Server_Hello::random
const SecureVector< byte > & random() const
Definition: tls_messages.h:235
Botan::Certificate::cert_chain
std::vector< X509_Certificate > cert_chain() const
Definition: tls_messages.h:122
Botan::Certificate::Certificate
Certificate(const MemoryRegion< byte > &buf)
Definition: tls_messages.h:126
Botan::byte
unsigned char byte
Definition: types.h:22
Botan::Server_Hello::version
Version_Code version()
Definition: tls_messages.h:230
Botan::Client_Hello
Definition: tls_messages.h:41
Botan::Server_Hello_Done::Server_Hello_Done
Server_Hello_Done(const MemoryRegion< byte > &buf)
Definition: tls_messages.h:289
Botan::Connection_Side
Connection_Side
Definition: tls_magic.h:29
Botan::Client_Hello::ciphersuites
std::vector< u16bit > ciphersuites() const
Definition: tls_messages.h:47
Botan::Hello_Request::Hello_Request
Hello_Request(const MemoryRegion< byte > &buf)
Definition: tls_messages.h:217
Botan::Client_Hello::hostname
std::string hostname() const
Definition: tls_messages.h:52
Botan::X509_Certificate
Definition: x509cert.h:23
Botan::Client_Hello::type
Handshake_Type type() const
Definition: tls_messages.h:44
Botan::Certificate
Definition: tls_messages.h:118
Botan::Server_Hello::session_id
const SecureVector< byte > & session_id() const
Definition: tls_messages.h:231
Botan::u16bit
unsigned short u16bit
Definition: types.h:27
Botan::Server_Key_Exchange::type
Handshake_Type type() const
Definition: tls_messages.h:259
Botan::Version_Code
Version_Code
Definition: tls_magic.h:22
Botan::Certificate_Req::acceptable_types
std::vector< Certificate_Type > acceptable_types() const
Definition: tls_messages.h:141
Botan::Client_Hello::version
Version_Code version() const
Definition: tls_messages.h:45
Botan::Client_Key_Exchange::type
Handshake_Type type() const
Definition: tls_messages.h:89
Botan::MemoryRegion< byte >
Botan
Definition: algo_base.h:14
Botan::Certificate_Verify::Certificate_Verify
Certificate_Verify(const MemoryRegion< byte > &buf)
Definition: tls_messages.h:174
Botan::Finished
Definition: tls_messages.h:185
Botan::Record_Writer
Definition: tls_record.h:39
Botan::HELLO_REQUEST
Definition: tls_magic.h:41
Botan::Public_Key
Definition: pk_keys.h:21
Botan::Server_Hello
Definition: tls_messages.h:226
Botan::Client_Hello::random
const SecureVector< byte > & random() const
Definition: tls_messages.h:50
Botan::Finished::Finished
Finished(const MemoryRegion< byte > &buf)
Definition: tls_messages.h:195
Botan::Hello_Request
Definition: tls_messages.h:211
Botan::CERTIFICATE
Definition: tls_magic.h:45
Botan::Client_Hello::Client_Hello
Client_Hello(const MemoryRegion< byte > &buf, Handshake_Type type)
Definition: tls_messages.h:61
Botan::SERVER_HELLO_DONE
Definition: tls_magic.h:48
Botan::Certificate_Req::acceptable_CAs
std::vector< X509_DN > acceptable_CAs() const
Definition: tls_messages.h:142
Botan::Server_Hello_Done::type
Handshake_Type type() const
Definition: tls_messages.h:286
Botan::CLIENT_KEX
Definition: tls_magic.h:50
Botan::CipherSuite
Definition: tls_suites.h:20
Botan::TLS_Policy
Definition: tls_policy.h:22
Botan::CLIENT_HELLO
Definition: tls_magic.h:42
Botan::Server_Key_Exchange::Server_Key_Exchange
Server_Key_Exchange(const MemoryRegion< byte > &buf)
Definition: tls_messages.h:270
Botan::HandshakeHash
Definition: tls_handshake_hash.h:20
Botan::SecureVector< byte >
Botan::Certificate_Req
Definition: tls_messages.h:136
Botan::Server_Hello::compression_algo
byte compression_algo() const
Definition: tls_messages.h:233
Botan::Certificate_Req::Certificate_Req
Certificate_Req(const MemoryRegion< byte > &buf)
Definition: tls_messages.h:151
Botan::Server_Key_Exchange
Definition: tls_messages.h:256
Botan::SERVER_HELLO
Definition: tls_magic.h:44
Botan::Server_Hello_Done
Definition: tls_messages.h:283
Botan::Certificate_Verify
Definition: tls_messages.h:163
Botan::CERTIFICATE_VERIFY
Definition: tls_magic.h:49
Botan::Client_Hello::srp_identifier
std::string srp_identifier() const
Definition: tls_messages.h:54
Botan::Server_Hello::ciphersuite
u16bit ciphersuite() const
Definition: tls_messages.h:232