]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/asio/ssl/detail/engine.hpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / boost / asio / ssl / detail / engine.hpp
1 //
2 // ssl/detail/engine.hpp
3 // ~~~~~~~~~~~~~~~~~~~~~
4 //
5 // Copyright (c) 2003-2022 Christopher M. Kohlhoff (chris at kohlhoff dot com)
6 //
7 // Distributed under the Boost Software License, Version 1.0. (See accompanying
8 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
9 //
10
11 #ifndef BOOST_ASIO_SSL_DETAIL_ENGINE_HPP
12 #define BOOST_ASIO_SSL_DETAIL_ENGINE_HPP
13
14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
15 # pragma once
16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
17
18 #include <boost/asio/detail/config.hpp>
19
20 #include <boost/asio/buffer.hpp>
21 #include <boost/asio/detail/static_mutex.hpp>
22 #include <boost/asio/ssl/detail/openssl_types.hpp>
23 #include <boost/asio/ssl/detail/verify_callback.hpp>
24 #include <boost/asio/ssl/stream_base.hpp>
25 #include <boost/asio/ssl/verify_mode.hpp>
26
27 #include <boost/asio/detail/push_options.hpp>
28
29 namespace boost {
30 namespace asio {
31 namespace ssl {
32 namespace detail {
33
34 class engine
35 {
36 public:
37 enum want
38 {
39 // Returned by functions to indicate that the engine wants input. The input
40 // buffer should be updated to point to the data. The engine then needs to
41 // be called again to retry the operation.
42 want_input_and_retry = -2,
43
44 // Returned by functions to indicate that the engine wants to write output.
45 // The output buffer points to the data to be written. The engine then
46 // needs to be called again to retry the operation.
47 want_output_and_retry = -1,
48
49 // Returned by functions to indicate that the engine doesn't need input or
50 // output.
51 want_nothing = 0,
52
53 // Returned by functions to indicate that the engine wants to write output.
54 // The output buffer points to the data to be written. After that the
55 // operation is complete, and the engine does not need to be called again.
56 want_output = 1
57 };
58
59 // Construct a new engine for the specified context.
60 BOOST_ASIO_DECL explicit engine(SSL_CTX* context);
61
62 // Construct a new engine for an existing native SSL implementation.
63 BOOST_ASIO_DECL explicit engine(SSL* ssl_impl);
64
65 #if defined(BOOST_ASIO_HAS_MOVE)
66 // Move construct from another engine.
67 BOOST_ASIO_DECL engine(engine&& other) BOOST_ASIO_NOEXCEPT;
68 #endif // defined(BOOST_ASIO_HAS_MOVE)
69
70 // Destructor.
71 BOOST_ASIO_DECL ~engine();
72
73 #if defined(BOOST_ASIO_HAS_MOVE)
74 // Move assign from another engine.
75 BOOST_ASIO_DECL engine& operator=(engine&& other) BOOST_ASIO_NOEXCEPT;
76 #endif // defined(BOOST_ASIO_HAS_MOVE)
77
78 // Get the underlying implementation in the native type.
79 BOOST_ASIO_DECL SSL* native_handle();
80
81 // Set the peer verification mode.
82 BOOST_ASIO_DECL boost::system::error_code set_verify_mode(
83 verify_mode v, boost::system::error_code& ec);
84
85 // Set the peer verification depth.
86 BOOST_ASIO_DECL boost::system::error_code set_verify_depth(
87 int depth, boost::system::error_code& ec);
88
89 // Set a peer certificate verification callback.
90 BOOST_ASIO_DECL boost::system::error_code set_verify_callback(
91 verify_callback_base* callback, boost::system::error_code& ec);
92
93 // Perform an SSL handshake using either SSL_connect (client-side) or
94 // SSL_accept (server-side).
95 BOOST_ASIO_DECL want handshake(
96 stream_base::handshake_type type, boost::system::error_code& ec);
97
98 // Perform a graceful shutdown of the SSL session.
99 BOOST_ASIO_DECL want shutdown(boost::system::error_code& ec);
100
101 // Write bytes to the SSL session.
102 BOOST_ASIO_DECL want write(const boost::asio::const_buffer& data,
103 boost::system::error_code& ec, std::size_t& bytes_transferred);
104
105 // Read bytes from the SSL session.
106 BOOST_ASIO_DECL want read(const boost::asio::mutable_buffer& data,
107 boost::system::error_code& ec, std::size_t& bytes_transferred);
108
109 // Get output data to be written to the transport.
110 BOOST_ASIO_DECL boost::asio::mutable_buffer get_output(
111 const boost::asio::mutable_buffer& data);
112
113 // Put input data that was read from the transport.
114 BOOST_ASIO_DECL boost::asio::const_buffer put_input(
115 const boost::asio::const_buffer& data);
116
117 // Map an error::eof code returned by the underlying transport according to
118 // the type and state of the SSL session. Returns a const reference to the
119 // error code object, suitable for passing to a completion handler.
120 BOOST_ASIO_DECL const boost::system::error_code& map_error_code(
121 boost::system::error_code& ec) const;
122
123 private:
124 // Disallow copying and assignment.
125 engine(const engine&);
126 engine& operator=(const engine&);
127
128 // Callback used when the SSL implementation wants to verify a certificate.
129 BOOST_ASIO_DECL static int verify_callback_function(
130 int preverified, X509_STORE_CTX* ctx);
131
132 #if (OPENSSL_VERSION_NUMBER < 0x10000000L)
133 // The SSL_accept function may not be thread safe. This mutex is used to
134 // protect all calls to the SSL_accept function.
135 BOOST_ASIO_DECL static boost::asio::detail::static_mutex& accept_mutex();
136 #endif // (OPENSSL_VERSION_NUMBER < 0x10000000L)
137
138 // Perform one operation. Returns >= 0 on success or error, want_read if the
139 // operation needs more input, or want_write if it needs to write some output
140 // before the operation can complete.
141 BOOST_ASIO_DECL want perform(int (engine::* op)(void*, std::size_t),
142 void* data, std::size_t length, boost::system::error_code& ec,
143 std::size_t* bytes_transferred);
144
145 // Adapt the SSL_accept function to the signature needed for perform().
146 BOOST_ASIO_DECL int do_accept(void*, std::size_t);
147
148 // Adapt the SSL_connect function to the signature needed for perform().
149 BOOST_ASIO_DECL int do_connect(void*, std::size_t);
150
151 // Adapt the SSL_shutdown function to the signature needed for perform().
152 BOOST_ASIO_DECL int do_shutdown(void*, std::size_t);
153
154 // Adapt the SSL_read function to the signature needed for perform().
155 BOOST_ASIO_DECL int do_read(void* data, std::size_t length);
156
157 // Adapt the SSL_write function to the signature needed for perform().
158 BOOST_ASIO_DECL int do_write(void* data, std::size_t length);
159
160 SSL* ssl_;
161 BIO* ext_bio_;
162 };
163
164 } // namespace detail
165 } // namespace ssl
166 } // namespace asio
167 } // namespace boost
168
169 #include <boost/asio/detail/pop_options.hpp>
170
171 #if defined(BOOST_ASIO_HEADER_ONLY)
172 # include <boost/asio/ssl/detail/impl/engine.ipp>
173 #endif // defined(BOOST_ASIO_HEADER_ONLY)
174
175 #endif // BOOST_ASIO_SSL_DETAIL_ENGINE_HPP