Chris@16: // Chris@16: // ssl/detail/engine.hpp Chris@16: // ~~~~~~~~~~~~~~~~~~~~~ Chris@16: // Chris@101: // Copyright (c) 2003-2015 Christopher M. Kohlhoff (chris at kohlhoff dot com) Chris@16: // Chris@16: // Distributed under the Boost Software License, Version 1.0. (See accompanying Chris@16: // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) Chris@16: // Chris@16: Chris@16: #ifndef BOOST_ASIO_SSL_DETAIL_ENGINE_HPP Chris@16: #define BOOST_ASIO_SSL_DETAIL_ENGINE_HPP Chris@16: Chris@16: #if defined(_MSC_VER) && (_MSC_VER >= 1200) Chris@16: # pragma once Chris@16: #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) Chris@16: Chris@16: #include Chris@16: Chris@16: #if !defined(BOOST_ASIO_ENABLE_OLD_SSL) Chris@16: # include Chris@16: # include Chris@16: # include Chris@16: # include Chris@16: # include Chris@16: # include Chris@16: #endif // !defined(BOOST_ASIO_ENABLE_OLD_SSL) Chris@16: Chris@16: #include Chris@16: Chris@16: namespace boost { Chris@16: namespace asio { Chris@16: namespace ssl { Chris@16: namespace detail { Chris@16: Chris@16: #if !defined(BOOST_ASIO_ENABLE_OLD_SSL) Chris@16: Chris@16: class engine Chris@16: { Chris@16: public: Chris@16: enum want Chris@16: { Chris@16: // Returned by functions to indicate that the engine wants input. The input Chris@16: // buffer should be updated to point to the data. The engine then needs to Chris@16: // be called again to retry the operation. Chris@16: want_input_and_retry = -2, Chris@16: Chris@16: // Returned by functions to indicate that the engine wants to write output. Chris@16: // The output buffer points to the data to be written. The engine then Chris@16: // needs to be called again to retry the operation. Chris@16: want_output_and_retry = -1, Chris@16: Chris@16: // Returned by functions to indicate that the engine doesn't need input or Chris@16: // output. Chris@16: want_nothing = 0, Chris@16: Chris@16: // Returned by functions to indicate that the engine wants to write output. Chris@16: // The output buffer points to the data to be written. After that the Chris@16: // operation is complete, and the engine does not need to be called again. Chris@16: want_output = 1 Chris@16: }; Chris@16: Chris@16: // Construct a new engine for the specified context. Chris@16: BOOST_ASIO_DECL explicit engine(SSL_CTX* context); Chris@16: Chris@16: // Destructor. Chris@16: BOOST_ASIO_DECL ~engine(); Chris@16: Chris@16: // Get the underlying implementation in the native type. Chris@16: BOOST_ASIO_DECL SSL* native_handle(); Chris@16: Chris@16: // Set the peer verification mode. Chris@16: BOOST_ASIO_DECL boost::system::error_code set_verify_mode( Chris@16: verify_mode v, boost::system::error_code& ec); Chris@16: Chris@16: // Set the peer verification depth. Chris@16: BOOST_ASIO_DECL boost::system::error_code set_verify_depth( Chris@16: int depth, boost::system::error_code& ec); Chris@16: Chris@16: // Set a peer certificate verification callback. Chris@16: BOOST_ASIO_DECL boost::system::error_code set_verify_callback( Chris@16: verify_callback_base* callback, boost::system::error_code& ec); Chris@16: Chris@16: // Perform an SSL handshake using either SSL_connect (client-side) or Chris@16: // SSL_accept (server-side). Chris@16: BOOST_ASIO_DECL want handshake( Chris@16: stream_base::handshake_type type, boost::system::error_code& ec); Chris@16: Chris@16: // Perform a graceful shutdown of the SSL session. Chris@16: BOOST_ASIO_DECL want shutdown(boost::system::error_code& ec); Chris@16: Chris@16: // Write bytes to the SSL session. Chris@16: BOOST_ASIO_DECL want write(const boost::asio::const_buffer& data, Chris@16: boost::system::error_code& ec, std::size_t& bytes_transferred); Chris@16: Chris@16: // Read bytes from the SSL session. Chris@16: BOOST_ASIO_DECL want read(const boost::asio::mutable_buffer& data, Chris@16: boost::system::error_code& ec, std::size_t& bytes_transferred); Chris@16: Chris@16: // Get output data to be written to the transport. Chris@16: BOOST_ASIO_DECL boost::asio::mutable_buffers_1 get_output( Chris@16: const boost::asio::mutable_buffer& data); Chris@16: Chris@16: // Put input data that was read from the transport. Chris@16: BOOST_ASIO_DECL boost::asio::const_buffer put_input( Chris@16: const boost::asio::const_buffer& data); Chris@16: Chris@16: // Map an error::eof code returned by the underlying transport according to Chris@16: // the type and state of the SSL session. Returns a const reference to the Chris@16: // error code object, suitable for passing to a completion handler. Chris@16: BOOST_ASIO_DECL const boost::system::error_code& map_error_code( Chris@16: boost::system::error_code& ec) const; Chris@16: Chris@16: private: Chris@16: // Disallow copying and assignment. Chris@16: engine(const engine&); Chris@16: engine& operator=(const engine&); Chris@16: Chris@16: // Callback used when the SSL implementation wants to verify a certificate. Chris@16: BOOST_ASIO_DECL static int verify_callback_function( Chris@16: int preverified, X509_STORE_CTX* ctx); Chris@16: Chris@16: // The SSL_accept function may not be thread safe. This mutex is used to Chris@16: // protect all calls to the SSL_accept function. Chris@16: BOOST_ASIO_DECL static boost::asio::detail::static_mutex& accept_mutex(); Chris@16: Chris@16: // Perform one operation. Returns >= 0 on success or error, want_read if the Chris@16: // operation needs more input, or want_write if it needs to write some output Chris@16: // before the operation can complete. Chris@16: BOOST_ASIO_DECL want perform(int (engine::* op)(void*, std::size_t), Chris@16: void* data, std::size_t length, boost::system::error_code& ec, Chris@16: std::size_t* bytes_transferred); Chris@16: Chris@16: // Adapt the SSL_accept function to the signature needed for perform(). Chris@16: BOOST_ASIO_DECL int do_accept(void*, std::size_t); Chris@16: Chris@16: // Adapt the SSL_connect function to the signature needed for perform(). Chris@16: BOOST_ASIO_DECL int do_connect(void*, std::size_t); Chris@16: Chris@16: // Adapt the SSL_shutdown function to the signature needed for perform(). Chris@16: BOOST_ASIO_DECL int do_shutdown(void*, std::size_t); Chris@16: Chris@16: // Adapt the SSL_read function to the signature needed for perform(). Chris@16: BOOST_ASIO_DECL int do_read(void* data, std::size_t length); Chris@16: Chris@16: // Adapt the SSL_write function to the signature needed for perform(). Chris@16: BOOST_ASIO_DECL int do_write(void* data, std::size_t length); Chris@16: Chris@16: SSL* ssl_; Chris@16: BIO* ext_bio_; Chris@16: }; Chris@16: Chris@16: #endif // !defined(BOOST_ASIO_ENABLE_OLD_SSL) Chris@16: Chris@16: } // namespace detail Chris@16: } // namespace ssl Chris@16: } // namespace asio Chris@16: } // namespace boost Chris@16: Chris@16: #include Chris@16: Chris@16: #if defined(BOOST_ASIO_HEADER_ONLY) Chris@16: # include Chris@16: #endif // defined(BOOST_ASIO_HEADER_ONLY) Chris@16: Chris@16: #endif // BOOST_ASIO_SSL_DETAIL_ENGINE_HPP