Coverage Report

Created: 2021-10-13 08:49

/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
164k
   {
22
164k
   switch(code)
23
164k
      {
24
1.53k
      case TLSEXT_SERVER_NAME_INDICATION:
25
1.53k
         return std::make_unique<Server_Name_Indicator>(reader, size);
26
27
18.5k
      case TLSEXT_SUPPORTED_GROUPS:
28
18.5k
         return std::make_unique<Supported_Groups>(reader, size);
29
30
905
      case TLSEXT_CERT_STATUS_REQUEST:
31
905
         return std::make_unique<Certificate_Status_Request>(reader, size, from);
32
33
3.59k
      case TLSEXT_EC_POINT_FORMATS:
34
3.59k
         return std::make_unique<Supported_Point_Formats>(reader, size);
35
36
786
      case TLSEXT_SAFE_RENEGOTIATION:
37
786
         return std::make_unique<Renegotiation_Extension>(reader, size);
38
39
822
      case TLSEXT_SIGNATURE_ALGORITHMS:
40
822
         return std::make_unique<Signature_Algorithms>(reader, size);
41
42
144
      case TLSEXT_USE_SRTP:
43
144
         return std::make_unique<SRTP_Protection_Profiles>(reader, size);
44
45
7.79k
      case TLSEXT_ALPN:
46
7.79k
         return std::make_unique<Application_Layer_Protocol_Notification>(reader, size);
47
48
6.85k
      case TLSEXT_EXTENDED_MASTER_SECRET:
49
6.85k
         return std::make_unique<Extended_Master_Secret>(reader, size);
50
51
557
      case TLSEXT_ENCRYPT_THEN_MAC:
52
557
         return std::make_unique<Encrypt_then_MAC>(reader, size);
53
54
3.12k
      case TLSEXT_SESSION_TICKET:
55
3.12k
         return std::make_unique<Session_Ticket>(reader, size);
56
57
367
      case TLSEXT_SUPPORTED_VERSIONS:
58
367
         return std::make_unique<Supported_Versions>(reader, size, from);
59
164k
      }
60
61
119k
   return std::make_unique<Unknown_Extension>(static_cast<Handshake_Extension_Type>(code),
62
119k
                                              reader, size);;
63
0
   }
64
65
}
66
67
void Extensions::deserialize(TLS_Data_Reader& reader, Connection_Side from)
68
25.1k
   {
69
25.1k
   if(reader.has_remaining())
70
24.4k
      {
71
24.4k
      const uint16_t all_extn_size = reader.get_uint16_t();
72
73
24.4k
      if(reader.remaining_bytes() != all_extn_size)
74
153
         throw Decoding_Error("Bad extension size");
75
76
189k
      while(reader.has_remaining())
77
164k
         {
78
164k
         const uint16_t extension_code = reader.get_uint16_t();
79
164k
         const uint16_t extension_size = reader.get_uint16_t();
80
81
164k
         const auto type = static_cast<Handshake_Extension_Type>(extension_code);
82
83
164k
         if(m_extensions.find(type) != m_extensions.end())
84
24
            throw TLS_Exception(TLS::Alert::DECODE_ERROR,
85
24
                                "Peer sent duplicated extensions");
86
87
164k
         this->add(make_extension(reader, extension_code, extension_size, from));
88
164k
         }
89
24.3k
      }
90
25.1k
   }
91
92
std::vector<uint8_t> Extensions::serialize(Connection_Side whoami) const
93
20.1k
   {
94
20.1k
   std::vector<uint8_t> buf(2); // 2 bytes for length field
95
96
20.1k
   for(auto& extn : m_extensions)
97
40.3k
      {
98
40.3k
      if(extn.second->empty())
99
0
         continue;
100
101
40.3k
      const uint16_t extn_code = static_cast<uint16_t>(extn.second->type());
102
103
40.3k
      const std::vector<uint8_t> extn_val = extn.second->serialize(whoami);
104
105
40.3k
      buf.push_back(get_byte<0>(extn_code));
106
40.3k
      buf.push_back(get_byte<1>(extn_code));
107
108
40.3k
      buf.push_back(get_byte<0>(static_cast<uint16_t>(extn_val.size())));
109
40.3k
      buf.push_back(get_byte<1>(static_cast<uint16_t>(extn_val.size())));
110
111
40.3k
      buf += extn_val;
112
40.3k
      }
113
114
20.1k
   const uint16_t extn_size = static_cast<uint16_t>(buf.size() - 2);
115
116
20.1k
   buf[0] = get_byte<0>(extn_size);
117
20.1k
   buf[1] = get_byte<1>(extn_size);
118
119
   // avoid sending a completely empty extensions block
120
20.1k
   if(buf.size() == 2)
121
2.59k
      return std::vector<uint8_t>();
122
123
17.5k
   return buf;
124
20.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
18.0k
   {
137
18.0k
   std::set<Handshake_Extension_Type> offers;
138
167k
   for(auto i = m_extensions.begin(); i != m_extensions.end(); ++i)
139
149k
      offers.insert(i->first);
140
18.0k
   return offers;
141
18.0k
   }
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
119k
   {
149
119k
   }
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
1.53k
   {
159
   /*
160
   * This is used by the server to confirm that it knew the name
161
   */
162
1.53k
   if(extension_size == 0)
163
1.16k
      return;
164
165
366
   uint16_t name_bytes = reader.get_uint16_t();
166
167
366
   if(name_bytes + 2 != extension_size)
168
79
      throw Decoding_Error("Bad encoding of SNI extension");
169
170
1.05k
   while(name_bytes)
171
767
      {
172
767
      uint8_t name_type = reader.get_byte();
173
767
      name_bytes--;
174
175
767
      if(name_type == 0) // DNS
176
565
         {
177
565
         m_sni_host_name = reader.get_string(2, 1, 65535);
178
565
         name_bytes -= static_cast<uint16_t>(2 + m_sni_host_name.size());
179
565
         }
180
202
      else // some other unknown name type
181
202
         {
182
202
         reader.discard_next(name_bytes);
183
202
         name_bytes = 0;
184
202
         }
185
767
      }
186
287
   }
187
188
std::vector<uint8_t> Server_Name_Indicator::serialize(Connection_Side /*whoami*/) const
189
1.51k
   {
190
1.51k
   std::vector<uint8_t> buf;
191
192
1.51k
   size_t name_len = m_sni_host_name.size();
193
194
1.51k
   buf.push_back(get_byte<0>(static_cast<uint16_t>(name_len+3)));
195
1.51k
   buf.push_back(get_byte<1>(static_cast<uint16_t>(name_len+3)));
196
1.51k
   buf.push_back(0); // DNS
197
198
1.51k
   buf.push_back(get_byte<0>(static_cast<uint16_t>(name_len)));
199
1.51k
   buf.push_back(get_byte<1>(static_cast<uint16_t>(name_len)));
200
201
1.51k
   buf += std::make_pair(
202
1.51k
      cast_char_ptr_to_uint8(m_sni_host_name.data()),
203
1.51k
      m_sni_host_name.size());
204
205
1.51k
   return buf;
206
1.51k
   }
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
786
   {
211
786
   if(m_reneg_data.size() + 1 != extension_size)
212
87
      throw Decoding_Error("Bad encoding for secure renegotiation extn");
213
786
   }
214
215
std::vector<uint8_t> Renegotiation_Extension::serialize(Connection_Side /*whoami*/) const
216
7.57k
   {
217
7.57k
   std::vector<uint8_t> buf;
218
7.57k
   append_tls_length_value(buf, m_reneg_data, 1);
219
7.57k
   return buf;
220
7.57k
   }
221
222
Application_Layer_Protocol_Notification::Application_Layer_Protocol_Notification(TLS_Data_Reader& reader,
223
                                                                                 uint16_t extension_size)
224
7.79k
   {
225
7.79k
   if(extension_size == 0)
226
5.26k
      return; // empty extension
227
228
2.53k
   const uint16_t name_bytes = reader.get_uint16_t();
229
230
2.53k
   size_t bytes_remaining = extension_size - 2;
231
232
2.53k
   if(name_bytes != bytes_remaining)
233
129
      throw Decoding_Error("Bad encoding of ALPN extension, bad length field");
234
235
20.3k
   while(bytes_remaining)
236
18.0k
      {
237
18.0k
      const std::string p = reader.get_string(1, 0, 255);
238
239
18.0k
      if(bytes_remaining < p.size() + 1)
240
19
         throw Decoding_Error("Bad encoding of ALPN, length field too long");
241
242
17.9k
      if(p.empty())
243
77
         throw Decoding_Error("Empty ALPN protocol not allowed");
244
245
17.9k
      bytes_remaining -= (p.size() + 1);
246
247
17.9k
      m_protocols.push_back(p);
248
17.9k
      }
249
2.40k
   }
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
5.21k
   {
262
5.21k
   std::vector<uint8_t> buf(2);
263
264
5.21k
   for(auto&& p: m_protocols)
265
5.21k
      {
266
5.21k
      if(p.length() >= 256)
267
0
         throw TLS_Exception(Alert::INTERNAL_ERROR, "ALPN name too long");
268
5.21k
      if(p != "")
269
5.21k
         append_tls_length_value(buf,
270
5.21k
                                 cast_char_ptr_to_uint8(p.data()),
271
5.21k
                                 p.size(),
272
5.21k
                                 1);
273
5.21k
      }
274
275
5.21k
   buf[0] = get_byte<0>(static_cast<uint16_t>(buf.size()-2));
276
5.21k
   buf[1] = get_byte<1>(static_cast<uint16_t>(buf.size()-2));
277
278
5.21k
   return buf;
279
5.21k
   }
280
281
Supported_Groups::Supported_Groups(const std::vector<Group_Params>& groups) : m_groups(groups)
282
1.51k
   {
283
1.51k
   }
284
285
std::vector<Group_Params> Supported_Groups::ec_groups() const
286
37.9k
   {
287
37.9k
   std::vector<Group_Params> ec;
288
37.9k
   for(auto g : m_groups)
289
164k
      {
290
164k
      if(group_param_is_dh(g) == false)
291
106k
         ec.push_back(g);
292
164k
      }
293
37.9k
   return ec;
294
37.9k
   }
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
1.51k
   {
309
1.51k
   std::vector<uint8_t> buf(2);
310
311
1.51k
   for(auto g : m_groups)
312
18.1k
      {
313
18.1k
      const uint16_t id = static_cast<uint16_t>(g);
314
315
18.1k
      if(id > 0)
316
18.1k
         {
317
18.1k
         buf.push_back(get_byte<0>(id));
318
18.1k
         buf.push_back(get_byte<1>(id));
319
18.1k
         }
320
18.1k
      }
321
322
1.51k
   buf[0] = get_byte<0>(static_cast<uint16_t>(buf.size()-2));
323
1.51k
   buf[1] = get_byte<1>(static_cast<uint16_t>(buf.size()-2));
324
325
1.51k
   return buf;
326
1.51k
   }
327
328
Supported_Groups::Supported_Groups(TLS_Data_Reader& reader,
329
                                   uint16_t extension_size)
330
18.5k
   {
331
18.5k
   const uint16_t len = reader.get_uint16_t();
332
333
18.5k
   if(len + 2 != extension_size)
334
66
      throw Decoding_Error("Inconsistent length field in supported groups list");
335
336
18.5k
   if(len % 2 == 1)
337
3
      throw Decoding_Error("Supported groups list of strange size");
338
339
18.5k
   const size_t elems = len / 2;
340
341
99.0k
   for(size_t i = 0; i != elems; ++i)
342
80.5k
      {
343
80.5k
      const uint16_t id = reader.get_uint16_t();
344
80.5k
      m_groups.push_back(static_cast<Group_Params>(id));
345
80.5k
      }
346
18.5k
   }
347
348
std::vector<uint8_t> Supported_Point_Formats::serialize(Connection_Side /*whoami*/) const
349
4.80k
   {
350
   // if this extension is sent, it MUST include uncompressed (RFC 4492, section 5.1)
351
4.80k
   if(m_prefers_compressed)
352
0
      {
353
0
      return std::vector<uint8_t>{2, ANSIX962_COMPRESSED_PRIME, UNCOMPRESSED};
354
0
      }
355
4.80k
   else
356
4.80k
      {
357
4.80k
      return std::vector<uint8_t>{1, UNCOMPRESSED};
358
4.80k
      }
359
4.80k
   }
360
361
Supported_Point_Formats::Supported_Point_Formats(TLS_Data_Reader& reader,
362
                                                 uint16_t extension_size)
363
3.59k
   {
364
3.59k
   uint8_t len = reader.get_byte();
365
366
3.59k
   if(len + 1 != extension_size)
367
63
      throw Decoding_Error("Inconsistent length field in supported point formats list");
368
369
6.12k
   for(size_t i = 0; i != len; ++i)
370
4.71k
      {
371
4.71k
      uint8_t format = reader.get_byte();
372
373
4.71k
      if(static_cast<ECPointFormat>(format) == UNCOMPRESSED)
374
189
         {
375
189
         m_prefers_compressed = false;
376
189
         reader.discard_next(len-i-1);
377
189
         return;
378
189
         }
379
4.52k
      else if(static_cast<ECPointFormat>(format) == ANSIX962_COMPRESSED_PRIME)
380
1.94k
         {
381
1.94k
         m_prefers_compressed = true;
382
1.94k
         reader.discard_next(len-i-1);
383
1.94k
         return;
384
1.94k
         }
385
386
      // ignore ANSIX962_COMPRESSED_CHAR2, we don't support these curves
387
4.71k
      }
388
3.53k
   }
389
390
std::vector<uint8_t> Signature_Algorithms::serialize(Connection_Side /*whoami*/) const
391
1.51k
   {
392
1.51k
   BOTAN_ASSERT(m_schemes.size() < 256, "Too many signature schemes");
393
394
1.51k
   std::vector<uint8_t> buf;
395
396
1.51k
   const uint16_t len = static_cast<uint16_t>(m_schemes.size() * 2);
397
398
1.51k
   buf.push_back(get_byte<0>(len));
399
1.51k
   buf.push_back(get_byte<1>(len));
400
401
1.51k
   for(Signature_Scheme scheme : m_schemes)
402
13.6k
      {
403
13.6k
      const uint16_t scheme_code = static_cast<uint16_t>(scheme);
404
405
13.6k
      buf.push_back(get_byte<0>(scheme_code));
406
13.6k
      buf.push_back(get_byte<1>(scheme_code));
407
13.6k
      }
408
409
1.51k
   return buf;
410
1.51k
   }
411
412
Signature_Algorithms::Signature_Algorithms(TLS_Data_Reader& reader,
413
                                           uint16_t extension_size)
414
822
   {
415
822
   uint16_t len = reader.get_uint16_t();
416
417
822
   if(len + 2 != extension_size || len % 2 == 1 || len == 0)
418
84
      {
419
84
      throw Decoding_Error("Bad encoding on signature algorithms extension");
420
84
      }
421
422
13.1k
   while(len)
423
12.4k
      {
424
12.4k
      const uint16_t scheme_code = reader.get_uint16_t();
425
12.4k
      m_schemes.push_back(static_cast<Signature_Scheme>(scheme_code));
426
12.4k
      len -= 2;
427
12.4k
      }
428
738
   }
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.12k
   {}
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
144
   {
437
144
   const std::vector<uint8_t> mki = reader.get_range<uint8_t>(1, 0, 255);
438
439
144
   if(m_pp.size() * 2 + mki.size() + 3 != extension_size)
440
95
      throw Decoding_Error("Bad encoding for SRTP protection extension");
441
442
49
   if(!mki.empty())
443
6
      throw Decoding_Error("Unhandled non-empty MKI for SRTP protection extension");
444
49
   }
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
6.85k
   {
468
6.85k
   if(extension_size != 0)
469
51
      throw Decoding_Error("Invalid extended_master_secret extension");
470
6.85k
   }
471
472
std::vector<uint8_t> Extended_Master_Secret::serialize(Connection_Side /*whoami*/) const
473
8.18k
   {
474
8.18k
   return std::vector<uint8_t>();
475
8.18k
   }
476
477
Encrypt_then_MAC::Encrypt_then_MAC(TLS_Data_Reader&,
478
                                   uint16_t extension_size)
479
557
   {
480
557
   if(extension_size != 0)
481
46
      throw Decoding_Error("Invalid encrypt_then_mac extension");
482
557
   }
483
484
std::vector<uint8_t> Encrypt_then_MAC::serialize(Connection_Side /*whoami*/) const
485
1.97k
   {
486
1.97k
   return std::vector<uint8_t>();
487
1.97k
   }
488
489
std::vector<uint8_t> Certificate_Status_Request::serialize(Connection_Side whoami) const
490
2.23k
   {
491
2.23k
   std::vector<uint8_t> buf;
492
493
2.23k
   if(whoami == Connection_Side::SERVER)
494
721
      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
1.51k
   buf.push_back(1); // CertificateStatusType ocsp
506
507
1.51k
   buf.push_back(0);
508
1.51k
   buf.push_back(0);
509
1.51k
   buf.push_back(0);
510
1.51k
   buf.push_back(0);
511
512
1.51k
   return buf;
513
2.23k
   }
514
515
Certificate_Status_Request::Certificate_Status_Request(TLS_Data_Reader& reader,
516
                                                       uint16_t extension_size,
517
                                                       Connection_Side from)
518
905
   {
519
905
   if(from == Connection_Side::SERVER)
520
19
      {
521
19
      if(extension_size != 0)
522
16
         throw Decoding_Error("Server sent non-empty Certificate_Status_Request extension");
523
19
      }
524
886
   else if(extension_size > 0)
525
533
      {
526
533
      const uint8_t type = reader.get_byte();
527
533
      if(type == 1)
528
59
         {
529
59
         const size_t len_resp_id_list = reader.get_uint16_t();
530
59
         m_ocsp_names = reader.get_fixed<uint8_t>(len_resp_id_list);
531
59
         const size_t len_requ_ext = reader.get_uint16_t();
532
59
         m_extension_bytes = reader.get_fixed<uint8_t>(len_requ_ext);
533
59
         }
534
474
      else
535
474
         {
536
474
         reader.discard_next(extension_size - 1);
537
474
         }
538
533
      }
539
905
   }
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
1.51k
   {
546
1.51k
   }
547
548
std::vector<uint8_t> Supported_Versions::serialize(Connection_Side whoami) const
549
1.51k
   {
550
1.51k
   std::vector<uint8_t> buf;
551
552
1.51k
   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
1.51k
   else
559
1.51k
      {
560
1.51k
      BOTAN_ASSERT_NOMSG(m_versions.size() >= 1);
561
1.51k
      const uint8_t len = static_cast<uint8_t>(m_versions.size() * 2);
562
563
1.51k
      buf.push_back(len);
564
565
1.51k
      for(Protocol_Version version : m_versions)
566
1.51k
         {
567
1.51k
         buf.push_back(version.major_version());
568
1.51k
         buf.push_back(version.minor_version());
569
1.51k
         }
570
1.51k
      }
571
572
1.51k
   return buf;
573
1.51k
   }
574
575
Supported_Versions::Supported_Versions(Protocol_Version offer, const Policy& policy)
576
1.51k
   {
577
1.51k
   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
1.51k
   else
583
1.51k
      {
584
1.51k
      if(offer >= Protocol_Version::TLS_V12 && policy.allow_tls12())
585
1.51k
         m_versions.push_back(Protocol_Version::TLS_V12);
586
1.51k
      }
587
1.51k
   }
588
589
Supported_Versions::Supported_Versions(TLS_Data_Reader& reader,
590
                                       uint16_t extension_size,
591
                                       Connection_Side from)
592
367
   {
593
367
   if(from == Connection_Side::SERVER)
594
19
      {
595
19
      if(extension_size != 2)
596
16
         throw Decoding_Error("Server sent invalid supported_versions extension");
597
3
      m_versions.push_back(Protocol_Version(reader.get_uint16_t()));
598
3
      }
599
348
   else
600
348
      {
601
348
      auto versions = reader.get_range<uint16_t>(1, 1, 127);
602
603
348
      for(auto v : versions)
604
2.69k
         m_versions.push_back(Protocol_Version(v));
605
606
348
      if(extension_size != 1+2*versions.size())
607
58
         throw Decoding_Error("Client sent invalid supported_versions extension");
608
348
      }
609
367
   }
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
}