• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

randombit / botan / 5111374265

29 May 2023 11:19AM UTC coverage: 92.227% (+0.5%) from 91.723%
5111374265

push

github

randombit
Next release will be 3.1.0. Update release notes

75588 of 81959 relevant lines covered (92.23%)

11886470.91 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

96.55
/src/lib/tls/tls12/msg_hello_verify.cpp
1
/*
2
* DTLS Hello Verify Request
3
* (C) 2012 Jack Lloyd
4
*
5
* Botan is released under the Simplified BSD License (see license.txt)
6
*/
7

8
#include <botan/tls_messages.h>
9

10
#include <botan/mac.h>
11

12
namespace Botan::TLS {
13

14
Hello_Verify_Request::Hello_Verify_Request(const std::vector<uint8_t>& buf) {
428✔
15
   if(buf.size() < 3)
428✔
16
      throw Decoding_Error("Hello verify request too small");
1✔
17

18
   Protocol_Version version(buf[0], buf[1]);
427✔
19

20
   if(!version.is_datagram_protocol()) {
427✔
21
      throw Decoding_Error("Unknown version from server in hello verify request");
1✔
22
   }
23

24
   if(static_cast<size_t>(buf[2]) + 3 != buf.size())
426✔
25
      throw Decoding_Error("Bad length in hello verify request");
3✔
26

27
   m_cookie.assign(buf.begin() + 3, buf.end());
423✔
28
}
428✔
29

30
Hello_Verify_Request::Hello_Verify_Request(const std::vector<uint8_t>& client_hello_bits,
736✔
31
                                           std::string_view client_identity,
32
                                           const SymmetricKey& secret_key) {
736✔
33
   auto hmac = MessageAuthenticationCode::create_or_throw("HMAC(SHA-256)");
736✔
34
   hmac->set_key(secret_key);
736✔
35

36
   hmac->update_be(static_cast<uint64_t>(client_hello_bits.size()));
736✔
37
   hmac->update(client_hello_bits);
736✔
38
   hmac->update_be(static_cast<uint64_t>(client_identity.size()));
736✔
39
   hmac->update(client_identity);
736✔
40

41
   m_cookie.resize(hmac->output_length());
736✔
42
   hmac->final(m_cookie.data());
736✔
43
}
736✔
44

45
std::vector<uint8_t> Hello_Verify_Request::serialize() const {
367✔
46
   /* DTLS 1.2 server implementations SHOULD use DTLS version 1.0
47
      regardless of the version of TLS that is expected to be
48
      negotiated (RFC 6347, section 4.2.1)
49
   */
50

51
   Protocol_Version format_version(254, 255);  // DTLS 1.0
367✔
52

53
   std::vector<uint8_t> bits;
54
   bits.push_back(format_version.major_version());
367✔
55
   bits.push_back(format_version.minor_version());
367✔
56
   bits.push_back(static_cast<uint8_t>(m_cookie.size()));
367✔
57
   bits += m_cookie;
367✔
58
   return bits;
367✔
59
}
×
60

61
}  // namespace Botan::TLS
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc