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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
|
/*
* Policies for TLS
* (C) 2004-2010,2012 Jack Lloyd
*
* Botan is released under the Simplified BSD License (see license.txt)
*/
#include <botan/tls_policy.h>
#include <botan/tls_ciphersuite.h>
#include <botan/tls_magic.h>
#include <botan/tls_exceptn.h>
#include <botan/internal/stl_util.h>
namespace Botan {
namespace TLS {
std::vector<std::string> Policy::allowed_ciphers() const
{
return std::vector<std::string>({
//"AES-256/OCB(12)",
//"AES-128/OCB(12)",
"ChaCha20Poly1305",
"AES-256/GCM",
"AES-128/GCM",
"AES-256/CCM",
"AES-128/CCM",
"AES-256/CCM-8",
"AES-128/CCM-8",
//"Camellia-256/GCM",
//"Camellia-128/GCM",
"AES-256",
"AES-128",
//"Camellia-256",
//"Camellia-128",
//"SEED"
//"3DES",
//"RC4",
});
}
std::vector<std::string> Policy::allowed_signature_hashes() const
{
return std::vector<std::string>({
"SHA-512",
"SHA-384",
"SHA-256",
"SHA-224",
//"SHA-1",
//"MD5",
});
}
std::vector<std::string> Policy::allowed_macs() const
{
return std::vector<std::string>({
"AEAD",
"SHA-384",
"SHA-256",
"SHA-1",
//"MD5",
});
}
std::vector<std::string> Policy::allowed_key_exchange_methods() const
{
return std::vector<std::string>({
"SRP_SHA",
//"ECDHE_PSK",
//"DHE_PSK",
//"PSK",
"ECDH",
"DH",
"RSA",
});
}
std::vector<std::string> Policy::allowed_signature_methods() const
{
return std::vector<std::string>({
"ECDSA",
"RSA",
"DSA",
//""
});
}
std::vector<std::string> Policy::allowed_ecc_curves() const
{
return std::vector<std::string>({
"brainpool512r1",
"secp521r1",
"brainpool384r1",
"secp384r1",
"brainpool256r1",
"secp256r1",
//"secp256k1",
//"secp224r1",
//"secp224k1",
//"secp192r1",
//"secp192k1",
//"secp160r2",
//"secp160r1",
//"secp160k1",
});
}
/*
* Choose an ECC curve to use
*/
std::string Policy::choose_curve(const std::vector<std::string>& curve_names) const
{
const std::vector<std::string> our_curves = allowed_ecc_curves();
for(size_t i = 0; i != our_curves.size(); ++i)
if(value_exists(curve_names, our_curves[i]))
return our_curves[i];
return ""; // no shared curve
}
DL_Group Policy::dh_group() const
{
return DL_Group("modp/ietf/2048");
}
size_t Policy::minimum_dh_group_size() const
{
return 1024;
}
/*
* Return allowed compression algorithms
*/
std::vector<byte> Policy::compression() const
{
return std::vector<byte>{ NO_COMPRESSION };
}
u32bit Policy::session_ticket_lifetime() const
{
return 86400; // ~1 day
}
bool Policy::send_fallback_scsv(Protocol_Version version) const
{
return version != latest_supported_version(version.is_datagram_protocol());
}
bool Policy::acceptable_protocol_version(Protocol_Version version) const
{
if(version.is_datagram_protocol())
return (version >= Protocol_Version::DTLS_V12);
else
return (version >= Protocol_Version::TLS_V10);
}
Protocol_Version Policy::latest_supported_version(bool datagram) const
{
if(datagram)
return Protocol_Version::latest_dtls_version();
else
return Protocol_Version::latest_tls_version();
}
bool Policy::acceptable_ciphersuite(const Ciphersuite&) const
{
return true;
}
bool Policy::negotiate_heartbeat_support() const
{
return false;
}
bool Policy::allow_server_initiated_renegotiation() const
{
return true;
}
std::vector<u16bit> Policy::srtp_profiles() const
{
return std::vector<u16bit>();
}
namespace {
class Ciphersuite_Preference_Ordering
{
public:
Ciphersuite_Preference_Ordering(const std::vector<std::string>& ciphers,
const std::vector<std::string>& macs,
const std::vector<std::string>& kex,
const std::vector<std::string>& sigs) :
m_ciphers(ciphers), m_macs(macs), m_kex(kex), m_sigs(sigs) {}
bool operator()(const Ciphersuite& a, const Ciphersuite& b) const
{
if(a.kex_algo() != b.kex_algo())
{
for(size_t i = 0; i != m_kex.size(); ++i)
{
if(a.kex_algo() == m_kex[i])
return true;
if(b.kex_algo() == m_kex[i])
return false;
}
}
if(a.cipher_algo() != b.cipher_algo())
{
for(size_t i = 0; i != m_ciphers.size(); ++i)
{
if(a.cipher_algo() == m_ciphers[i])
return true;
if(b.cipher_algo() == m_ciphers[i])
return false;
}
}
if(a.cipher_keylen() != b.cipher_keylen())
{
if(a.cipher_keylen() < b.cipher_keylen())
return false;
if(a.cipher_keylen() > b.cipher_keylen())
return true;
}
if(a.sig_algo() != b.sig_algo())
{
for(size_t i = 0; i != m_sigs.size(); ++i)
{
if(a.sig_algo() == m_sigs[i])
return true;
if(b.sig_algo() == m_sigs[i])
return false;
}
}
if(a.mac_algo() != b.mac_algo())
{
for(size_t i = 0; i != m_macs.size(); ++i)
{
if(a.mac_algo() == m_macs[i])
return true;
if(b.mac_algo() == m_macs[i])
return false;
}
}
return false; // equal (?!?)
}
private:
std::vector<std::string> m_ciphers, m_macs, m_kex, m_sigs;
};
}
std::vector<u16bit> Policy::ciphersuite_list(Protocol_Version version,
bool have_srp) const
{
const std::vector<std::string> ciphers = allowed_ciphers();
const std::vector<std::string> macs = allowed_macs();
const std::vector<std::string> kex = allowed_key_exchange_methods();
const std::vector<std::string> sigs = allowed_signature_methods();
Ciphersuite_Preference_Ordering order(ciphers, macs, kex, sigs);
std::set<Ciphersuite, Ciphersuite_Preference_Ordering> ciphersuites(order);
for(auto&& suite : Ciphersuite::all_known_ciphersuites())
{
if(!acceptable_ciphersuite(suite))
continue;
if(!have_srp && suite.kex_algo() == "SRP_SHA")
continue;
if(version.is_datagram_protocol() && suite.cipher_algo() == "RC4")
continue;
if(!version.supports_aead_modes() && suite.mac_algo() == "AEAD")
continue;
if(!value_exists(kex, suite.kex_algo()))
continue; // unsupported key exchange
if(!value_exists(ciphers, suite.cipher_algo()))
continue; // unsupported cipher
if(!value_exists(macs, suite.mac_algo()))
continue; // unsupported MAC algo
if(!value_exists(sigs, suite.sig_algo()))
{
// allow if it's an empty sig algo and we want to use PSK
if(suite.sig_algo() != "" || !suite.psk_ciphersuite())
continue;
}
// OK, allow it:
ciphersuites.insert(suite);
}
if(ciphersuites.empty())
throw std::logic_error("Policy does not allow any available cipher suite");
std::vector<u16bit> ciphersuite_codes;
for(auto i : ciphersuites)
ciphersuite_codes.push_back(i.ciphersuite_code());
return ciphersuite_codes;
}
}
}
|