/Src/Dependencies/Boost/boost/asio/ssl/detail/engine.hpp

http://hadesmem.googlecode.com/ · C++ Header · 162 lines · 77 code · 38 blank · 47 comment · 1 complexity · 24047027e245b1681e7651b805b2c971 MD5 · raw file

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