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

randombit / botan / 6550993123

17 Oct 2023 01:46PM UTC coverage: 91.709% (-0.001%) from 91.71%
6550993123

push

github

web-flow
Merge pull request #3762 from Rohde-Schwarz/fix/handshake_complete

Introduce TLS::Channel::is_handshake complete()

80126 of 87370 relevant lines covered (91.71%)

8549643.33 hits per line

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

83.33
/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,573✔
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,573✔
39
   BOTAN_ARG_CHECK(policy->acceptable_protocol_version(offer_version),
3,573✔
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,573✔
44
      m_impl = std::make_unique<Client_Impl_13>(
1,077✔
45
         callbacks, session_manager, creds, policy, rng, std::move(info), next_protocols);
1,077✔
46

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

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

57
      return;
1,077✔
58
   }
59
#endif
60

61
   m_impl = std::make_unique<Client_Impl_12>(callbacks,
7,488✔
62
                                             session_manager,
63
                                             creds,
64
                                             policy,
65
                                             rng,
66
                                             std::move(info),
2,496✔
67
                                             offer_version.is_datagram_protocol(),
4,992✔
68
                                             next_protocols,
69
                                             io_buf_sz);
2,496✔
70
}
×
71

72
Client::~Client() = default;
5,138✔
73

74
size_t Client::downgrade() {
574✔
75
   BOTAN_ASSERT_NOMSG(m_impl->is_downgrading());
574✔
76

77
   auto info = m_impl->extract_downgrade_info();
574✔
78
   m_impl = std::make_unique<Client_Impl_12>(*info);
1,148✔
79

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

90
size_t Client::from_peer(std::span<const uint8_t> data) {
82,112✔
91
   auto read = m_impl->from_peer(data);
82,112✔
92

93
   if(m_impl->is_downgrading()) {
79,758✔
94
      read = downgrade();
458✔
95
   }
96

97
   return read;
79,675✔
98
}
99

100
bool Client::is_handshake_complete() const {
105✔
101
   return m_impl->is_handshake_complete();
105✔
102
}
103

104
bool Client::is_active() const {
2,208✔
105
   return m_impl->is_active();
2,208✔
106
}
107

108
bool Client::is_closed() const {
510✔
109
   return m_impl->is_closed();
510✔
110
}
111

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

116
bool Client::is_closed_for_writing() const {
×
117
   return m_impl->is_closed_for_writing();
×
118
}
119

120
std::vector<X509_Certificate> Client::peer_cert_chain() const {
×
121
   return m_impl->peer_cert_chain();
×
122
}
123

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

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

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

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

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

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

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

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

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

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

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

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

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