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

randombit / botan / 20337522608

18 Dec 2025 12:50PM UTC coverage: 90.555% (+0.2%) from 90.358%
20337522608

Pull #5167

github

web-flow
Merge 4a0197138 into 1fd0d0cf5
Pull Request #5167: Changes to reduce unnecessary inclusions

101518 of 112106 relevant lines covered (90.56%)

12598813.82 hits per line

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

83.56
/src/lib/tls/tls_client.cpp
1
/*
2
* TLS Client
3
* (C) 2004-2011,2012,2015,2016 Jack Lloyd
4
*     2016 Matthias Gierlings
5
*     2017 Harry Reimann, Rohde & Schwarz Cybersecurity
6
*     2021 Elektrobit Automotive GmbH
7
*
8
* Botan is released under the Simplified BSD License (see license.txt)
9
*/
10

11
#include <botan/tls_client.h>
12

13
#include <botan/tls_messages.h>
14
#include <botan/tls_policy.h>
15
#include <botan/internal/tls_client_impl_12.h>
16
#include <botan/internal/tls_handshake_state.h>
17

18
#if defined(BOTAN_HAS_TLS_13)
19
   #include <botan/internal/tls_client_impl_13.h>
20
#endif
21

22
namespace Botan::TLS {
23

24
/*
25
* TLS Client Constructor
26
*/
27
Client::Client(const std::shared_ptr<Callbacks>& callbacks,
3,651✔
28
               const std::shared_ptr<Session_Manager>& session_manager,
29
               const std::shared_ptr<Credentials_Manager>& creds,
30
               const std::shared_ptr<const Policy>& policy,
31
               const std::shared_ptr<RandomNumberGenerator>& rng,
32
               Server_Information info,
33
               Protocol_Version offer_version,
34
               const std::vector<std::string>& next_protocols,
35
               size_t io_buf_sz) {
3,651✔
36
   BOTAN_ARG_CHECK(policy->acceptable_protocol_version(offer_version),
3,651✔
37
                   "Policy does not allow to offer requested protocol version");
38

39
#if defined(BOTAN_HAS_TLS_13)
40
   if(offer_version == Protocol_Version::TLS_V13) {
3,651✔
41
      m_impl = std::make_unique<Client_Impl_13>(
1,104✔
42
         callbacks, session_manager, creds, policy, rng, std::move(info), next_protocols);
1,104✔
43

44
      if(m_impl->expects_downgrade()) {
1,104✔
45
         m_impl->set_io_buffer_size(io_buf_sz);
1,075✔
46
      }
47

48
      if(m_impl->is_downgrading()) {
1,104✔
49
         // TLS 1.3 implementation found a resumable TLS 1.2 session and
50
         // requested a downgrade right away.
51
         downgrade();
116✔
52
      }
53

54
      return;
1,104✔
55
   }
56
#endif
57

58
   m_impl = std::make_unique<Client_Impl_12>(callbacks,
7,641✔
59
                                             session_manager,
60
                                             creds,
61
                                             policy,
62
                                             rng,
63
                                             std::move(info),
64
                                             offer_version.is_datagram_protocol(),
5,094✔
65
                                             next_protocols,
66
                                             io_buf_sz);
2,547✔
67
}
×
68

69
Client::~Client() = default;
5,291✔
70

71
size_t Client::downgrade() {
603✔
72
   BOTAN_ASSERT_NOMSG(m_impl->is_downgrading());
603✔
73

74
   auto info = m_impl->extract_downgrade_info();
603✔
75
   m_impl = std::make_unique<Client_Impl_12>(*info);
1,206✔
76

77
   if(!info->peer_transcript.empty()) {
603✔
78
      // replay peer data received so far
79
      return m_impl->from_peer(info->peer_transcript);
487✔
80
   } else {
81
      // the downgrade happened due to a resumable TLS 1.2 session
82
      // before any data was transferred
83
      return 0;
84
   }
85
}
603✔
86

87
size_t Client::from_peer(std::span<const uint8_t> data) {
88,886✔
88
   auto read = m_impl->from_peer(data);
88,886✔
89

90
   if(m_impl->is_downgrading()) {
86,522✔
91
      read = downgrade();
487✔
92
   }
93

94
   return read;
86,428✔
95
}
96

97
bool Client::is_handshake_complete() const {
130✔
98
   return m_impl->is_handshake_complete();
130✔
99
}
100

101
bool Client::is_active() const {
2,355✔
102
   return m_impl->is_active();
2,355✔
103
}
104

105
bool Client::is_closed() const {
558✔
106
   return m_impl->is_closed();
558✔
107
}
108

109
bool Client::is_closed_for_reading() const {
×
110
   return m_impl->is_closed_for_reading();
×
111
}
112

113
bool Client::is_closed_for_writing() const {
×
114
   return m_impl->is_closed_for_writing();
×
115
}
116

117
std::vector<X509_Certificate> Client::peer_cert_chain() const {
×
118
   return m_impl->peer_cert_chain();
×
119
}
120

121
std::shared_ptr<const Public_Key> Client::peer_raw_public_key() const {
1✔
122
   return m_impl->peer_raw_public_key();
1✔
123
}
124

125
std::optional<std::string> Client::external_psk_identity() const {
×
126
   return m_impl->external_psk_identity();
×
127
}
128

129
SymmetricKey Client::key_material_export(std::string_view label, std::string_view context, size_t length) const {
212✔
130
   return m_impl->key_material_export(label, context, length);
212✔
131
}
132

133
void Client::renegotiate(bool force_full_renegotiation) {
×
134
   m_impl->renegotiate(force_full_renegotiation);
×
135
}
×
136

137
void Client::update_traffic_keys(bool request_peer_update) {
1✔
138
   m_impl->update_traffic_keys(request_peer_update);
1✔
139
}
1✔
140

141
bool Client::secure_renegotiation_supported() const {
11✔
142
   return m_impl->secure_renegotiation_supported();
11✔
143
}
144

145
void Client::to_peer(std::span<const uint8_t> data) {
1,778✔
146
   m_impl->to_peer(data);
1,778✔
147
}
1,778✔
148

149
void Client::send_alert(const Alert& alert) {
934✔
150
   m_impl->send_alert(alert);
934✔
151
}
934✔
152

153
void Client::send_warning_alert(Alert::Type type) {
119✔
154
   m_impl->send_warning_alert(type);
119✔
155
}
119✔
156

157
void Client::send_fatal_alert(Alert::Type type) {
16✔
158
   m_impl->send_fatal_alert(type);
16✔
159
}
16✔
160

161
void Client::close() {
193✔
162
   m_impl->close();
193✔
163
}
193✔
164

165
bool Client::timeout_check() {
45✔
166
   return m_impl->timeout_check();
45✔
167
}
168

169
std::string Client::application_protocol() const {
1,188✔
170
   return m_impl->application_protocol();
1,188✔
171
}
172

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