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

randombit / botan / 16245054916

13 Jul 2025 03:51AM UTC coverage: 90.581% (+0.009%) from 90.572%
16245054916

Pull #4982

github

web-flow
Merge 11956826b into e87c8e33a
Pull Request #4982: Enable and fix clang-tidy warning cert-err58-cpp

99186 of 109500 relevant lines covered (90.58%)

12549723.2 hits per line

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

97.87
/src/tests/test_tls_handshake_state_13.cpp
1
/*
2
* (C) 2022 Jack Lloyd
3
* (C) 2022 Hannes Rantzsch, René Meusel - neXenio
4
*
5
* Botan is released under the Simplified BSD License (see license.txt)
6
*/
7

8
#include "tests.h"
9

10
#if defined(BOTAN_HAS_TLS_13)
11
   #include <botan/tls_exceptn.h>
12
   #include <botan/internal/tls_handshake_state_13.h>
13
#endif
14

15
namespace Botan_Tests {
16

17
namespace {
18

19
#if defined(BOTAN_HAS_TLS_13)
20

21
// From RFC 8448
22
const auto client_hello_message_hex =
23
   "03 03 cb"
24
   "34 ec b1 e7 81 63 ba 1c 38 c6 da cb 19 6a 6d ff a2 1a 8d 99 12"
25
   "ec 18 a2 ef 62 83 02 4d ec e7 00 00 06 13 01 13 03 13 02 01 00"
26
   "00 91 00 00 00 0b 00 09 00 00 06 73 65 72 76 65 72 ff 01 00 01"
27
   "00 00 0a 00 14 00 12 00 1d 00 17 00 18 00 19 01 00 01 01 01 02"
28
   "01 03 01 04 00 23 00 00 00 33 00 26 00 24 00 1d 00 20 99 38 1d"
29
   "e5 60 e4 bd 43 d2 3d 8e 43 5a 7d ba fe b3 c0 6e 51 c1 3c ae 4d"
30
   "54 13 69 1e 52 9a af 2c 00 2b 00 03 02 03 04 00 0d 00 20 00 1e"
31
   "04 03 05 03 06 03 02 03 08 04 08 05 08 06 04 01 05 01 06 01 02"
32
   "01 04 02 05 02 06 02 02 02 00 2d 00 02 01 01 00 1c 00 02 40 01";
33

34
const auto server_hello_message_hex =
35
   "03 03 a6"
36
   "af 06 a4 12 18 60 dc 5e 6e 60 24 9c d3 4c 95 93 0c 8a c5 cb 14"
37
   "34 da c1 55 77 2e d3 e2 69 28 00 13 01 00 00 2e 00 33 00 24 00"
38
   "1d 00 20 c9 82 88 76 11 20 95 fe 66 76 2b db f7 c6 72 e1 56 d6"
39
   "cc 25 3b 83 3d f1 dd 69 b1 b0 4e 75 1f 0f 00 2b 00 02 03 04";
40

41
const auto server_finished_message_hex =
42
   "9b 9b 14 1d 90 63 37 fb"
43
   "d2 cb dc e7 1d f4 de da 4a b4 2c 30"
44
   "95 72 cb 7f ff ee 54 54 b7 8f 07 18";
45

46
const auto client_finished_message_hex =
47
   "a8 ec 43 6d 67 76 34 ae 52 5a c1"
48
   "fc eb e1 1a 03 9e c1 76 94 fa c6 e9 85 27 b6 42 f2 ed d5 ce 61";
49

50
std::vector<Test::Result> finished_message_handling() {
1✔
51
   return {
1✔
52
      CHECK("Client sends and receives Finished messages",
53
            [&](auto& result) {
1✔
54
               Botan::TLS::Client_Handshake_State_13 state;
1✔
55

56
               const auto client_finished_message = Botan::hex_decode(client_finished_message_hex);
1✔
57
               const auto server_finished_message = Botan::hex_decode(server_finished_message_hex);
1✔
58

59
               Botan::TLS::Finished_13 client_finished(client_finished_message);
1✔
60

61
               [[maybe_unused]]  // just making sure that the return type of .sending is correct
62
               std::reference_wrapper<Botan::TLS::Finished_13>
63
                  client_fin = state.sending(std::move(client_finished));
1✔
64
               result.test_throws("not stored as server Finished", [&] { state.server_finished(); });
4✔
65
               result.test_eq(
4✔
66
                  "correct client Finished stored", state.client_finished().serialize(), client_finished_message);
1✔
67

68
               Botan::TLS::Finished_13 server_finished(server_finished_message);
1✔
69

70
               auto server_fin = state.received(std::move(server_finished));
2✔
71
               result.require("client can receive server finished",
2✔
72
                              std::holds_alternative<std::reference_wrapper<Botan::TLS::Finished_13>>(server_fin));
1✔
73
               result.test_eq(
4✔
74
                  "correct client Finished stored", state.client_finished().serialize(), client_finished_message);
1✔
75
               result.test_eq(
4✔
76
                  "correct server Finished stored", state.server_finished().serialize(), server_finished_message);
1✔
77
            }),
3✔
78
   };
2✔
79
}
1✔
80

81
std::vector<Test::Result> handshake_message_filtering() {
1✔
82
   return {
1✔
83
      CHECK("Client with client hello",
84
            [&](auto& result) {
1✔
85
               Botan::TLS::Client_Handshake_State_13 state;
1✔
86

87
               const auto client_hello_message = Botan::hex_decode(client_hello_message_hex);
1✔
88

89
               auto client_hello =
3✔
90
                  std::get<Botan::TLS::Client_Hello_13>(Botan::TLS::Client_Hello_13::parse(client_hello_message));
91

92
               [[maybe_unused]]  // just making sure that the return type of .sending is correct
93
               std::reference_wrapper<Botan::TLS::Client_Hello_13>
94
                  filtered = state.sending(std::move(client_hello));
2✔
95
               result.test_eq("correct client hello stored", state.client_hello().serialize(), client_hello_message);
2✔
96

97
               result.template test_throws<Botan::TLS::TLS_Exception>(
3✔
98
                  "client cannot receive client hello", "received an illegal handshake message", [&] {
1✔
99
                     auto ch =
2✔
100
                        std::get<Botan::TLS::Client_Hello_13>(Botan::TLS::Client_Hello_13::parse(client_hello_message));
101
                     state.received(std::move(ch));
2✔
102
                  });
×
103
            }),
2✔
104
      CHECK("Client with server hello",
105
            [&](auto& result) {
1✔
106
               Botan::TLS::Client_Handshake_State_13 state;
1✔
107

108
               const auto server_hello_message = Botan::hex_decode(server_hello_message_hex);
1✔
109

110
               auto server_hello =
3✔
111
                  std::get<Botan::TLS::Server_Hello_13>(Botan::TLS::Server_Hello_13::parse(server_hello_message));
112

113
               auto filtered = state.received(std::move(server_hello));
2✔
114
               result.confirm("client can receive server hello",
1✔
115
                              std::holds_alternative<std::reference_wrapper<Botan::TLS::Server_Hello_13>>(filtered));
1✔
116

117
               result.test_eq("correct server hello stored", state.server_hello().serialize(), server_hello_message);
3✔
118
            }),
2✔
119
   };
3✔
120
}
1✔
121

122
BOTAN_REGISTER_TEST_FN("tls", "tls_handshake_state_13", finished_message_handling, handshake_message_filtering);
123

124
#endif
125

126
}  // namespace
127

128
}  // namespace Botan_Tests
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

© 2025 Coveralls, Inc