blob: 01a4253b34df7223ff8a439d115c741bfb86b42b (
plain)
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
/*
* TLS Extensions
* (C) 2011 Jack Lloyd
*
* Released under the terms of the Botan license
*/
#ifndef BOTAN_TLS_EXTENSIONS_H__
#define BOTAN_TLS_EXTENSIONS_H__
#include <botan/secmem.h>
#include <botan/tls_magic.h>
#include <vector>
#include <string>
namespace Botan {
class TLS_Data_Reader;
/**
* Base class representing a TLS extension of some kind
*/
class TLS_Extension
{
public:
virtual TLS_Handshake_Extension_Type type() const = 0;
virtual MemoryVector<byte> serialize() const = 0;
virtual bool empty() const = 0;
virtual ~TLS_Extension() {}
};
/**
* Server Name Indicator extension (RFC 3546)
*/
class Server_Name_Indicator : public TLS_Extension
{
public:
TLS_Handshake_Extension_Type type() const
{ return TLSEXT_SERVER_NAME_INDICATION; }
Server_Name_Indicator(const std::string& host_name) :
sni_host_name(host_name) {}
Server_Name_Indicator(TLS_Data_Reader& reader);
std::string host_name() const { return sni_host_name; }
MemoryVector<byte> serialize() const;
bool empty() const { return sni_host_name == ""; }
private:
std::string sni_host_name;
};
/**
* SRP identifier extension (RFC 5054)
*/
class SRP_Identifier : public TLS_Extension
{
public:
TLS_Handshake_Extension_Type type() const
{ return TLSEXT_SRP_IDENTIFIER; }
SRP_Identifier(const std::string& identifier) :
srp_identifier(identifier) {}
SRP_Identifier(TLS_Data_Reader& reader);
std::string identifier() const { return srp_identifier; }
MemoryVector<byte> serialize() const;
bool empty() const { return srp_identifier == ""; }
private:
std::string srp_identifier;
};
/**
* Represents a block of extensions in a hello message
*/
class TLS_Extensions
{
public:
size_t count() const { return extensions.size(); }
TLS_Extension* at(size_t idx) { return extensions.at(idx); }
void push_back(TLS_Extension* extn)
{ extensions.push_back(extn); }
MemoryVector<byte> serialize() const;
TLS_Extensions() {}
TLS_Extensions(TLS_Data_Reader& reader); // deserialize
~TLS_Extensions();
private:
TLS_Extensions(const TLS_Extensions&) {}
TLS_Extensions& operator=(const TLS_Extensions&) { return (*this); }
std::vector<TLS_Extension*> extensions;
};
}
#endif
|