Coverage Report

Created: 2021-11-25 09:31

/src/botan/src/lib/tls/tls_extensions.cpp
Line
Count
Source (jump to first uncovered line)
1
/*
2
* TLS Extensions
3
* (C) 2011,2012,2015,2016 Jack Lloyd
4
*     2016 Juraj Somorovsky
5
*
6
* Botan is released under the Simplified BSD License (see license.txt)
7
*/
8
9
#include <botan/tls_extensions.h>
10
#include <botan/internal/tls_reader.h>
11
#include <botan/tls_exceptn.h>
12
#include <botan/tls_policy.h>
13
14
namespace Botan {
15
16
namespace TLS {
17
18
namespace {
19
20
std::unique_ptr<Extension> make_extension(TLS_Data_Reader& reader, uint16_t code, uint16_t size, Connection_Side from)
21
179k
   {
22
179k
   switch(code)
23
179k
      {
24
2.25k
      case TLSEXT_SERVER_NAME_INDICATION:
25
2.25k
         return std::make_unique<Server_Name_Indicator>(reader, size);
26
27
19.8k
      case TLSEXT_SUPPORTED_GROUPS:
28
19.8k
         return std::make_unique<Supported_Groups>(reader, size);
29
30
1.04k
      case TLSEXT_CERT_STATUS_REQUEST:
31
1.04k
         return std::make_unique<Certificate_Status_Request>(reader, size, from);
32
33
3.30k
      case TLSEXT_EC_POINT_FORMATS:
34
3.30k
         return std::make_unique<Supported_Point_Formats>(reader, size);
35
36
912
      case TLSEXT_SAFE_RENEGOTIATION:
37
912
         return std::make_unique<Renegotiation_Extension>(reader, size);
38
39
1.46k
      case TLSEXT_SIGNATURE_ALGORITHMS:
40
1.46k
         return std::make_unique<Signature_Algorithms>(reader, size);
41
42
214
      case TLSEXT_USE_SRTP:
43
214
         return std::make_unique<SRTP_Protection_Profiles>(reader, size);
44
45
9.70k
      case TLSEXT_ALPN:
46
9.70k
         return std::make_unique<Application_Layer_Protocol_Notification>(reader, size);
47
48
4.21k
      case TLSEXT_EXTENDED_MASTER_SECRET:
49
4.21k
         return std::make_unique<Extended_Master_Secret>(reader, size);
50
51
376
      case TLSEXT_ENCRYPT_THEN_MAC:
52
376
         return std::make_unique<Encrypt_then_MAC>(reader, size);
53
54
3.33k
      case TLSEXT_SESSION_TICKET:
55
3.33k
         return std::make_unique<Session_Ticket>(reader, size);
56
57
411
      case TLSEXT_SUPPORTED_VERSIONS:
58
411
         return std::make_unique<Supported_Versions>(reader, size, from);
59
179k
      }
60
61
132k
   return std::make_unique<Unknown_Extension>(static_cast<Handshake_Extension_Type>(code),
62
132k
                                              reader, size);;
63
0
   }
64
65
}
66
67
void Extensions::deserialize(TLS_Data_Reader& reader, Connection_Side from)
68
27.7k
   {
69
27.7k
   if(reader.has_remaining())
70
26.9k
      {
71
26.9k
      const uint16_t all_extn_size = reader.get_uint16_t();
72
73
26.9k
      if(reader.remaining_bytes() != all_extn_size)
74
185
         throw Decoding_Error("Bad extension size");
75
76
206k
      while(reader.has_remaining())
77
180k
         {
78
180k
         const uint16_t extension_code = reader.get_uint16_t();
79
180k
         const uint16_t extension_size = reader.get_uint16_t();
80
81
180k
         const auto type = static_cast<Handshake_Extension_Type>(extension_code);
82
83
180k
         if(m_extensions.find(type) != m_extensions.end())
84
46
            throw TLS_Exception(TLS::Alert::DECODE_ERROR,
85
46
                                "Peer sent duplicated extensions");
86
87
179k
         this->add(make_extension(reader, extension_code, extension_size, from));
88
179k
         }
89
26.7k
      }
90
27.7k
   }
91
92
std::vector<uint8_t> Extensions::serialize(Connection_Side whoami) const
93
23.1k
   {
94
23.1k
   std::vector<uint8_t> buf(2); // 2 bytes for length field
95
96
23.1k
   for(auto& extn : m_extensions)
97
55.4k
      {
98
55.4k
      if(extn.second->empty())
99
0
         continue;
100
101
55.4k
      const uint16_t extn_code = static_cast<uint16_t>(extn.second->type());
102
103
55.4k
      const std::vector<uint8_t> extn_val = extn.second->serialize(whoami);
104
105
55.4k
      buf.push_back(get_byte<0>(extn_code));
106
55.4k
      buf.push_back(get_byte<1>(extn_code));
107
108
55.4k
      buf.push_back(get_byte<0>(static_cast<uint16_t>(extn_val.size())));
109
55.4k
      buf.push_back(get_byte<1>(static_cast<uint16_t>(extn_val.size())));
110
111
55.4k
      buf += extn_val;
112
55.4k
      }
113
114
23.1k
   const uint16_t extn_size = static_cast<uint16_t>(buf.size() - 2);
115
116
23.1k
   buf[0] = get_byte<0>(extn_size);
117
23.1k
   buf[1] = get_byte<1>(extn_size);
118
119
   // avoid sending a completely empty extensions block
120
23.1k
   if(buf.size() == 2)
121
3.57k
      return std::vector<uint8_t>();
122
123
19.6k
   return buf;
124
23.1k
   }
125
126
bool Extensions::remove_extension(Handshake_Extension_Type typ)
127
0
   {
128
0
   auto i = m_extensions.find(typ);
129
0
   if(i == m_extensions.end())
130
0
      return false;
131
0
   m_extensions.erase(i);
132
0
   return true;
133
0
   }
134
135
std::set<Handshake_Extension_Type> Extensions::extension_types() const
136
19.2k
   {
137
19.2k
   std::set<Handshake_Extension_Type> offers;
138
179k
   for(auto i = m_extensions.begin(); i != m_extensions.end(); ++i)
139
160k
      offers.insert(i->first);
140
19.2k
   return offers;
141
19.2k
   }
142
143
Unknown_Extension::Unknown_Extension(Handshake_Extension_Type type,
144
                                     TLS_Data_Reader& reader,
145
                                     uint16_t extension_size) :
146
   m_type(type),
147
   m_value(reader.get_fixed<uint8_t>(extension_size))
148
132k
   {
149
132k
   }
150
151
std::vector<uint8_t> Unknown_Extension::serialize(Connection_Side /*whoami*/) const
152
0
   {
153
0
   throw Invalid_State("Cannot encode an unknown TLS extension");
154
0
   }
155
156
Server_Name_Indicator::Server_Name_Indicator(TLS_Data_Reader& reader,
157
                                             uint16_t extension_size)
158
2.25k
   {
159
   /*
160
   * This is used by the server to confirm that it knew the name
161
   */
162
2.25k
   if(extension_size == 0)
163
1.71k
      return;
164
165
538
   uint16_t name_bytes = reader.get_uint16_t();
166
167
538
   if(name_bytes + 2 != extension_size)
168
102
      throw Decoding_Error("Bad encoding of SNI extension");
169
170
1.66k
   while(name_bytes)
171
1.22k
      {
172
1.22k
      uint8_t name_type = reader.get_byte();
173
1.22k
      name_bytes--;
174
175
1.22k
      if(name_type == 0) // DNS
176
916
         {
177
916
         m_sni_host_name = reader.get_string(2, 1, 65535);
178
916
         name_bytes -= static_cast<uint16_t>(2 + m_sni_host_name.size());
179
916
         }
180
311
      else // some other unknown name type
181
311
         {
182
311
         reader.discard_next(name_bytes);
183
311
         name_bytes = 0;
184
311
         }
185
1.22k
      }
186
436
   }
187
188
std::vector<uint8_t> Server_Name_Indicator::serialize(Connection_Side /*whoami*/) const
189
3.01k
   {
190
3.01k
   std::vector<uint8_t> buf;
191
192
3.01k
   size_t name_len = m_sni_host_name.size();
193
194
3.01k
   buf.push_back(get_byte<0>(static_cast<uint16_t>(name_len+3)));
195
3.01k
   buf.push_back(get_byte<1>(static_cast<uint16_t>(name_len+3)));
196
3.01k
   buf.push_back(0); // DNS
197
198
3.01k
   buf.push_back(get_byte<0>(static_cast<uint16_t>(name_len)));
199
3.01k
   buf.push_back(get_byte<1>(static_cast<uint16_t>(name_len)));
200
201
3.01k
   buf += std::make_pair(
202
3.01k
      cast_char_ptr_to_uint8(m_sni_host_name.data()),
203
3.01k
      m_sni_host_name.size());
204
205
3.01k
   return buf;
206
3.01k
   }
207
208
Renegotiation_Extension::Renegotiation_Extension(TLS_Data_Reader& reader,
209
                                                 uint16_t extension_size) : m_reneg_data(reader.get_range<uint8_t>(1, 0, 255))
210
912
   {
211
912
   if(m_reneg_data.size() + 1 != extension_size)
212
123
      throw Decoding_Error("Bad encoding for secure renegotiation extn");
213
912
   }
214
215
std::vector<uint8_t> Renegotiation_Extension::serialize(Connection_Side /*whoami*/) const
216
9.80k
   {
217
9.80k
   std::vector<uint8_t> buf;
218
9.80k
   append_tls_length_value(buf, m_reneg_data, 1);
219
9.80k
   return buf;
220
9.80k
   }
221
222
Application_Layer_Protocol_Notification::Application_Layer_Protocol_Notification(TLS_Data_Reader& reader,
223
                                                                                 uint16_t extension_size)
224
9.70k
   {
225
9.70k
   if(extension_size == 0)
226
7.33k
      return; // empty extension
227
228
2.36k
   const uint16_t name_bytes = reader.get_uint16_t();
229
230
2.36k
   size_t bytes_remaining = extension_size - 2;
231
232
2.36k
   if(name_bytes != bytes_remaining)
233
162
      throw Decoding_Error("Bad encoding of ALPN extension, bad length field");
234
235
21.3k
   while(bytes_remaining)
236
19.2k
      {
237
19.2k
      const std::string p = reader.get_string(1, 0, 255);
238
239
19.2k
      if(bytes_remaining < p.size() + 1)
240
29
         throw Decoding_Error("Bad encoding of ALPN, length field too long");
241
242
19.2k
      if(p.empty())
243
100
         throw Decoding_Error("Empty ALPN protocol not allowed");
244
245
19.1k
      bytes_remaining -= (p.size() + 1);
246
247
19.1k
      m_protocols.push_back(p);
248
19.1k
      }
249
2.20k
   }
250
251
const std::string& Application_Layer_Protocol_Notification::single_protocol() const
252
0
   {
253
0
   if(m_protocols.size() != 1)
254
0
      throw TLS_Exception(Alert::HANDSHAKE_FAILURE,
255
0
                          "Server sent " + std::to_string(m_protocols.size()) +
256
0
                          " protocols in ALPN extension response");
257
0
   return m_protocols[0];
258
0
   }
259
260
std::vector<uint8_t> Application_Layer_Protocol_Notification::serialize(Connection_Side /*whoami*/) const
261
7.26k
   {
262
7.26k
   std::vector<uint8_t> buf(2);
263
264
7.26k
   for(auto&& p: m_protocols)
265
7.26k
      {
266
7.26k
      if(p.length() >= 256)
267
0
         throw TLS_Exception(Alert::INTERNAL_ERROR, "ALPN name too long");
268
7.26k
      if(p != "")
269
7.26k
         append_tls_length_value(buf,
270
7.26k
                                 cast_char_ptr_to_uint8(p.data()),
271
7.26k
                                 p.size(),
272
7.26k
                                 1);
273
7.26k
      }
274
275
7.26k
   buf[0] = get_byte<0>(static_cast<uint16_t>(buf.size()-2));
276
7.26k
   buf[1] = get_byte<1>(static_cast<uint16_t>(buf.size()-2));
277
278
7.26k
   return buf;
279
7.26k
   }
280
281
Supported_Groups::Supported_Groups(const std::vector<Group_Params>& groups) : m_groups(groups)
282
3.01k
   {
283
3.01k
   }
284
285
std::vector<Group_Params> Supported_Groups::ec_groups() const
286
41.7k
   {
287
41.7k
   std::vector<Group_Params> ec;
288
41.7k
   for(auto g : m_groups)
289
193k
      {
290
193k
      if(group_param_is_dh(g) == false)
291
138k
         ec.push_back(g);
292
193k
      }
293
41.7k
   return ec;
294
41.7k
   }
295
296
std::vector<Group_Params> Supported_Groups::dh_groups() const
297
0
   {
298
0
   std::vector<Group_Params> dh;
299
0
   for(auto g : m_groups)
300
0
      {
301
0
      if(group_param_is_dh(g) == true)
302
0
         dh.push_back(g);
303
0
      }
304
0
   return dh;
305
0
   }
306
307
std::vector<uint8_t> Supported_Groups::serialize(Connection_Side /*whoami*/) const
308
3.01k
   {
309
3.01k
   std::vector<uint8_t> buf(2);
310
311
3.01k
   for(auto g : m_groups)
312
36.2k
      {
313
36.2k
      const uint16_t id = static_cast<uint16_t>(g);
314
315
36.2k
      if(id > 0)
316
36.2k
         {
317
36.2k
         buf.push_back(get_byte<0>(id));
318
36.2k
         buf.push_back(get_byte<1>(id));
319
36.2k
         }
320
36.2k
      }
321
322
3.01k
   buf[0] = get_byte<0>(static_cast<uint16_t>(buf.size()-2));
323
3.01k
   buf[1] = get_byte<1>(static_cast<uint16_t>(buf.size()-2));
324
325
3.01k
   return buf;
326
3.01k
   }
327
328
Supported_Groups::Supported_Groups(TLS_Data_Reader& reader,
329
                                   uint16_t extension_size)
330
19.8k
   {
331
19.8k
   const uint16_t len = reader.get_uint16_t();
332
333
19.8k
   if(len + 2 != extension_size)
334
101
      throw Decoding_Error("Inconsistent length field in supported groups list");
335
336
19.7k
   if(len % 2 == 1)
337
4
      throw Decoding_Error("Supported groups list of strange size");
338
339
19.6k
   const size_t elems = len / 2;
340
341
108k
   for(size_t i = 0; i != elems; ++i)
342
88.9k
      {
343
88.9k
      const uint16_t id = reader.get_uint16_t();
344
88.9k
      m_groups.push_back(static_cast<Group_Params>(id));
345
88.9k
      }
346
19.6k
   }
347
348
std::vector<uint8_t> Supported_Point_Formats::serialize(Connection_Side /*whoami*/) const
349
5.96k
   {
350
   // if this extension is sent, it MUST include uncompressed (RFC 4492, section 5.1)
351
5.96k
   if(m_prefers_compressed)
352
0
      {
353
0
      return std::vector<uint8_t>{2, ANSIX962_COMPRESSED_PRIME, UNCOMPRESSED};
354
0
      }
355
5.96k
   else
356
5.96k
      {
357
5.96k
      return std::vector<uint8_t>{1, UNCOMPRESSED};
358
5.96k
      }
359
5.96k
   }
360
361
Supported_Point_Formats::Supported_Point_Formats(TLS_Data_Reader& reader,
362
                                                 uint16_t extension_size)
363
3.30k
   {
364
3.30k
   uint8_t len = reader.get_byte();
365
366
3.30k
   if(len + 1 != extension_size)
367
84
      throw Decoding_Error("Inconsistent length field in supported point formats list");
368
369
5.51k
   for(size_t i = 0; i != len; ++i)
370
4.17k
      {
371
4.17k
      uint8_t format = reader.get_byte();
372
373
4.17k
      if(static_cast<ECPointFormat>(format) == UNCOMPRESSED)
374
177
         {
375
177
         m_prefers_compressed = false;
376
177
         reader.discard_next(len-i-1);
377
177
         return;
378
177
         }
379
3.99k
      else if(static_cast<ECPointFormat>(format) == ANSIX962_COMPRESSED_PRIME)
380
1.69k
         {
381
1.69k
         m_prefers_compressed = true;
382
1.69k
         reader.discard_next(len-i-1);
383
1.69k
         return;
384
1.69k
         }
385
386
      // ignore ANSIX962_COMPRESSED_CHAR2, we don't support these curves
387
4.17k
      }
388
3.22k
   }
389
390
std::vector<uint8_t> Signature_Algorithms::serialize(Connection_Side /*whoami*/) const
391
3.01k
   {
392
3.01k
   BOTAN_ASSERT(m_schemes.size() < 256, "Too many signature schemes");
393
394
3.01k
   std::vector<uint8_t> buf;
395
396
3.01k
   const uint16_t len = static_cast<uint16_t>(m_schemes.size() * 2);
397
398
3.01k
   buf.push_back(get_byte<0>(len));
399
3.01k
   buf.push_back(get_byte<1>(len));
400
401
3.01k
   for(Signature_Scheme scheme : m_schemes)
402
27.1k
      {
403
27.1k
      const uint16_t scheme_code = static_cast<uint16_t>(scheme);
404
405
27.1k
      buf.push_back(get_byte<0>(scheme_code));
406
27.1k
      buf.push_back(get_byte<1>(scheme_code));
407
27.1k
      }
408
409
3.01k
   return buf;
410
3.01k
   }
411
412
Signature_Algorithms::Signature_Algorithms(TLS_Data_Reader& reader,
413
                                           uint16_t extension_size)
414
1.46k
   {
415
1.46k
   uint16_t len = reader.get_uint16_t();
416
417
1.46k
   if(len + 2 != extension_size || len % 2 == 1 || len == 0)
418
106
      {
419
106
      throw Decoding_Error("Bad encoding on signature algorithms extension");
420
106
      }
421
422
24.4k
   while(len)
423
23.0k
      {
424
23.0k
      const uint16_t scheme_code = reader.get_uint16_t();
425
23.0k
      m_schemes.push_back(static_cast<Signature_Scheme>(scheme_code));
426
23.0k
      len -= 2;
427
23.0k
      }
428
1.36k
   }
429
430
Session_Ticket::Session_Ticket(TLS_Data_Reader& reader,
431
                               uint16_t extension_size) : m_ticket(reader.get_elem<uint8_t, std::vector<uint8_t>>(extension_size))
432
3.33k
   {}
433
434
SRTP_Protection_Profiles::SRTP_Protection_Profiles(TLS_Data_Reader& reader,
435
                                                   uint16_t extension_size) : m_pp(reader.get_range<uint16_t>(2, 0, 65535))
436
214
   {
437
214
   const std::vector<uint8_t> mki = reader.get_range<uint8_t>(1, 0, 255);
438
439
214
   if(m_pp.size() * 2 + mki.size() + 3 != extension_size)
440
139
      throw Decoding_Error("Bad encoding for SRTP protection extension");
441
442
75
   if(!mki.empty())
443
9
      throw Decoding_Error("Unhandled non-empty MKI for SRTP protection extension");
444
75
   }
445
446
std::vector<uint8_t> SRTP_Protection_Profiles::serialize(Connection_Side /*whoami*/) const
447
0
   {
448
0
   std::vector<uint8_t> buf;
449
450
0
   const uint16_t pp_len = static_cast<uint16_t>(m_pp.size() * 2);
451
0
   buf.push_back(get_byte<0>(pp_len));
452
0
   buf.push_back(get_byte<1>(pp_len));
453
454
0
   for(uint16_t pp : m_pp)
455
0
      {
456
0
      buf.push_back(get_byte<0>(pp));
457
0
      buf.push_back(get_byte<1>(pp));
458
0
      }
459
460
0
   buf.push_back(0); // srtp_mki, always empty here
461
462
0
   return buf;
463
0
   }
464
465
Extended_Master_Secret::Extended_Master_Secret(TLS_Data_Reader&,
466
                                               uint16_t extension_size)
467
4.21k
   {
468
4.21k
   if(extension_size != 0)
469
61
      throw Decoding_Error("Invalid extended_master_secret extension");
470
4.21k
   }
471
472
std::vector<uint8_t> Extended_Master_Secret::serialize(Connection_Side /*whoami*/) const
473
7.05k
   {
474
7.05k
   return std::vector<uint8_t>();
475
7.05k
   }
476
477
Encrypt_then_MAC::Encrypt_then_MAC(TLS_Data_Reader&,
478
                                   uint16_t extension_size)
479
376
   {
480
376
   if(extension_size != 0)
481
65
      throw Decoding_Error("Invalid encrypt_then_mac extension");
482
376
   }
483
484
std::vector<uint8_t> Encrypt_then_MAC::serialize(Connection_Side /*whoami*/) const
485
3.27k
   {
486
3.27k
   return std::vector<uint8_t>();
487
3.27k
   }
488
489
std::vector<uint8_t> Certificate_Status_Request::serialize(Connection_Side whoami) const
490
3.83k
   {
491
3.83k
   std::vector<uint8_t> buf;
492
493
3.83k
   if(whoami == Connection_Side::SERVER)
494
816
      return buf; // server reply is empty
495
496
   /*
497
   opaque ResponderID<1..2^16-1>;
498
   opaque Extensions<0..2^16-1>;
499
500
   CertificateStatusType status_type = ocsp(1)
501
   ResponderID responder_id_list<0..2^16-1>
502
   Extensions  request_extensions;
503
   */
504
505
3.01k
   buf.push_back(1); // CertificateStatusType ocsp
506
507
3.01k
   buf.push_back(0);
508
3.01k
   buf.push_back(0);
509
3.01k
   buf.push_back(0);
510
3.01k
   buf.push_back(0);
511
512
3.01k
   return buf;
513
3.83k
   }
514
515
Certificate_Status_Request::Certificate_Status_Request(TLS_Data_Reader& reader,
516
                                                       uint16_t extension_size,
517
                                                       Connection_Side from)
518
1.04k
   {
519
1.04k
   if(from == Connection_Side::SERVER)
520
52
      {
521
52
      if(extension_size != 0)
522
28
         throw Decoding_Error("Server sent non-empty Certificate_Status_Request extension");
523
52
      }
524
994
   else if(extension_size > 0)
525
454
      {
526
454
      const uint8_t type = reader.get_byte();
527
454
      if(type == 1)
528
54
         {
529
54
         const size_t len_resp_id_list = reader.get_uint16_t();
530
54
         m_ocsp_names = reader.get_fixed<uint8_t>(len_resp_id_list);
531
54
         const size_t len_requ_ext = reader.get_uint16_t();
532
54
         m_extension_bytes = reader.get_fixed<uint8_t>(len_requ_ext);
533
54
         }
534
400
      else
535
400
         {
536
400
         reader.discard_next(extension_size - 1);
537
400
         }
538
454
      }
539
1.04k
   }
540
541
Certificate_Status_Request::Certificate_Status_Request(const std::vector<uint8_t>& ocsp_responder_ids,
542
                                                       const std::vector<std::vector<uint8_t>>& ocsp_key_ids) :
543
   m_ocsp_names(ocsp_responder_ids),
544
   m_ocsp_keys(ocsp_key_ids)
545
3.01k
   {
546
3.01k
   }
547
548
std::vector<uint8_t> Supported_Versions::serialize(Connection_Side whoami) const
549
3.01k
   {
550
3.01k
   std::vector<uint8_t> buf;
551
552
3.01k
   if(whoami == Connection_Side::SERVER)
553
0
      {
554
0
      BOTAN_ASSERT_NOMSG(m_versions.size() == 1);
555
0
      buf.push_back(m_versions[0].major_version());
556
0
      buf.push_back(m_versions[0].minor_version());
557
0
      }
558
3.01k
   else
559
3.01k
      {
560
3.01k
      BOTAN_ASSERT_NOMSG(m_versions.size() >= 1);
561
3.01k
      const uint8_t len = static_cast<uint8_t>(m_versions.size() * 2);
562
563
3.01k
      buf.push_back(len);
564
565
3.01k
      for(Protocol_Version version : m_versions)
566
3.01k
         {
567
3.01k
         buf.push_back(version.major_version());
568
3.01k
         buf.push_back(version.minor_version());
569
3.01k
         }
570
3.01k
      }
571
572
3.01k
   return buf;
573
3.01k
   }
574
575
Supported_Versions::Supported_Versions(Protocol_Version offer, const Policy& policy)
576
3.01k
   {
577
3.01k
   if(offer.is_datagram_protocol())
578
0
      {
579
0
      if(offer >= Protocol_Version::DTLS_V12 && policy.allow_dtls12())
580
0
         m_versions.push_back(Protocol_Version::DTLS_V12);
581
0
      }
582
3.01k
   else
583
3.01k
      {
584
3.01k
      if(offer >= Protocol_Version::TLS_V12 && policy.allow_tls12())
585
3.01k
         m_versions.push_back(Protocol_Version::TLS_V12);
586
3.01k
      }
587
3.01k
   }
588
589
Supported_Versions::Supported_Versions(TLS_Data_Reader& reader,
590
                                       uint16_t extension_size,
591
                                       Connection_Side from)
592
411
   {
593
411
   if(from == Connection_Side::SERVER)
594
40
      {
595
40
      if(extension_size != 2)
596
34
         throw Decoding_Error("Server sent invalid supported_versions extension");
597
6
      m_versions.push_back(Protocol_Version(reader.get_uint16_t()));
598
6
      }
599
371
   else
600
371
      {
601
371
      auto versions = reader.get_range<uint16_t>(1, 1, 127);
602
603
371
      for(auto v : versions)
604
2.42k
         m_versions.push_back(Protocol_Version(v));
605
606
371
      if(extension_size != 1+2*versions.size())
607
51
         throw Decoding_Error("Client sent invalid supported_versions extension");
608
371
      }
609
411
   }
610
611
bool Supported_Versions::supports(Protocol_Version version) const
612
0
   {
613
0
   for(auto v : m_versions)
614
0
      if(version == v)
615
0
         return true;
616
0
   return false;
617
0
   }
618
619
}
620
621
}