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

randombit / botan / 11844561993

14 Nov 2024 07:58PM UTC coverage: 91.178% (+0.1%) from 91.072%
11844561993

Pull #4435

github

web-flow
Merge 81dcb29da into e430f157a
Pull Request #4435: Test duration values ​​are now presented in seconds with six digits of precision. Tests without time measurements have been edited.

91856 of 100744 relevant lines covered (91.18%)

9311006.71 hits per line

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

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

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

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

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

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

55
               Botan::TLS::Client_Handshake_State_13 state;
1✔
56

57
               Botan::TLS::Finished_13 client_finished(client_finished_message);
1✔
58

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

66
               Botan::TLS::Finished_13 server_finished(server_finished_message);
1✔
67

68
               auto server_fin = state.received(std::move(server_finished));
2✔
69
               result.require("client can receive server finished",
2✔
70
                              std::holds_alternative<std::reference_wrapper<Botan::TLS::Finished_13>>(server_fin));
1✔
71
               result.test_eq(
3✔
72
                  "correct client Finished stored", state.client_finished().serialize(), client_finished_message);
1✔
73
               result.test_eq(
2✔
74
                  "correct server Finished stored", state.server_finished().serialize(), server_finished_message);
1✔
75
               
76
               result.end_timer();
1✔
77
            }),
1✔
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
               result.start_timer();
1✔
86

87
               Botan::TLS::Client_Handshake_State_13 state;
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>(
2✔
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
                  
104
               result.end_timer();
1✔
105
            }),
1✔
106
      CHECK("Client with server hello",
107
            [&](auto& result) {
1✔
108
               result.start_timer();
1✔
109
               Botan::TLS::Client_Handshake_State_13 state;
1✔
110

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

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

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

124
BOTAN_REGISTER_TEST_FN("tls", "tls_handshake_state_13", finished_message_handling, handshake_message_filtering);
125

126
#endif
127

128
}  // namespace
129

130
}  // 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

© 2026 Coveralls, Inc