Botan 1.10.17
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
19namespace Botan {
20
21/**
22* TLS Handshake Message Base Class
23*/
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*/
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
60
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*/
87 {
88 public:
89 Handshake_Type type() const { return CLIENT_KEX; }
90
92
94 const Private_Key* key,
95 Version_Code version);
96
98 Record_Writer& output,
99 HandshakeHash& hash,
100 const Public_Key* my_key,
101 Version_Code using_version,
102 Version_Code pref_version);
103
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*/
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>&,
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*/
137 {
138 public:
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 */
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*/
164 {
165 public:
167
169
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*/
186 {
187 public:
188 Handshake_Type type() const { return FINISHED; }
189
192
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>&,
203
204 Connection_Side side;
205 SecureVector<byte> verification_data;
206 };
207
208/**
209* Hello Request Message
210*/
212 {
213 public:
215
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*/
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
238 Record_Writer&, const TLS_Policy&,
239 const std::vector<X509_Certificate>&,
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*/
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
266 Record_Writer&, const Public_Key*,
267 const Private_Key*, const MemoryRegion<byte>&,
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*/
284 {
285 public:
287
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
std::vector< Certificate_Type > acceptable_types() const
Certificate_Req(Record_Writer &, HandshakeHash &, const std::vector< X509_Certificate > &)
Definition cert_req.cpp:20
Handshake_Type type() const
std::vector< X509_DN > acceptable_CAs() const
Certificate_Req(const MemoryRegion< byte > &buf)
bool verify(const X509_Certificate &, HandshakeHash &)
Definition cert_ver.cpp:73
Certificate_Verify(const MemoryRegion< byte > &buf)
Handshake_Type type() const
Certificate_Verify(RandomNumberGenerator &rng, Record_Writer &, HandshakeHash &, const Private_Key *)
Definition cert_ver.cpp:21
Certificate(Record_Writer &, const std::vector< X509_Certificate > &, HandshakeHash &)
Definition cert_req.cpp:86
Handshake_Type type() const
std::vector< X509_Certificate > cert_chain() const
Certificate(const MemoryRegion< byte > &buf)
std::string srp_identifier() const
const SecureVector< byte > & random() const
Client_Hello(const MemoryRegion< byte > &buf, Handshake_Type type)
const SecureVector< byte > & session_id() const
Client_Hello(RandomNumberGenerator &rng, Record_Writer &, const TLS_Policy &, HandshakeHash &)
Definition hello.cpp:65
std::string hostname() const
bool offered_suite(u16bit) const
Definition hello.cpp:212
std::vector< byte > compression_algos() const
Version_Code version() const
std::vector< u16bit > ciphersuites() const
Handshake_Type type() const
Client_Key_Exchange(RandomNumberGenerator &rng, Record_Writer &output, HandshakeHash &hash, const Public_Key *my_key, Version_Code using_version, Version_Code pref_version)
Definition c_kex.cpp:22
Handshake_Type type() const
SecureVector< byte > pre_master_secret() const
Definition c_kex.cpp:160
Finished(Record_Writer &, Version_Code, Connection_Side, const MemoryRegion< byte > &, HandshakeHash &)
Definition finished.cpp:16
bool verify(const MemoryRegion< byte > &, Version_Code, const HandshakeHash &, Connection_Side)
Definition finished.cpp:44
Finished(const MemoryRegion< byte > &buf)
Handshake_Type type() const
virtual Handshake_Type type() const =0
void send(Record_Writer &, HandshakeHash &) const
Definition hello.cpp:16
Hello_Request(Record_Writer &)
Definition hello.cpp:39
Handshake_Type type() const
Hello_Request(const MemoryRegion< byte > &buf)
Handshake_Type type() const
Server_Hello_Done(const MemoryRegion< byte > &buf)
Server_Hello_Done(Record_Writer &, HandshakeHash &)
Definition hello.cpp:308
const SecureVector< byte > & session_id() const
byte compression_algo() const
Server_Hello(const MemoryRegion< byte > &buf)
Handshake_Type type() const
const SecureVector< byte > & random() const
Server_Hello(RandomNumberGenerator &rng, Record_Writer &, const TLS_Policy &, const std::vector< X509_Certificate > &, const Client_Hello &, Version_Code, HandshakeHash &)
Definition hello.cpp:223
u16bit ciphersuite() const
Version_Code version()
Handshake_Type type() const
Public_Key * key() const
Definition s_kex.cpp:136
bool verify(const X509_Certificate &, const MemoryRegion< byte > &, const MemoryRegion< byte > &) const
Definition s_kex.cpp:149
Server_Key_Exchange(const MemoryRegion< byte > &buf)
Server_Key_Exchange(RandomNumberGenerator &rng, Record_Writer &, const Public_Key *, const Private_Key *, const MemoryRegion< byte > &, const MemoryRegion< byte > &, HandshakeHash &)
Definition s_kex.cpp:22
Connection_Side
Definition tls_magic.h:29
unsigned short u16bit
Definition types.h:27
Handshake_Type
Definition tls_magic.h:40
@ CLIENT_HELLO
Definition tls_magic.h:42
@ HELLO_REQUEST
Definition tls_magic.h:41
@ CERTIFICATE_VERIFY
Definition tls_magic.h:49
@ SERVER_HELLO
Definition tls_magic.h:44
@ FINISHED
Definition tls_magic.h:51
@ CERTIFICATE
Definition tls_magic.h:45
@ CERTIFICATE_REQUEST
Definition tls_magic.h:47
@ SERVER_KEX
Definition tls_magic.h:46
@ CLIENT_KEX
Definition tls_magic.h:50
@ SERVER_HELLO_DONE
Definition tls_magic.h:48
Version_Code
Definition tls_magic.h:22