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

randombit / botan / 5079590438

25 May 2023 12:28PM UTC coverage: 92.228% (+0.5%) from 91.723%
5079590438

Pull #3502

github

Pull Request #3502: Apply clang-format to the codebase

75589 of 81959 relevant lines covered (92.23%)

12139530.51 hits per line

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

91.11
/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/internal/stl_util.h>
15
#include <botan/internal/tls_handshake_state.h>
16

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

22
#include <iterator>
23
#include <sstream>
24

25
namespace Botan::TLS {
26

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

42
#if defined(BOTAN_HAS_TLS_13)
43
   if(offer_version == Protocol_Version::TLS_V13) {
3,555✔
44
      m_impl = std::make_unique<Client_Impl_13>(
1,065✔
45
         callbacks, session_manager, creds, policy, rng, std::move(info), next_protocols);
1,065✔
46

47
      if(m_impl->expects_downgrade()) {
1,065✔
48
         m_impl->set_io_buffer_size(io_buf_sz);
1,045✔
49
      }
50

51
      if(m_impl->is_downgrading()) {
1,065✔
52
         // TLS 1.3 implementation found a resumable TLS 1.2 session and
53
         // requested a downgrade right away.
54
         downgrade();
115✔
55
      }
56
   } else
57
#endif
58
      m_impl = std::make_unique<Client_Impl_12>(callbacks,
7,470✔
59
                                                session_manager,
60
                                                creds,
61
                                                policy,
62
                                                rng,
63
                                                std::move(info),
2,490✔
64
                                                offer_version.is_datagram_protocol(),
4,980✔
65
                                                next_protocols,
66
                                                io_buf_sz);
2,490✔
67
}
3,555✔
68

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

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

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

77
   if(!info->peer_transcript.empty()) {
570✔
78
      // replay peer data received so far
79
      return m_impl->from_peer(info->peer_transcript);
455✔
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
}
570✔
86

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

90
   if(m_impl->is_downgrading()) {
81,349✔
91
      read = downgrade();
455✔
92
   }
93

94
   return read;
81,265✔
95
}
96

97
bool Client::is_active() const { return m_impl->is_active(); }
2,321✔
98

99
bool Client::is_closed() const { return m_impl->is_closed(); }
509✔
100

101
bool Client::is_closed_for_reading() const { return m_impl->is_closed_for_reading(); }
×
102

103
bool Client::is_closed_for_writing() const { return m_impl->is_closed_for_writing(); }
×
104

105
std::vector<X509_Certificate> Client::peer_cert_chain() const { return m_impl->peer_cert_chain(); }
×
106

107
SymmetricKey Client::key_material_export(std::string_view label, std::string_view context, size_t length) const {
211✔
108
   return m_impl->key_material_export(label, context, length);
211✔
109
}
110

111
void Client::renegotiate(bool force_full_renegotiation) { m_impl->renegotiate(force_full_renegotiation); }
×
112

113
void Client::update_traffic_keys(bool request_peer_update) { m_impl->update_traffic_keys(request_peer_update); }
1✔
114

115
bool Client::secure_renegotiation_supported() const { return m_impl->secure_renegotiation_supported(); }
11✔
116

117
void Client::to_peer(std::span<const uint8_t> data) { m_impl->to_peer(data); }
1,938✔
118

119
void Client::send_alert(const Alert& alert) { m_impl->send_alert(alert); }
902✔
120

121
void Client::send_warning_alert(Alert::Type type) { m_impl->send_warning_alert(type); }
116✔
122

123
void Client::send_fatal_alert(Alert::Type type) { m_impl->send_fatal_alert(type); }
16✔
124

125
void Client::close() { m_impl->close(); }
183✔
126

127
bool Client::timeout_check() { return m_impl->timeout_check(); }
21✔
128

129
std::string Client::application_protocol() const { return m_impl->application_protocol(); }
1,152✔
130

131
}
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