src/openssl/src/openssl_stream.cpp
73.7% Lines (341/463)
89.7% List of functions (26/29)
43.2% Branches (468/1084)
Functions (29)
Function
Calls
Lines
Branches
Blocks
boost::corosio::(anonymous namespace)::tls_method_compat()
:65
1850x
100.0%
50.0%
66.0%
boost::corosio::(anonymous namespace)::apply_hostname_verification(ssl_st*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&)
:75
1875x
100.0%
100.0%
100.0%
boost::corosio::(anonymous namespace)::normalize_openssl_shutdown_read_error(std::__1::error_code)
:91
8x
70.0%
50.0%
63.0%
boost::corosio::detail::password_callback(char*, int, int, void*)
:116
0
0.0%
0.0%
0.0%
boost::corosio::detail::sni_callback(ssl_st*, int*, void*)
:138
2x
92.3%
62.5%
88.0%
boost::corosio::detail::openssl_native_context::openssl_native_context(boost::corosio::detail::tls_context_data const&)
:163
3700x
93.7%
57.4%
100.0%
boost::corosio::detail::openssl_native_context::~openssl_native_context()
:295
5550x
100.0%
50.0%
100.0%
boost::corosio::detail::get_openssl_context(boost::corosio::detail::tls_context_data const&)
:303
1855x
100.0%
–
100.0%
boost::corosio::detail::get_openssl_context(boost::corosio::detail::tls_context_data const&)::'lambda'()::operator()() const
:306
1850x
100.0%
50.0%
50.0%
boost::corosio::openssl_stream::impl::impl(boost::capy::any_stream&, boost::corosio::tls_context)
:325
3710x
100.0%
50.0%
100.0%
boost::corosio::openssl_stream::impl::~impl()
:331
3710x
100.0%
50.0%
100.0%
boost::corosio::openssl_stream::impl::reset()
:339
20x
80.0%
50.0%
71.0%
boost::corosio::openssl_stream::impl::flush_output()
:359
135231x
88.5%
50.0%
53.0%
boost::corosio::openssl_stream::impl::read_input()
:390
19403x
86.7%
44.6%
48.0%
boost::corosio::openssl_stream::impl::do_read_some(boost::capy::buffer_array<16ul, false>)
:411
115095x
56.9%
35.2%
41.0%
boost::corosio::openssl_stream::impl::do_write_some(boost::capy::buffer_array<16ul, true>)
:497
115084x
47.6%
19.7%
26.0%
boost::corosio::openssl_stream::impl::do_handshake(int)
:558
1303x
86.5%
46.9%
51.0%
boost::corosio::openssl_stream::impl::do_shutdown()
:611
36x
68.2%
44.6%
47.0%
boost::corosio::openssl_stream::impl::init_ssl()
:679
1855x
52.2%
50.0%
62.0%
boost::corosio::openssl_stream::make_impl(boost::capy::any_stream&, boost::corosio::tls_context const&)
:717
1855x
75.0%
25.0%
36.0%
boost::corosio::openssl_stream::~openssl_stream()
:731
3710x
100.0%
50.0%
100.0%
boost::corosio::openssl_stream::openssl_stream(boost::corosio::openssl_stream&&)
:736
0
0.0%
–
0.0%
boost::corosio::openssl_stream::operator=(boost::corosio::openssl_stream&&)
:744
0
0.0%
0.0%
0.0%
boost::corosio::openssl_stream::do_read_some(boost::capy::buffer_array<16ul, false>)
:757
115095x
100.0%
50.0%
48.0%
boost::corosio::openssl_stream::do_write_some(boost::capy::buffer_array<16ul, true>)
:764
115084x
100.0%
50.0%
48.0%
boost::corosio::openssl_stream::handshake(boost::corosio::tls_stream::handshake_type)
:771
1303x
100.0%
50.0%
48.0%
boost::corosio::openssl_stream::shutdown()
:777
36x
100.0%
50.0%
48.0%
boost::corosio::openssl_stream::reset()
:783
16x
100.0%
–
100.0%
boost::corosio::openssl_stream::name() const
:789
1x
100.0%
50.0%
66.0%
| Line | Branch | TLA | Hits | Source Code |
|---|---|---|---|---|
| 1 | // | |||
| 2 | // Copyright (c) 2025 Vinnie Falco ([email protected]) | |||
| 3 | // | |||
| 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying | |||
| 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | |||
| 6 | // | |||
| 7 | // Official repository: https://github.com/cppalliance/corosio | |||
| 8 | // | |||
| 9 | ||||
| 10 | #include <boost/corosio/openssl_stream.hpp> | |||
| 11 | #include <boost/corosio/detail/config.hpp> | |||
| 12 | #include <boost/capy/buffers/buffer_array.hpp> | |||
| 13 | #include <boost/capy/ex/async_mutex.hpp> | |||
| 14 | #include <boost/capy/error.hpp> | |||
| 15 | #include <boost/capy/write.hpp> | |||
| 16 | ||||
| 17 | // Internal context implementation | |||
| 18 | #include "src/tls/detail/context_impl.hpp" | |||
| 19 | ||||
| 20 | #include <openssl/ssl.h> | |||
| 21 | #include <openssl/err.h> | |||
| 22 | #include <openssl/bio.h> | |||
| 23 | #include <openssl/x509.h> | |||
| 24 | ||||
| 25 | #include <algorithm> | |||
| 26 | #include <array> | |||
| 27 | #include <cstring> | |||
| 28 | #include <vector> | |||
| 29 | ||||
| 30 | /* | |||
| 31 | openssl_stream Architecture | |||
| 32 | =========================== | |||
| 33 | ||||
| 34 | TLS layer wrapping an underlying stream (via any_stream). Supports one | |||
| 35 | concurrent read_some and one concurrent write_some (like Asio's ssl::stream). | |||
| 36 | ||||
| 37 | Data Flow (using BIO pairs) | |||
| 38 | --------------------------- | |||
| 39 | App -> SSL_write -> int_bio_ -> BIO_read(ext_bio_) -> out_buf_ -> s_.write_some -> Network | |||
| 40 | App <- SSL_read <- int_bio_ <- BIO_write(ext_bio_) <- in_buf_ <- s_.read_some <- Network | |||
| 41 | ||||
| 42 | WANT_READ / WANT_WRITE Pattern | |||
| 43 | ------------------------------ | |||
| 44 | OpenSSL's SSL_read/SSL_write return SSL_ERROR_WANT_READ or SSL_ERROR_WANT_WRITE | |||
| 45 | when they need I/O. Our coroutine handles this by: | |||
| 46 | ||||
| 47 | 1. Call SSL_read or SSL_write | |||
| 48 | 2. Check for pending output in ext_bio_ via BIO_ctrl_pending | |||
| 49 | 3. If output pending: write to network via s_.write_some | |||
| 50 | 4. If SSL_ERROR_WANT_READ: read from network into ext_bio_ via s_.read_some + BIO_write | |||
| 51 | 5. Loop back to step 1 | |||
| 52 | ||||
| 53 | Renegotiation causes cross-direction I/O: SSL_read may need to write | |||
| 54 | handshake data, SSL_write may need to read. Each operation handles | |||
| 55 | whatever I/O direction OpenSSL requests. | |||
| 56 | */ | |||
| 57 | ||||
| 58 | namespace boost::corosio { | |||
| 59 | ||||
| 60 | namespace { | |||
| 61 | ||||
| 62 | constexpr std::size_t default_buffer_size = 16384; | |||
| 63 | ||||
| 64 | inline SSL_METHOD const* | |||
| 65 | 1850x | tls_method_compat() noexcept | ||
| 66 | { | |||
| 67 | #if OPENSSL_VERSION_NUMBER >= 0x10100000L | |||
| 68 |
1/2✓ Branch 0 taken 1850 times.
✗ Branch 1 not taken.
|
1850x | return TLS_method(); | |
| 69 | #else | |||
| 70 | return SSLv23_method(); | |||
| 71 | #endif | |||
| 72 | } | |||
| 73 | ||||
| 74 | inline void | |||
| 75 | 1875x | apply_hostname_verification(SSL* ssl, std::string const& hostname) | ||
| 76 | { | |||
| 77 |
2/2✓ Branch 0 taken 1871 times.
✓ Branch 1 taken 4 times.
|
1875x | if (hostname.empty()) | |
| 78 | 1871x | return; | ||
| 79 | ||||
| 80 | 4x | SSL_set_tlsext_host_name(ssl, hostname.c_str()); | ||
| 81 | ||||
| 82 | #if OPENSSL_VERSION_NUMBER >= 0x10100000L | |||
| 83 | 4x | SSL_set1_host(ssl, hostname.c_str()); | ||
| 84 | #else | |||
| 85 | if (auto* param = SSL_get0_param(ssl)) | |||
| 86 | X509_VERIFY_PARAM_set1_host(param, hostname.c_str(), 0); | |||
| 87 | #endif | |||
| 88 | 1875x | } | ||
| 89 | ||||
| 90 | inline std::error_code | |||
| 91 | 8x | normalize_openssl_shutdown_read_error(std::error_code ec) noexcept | ||
| 92 | { | |||
| 93 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
|
8x | if (!ec) | |
| 94 | ✗ | return ec; | ||
| 95 | ||||
| 96 |
3/4✓ Branch 0 taken 2 times.
✓ Branch 1 taken 6 times.
✓ Branch 2 taken 8 times.
✗ Branch 3 not taken.
|
10x | if (ec == make_error_code(capy::error::eof) || | |
| 97 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2x | ec == make_error_code(capy::error::canceled) || | |
| 98 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2x | ec == std::errc::connection_reset || | |
| 99 | ✗ | ec == std::errc::connection_aborted || ec == std::errc::broken_pipe) | ||
| 100 | 8x | return make_error_code(capy::error::stream_truncated); | ||
| 101 | ||||
| 102 | ✗ | return ec; | ||
| 103 | 8x | } | ||
| 104 | ||||
| 105 | } // namespace | |||
| 106 | ||||
| 107 | // | |||
| 108 | // Native context caching | |||
| 109 | // | |||
| 110 | ||||
| 111 | namespace detail { | |||
| 112 | ||||
| 113 | static int sni_ctx_data_index = -1; | |||
| 114 | ||||
| 115 | static int | |||
| 116 | ✗ | password_callback(char* buf, int size, int rwflag, void* userdata) | ||
| 117 | { | |||
| 118 | ✗ | auto* cd = static_cast<tls_context_data const*>(userdata); | ||
| 119 | ✗ | if (!cd || !cd->password_callback) | ||
| 120 | ✗ | return 0; | ||
| 121 | ||||
| 122 | ✗ | tls_password_purpose purpose = (rwflag == 0) | ||
| 123 | ? tls_password_purpose::for_reading | |||
| 124 | : tls_password_purpose::for_writing; | |||
| 125 | ||||
| 126 | std::string password = | |||
| 127 | ✗ | cd->password_callback(static_cast<std::size_t>(size), purpose); | ||
| 128 | ||||
| 129 | ✗ | int len = static_cast<int>(password.size()); | ||
| 130 | ✗ | if (len > size) | ||
| 131 | ✗ | len = size; | ||
| 132 | ||||
| 133 | ✗ | std::memcpy(buf, password.data(), static_cast<std::size_t>(len)); | ||
| 134 | ✗ | return len; | ||
| 135 | ✗ | } | ||
| 136 | ||||
| 137 | static int | |||
| 138 | 2x | sni_callback(SSL* ssl, int* /* alert */, void* /* arg */) | ||
| 139 | { | |||
| 140 | 2x | char const* servername = SSL_get_servername(ssl, TLSEXT_NAMETYPE_host_name); | ||
| 141 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2x | if (!servername) | |
| 142 | ✗ | return SSL_TLSEXT_ERR_NOACK; | ||
| 143 | ||||
| 144 | 2x | SSL_CTX* ctx = SSL_get_SSL_CTX(ssl); | ||
| 145 | 2x | auto* cd = static_cast<tls_context_data const*>( | ||
| 146 | 2x | SSL_CTX_get_ex_data(ctx, sni_ctx_data_index)); | ||
| 147 | ||||
| 148 |
2/4✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
|
2x | if (cd && cd->servername_callback) | |
| 149 | { | |||
| 150 |
2/2✓ Branch 0 taken 1 time.
✓ Branch 1 taken 1 time.
|
2x | if (!cd->servername_callback(servername)) | |
| 151 | 1x | return SSL_TLSEXT_ERR_ALERT_FATAL; | ||
| 152 | 1x | } | ||
| 153 | ||||
| 154 | 1x | return SSL_TLSEXT_ERR_OK; | ||
| 155 | 2x | } | ||
| 156 | ||||
| 157 | class openssl_native_context : public native_context_base | |||
| 158 | { | |||
| 159 | public: | |||
| 160 | SSL_CTX* ctx_; | |||
| 161 | tls_context_data const* cd_; | |||
| 162 | ||||
| 163 | 3700x | explicit openssl_native_context(tls_context_data const& cd) | ||
| 164 | 1850x | : ctx_(nullptr) | ||
| 165 | 1850x | , cd_(&cd) | ||
| 166 | 3700x | { | ||
| 167 |
1/2✓ Branch 0 taken 1850 times.
✗ Branch 1 not taken.
|
1850x | ctx_ = SSL_CTX_new(tls_method_compat()); | |
| 168 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1850 times.
|
1850x | if (!ctx_) | |
| 169 | ✗ | return; | ||
| 170 | ||||
| 171 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 1846 times.
|
1850x | if (sni_ctx_data_index < 0) | |
| 172 | 4x | sni_ctx_data_index = | ||
| 173 |
1/2✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
|
4x | SSL_CTX_get_ex_new_index(0, nullptr, nullptr, nullptr, nullptr); | |
| 174 | ||||
| 175 |
1/2✓ Branch 0 taken 1850 times.
✗ Branch 1 not taken.
|
1850x | SSL_CTX_set_ex_data( | |
| 176 | 1850x | ctx_, sni_ctx_data_index, const_cast<tls_context_data*>(&cd)); | ||
| 177 | ||||
| 178 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1848 times.
|
1850x | if (cd.servername_callback) | |
| 179 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2x | SSL_CTX_set_tlsext_servername_callback(ctx_, sni_callback); | |
| 180 | ||||
| 181 |
1/2✓ Branch 0 taken 1850 times.
✗ Branch 1 not taken.
|
1850x | SSL_CTX_set_mode(ctx_, SSL_MODE_ENABLE_PARTIAL_WRITE); | |
| 182 |
1/2✓ Branch 0 taken 1850 times.
✗ Branch 1 not taken.
|
1850x | SSL_CTX_set_mode(ctx_, SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER); | |
| 183 | #if defined(SSL_MODE_RELEASE_BUFFERS) | |||
| 184 |
1/2✓ Branch 0 taken 1850 times.
✗ Branch 1 not taken.
|
1850x | SSL_CTX_set_mode(ctx_, SSL_MODE_RELEASE_BUFFERS); | |
| 185 | #endif | |||
| 186 | ||||
| 187 | 1850x | int verify_mode_flag = SSL_VERIFY_NONE; | ||
| 188 |
2/2✓ Branch 0 taken 921 times.
✓ Branch 1 taken 929 times.
|
1850x | if (cd.verification_mode == tls_verify_mode::peer) | |
| 189 | 921x | verify_mode_flag = SSL_VERIFY_PEER; | ||
| 190 |
2/2✓ Branch 0 taken 926 times.
✓ Branch 1 taken 3 times.
|
929x | else if (cd.verification_mode == tls_verify_mode::require_peer) | |
| 191 | 3x | verify_mode_flag = | ||
| 192 | SSL_VERIFY_PEER | SSL_VERIFY_FAIL_IF_NO_PEER_CERT; | |||
| 193 |
1/2✓ Branch 0 taken 1850 times.
✗ Branch 1 not taken.
|
1850x | SSL_CTX_set_verify(ctx_, verify_mode_flag, nullptr); | |
| 194 | ||||
| 195 |
2/2✓ Branch 0 taken 926 times.
✓ Branch 1 taken 924 times.
|
1850x | if (!cd.entity_certificate.empty()) | |
| 196 | { | |||
| 197 |
1/2✓ Branch 0 taken 926 times.
✗ Branch 1 not taken.
|
926x | BIO* bio = BIO_new_mem_buf( | |
| 198 | 926x | cd.entity_certificate.data(), | ||
| 199 | 926x | static_cast<int>(cd.entity_certificate.size())); | ||
| 200 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 926 times.
|
926x | if (bio) | |
| 201 | { | |||
| 202 | 926x | X509* cert = nullptr; | ||
| 203 |
1/2✓ Branch 0 taken 926 times.
✗ Branch 1 not taken.
|
926x | if (cd.entity_cert_format == tls_file_format::pem) | |
| 204 |
1/2✓ Branch 0 taken 926 times.
✗ Branch 1 not taken.
|
926x | cert = PEM_read_bio_X509(bio, nullptr, nullptr, nullptr); | |
| 205 | else | |||
| 206 | ✗ | cert = d2i_X509_bio(bio, nullptr); | ||
| 207 |
1/2✓ Branch 0 taken 926 times.
✗ Branch 1 not taken.
|
926x | if (cert) | |
| 208 | { | |||
| 209 |
1/2✓ Branch 0 taken 926 times.
✗ Branch 1 not taken.
|
926x | SSL_CTX_use_certificate(ctx_, cert); | |
| 210 |
1/2✓ Branch 0 taken 926 times.
✗ Branch 1 not taken.
|
926x | X509_free(cert); | |
| 211 | 926x | } | ||
| 212 |
1/2✓ Branch 0 taken 926 times.
✗ Branch 1 not taken.
|
926x | BIO_free(bio); | |
| 213 | 926x | } | ||
| 214 | 926x | } | ||
| 215 | ||||
| 216 |
2/2✓ Branch 0 taken 1 time.
✓ Branch 1 taken 1849 times.
|
1850x | if (!cd.certificate_chain.empty()) | |
| 217 | { | |||
| 218 |
1/2✓ Branch 0 taken 1 time.
✗ Branch 1 not taken.
|
1x | BIO* bio = BIO_new_mem_buf( | |
| 219 | 1x | cd.certificate_chain.data(), | ||
| 220 | 1x | static_cast<int>(cd.certificate_chain.size())); | ||
| 221 |
1/2✓ Branch 0 taken 1 time.
✗ Branch 1 not taken.
|
1x | if (bio) | |
| 222 | { | |||
| 223 | 1x | X509* entity = | ||
| 224 |
1/2✓ Branch 0 taken 1 time.
✗ Branch 1 not taken.
|
1x | PEM_read_bio_X509(bio, nullptr, nullptr, nullptr); | |
| 225 |
1/2✓ Branch 0 taken 1 time.
✗ Branch 1 not taken.
|
1x | if (entity) | |
| 226 | { | |||
| 227 |
1/2✓ Branch 0 taken 1 time.
✗ Branch 1 not taken.
|
1x | SSL_CTX_use_certificate(ctx_, entity); | |
| 228 |
1/2✓ Branch 0 taken 1 time.
✗ Branch 1 not taken.
|
1x | X509_free(entity); | |
| 229 | 1x | } | ||
| 230 | ||||
| 231 | X509* cert; | |||
| 232 |
5/6✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 time.
✓ Branch 3 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 5 taken 1 time.
|
2x | while ((cert = PEM_read_bio_X509( | |
| 233 | 2x | bio, nullptr, nullptr, nullptr)) != nullptr) | ||
| 234 | { | |||
| 235 |
1/2✓ Branch 0 taken 1 time.
✗ Branch 1 not taken.
|
1x | SSL_CTX_add_extra_chain_cert(ctx_, cert); | |
| 236 | } | |||
| 237 |
1/2✓ Branch 0 taken 1 time.
✗ Branch 1 not taken.
|
1x | ERR_clear_error(); | |
| 238 |
1/2✓ Branch 0 taken 1 time.
✗ Branch 1 not taken.
|
1x | BIO_free(bio); | |
| 239 | 1x | } | ||
| 240 | 1x | } | ||
| 241 | ||||
| 242 |
2/2✓ Branch 0 taken 927 times.
✓ Branch 1 taken 923 times.
|
1850x | if (!cd.private_key.empty()) | |
| 243 | { | |||
| 244 |
1/2✓ Branch 0 taken 927 times.
✗ Branch 1 not taken.
|
927x | BIO* bio = BIO_new_mem_buf( | |
| 245 | 927x | cd.private_key.data(), static_cast<int>(cd.private_key.size())); | ||
| 246 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 927 times.
|
927x | if (bio) | |
| 247 | { | |||
| 248 | 927x | EVP_PKEY* pkey = nullptr; | ||
| 249 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 927 times.
|
927x | if (cd.private_key_format == tls_file_format::pem) | |
| 250 | { | |||
| 251 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 927 times.
|
927x | if (cd.password_callback) | |
| 252 | ✗ | pkey = PEM_read_bio_PrivateKey( | ||
| 253 | ✗ | bio, nullptr, password_callback, | ||
| 254 | ✗ | const_cast<tls_context_data*>(&cd)); | ||
| 255 | else | |||
| 256 |
1/2✓ Branch 0 taken 927 times.
✗ Branch 1 not taken.
|
927x | pkey = PEM_read_bio_PrivateKey( | |
| 257 | 927x | bio, nullptr, nullptr, nullptr); | ||
| 258 | 927x | } | ||
| 259 | else | |||
| 260 | ✗ | pkey = d2i_PrivateKey_bio(bio, nullptr); | ||
| 261 |
1/2✓ Branch 0 taken 927 times.
✗ Branch 1 not taken.
|
927x | if (pkey) | |
| 262 | { | |||
| 263 |
1/2✓ Branch 0 taken 927 times.
✗ Branch 1 not taken.
|
927x | SSL_CTX_use_PrivateKey(ctx_, pkey); | |
| 264 |
1/2✓ Branch 0 taken 927 times.
✗ Branch 1 not taken.
|
927x | EVP_PKEY_free(pkey); | |
| 265 | 927x | } | ||
| 266 |
1/2✓ Branch 0 taken 927 times.
✗ Branch 1 not taken.
|
927x | BIO_free(bio); | |
| 267 | 927x | } | ||
| 268 | 927x | } | ||
| 269 | ||||
| 270 |
1/2✓ Branch 0 taken 1850 times.
✗ Branch 1 not taken.
|
1850x | X509_STORE* store = SSL_CTX_get_cert_store(ctx_); | |
| 271 |
2/2✓ Branch 0 taken 1850 times.
✓ Branch 1 taken 935 times.
|
2785x | for (auto const& ca : cd.ca_certificates) | |
| 272 | { | |||
| 273 |
1/2✓ Branch 0 taken 935 times.
✗ Branch 1 not taken.
|
935x | BIO* bio = BIO_new_mem_buf(ca.data(), static_cast<int>(ca.size())); | |
| 274 |
1/2✓ Branch 0 taken 935 times.
✗ Branch 1 not taken.
|
935x | if (bio) | |
| 275 | { | |||
| 276 |
1/2✓ Branch 0 taken 935 times.
✗ Branch 1 not taken.
|
935x | X509* cert = PEM_read_bio_X509(bio, nullptr, nullptr, nullptr); | |
| 277 |
2/2✓ Branch 0 taken 934 times.
✓ Branch 1 taken 1 time.
|
935x | if (cert) | |
| 278 | { | |||
| 279 |
1/2✓ Branch 0 taken 934 times.
✗ Branch 1 not taken.
|
934x | X509_STORE_add_cert(store, cert); | |
| 280 |
1/2✓ Branch 0 taken 934 times.
✗ Branch 1 not taken.
|
934x | X509_free(cert); | |
| 281 | 934x | } | ||
| 282 |
1/2✓ Branch 0 taken 935 times.
✗ Branch 1 not taken.
|
935x | BIO_free(bio); | |
| 283 | 935x | } | ||
| 284 | } | |||
| 285 | ||||
| 286 |
1/2✓ Branch 0 taken 1850 times.
✗ Branch 1 not taken.
|
1850x | SSL_CTX_set_verify_depth(ctx_, cd.verify_depth); | |
| 287 | ||||
| 288 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 1847 times.
|
1850x | if (!cd.ciphersuites.empty()) | |
| 289 | { | |||
| 290 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3x | SSL_CTX_set_security_level(ctx_, 0); | |
| 291 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3x | SSL_CTX_set_cipher_list(ctx_, cd.ciphersuites.c_str()); | |
| 292 | 3x | } | ||
| 293 | 3700x | } | ||
| 294 | ||||
| 295 | 5550x | ~openssl_native_context() override | ||
| 296 | 5550x | { | ||
| 297 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1850 times.
|
1850x | if (ctx_) | |
| 298 |
1/2✓ Branch 0 taken 1850 times.
✗ Branch 1 not taken.
|
1850x | SSL_CTX_free(ctx_); | |
| 299 | 5550x | } | ||
| 300 | }; | |||
| 301 | ||||
| 302 | inline SSL_CTX* | |||
| 303 | 1855x | get_openssl_context(tls_context_data const& cd) | ||
| 304 | { | |||
| 305 | static char key; | |||
| 306 |
1/2✓ Branch 0 taken 1850 times.
✗ Branch 1 not taken.
|
3705x | auto* p = cd.find(&key, [&] { return new openssl_native_context(cd); }); | |
| 307 | 1855x | return static_cast<openssl_native_context*>(p)->ctx_; | ||
| 308 | } | |||
| 309 | ||||
| 310 | } // namespace detail | |||
| 311 | ||||
| 312 | struct openssl_stream::impl | |||
| 313 | { | |||
| 314 | capy::any_stream& s_; | |||
| 315 | tls_context ctx_; | |||
| 316 | 1855x | SSL* ssl_ = nullptr; | ||
| 317 | 1855x | BIO* ext_bio_ = nullptr; | ||
| 318 | 1855x | bool used_ = false; | ||
| 319 | ||||
| 320 | std::vector<char> in_buf_; | |||
| 321 | std::vector<char> out_buf_; | |||
| 322 | ||||
| 323 | capy::async_mutex io_cm_; | |||
| 324 | ||||
| 325 | 5565x | impl(capy::any_stream& s, tls_context ctx) : s_(s), ctx_(std::move(ctx)) | ||
| 326 | 1855x | { | ||
| 327 |
1/2✓ Branch 0 taken 1855 times.
✗ Branch 1 not taken.
|
1855x | in_buf_.resize(default_buffer_size); | |
| 328 |
1/2✓ Branch 0 taken 1855 times.
✗ Branch 1 not taken.
|
1855x | out_buf_.resize(default_buffer_size); | |
| 329 | 3710x | } | ||
| 330 | ||||
| 331 | 3710x | ~impl() | ||
| 332 | 1855x | { | ||
| 333 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1855 times.
|
1855x | if (ext_bio_) | |
| 334 |
1/2✓ Branch 0 taken 1855 times.
✗ Branch 1 not taken.
|
1855x | BIO_free(ext_bio_); | |
| 335 |
1/2✓ Branch 0 taken 1855 times.
✗ Branch 1 not taken.
|
1855x | if (ssl_) | |
| 336 |
1/2✓ Branch 0 taken 1855 times.
✗ Branch 1 not taken.
|
1855x | SSL_free(ssl_); | |
| 337 | 3710x | } | ||
| 338 | ||||
| 339 | 20x | void reset() | ||
| 340 | { | |||
| 341 |
1/2✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
|
20x | if (!ssl_) | |
| 342 | ✗ | return; | ||
| 343 | ||||
| 344 | // Preserves SSL* and BIO pair, releases session state | |||
| 345 | 20x | SSL_clear(ssl_); | ||
| 346 | ||||
| 347 | // Drain stale data from the external BIO | |||
| 348 | char drain[1024]; | |||
| 349 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 20 times.
|
20x | while (BIO_ctrl_pending(ext_bio_) > 0) | |
| 350 | ✗ | BIO_read(ext_bio_, drain, sizeof(drain)); | ||
| 351 | ||||
| 352 | // SSL_clear clears per-session settings; reapply hostname | |||
| 353 | 20x | auto& cd = detail::get_tls_context_data(ctx_); | ||
| 354 | 20x | apply_hostname_verification(ssl_, cd.hostname); | ||
| 355 | ||||
| 356 | 20x | used_ = false; | ||
| 357 | 20x | } | ||
| 358 | ||||
| 359 |
10/24✓ Branch 0 taken 135231 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 135231 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 135231 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 135231 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✓ Branch 10 taken 135231 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✓ Branch 14 taken 135231 times.
✓ Branch 15 taken 135231 times.
✓ Branch 16 taken 135231 times.
✗ Branch 17 not taken.
✓ Branch 18 taken 234284 times.
✓ Branch 19 taken 135231 times.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
|
1144723x | capy::task<std::error_code> flush_output() | |
| 360 | 135231x | { | ||
| 361 |
3/4✓ Branch 0 taken 252370 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 135228 times.
✓ Branch 3 taken 117142 times.
|
252370x | while (BIO_ctrl_pending(ext_bio_) > 0) | |
| 362 | { | |||
| 363 | 117142x | std::size_t got = 0; | ||
| 364 |
5/6✓ Branch 0 taken 234284 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 117136 times.
✓ Branch 3 taken 117148 times.
✓ Branch 4 taken 117142 times.
✓ Branch 5 taken 117142 times.
|
234284x | while (BIO_ctrl_pending(ext_bio_) > 0 && got < out_buf_.size()) | |
| 365 | { | |||
| 366 |
1/2✓ Branch 0 taken 117142 times.
✗ Branch 1 not taken.
|
117142x | int put = static_cast<int>(BIO_ctrl_pending(ext_bio_)); | |
| 367 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 117142 times.
|
117142x | put = (std::min)(put, static_cast<int>(out_buf_.size() - got)); | |
| 368 |
1/2✓ Branch 0 taken 117142 times.
✗ Branch 1 not taken.
|
117142x | int r = BIO_read(ext_bio_, out_buf_.data() + got, put); | |
| 369 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 117142 times.
|
117142x | if (r <= 0) | |
| 370 | ✗ | break; | ||
| 371 | 117142x | got += static_cast<std::size_t>(r); | ||
| 372 | 117142x | } | ||
| 373 |
1/2✓ Branch 0 taken 117142 times.
✗ Branch 1 not taken.
|
117142x | if (got == 0) | |
| 374 | ✗ | break; | ||
| 375 | ||||
| 376 | { | |||
| 377 |
5/12✓ Branch 0 taken 117142 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 117142 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 117142 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 234284 times.
✓ Branch 11 taken 351426 times.
|
117142x | auto [lec] = co_await io_cm_.lock(); | |
| 378 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 351426 times.
|
351426x | if (lec) | |
| 379 | ✗ | co_return lec; | ||
| 380 | 351426x | capy::async_mutex::lock_guard io_guard(&io_cm_); | ||
| 381 |
9/16✗ Branch 0 not taken.
✓ Branch 1 taken 351426 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 351426 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 351426 times.
✓ Branch 6 taken 117142 times.
✓ Branch 7 taken 234284 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 117142 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✓ Branch 12 taken 117142 times.
✓ Branch 13 taken 117142 times.
✗ Branch 14 not taken.
✓ Branch 15 taken 117142 times.
|
819994x | auto [ec, n] = co_await capy::write( | |
| 382 | 351426x | s_, capy::const_buffer(out_buf_.data(), got)); | ||
| 383 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 117139 times.
|
117142x | if (ec) | |
| 384 |
2/4✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
|
6x | co_return ec; | |
| 385 | 351426x | } | ||
| 386 | 351426x | } | ||
| 387 |
1/2✓ Branch 0 taken 135228 times.
✗ Branch 1 not taken.
|
135228x | co_return std::error_code{}; | |
| 388 | 234284x | } | ||
| 389 | ||||
| 390 |
10/24✓ Branch 0 taken 19403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 19403 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 19403 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 19403 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✓ Branch 10 taken 19403 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✓ Branch 14 taken 19403 times.
✓ Branch 15 taken 19403 times.
✓ Branch 16 taken 19403 times.
✗ Branch 17 not taken.
✓ Branch 18 taken 38806 times.
✓ Branch 19 taken 19403 times.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
|
174627x | capy::task<std::error_code> read_input() | |
| 391 | 19403x | { | ||
| 392 |
4/10✓ Branch 0 taken 19403 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 19403 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 38806 times.
✓ Branch 9 taken 58209 times.
|
19403x | auto [lec] = co_await io_cm_.lock(); | |
| 393 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 58209 times.
|
58209x | if (lec) | |
| 394 | ✗ | co_return lec; | ||
| 395 | 58209x | capy::async_mutex::lock_guard io_guard(&io_cm_); | ||
| 396 |
9/16✓ Branch 0 taken 58209 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 58209 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 58209 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 19403 times.
✓ Branch 7 taken 38806 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 19403 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✓ Branch 12 taken 19403 times.
✓ Branch 13 taken 19403 times.
✗ Branch 14 not taken.
✓ Branch 15 taken 19403 times.
|
135821x | auto [ec, n] = co_await s_.read_some( | |
| 397 | 58209x | capy::mutable_buffer(in_buf_.data(), in_buf_.size())); | ||
| 398 |
2/2✓ Branch 0 taken 591 times.
✓ Branch 1 taken 18812 times.
|
19403x | if (ec) | |
| 399 |
2/4✓ Branch 0 taken 591 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 591 times.
✗ Branch 3 not taken.
|
1182x | co_return ec; | |
| 400 | ||||
| 401 |
2/4✓ Branch 0 taken 18812 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 18812 times.
✗ Branch 3 not taken.
|
37624x | int got = BIO_write(ext_bio_, in_buf_.data(), static_cast<int>(n)); | |
| 402 |
2/4✗ Branch 0 not taken.
✓ Branch 1 taken 18812 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 18812 times.
|
37624x | if (got < static_cast<int>(n)) | |
| 403 | { | |||
| 404 | ✗ | co_return make_error_code(std::errc::no_buffer_space); | ||
| 405 | } | |||
| 406 | ||||
| 407 |
1/2✓ Branch 0 taken 18812 times.
✗ Branch 1 not taken.
|
18812x | co_return std::error_code{}; | |
| 408 | 97015x | } | ||
| 409 | ||||
| 410 | capy::io_task<std::size_t> | |||
| 411 |
9/24✓ Branch 0 taken 115095 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 115095 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 115095 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 115095 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✓ Branch 10 taken 115095 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✓ Branch 14 taken 115095 times.
✓ Branch 15 taken 115095 times.
✓ Branch 16 taken 115095 times.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✓ Branch 19 taken 115095 times.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
|
575475x | do_read_some(capy::mutable_buffer_array<capy::detail::max_iovec_> buffers) | |
| 412 | 115095x | { | ||
| 413 | 115095x | std::error_code ec; | ||
| 414 | 115095x | std::size_t total_read = 0; | ||
| 415 | ||||
| 416 |
2/4✗ Branch 0 not taken.
✓ Branch 1 taken 115095 times.
✓ Branch 2 taken 115095 times.
✗ Branch 3 not taken.
|
230190x | for (auto& buf : buffers) | |
| 417 | { | |||
| 418 | 115095x | char* dest = static_cast<char*>(buf.data()); | ||
| 419 | 115095x | int remaining = static_cast<int>(buf.size()); | ||
| 420 | ||||
| 421 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 168169 times.
|
168169x | while (remaining > 0) | |
| 422 | { | |||
| 423 |
1/2✓ Branch 0 taken 168169 times.
✗ Branch 1 not taken.
|
168169x | ERR_clear_error(); | |
| 424 |
1/2✓ Branch 0 taken 168169 times.
✗ Branch 1 not taken.
|
168169x | int ret = SSL_read(ssl_, dest, remaining); | |
| 425 | ||||
| 426 |
2/2✓ Branch 0 taken 115068 times.
✓ Branch 1 taken 53101 times.
|
168169x | if (ret > 0) | |
| 427 | { | |||
| 428 | 115068x | dest += ret; | ||
| 429 | 115068x | remaining -= ret; | ||
| 430 | 115068x | total_read += static_cast<std::size_t>(ret); | ||
| 431 | ||||
| 432 |
1/2✓ Branch 0 taken 115068 times.
✗ Branch 1 not taken.
|
115068x | if (total_read > 0) | |
| 433 |
2/4✓ Branch 0 taken 115068 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 115068 times.
✗ Branch 3 not taken.
|
230163x | co_return {std::error_code{}, total_read}; | |
| 434 | ✗ | } | ||
| 435 | else | |||
| 436 | { | |||
| 437 |
1/2✓ Branch 0 taken 53101 times.
✗ Branch 1 not taken.
|
53101x | int err = SSL_get_error(ssl_, ret); | |
| 438 | ||||
| 439 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 53101 times.
|
53101x | if (err == SSL_ERROR_WANT_WRITE) | |
| 440 | { | |||
| 441 | ✗ | ec = co_await flush_output(); | ||
| 442 | ✗ | if (ec) | ||
| 443 | ✗ | co_return {ec, total_read}; | ||
| 444 | ✗ | } | ||
| 445 |
2/2✓ Branch 0 taken 53079 times.
✓ Branch 1 taken 22 times.
|
53101x | else if (err == SSL_ERROR_WANT_READ) | |
| 446 | { | |||
| 447 |
9/14✓ Branch 0 taken 53079 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 53079 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 17693 times.
✓ Branch 5 taken 35386 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 17693 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✓ Branch 10 taken 17693 times.
✓ Branch 11 taken 17693 times.
✓ Branch 12 taken 35386 times.
✓ Branch 13 taken 53079 times.
|
70772x | ec = co_await flush_output(); | |
| 448 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 53079 times.
|
53079x | if (ec) | |
| 449 | ✗ | co_return {ec, total_read}; | ||
| 450 | ||||
| 451 |
8/14✓ Branch 0 taken 53079 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 53079 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 17693 times.
✓ Branch 5 taken 35386 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 17693 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✓ Branch 10 taken 17693 times.
✓ Branch 11 taken 17693 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 17693 times.
|
70772x | ec = co_await read_input(); | |
| 452 |
2/2✓ Branch 0 taken 5 times.
✓ Branch 1 taken 17688 times.
|
17693x | if (ec) | |
| 453 | { | |||
| 454 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
|
5x | if (ec == make_error_code(capy::error::eof)) | |
| 455 | { | |||
| 456 | ✗ | if (SSL_get_shutdown(ssl_) & | ||
| 457 | SSL_RECEIVED_SHUTDOWN) | |||
| 458 | ✗ | ec = make_error_code(capy::error::eof); | ||
| 459 | else | |||
| 460 | ✗ | ec = make_error_code( | ||
| 461 | capy::error::stream_truncated); | |||
| 462 | ✗ | } | ||
| 463 |
2/4✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
|
5x | co_return {ec, total_read}; | |
| 464 | } | |||
| 465 | 17688x | } | ||
| 466 |
1/2✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
|
22x | else if (err == SSL_ERROR_ZERO_RETURN) | |
| 467 | { | |||
| 468 |
3/6✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 22 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 22 times.
✗ Branch 5 not taken.
|
44x | co_return { | |
| 469 | 22x | make_error_code(capy::error::eof), total_read}; | ||
| 470 | } | |||
| 471 | ✗ | else if (err == SSL_ERROR_SYSCALL) | ||
| 472 | { | |||
| 473 | ✗ | unsigned long ssl_err = ERR_get_error(); | ||
| 474 | ✗ | if (ssl_err == 0) | ||
| 475 | ✗ | ec = make_error_code(capy::error::stream_truncated); | ||
| 476 | else | |||
| 477 | ✗ | ec = std::error_code( | ||
| 478 | ✗ | static_cast<int>(ssl_err), | ||
| 479 | ✗ | std::system_category()); | ||
| 480 | ✗ | co_return {ec, total_read}; | ||
| 481 | ✗ | } | ||
| 482 | else | |||
| 483 | { | |||
| 484 | ✗ | unsigned long ssl_err = ERR_get_error(); | ||
| 485 | ✗ | ec = std::error_code( | ||
| 486 | ✗ | static_cast<int>(ssl_err), std::system_category()); | ||
| 487 | ✗ | co_return {ec, total_read}; | ||
| 488 | ✗ | } | ||
| 489 | 53101x | } | ||
| 490 | 168169x | } | ||
| 491 | 115095x | } | ||
| 492 | ||||
| 493 | ✗ | co_return {std::error_code{}, total_read}; | ||
| 494 | 185867x | } | ||
| 495 | ||||
| 496 | capy::io_task<std::size_t> | |||
| 497 |
9/24✓ Branch 0 taken 115084 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 115084 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 115084 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 115084 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✓ Branch 10 taken 115084 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✓ Branch 14 taken 115084 times.
✓ Branch 15 taken 115084 times.
✓ Branch 16 taken 115084 times.
✗ Branch 17 not taken.
✓ Branch 18 taken 115084 times.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
|
575420x | do_write_some(capy::const_buffer_array<capy::detail::max_iovec_> buffers) | |
| 498 | 115084x | { | ||
| 499 | 115084x | std::error_code ec; | ||
| 500 | 115084x | std::size_t total_written = 0; | ||
| 501 | ||||
| 502 |
2/4✓ Branch 0 taken 115084 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 115084 times.
✗ Branch 3 not taken.
|
230168x | for (auto const& buf : buffers) | |
| 503 | { | |||
| 504 | 115084x | char const* src = static_cast<char const*>(buf.data()); | ||
| 505 | 115084x | int remaining = static_cast<int>(buf.size()); | ||
| 506 | ||||
| 507 |
1/2✓ Branch 0 taken 345252 times.
✗ Branch 1 not taken.
|
345252x | while (remaining > 0) | |
| 508 | { | |||
| 509 |
1/2✓ Branch 0 taken 345252 times.
✗ Branch 1 not taken.
|
345252x | ERR_clear_error(); | |
| 510 |
1/2✓ Branch 0 taken 345252 times.
✗ Branch 1 not taken.
|
345252x | int ret = SSL_write(ssl_, src, remaining); | |
| 511 | ||||
| 512 |
1/2✓ Branch 0 taken 345252 times.
✗ Branch 1 not taken.
|
345252x | if (ret > 0) | |
| 513 | { | |||
| 514 | 345252x | src += ret; | ||
| 515 | 345252x | remaining -= ret; | ||
| 516 | 345252x | total_written += static_cast<std::size_t>(ret); | ||
| 517 | ||||
| 518 |
1/2✓ Branch 0 taken 345252 times.
✗ Branch 1 not taken.
|
345252x | if (total_written > 0) | |
| 519 | { | |||
| 520 |
8/14✗ Branch 0 not taken.
✓ Branch 1 taken 345252 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 345252 times.
✓ Branch 4 taken 115084 times.
✓ Branch 5 taken 230168 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 115084 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✓ Branch 10 taken 115084 times.
✓ Branch 11 taken 115084 times.
✓ Branch 12 taken 115084 times.
✗ Branch 13 not taken.
|
575420x | ec = co_await flush_output(); | |
| 521 |
2/4✓ Branch 0 taken 115084 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 115084 times.
✗ Branch 3 not taken.
|
115084x | co_return {ec, total_written}; | |
| 522 | } | |||
| 523 | ✗ | } | ||
| 524 | else | |||
| 525 | { | |||
| 526 | ✗ | int err = SSL_get_error(ssl_, ret); | ||
| 527 | ||||
| 528 | ✗ | if (err == SSL_ERROR_WANT_WRITE) | ||
| 529 | { | |||
| 530 | ✗ | ec = co_await flush_output(); | ||
| 531 | ✗ | if (ec) | ||
| 532 | ✗ | co_return {ec, total_written}; | ||
| 533 | ✗ | } | ||
| 534 | ✗ | else if (err == SSL_ERROR_WANT_READ) | ||
| 535 | { | |||
| 536 | ✗ | ec = co_await flush_output(); | ||
| 537 | ✗ | if (ec) | ||
| 538 | ✗ | co_return {ec, total_written}; | ||
| 539 | ||||
| 540 | ✗ | ec = co_await read_input(); | ||
| 541 | ✗ | if (ec) | ||
| 542 | ✗ | co_return {ec, total_written}; | ||
| 543 | ✗ | } | ||
| 544 | else | |||
| 545 | { | |||
| 546 | ✗ | unsigned long ssl_err = ERR_get_error(); | ||
| 547 | ✗ | ec = std::error_code( | ||
| 548 | ✗ | static_cast<int>(ssl_err), std::system_category()); | ||
| 549 | ✗ | co_return {ec, total_written}; | ||
| 550 | ✗ | } | ||
| 551 | ✗ | } | ||
| 552 | 115084x | } | ||
| 553 | 115084x | } | ||
| 554 | ||||
| 555 | ✗ | co_return {std::error_code{}, total_written}; | ||
| 556 | 345252x | } | ||
| 557 | ||||
| 558 |
11/24✓ Branch 0 taken 1303 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1303 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1303 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1432 times.
✓ Branch 7 taken 2735 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✓ Branch 10 taken 1303 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✓ Branch 14 taken 1303 times.
✓ Branch 15 taken 1303 times.
✓ Branch 16 taken 1303 times.
✗ Branch 17 not taken.
✓ Branch 18 taken 1432 times.
✓ Branch 19 taken 1303 times.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
|
7947x | capy::io_task<> do_handshake(int type) | |
| 559 | 1303x | { | ||
| 560 |
2/2✓ Branch 0 taken 2731 times.
✓ Branch 1 taken 4 times.
|
2735x | if (used_) | |
| 561 |
1/2✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
|
4x | reset(); | |
| 562 | ||||
| 563 | 2735x | std::error_code ec; | ||
| 564 | ||||
| 565 | 7161x | while (true) | ||
| 566 | { | |||
| 567 |
1/2✓ Branch 0 taken 7161 times.
✗ Branch 1 not taken.
|
7161x | ERR_clear_error(); | |
| 568 | 7161x | int ret; | ||
| 569 |
2/2✓ Branch 0 taken 1302 times.
✓ Branch 1 taken 5859 times.
|
7161x | if (type == openssl_stream::client) | |
| 570 |
1/2✓ Branch 0 taken 1302 times.
✗ Branch 1 not taken.
|
1302x | ret = SSL_connect(ssl_); | |
| 571 | else | |||
| 572 |
1/2✓ Branch 0 taken 5859 times.
✗ Branch 1 not taken.
|
5859x | ret = SSL_accept(ssl_); | |
| 573 | ||||
| 574 |
2/2✓ Branch 0 taken 2148 times.
✓ Branch 1 taken 5013 times.
|
7161x | if (ret == 1) | |
| 575 | { | |||
| 576 | 2148x | used_ = true; | ||
| 577 |
8/14✓ Branch 0 taken 2148 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2148 times.
✓ Branch 4 taken 716 times.
✓ Branch 5 taken 1432 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 716 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✓ Branch 10 taken 716 times.
✓ Branch 11 taken 716 times.
✓ Branch 12 taken 716 times.
✗ Branch 13 not taken.
|
4167x | ec = co_await flush_output(); | |
| 578 |
2/4✓ Branch 0 taken 716 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 716 times.
✗ Branch 3 not taken.
|
716x | co_return {ec}; | |
| 579 | } | |||
| 580 | else | |||
| 581 | { | |||
| 582 |
1/2✓ Branch 0 taken 5013 times.
✗ Branch 1 not taken.
|
5013x | int err = SSL_get_error(ssl_, ret); | |
| 583 | ||||
| 584 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5013 times.
|
5013x | if (err == SSL_ERROR_WANT_WRITE) | |
| 585 | { | |||
| 586 | ✗ | ec = co_await flush_output(); | ||
| 587 | ✗ | if (ec) | ||
| 588 | ✗ | co_return {ec}; | ||
| 589 | ✗ | } | ||
| 590 |
2/2✓ Branch 0 taken 5004 times.
✓ Branch 1 taken 9 times.
|
5013x | else if (err == SSL_ERROR_WANT_READ) | |
| 591 | { | |||
| 592 |
9/14✗ Branch 0 not taken.
✓ Branch 1 taken 5004 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 5004 times.
✓ Branch 4 taken 1668 times.
✓ Branch 5 taken 3336 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 1668 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✓ Branch 10 taken 1668 times.
✓ Branch 11 taken 1668 times.
✓ Branch 12 taken 3336 times.
✓ Branch 13 taken 5004 times.
|
6672x | ec = co_await flush_output(); | |
| 593 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5004 times.
|
5004x | if (ec) | |
| 594 | ✗ | co_return {ec}; | ||
| 595 | ||||
| 596 |
8/14✓ Branch 0 taken 5004 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5004 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1668 times.
✓ Branch 5 taken 3336 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 1668 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✓ Branch 10 taken 1668 times.
✓ Branch 11 taken 1668 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 1668 times.
|
6672x | ec = co_await read_input(); | |
| 597 |
2/2✓ Branch 0 taken 578 times.
✓ Branch 1 taken 1090 times.
|
1668x | if (ec) | |
| 598 |
2/4✓ Branch 0 taken 578 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 578 times.
✗ Branch 3 not taken.
|
578x | co_return {ec}; | |
| 599 | 1090x | } | ||
| 600 | else | |||
| 601 | { | |||
| 602 |
1/2✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
|
9x | unsigned long ssl_err = ERR_get_error(); | |
| 603 | 18x | ec = std::error_code( | ||
| 604 | 9x | static_cast<int>(ssl_err), std::system_category()); | ||
| 605 |
2/4✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
|
9x | co_return {ec}; | |
| 606 | 9x | } | ||
| 607 | 5013x | } | ||
| 608 | 5729x | } | ||
| 609 | 9407x | } | ||
| 610 | ||||
| 611 |
11/24✓ Branch 0 taken 36 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 36 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 36 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 56 times.
✓ Branch 7 taken 92 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✓ Branch 10 taken 36 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✓ Branch 14 taken 36 times.
✓ Branch 15 taken 36 times.
✓ Branch 16 taken 36 times.
✗ Branch 17 not taken.
✓ Branch 18 taken 36 times.
✓ Branch 19 taken 56 times.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
|
236x | capy::io_task<> do_shutdown() | |
| 612 | 36x | { | ||
| 613 | 92x | std::error_code ec; | ||
| 614 | ||||
| 615 | 210x | while (true) | ||
| 616 | { | |||
| 617 |
1/2✓ Branch 0 taken 210 times.
✗ Branch 1 not taken.
|
210x | ERR_clear_error(); | |
| 618 |
1/2✓ Branch 0 taken 210 times.
✗ Branch 1 not taken.
|
210x | int ret = SSL_shutdown(ssl_); | |
| 619 | ||||
| 620 |
2/2✓ Branch 0 taken 84 times.
✓ Branch 1 taken 126 times.
|
210x | if (ret == 1) | |
| 621 | { | |||
| 622 |
8/14✗ Branch 0 not taken.
✓ Branch 1 taken 84 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 84 times.
✓ Branch 4 taken 28 times.
✓ Branch 5 taken 56 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 28 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✓ Branch 10 taken 28 times.
✓ Branch 11 taken 28 times.
✓ Branch 12 taken 28 times.
✗ Branch 13 not taken.
|
112x | ec = co_await flush_output(); | |
| 623 |
2/4✓ Branch 0 taken 28 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 28 times.
✗ Branch 3 not taken.
|
28x | co_return {ec}; | |
| 624 | } | |||
| 625 |
2/2✓ Branch 0 taken 60 times.
✓ Branch 1 taken 66 times.
|
126x | else if (ret == 0) | |
| 626 | { | |||
| 627 |
9/14✗ Branch 0 not taken.
✓ Branch 1 taken 66 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 66 times.
✓ Branch 4 taken 22 times.
✓ Branch 5 taken 44 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 22 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✓ Branch 10 taken 22 times.
✓ Branch 11 taken 22 times.
✓ Branch 12 taken 44 times.
✓ Branch 13 taken 66 times.
|
88x | ec = co_await flush_output(); | |
| 628 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 66 times.
|
66x | if (ec) | |
| 629 | ✗ | co_return {ec}; | ||
| 630 | ||||
| 631 |
8/14✗ Branch 0 not taken.
✓ Branch 1 taken 66 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 66 times.
✓ Branch 4 taken 22 times.
✓ Branch 5 taken 44 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 22 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✓ Branch 10 taken 22 times.
✓ Branch 11 taken 22 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 22 times.
|
88x | ec = co_await read_input(); | |
| 632 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 20 times.
|
22x | if (ec) | |
| 633 | { | |||
| 634 | 2x | ec = normalize_openssl_shutdown_read_error(ec); | ||
| 635 |
2/4✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
|
2x | co_return {ec}; | |
| 636 | } | |||
| 637 | 20x | } | ||
| 638 | else | |||
| 639 | { | |||
| 640 |
1/2✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
|
60x | int err = SSL_get_error(ssl_, ret); | |
| 641 | ||||
| 642 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 60 times.
|
60x | if (err == SSL_ERROR_WANT_WRITE) | |
| 643 | { | |||
| 644 | ✗ | ec = co_await flush_output(); | ||
| 645 | ✗ | if (ec) | ||
| 646 | ✗ | co_return {ec}; | ||
| 647 | ✗ | } | ||
| 648 |
1/2✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
|
60x | else if (err == SSL_ERROR_WANT_READ) | |
| 649 | { | |||
| 650 |
9/14✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 60 times.
✓ Branch 4 taken 20 times.
✓ Branch 5 taken 40 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 20 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✓ Branch 10 taken 20 times.
✓ Branch 11 taken 20 times.
✓ Branch 12 taken 40 times.
✓ Branch 13 taken 60 times.
|
80x | ec = co_await flush_output(); | |
| 651 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 60 times.
|
60x | if (ec) | |
| 652 | ✗ | co_return {ec}; | ||
| 653 | ||||
| 654 |
8/14✗ Branch 0 not taken.
✓ Branch 1 taken 60 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 60 times.
✓ Branch 4 taken 20 times.
✓ Branch 5 taken 40 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 20 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✓ Branch 10 taken 20 times.
✓ Branch 11 taken 20 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 20 times.
|
80x | ec = co_await read_input(); | |
| 655 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 14 times.
|
20x | if (ec) | |
| 656 | { | |||
| 657 | 6x | ec = normalize_openssl_shutdown_read_error(ec); | ||
| 658 |
2/4✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
|
6x | co_return {ec}; | |
| 659 | } | |||
| 660 | 14x | } | ||
| 661 | else | |||
| 662 | { | |||
| 663 | ✗ | unsigned long ssl_err = ERR_get_error(); | ||
| 664 | ✗ | if (ssl_err == 0 && err == SSL_ERROR_SYSCALL) | ||
| 665 | { | |||
| 666 | ✗ | ec = {}; | ||
| 667 | ✗ | } | ||
| 668 | else | |||
| 669 | { | |||
| 670 | ✗ | ec = std::error_code( | ||
| 671 | ✗ | static_cast<int>(ssl_err), std::system_category()); | ||
| 672 | } | |||
| 673 | ✗ | co_return {ec}; | ||
| 674 | ✗ | } | ||
| 675 | 60x | } | ||
| 676 | 154x | } | ||
| 677 | 260x | } | ||
| 678 | ||||
| 679 | 1855x | std::error_code init_ssl() | ||
| 680 | { | |||
| 681 | 1855x | auto& cd = detail::get_tls_context_data(ctx_); | ||
| 682 | 1855x | SSL_CTX* native_ctx = detail::get_openssl_context(cd); | ||
| 683 |
1/2✓ Branch 0 taken 1855 times.
✗ Branch 1 not taken.
|
1855x | if (!native_ctx) | |
| 684 | { | |||
| 685 | ✗ | unsigned long err = ERR_get_error(); | ||
| 686 | ✗ | return std::error_code( | ||
| 687 | ✗ | static_cast<int>(err), std::system_category()); | ||
| 688 | } | |||
| 689 | ||||
| 690 | 1855x | ssl_ = SSL_new(native_ctx); | ||
| 691 |
1/2✓ Branch 0 taken 1855 times.
✗ Branch 1 not taken.
|
1855x | if (!ssl_) | |
| 692 | { | |||
| 693 | ✗ | unsigned long err = ERR_get_error(); | ||
| 694 | ✗ | return std::error_code( | ||
| 695 | ✗ | static_cast<int>(err), std::system_category()); | ||
| 696 | } | |||
| 697 | ||||
| 698 | 1855x | BIO* int_bio = nullptr; | ||
| 699 |
1/2✓ Branch 0 taken 1855 times.
✗ Branch 1 not taken.
|
1855x | if (!BIO_new_bio_pair(&int_bio, 0, &ext_bio_, 0)) | |
| 700 | { | |||
| 701 | ✗ | unsigned long err = ERR_get_error(); | ||
| 702 | ✗ | SSL_free(ssl_); | ||
| 703 | ✗ | ssl_ = nullptr; | ||
| 704 | ✗ | return std::error_code( | ||
| 705 | ✗ | static_cast<int>(err), std::system_category()); | ||
| 706 | } | |||
| 707 | ||||
| 708 | 1855x | SSL_set_bio(ssl_, int_bio, int_bio); | ||
| 709 | ||||
| 710 | 1855x | apply_hostname_verification(ssl_, cd.hostname); | ||
| 711 | ||||
| 712 | 1855x | return {}; | ||
| 713 | 1855x | } | ||
| 714 | }; | |||
| 715 | ||||
| 716 | openssl_stream::impl* | |||
| 717 | 1855x | openssl_stream::make_impl(capy::any_stream& stream, tls_context const& ctx) | ||
| 718 | { | |||
| 719 |
1/4✓ Branch 0 taken 1855 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
1855x | auto* p = new impl(stream, ctx); | |
| 720 | ||||
| 721 | 1855x | auto ec = p->init_ssl(); | ||
| 722 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1855 times.
|
1855x | if (ec) | |
| 723 | { | |||
| 724 | ✗ | delete p; | ||
| 725 | ✗ | return nullptr; | ||
| 726 | } | |||
| 727 | ||||
| 728 | 1855x | return p; | ||
| 729 | 1855x | } | ||
| 730 | ||||
| 731 | 3710x | openssl_stream::~openssl_stream() | ||
| 732 | 1855x | { | ||
| 733 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1855 times.
|
1855x | delete impl_; | |
| 734 | 3710x | } | ||
| 735 | ||||
| 736 | ✗ | openssl_stream::openssl_stream(openssl_stream&& other) noexcept | ||
| 737 | ✗ | : stream_(std::move(other.stream_)) | ||
| 738 | ✗ | , impl_(other.impl_) | ||
| 739 | ✗ | { | ||
| 740 | ✗ | other.impl_ = nullptr; | ||
| 741 | ✗ | } | ||
| 742 | ||||
| 743 | openssl_stream& | |||
| 744 | ✗ | openssl_stream::operator=(openssl_stream&& other) noexcept | ||
| 745 | { | |||
| 746 | ✗ | if (this != &other) | ||
| 747 | { | |||
| 748 | ✗ | delete impl_; | ||
| 749 | ✗ | stream_ = std::move(other.stream_); | ||
| 750 | ✗ | impl_ = other.impl_; | ||
| 751 | ✗ | other.impl_ = nullptr; | ||
| 752 | ✗ | } | ||
| 753 | ✗ | return *this; | ||
| 754 | } | |||
| 755 | ||||
| 756 | capy::io_task<std::size_t> | |||
| 757 |
11/24✓ Branch 0 taken 115095 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 115095 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 115095 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 230190 times.
✓ Branch 7 taken 345285 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✓ Branch 10 taken 115095 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✓ Branch 14 taken 115095 times.
✓ Branch 15 taken 115095 times.
✓ Branch 16 taken 115095 times.
✗ Branch 17 not taken.
✓ Branch 18 taken 230190 times.
✓ Branch 19 taken 115095 times.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
|
805665x | openssl_stream::do_read_some( | |
| 758 | capy::mutable_buffer_array<capy::detail::max_iovec_> buffers) | |||
| 759 | 115095x | { | ||
| 760 |
9/16✓ Branch 0 taken 345285 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 345285 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 115095 times.
✓ Branch 5 taken 230190 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 115095 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✓ Branch 10 taken 115095 times.
✓ Branch 11 taken 115095 times.
✓ Branch 12 taken 115095 times.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✓ Branch 15 taken 115095 times.
|
575475x | co_return co_await impl_->do_read_some(buffers); | |
| 761 | 230190x | } | ||
| 762 | ||||
| 763 | capy::io_task<std::size_t> | |||
| 764 |
11/24✓ Branch 0 taken 115084 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 115084 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 115084 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 230168 times.
✓ Branch 7 taken 345252 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✓ Branch 10 taken 115084 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✓ Branch 14 taken 115084 times.
✓ Branch 15 taken 115084 times.
✓ Branch 16 taken 115084 times.
✗ Branch 17 not taken.
✓ Branch 18 taken 230168 times.
✓ Branch 19 taken 115084 times.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
|
805588x | openssl_stream::do_write_some( | |
| 765 | capy::const_buffer_array<capy::detail::max_iovec_> buffers) | |||
| 766 | 115084x | { | ||
| 767 |
9/16✓ Branch 0 taken 345252 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 345252 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 115084 times.
✓ Branch 5 taken 230168 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 115084 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✓ Branch 10 taken 115084 times.
✓ Branch 11 taken 115084 times.
✓ Branch 12 taken 115084 times.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✓ Branch 15 taken 115084 times.
|
575420x | co_return co_await impl_->do_write_some(buffers); | |
| 768 | 230168x | } | ||
| 769 | ||||
| 770 | capy::io_task<> | |||
| 771 |
11/24✓ Branch 0 taken 1303 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1303 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1303 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2606 times.
✓ Branch 7 taken 3909 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✓ Branch 10 taken 1303 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✓ Branch 14 taken 1303 times.
✓ Branch 15 taken 1303 times.
✓ Branch 16 taken 1303 times.
✗ Branch 17 not taken.
✓ Branch 18 taken 2606 times.
✓ Branch 19 taken 1303 times.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
|
9121x | openssl_stream::handshake(handshake_type type) | |
| 772 | 1303x | { | ||
| 773 |
9/16✓ Branch 0 taken 3909 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3909 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1303 times.
✓ Branch 5 taken 2606 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 1303 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✓ Branch 10 taken 1303 times.
✓ Branch 11 taken 1303 times.
✓ Branch 12 taken 1303 times.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✓ Branch 15 taken 1303 times.
|
6515x | co_return co_await impl_->do_handshake(type); | |
| 774 | 2606x | } | ||
| 775 | ||||
| 776 | capy::io_task<> | |||
| 777 |
11/24✓ Branch 0 taken 36 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 36 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 36 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 72 times.
✓ Branch 7 taken 108 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✓ Branch 10 taken 36 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✓ Branch 14 taken 36 times.
✓ Branch 15 taken 36 times.
✓ Branch 16 taken 36 times.
✗ Branch 17 not taken.
✓ Branch 18 taken 72 times.
✓ Branch 19 taken 36 times.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
|
252x | openssl_stream::shutdown() | |
| 778 | 36x | { | ||
| 779 |
9/16✓ Branch 0 taken 108 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 108 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 36 times.
✓ Branch 5 taken 72 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 36 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✓ Branch 10 taken 36 times.
✓ Branch 11 taken 36 times.
✓ Branch 12 taken 36 times.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✓ Branch 15 taken 36 times.
|
144x | co_return co_await impl_->do_shutdown(); | |
| 780 | 72x | } | ||
| 781 | ||||
| 782 | void | |||
| 783 | 16x | openssl_stream::reset() | ||
| 784 | { | |||
| 785 | 16x | impl_->reset(); | ||
| 786 | 16x | } | ||
| 787 | ||||
| 788 | std::string_view | |||
| 789 | 1x | openssl_stream::name() const noexcept | ||
| 790 | { | |||
| 791 |
1/2✓ Branch 0 taken 1 time.
✗ Branch 1 not taken.
|
1x | return "openssl"; | |
| 792 | } | |||
| 793 | ||||
| 794 | } // namespace boost::corosio | |||
| 795 |