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