update boost on linux

This commit is contained in:
Bassem Girgis
2019-08-10 16:06:25 -05:00
parent 76ad52be58
commit 861b918727
5363 changed files with 483306 additions and 116507 deletions

View File

@@ -1,42 +0,0 @@
//
// ssl/basic_context.hpp
// ~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef BOOST_ASIO_SSL_BASIC_CONTEXT_HPP
#define BOOST_ASIO_SSL_BASIC_CONTEXT_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/config.hpp>
#if defined(BOOST_ASIO_ENABLE_OLD_SSL)
# include <boost/asio/ssl/old/basic_context.hpp>
#endif // defined(BOOST_ASIO_ENABLE_OLD_SSL)
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
namespace ssl {
#if defined(BOOST_ASIO_ENABLE_OLD_SSL)
using boost::asio::ssl::old::basic_context;
#endif // defined(BOOST_ASIO_ENABLE_OLD_SSL)
} // namespace ssl
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_SSL_BASIC_CONTEXT_HPP

View File

@@ -2,7 +2,7 @@
// ssl/context.hpp
// ~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
@@ -17,20 +17,15 @@
#include <boost/asio/detail/config.hpp>
#if defined(BOOST_ASIO_ENABLE_OLD_SSL)
# include <boost/asio/ssl/basic_context.hpp>
# include <boost/asio/ssl/context_service.hpp>
#else // defined(BOOST_ASIO_ENABLE_OLD_SSL)
# include <string>
# include <boost/asio/buffer.hpp>
# include <boost/asio/io_service.hpp>
# include <boost/asio/ssl/context_base.hpp>
# include <boost/asio/ssl/detail/openssl_types.hpp>
# include <boost/asio/ssl/detail/openssl_init.hpp>
# include <boost/asio/ssl/detail/password_callback.hpp>
# include <boost/asio/ssl/detail/verify_callback.hpp>
# include <boost/asio/ssl/verify_mode.hpp>
#endif // defined(BOOST_ASIO_ENABLE_OLD_SSL)
#include <string>
#include <boost/asio/buffer.hpp>
#include <boost/asio/io_context.hpp>
#include <boost/asio/ssl/context_base.hpp>
#include <boost/asio/ssl/detail/openssl_types.hpp>
#include <boost/asio/ssl/detail/openssl_init.hpp>
#include <boost/asio/ssl/detail/password_callback.hpp>
#include <boost/asio/ssl/detail/verify_callback.hpp>
#include <boost/asio/ssl/verify_mode.hpp>
#include <boost/asio/detail/push_options.hpp>
@@ -38,13 +33,6 @@ namespace boost {
namespace asio {
namespace ssl {
#if defined(BOOST_ASIO_ENABLE_OLD_SSL)
/// Typedef for the typical usage of context.
typedef basic_context<context_service> context;
#else // defined(BOOST_ASIO_ENABLE_OLD_SSL)
class context
: public context_base,
private noncopyable
@@ -53,15 +41,9 @@ public:
/// The native handle type of the SSL context.
typedef SSL_CTX* native_handle_type;
/// (Deprecated: Use native_handle_type.) The native type of the SSL context.
typedef SSL_CTX* impl_type;
/// Constructor.
BOOST_ASIO_DECL explicit context(method m);
/// Deprecated constructor taking a reference to an io_service object.
BOOST_ASIO_DECL context(boost::asio::io_service&, method m);
#if defined(BOOST_ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
/// Move-construct a context from another.
/**
@@ -101,15 +83,6 @@ public:
*/
BOOST_ASIO_DECL native_handle_type native_handle();
/// (Deprecated: Use native_handle().) Get the underlying implementation in
/// the native type.
/**
* This function may be used to obtain the underlying implementation of the
* context. This is intended to allow access to context functionality that is
* not otherwise provided.
*/
BOOST_ASIO_DECL impl_type impl();
/// Clear options on the context.
/**
* This function may be used to configure the SSL options used by the context.
@@ -136,7 +109,7 @@ public:
*
* @note Calls @c SSL_CTX_clear_options.
*/
BOOST_ASIO_DECL boost::system::error_code clear_options(options o,
BOOST_ASIO_DECL BOOST_ASIO_SYNC_OP_VOID clear_options(options o,
boost::system::error_code& ec);
/// Set options on the context.
@@ -165,7 +138,7 @@ public:
*
* @note Calls @c SSL_CTX_set_options.
*/
BOOST_ASIO_DECL boost::system::error_code set_options(options o,
BOOST_ASIO_DECL BOOST_ASIO_SYNC_OP_VOID set_options(options o,
boost::system::error_code& ec);
/// Set the peer verification mode.
@@ -194,7 +167,7 @@ public:
*
* @note Calls @c SSL_CTX_set_verify.
*/
BOOST_ASIO_DECL boost::system::error_code set_verify_mode(
BOOST_ASIO_DECL BOOST_ASIO_SYNC_OP_VOID set_verify_mode(
verify_mode v, boost::system::error_code& ec);
/// Set the peer verification depth.
@@ -223,7 +196,7 @@ public:
*
* @note Calls @c SSL_CTX_set_verify_depth.
*/
BOOST_ASIO_DECL boost::system::error_code set_verify_depth(
BOOST_ASIO_DECL BOOST_ASIO_SYNC_OP_VOID set_verify_depth(
int depth, boost::system::error_code& ec);
/// Set the callback used to verify peer certificates.
@@ -266,7 +239,7 @@ public:
* @note Calls @c SSL_CTX_set_verify.
*/
template <typename VerifyCallback>
boost::system::error_code set_verify_callback(VerifyCallback callback,
BOOST_ASIO_SYNC_OP_VOID set_verify_callback(VerifyCallback callback,
boost::system::error_code& ec);
/// Load a certification authority file for performing verification.
@@ -295,7 +268,7 @@ public:
*
* @note Calls @c SSL_CTX_load_verify_locations.
*/
BOOST_ASIO_DECL boost::system::error_code load_verify_file(
BOOST_ASIO_DECL BOOST_ASIO_SYNC_OP_VOID load_verify_file(
const std::string& filename, boost::system::error_code& ec);
/// Add certification authority for performing verification.
@@ -324,7 +297,7 @@ public:
*
* @note Calls @c SSL_CTX_get_cert_store and @c X509_STORE_add_cert.
*/
BOOST_ASIO_DECL boost::system::error_code add_certificate_authority(
BOOST_ASIO_DECL BOOST_ASIO_SYNC_OP_VOID add_certificate_authority(
const const_buffer& ca, boost::system::error_code& ec);
/// Configures the context to use the default directories for finding
@@ -351,7 +324,7 @@ public:
*
* @note Calls @c SSL_CTX_set_default_verify_paths.
*/
BOOST_ASIO_DECL boost::system::error_code set_default_verify_paths(
BOOST_ASIO_DECL BOOST_ASIO_SYNC_OP_VOID set_default_verify_paths(
boost::system::error_code& ec);
/// Add a directory containing certificate authority files to be used for
@@ -384,7 +357,7 @@ public:
*
* @note Calls @c SSL_CTX_load_verify_locations.
*/
BOOST_ASIO_DECL boost::system::error_code add_verify_path(
BOOST_ASIO_DECL BOOST_ASIO_SYNC_OP_VOID add_verify_path(
const std::string& path, boost::system::error_code& ec);
/// Use a certificate from a memory buffer.
@@ -414,7 +387,7 @@ public:
*
* @note Calls @c SSL_CTX_use_certificate or SSL_CTX_use_certificate_ASN1.
*/
BOOST_ASIO_DECL boost::system::error_code use_certificate(
BOOST_ASIO_DECL BOOST_ASIO_SYNC_OP_VOID use_certificate(
const const_buffer& certificate, file_format format,
boost::system::error_code& ec);
@@ -445,7 +418,7 @@ public:
*
* @note Calls @c SSL_CTX_use_certificate_file.
*/
BOOST_ASIO_DECL boost::system::error_code use_certificate_file(
BOOST_ASIO_DECL BOOST_ASIO_SYNC_OP_VOID use_certificate_file(
const std::string& filename, file_format format,
boost::system::error_code& ec);
@@ -475,7 +448,7 @@ public:
*
* @note Calls @c SSL_CTX_use_certificate and SSL_CTX_add_extra_chain_cert.
*/
BOOST_ASIO_DECL boost::system::error_code use_certificate_chain(
BOOST_ASIO_DECL BOOST_ASIO_SYNC_OP_VOID use_certificate_chain(
const const_buffer& chain, boost::system::error_code& ec);
/// Use a certificate chain from a file.
@@ -504,7 +477,7 @@ public:
*
* @note Calls @c SSL_CTX_use_certificate_chain_file.
*/
BOOST_ASIO_DECL boost::system::error_code use_certificate_chain_file(
BOOST_ASIO_DECL BOOST_ASIO_SYNC_OP_VOID use_certificate_chain_file(
const std::string& filename, boost::system::error_code& ec);
/// Use a private key from a memory buffer.
@@ -534,7 +507,7 @@ public:
*
* @note Calls @c SSL_CTX_use_PrivateKey or SSL_CTX_use_PrivateKey_ASN1.
*/
BOOST_ASIO_DECL boost::system::error_code use_private_key(
BOOST_ASIO_DECL BOOST_ASIO_SYNC_OP_VOID use_private_key(
const const_buffer& private_key, file_format format,
boost::system::error_code& ec);
@@ -565,7 +538,7 @@ public:
*
* @note Calls @c SSL_CTX_use_PrivateKey_file.
*/
BOOST_ASIO_DECL boost::system::error_code use_private_key_file(
BOOST_ASIO_DECL BOOST_ASIO_SYNC_OP_VOID use_private_key_file(
const std::string& filename, file_format format,
boost::system::error_code& ec);
@@ -598,7 +571,7 @@ public:
*
* @note Calls @c SSL_CTX_use_RSAPrivateKey or SSL_CTX_use_RSAPrivateKey_ASN1.
*/
BOOST_ASIO_DECL boost::system::error_code use_rsa_private_key(
BOOST_ASIO_DECL BOOST_ASIO_SYNC_OP_VOID use_rsa_private_key(
const const_buffer& private_key, file_format format,
boost::system::error_code& ec);
@@ -631,7 +604,7 @@ public:
*
* @note Calls @c SSL_CTX_use_RSAPrivateKey_file.
*/
BOOST_ASIO_DECL boost::system::error_code use_rsa_private_key_file(
BOOST_ASIO_DECL BOOST_ASIO_SYNC_OP_VOID use_rsa_private_key_file(
const std::string& filename, file_format format,
boost::system::error_code& ec);
@@ -663,7 +636,7 @@ public:
*
* @note Calls @c SSL_CTX_set_tmp_dh.
*/
BOOST_ASIO_DECL boost::system::error_code use_tmp_dh(
BOOST_ASIO_DECL BOOST_ASIO_SYNC_OP_VOID use_tmp_dh(
const const_buffer& dh, boost::system::error_code& ec);
/// Use the specified file to obtain the temporary Diffie-Hellman parameters.
@@ -692,7 +665,7 @@ public:
*
* @note Calls @c SSL_CTX_set_tmp_dh.
*/
BOOST_ASIO_DECL boost::system::error_code use_tmp_dh_file(
BOOST_ASIO_DECL BOOST_ASIO_SYNC_OP_VOID use_tmp_dh_file(
const std::string& filename, boost::system::error_code& ec);
/// Set the password callback.
@@ -733,7 +706,7 @@ public:
* @note Calls @c SSL_CTX_set_default_passwd_cb.
*/
template <typename PasswordCallback>
boost::system::error_code set_password_callback(PasswordCallback callback,
BOOST_ASIO_SYNC_OP_VOID set_password_callback(PasswordCallback callback,
boost::system::error_code& ec);
private:
@@ -744,7 +717,7 @@ private:
struct dh_cleanup;
// Helper function used to set a peer certificate verification callback.
BOOST_ASIO_DECL boost::system::error_code do_set_verify_callback(
BOOST_ASIO_DECL BOOST_ASIO_SYNC_OP_VOID do_set_verify_callback(
detail::verify_callback_base* callback, boost::system::error_code& ec);
// Callback used when the SSL implementation wants to verify a certificate.
@@ -752,7 +725,7 @@ private:
int preverified, X509_STORE_CTX* ctx);
// Helper function used to set a password callback.
BOOST_ASIO_DECL boost::system::error_code do_set_password_callback(
BOOST_ASIO_DECL BOOST_ASIO_SYNC_OP_VOID do_set_password_callback(
detail::password_callback_base* callback, boost::system::error_code& ec);
// Callback used when the SSL implementation wants a password.
@@ -760,7 +733,7 @@ private:
char* buf, int size, int purpose, void* data);
// Helper function to set the temporary Diffie-Hellman parameters from a BIO.
BOOST_ASIO_DECL boost::system::error_code do_use_tmp_dh(
BOOST_ASIO_DECL BOOST_ASIO_SYNC_OP_VOID do_use_tmp_dh(
BIO* bio, boost::system::error_code& ec);
// Helper function to make a BIO from a memory buffer.
@@ -773,8 +746,6 @@ private:
boost::asio::ssl::detail::openssl_init<> init_;
};
#endif // defined(BOOST_ASIO_ENABLE_OLD_SSL)
} // namespace ssl
} // namespace asio
} // namespace boost

View File

@@ -2,7 +2,7 @@
// ssl/context_base.hpp
// ~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
@@ -86,6 +86,15 @@ public:
/// TLS version 1.2 server.
tlsv12_server,
/// Generic TLS version 1.3.
tlsv13,
/// TLS version 1.3 client.
tlsv13_client,
/// TLS version 1.3 server.
tlsv13_server,
/// Generic TLS.
tls,
@@ -121,6 +130,9 @@ public:
/// Disable TLS v1.2.
static const long no_tlsv1_2 = implementation_defined;
/// Disable TLS v1.3.
static const long no_tlsv1_3 = implementation_defined;
/// Disable compression. Compression is disabled by default.
static const long no_compression = implementation_defined;
#else
@@ -139,6 +151,11 @@ public:
# else // defined(SSL_OP_NO_TLSv1_2)
BOOST_ASIO_STATIC_CONSTANT(long, no_tlsv1_2 = 0x08000000L);
# endif // defined(SSL_OP_NO_TLSv1_2)
# if defined(SSL_OP_NO_TLSv1_3)
BOOST_ASIO_STATIC_CONSTANT(long, no_tlsv1_3 = SSL_OP_NO_TLSv1_3);
# else // defined(SSL_OP_NO_TLSv1_3)
BOOST_ASIO_STATIC_CONSTANT(long, no_tlsv1_3 = 0x20000000L);
# endif // defined(SSL_OP_NO_TLSv1_3)
# if defined(SSL_OP_NO_COMPRESSION)
BOOST_ASIO_STATIC_CONSTANT(long, no_compression = SSL_OP_NO_COMPRESSION);
# else // defined(SSL_OP_NO_COMPRESSION)

View File

@@ -1,42 +0,0 @@
//
// ssl/context_service.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef BOOST_ASIO_SSL_CONTEXT_SERVICE_HPP
#define BOOST_ASIO_SSL_CONTEXT_SERVICE_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/config.hpp>
#if defined(BOOST_ASIO_ENABLE_OLD_SSL)
# include <boost/asio/ssl/old/context_service.hpp>
#endif // defined(BOOST_ASIO_ENABLE_OLD_SSL)
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
namespace ssl {
#if defined(BOOST_ASIO_ENABLE_OLD_SSL)
using boost::asio::ssl::old::context_service;
#endif // defined(BOOST_ASIO_ENABLE_OLD_SSL)
} // namespace ssl
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_SSL_CONTEXT_SERVICE_HPP

View File

@@ -2,7 +2,7 @@
// ssl/detail/buffered_handshake_op.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
@@ -17,9 +17,7 @@
#include <boost/asio/detail/config.hpp>
#if !defined(BOOST_ASIO_ENABLE_OLD_SSL)
# include <boost/asio/ssl/detail/engine.hpp>
#endif // !defined(BOOST_ASIO_ENABLE_OLD_SSL)
#include <boost/asio/ssl/detail/engine.hpp>
#include <boost/asio/detail/push_options.hpp>
@@ -28,8 +26,6 @@ namespace asio {
namespace ssl {
namespace detail {
#if !defined(BOOST_ASIO_ENABLE_OLD_SSL)
template <typename ConstBufferSequence>
class buffered_handshake_op
{
@@ -46,8 +42,27 @@ public:
boost::system::error_code& ec,
std::size_t& bytes_transferred) const
{
typename ConstBufferSequence::const_iterator iter = buffers_.begin();
typename ConstBufferSequence::const_iterator end = buffers_.end();
return this->process(eng, ec, bytes_transferred,
boost::asio::buffer_sequence_begin(buffers_),
boost::asio::buffer_sequence_end(buffers_));
}
template <typename Handler>
void call_handler(Handler& handler,
const boost::system::error_code& ec,
const std::size_t& bytes_transferred) const
{
handler(ec, bytes_transferred);
}
private:
template <typename Iterator>
engine::want process(engine& eng,
boost::system::error_code& ec,
std::size_t& bytes_transferred,
Iterator begin, Iterator end) const
{
Iterator iter = begin;
std::size_t accumulated_size = 0;
for (;;)
@@ -63,9 +78,9 @@ public:
const_buffer buffer(*iter);
// Skip over any buffers which have already been consumed by the engine.
if (bytes_transferred >= accumulated_size + buffer_size(buffer))
if (bytes_transferred >= accumulated_size + buffer.size())
{
accumulated_size += buffer_size(buffer);
accumulated_size += buffer.size();
++iter;
continue;
}
@@ -78,30 +93,19 @@ public:
// Pass the buffer to the engine, and update the bytes transferred to
// reflect the total number of bytes consumed so far.
bytes_transferred += buffer_size(buffer);
bytes_transferred += buffer.size();
buffer = eng.put_input(buffer);
bytes_transferred -= buffer_size(buffer);
bytes_transferred -= buffer.size();
break;
}
}
}
template <typename Handler>
void call_handler(Handler& handler,
const boost::system::error_code& ec,
const std::size_t& bytes_transferred) const
{
handler(ec, bytes_transferred);
}
private:
stream_base::handshake_type type_;
ConstBufferSequence buffers_;
std::size_t total_buffer_size_;
};
#endif // !defined(BOOST_ASIO_ENABLE_OLD_SSL)
} // namespace detail
} // namespace ssl
} // namespace asio

View File

@@ -2,7 +2,7 @@
// ssl/detail/engine.hpp
// ~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
@@ -17,14 +17,12 @@
#include <boost/asio/detail/config.hpp>
#if !defined(BOOST_ASIO_ENABLE_OLD_SSL)
# include <boost/asio/buffer.hpp>
# include <boost/asio/detail/static_mutex.hpp>
# include <boost/asio/ssl/detail/openssl_types.hpp>
# include <boost/asio/ssl/detail/verify_callback.hpp>
# include <boost/asio/ssl/stream_base.hpp>
# include <boost/asio/ssl/verify_mode.hpp>
#endif // !defined(BOOST_ASIO_ENABLE_OLD_SSL)
#include <boost/asio/buffer.hpp>
#include <boost/asio/detail/static_mutex.hpp>
#include <boost/asio/ssl/detail/openssl_types.hpp>
#include <boost/asio/ssl/detail/verify_callback.hpp>
#include <boost/asio/ssl/stream_base.hpp>
#include <boost/asio/ssl/verify_mode.hpp>
#include <boost/asio/detail/push_options.hpp>
@@ -33,8 +31,6 @@ namespace asio {
namespace ssl {
namespace detail {
#if !defined(BOOST_ASIO_ENABLE_OLD_SSL)
class engine
{
public:
@@ -98,7 +94,7 @@ public:
boost::system::error_code& ec, std::size_t& bytes_transferred);
// Get output data to be written to the transport.
BOOST_ASIO_DECL boost::asio::mutable_buffers_1 get_output(
BOOST_ASIO_DECL boost::asio::mutable_buffer get_output(
const boost::asio::mutable_buffer& data);
// Put input data that was read from the transport.
@@ -120,9 +116,11 @@ private:
BOOST_ASIO_DECL static int verify_callback_function(
int preverified, X509_STORE_CTX* ctx);
#if (OPENSSL_VERSION_NUMBER < 0x10000000L)
// The SSL_accept function may not be thread safe. This mutex is used to
// protect all calls to the SSL_accept function.
BOOST_ASIO_DECL static boost::asio::detail::static_mutex& accept_mutex();
#endif // (OPENSSL_VERSION_NUMBER < 0x10000000L)
// Perform one operation. Returns >= 0 on success or error, want_read if the
// operation needs more input, or want_write if it needs to write some output
@@ -150,8 +148,6 @@ private:
BIO* ext_bio_;
};
#endif // !defined(BOOST_ASIO_ENABLE_OLD_SSL)
} // namespace detail
} // namespace ssl
} // namespace asio

View File

@@ -2,7 +2,7 @@
// ssl/detail/handshake_op.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
@@ -17,9 +17,7 @@
#include <boost/asio/detail/config.hpp>
#if !defined(BOOST_ASIO_ENABLE_OLD_SSL)
# include <boost/asio/ssl/detail/engine.hpp>
#endif // !defined(BOOST_ASIO_ENABLE_OLD_SSL)
#include <boost/asio/ssl/detail/engine.hpp>
#include <boost/asio/detail/push_options.hpp>
@@ -28,8 +26,6 @@ namespace asio {
namespace ssl {
namespace detail {
#if !defined(BOOST_ASIO_ENABLE_OLD_SSL)
class handshake_op
{
public:
@@ -58,8 +54,6 @@ private:
stream_base::handshake_type type_;
};
#endif // !defined(BOOST_ASIO_ENABLE_OLD_SSL)
} // namespace detail
} // namespace ssl
} // namespace asio

View File

@@ -2,7 +2,7 @@
// ssl/detail/impl/engine.ipp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
@@ -17,13 +17,11 @@
#include <boost/asio/detail/config.hpp>
#if !defined(BOOST_ASIO_ENABLE_OLD_SSL)
# include <boost/asio/detail/throw_error.hpp>
# include <boost/asio/error.hpp>
# include <boost/asio/ssl/detail/engine.hpp>
# include <boost/asio/ssl/error.hpp>
# include <boost/asio/ssl/verify_context.hpp>
#endif // !defined(BOOST_ASIO_ENABLE_OLD_SSL)
#include <boost/asio/detail/throw_error.hpp>
#include <boost/asio/error.hpp>
#include <boost/asio/ssl/detail/engine.hpp>
#include <boost/asio/ssl/error.hpp>
#include <boost/asio/ssl/verify_context.hpp>
#include <boost/asio/detail/push_options.hpp>
@@ -32,8 +30,6 @@ namespace asio {
namespace ssl {
namespace detail {
#if !defined(BOOST_ASIO_ENABLE_OLD_SSL)
engine::engine(SSL_CTX* context)
: ssl_(::SSL_new(context))
{
@@ -45,7 +41,9 @@ engine::engine(SSL_CTX* context)
boost::asio::detail::throw_error(ec, "engine");
}
#if (OPENSSL_VERSION_NUMBER < 0x10000000L)
accept_mutex().init();
#endif // (OPENSSL_VERSION_NUMBER < 0x10000000L)
::SSL_set_mode(ssl_, SSL_MODE_ENABLE_PARTIAL_WRITE);
::SSL_set_mode(ssl_, SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER);
@@ -146,37 +144,35 @@ engine::want engine::shutdown(boost::system::error_code& ec)
engine::want engine::write(const boost::asio::const_buffer& data,
boost::system::error_code& ec, std::size_t& bytes_transferred)
{
if (boost::asio::buffer_size(data) == 0)
if (data.size() == 0)
{
ec = boost::system::error_code();
return engine::want_nothing;
}
return perform(&engine::do_write,
const_cast<void*>(boost::asio::buffer_cast<const void*>(data)),
boost::asio::buffer_size(data), ec, &bytes_transferred);
const_cast<void*>(data.data()),
data.size(), ec, &bytes_transferred);
}
engine::want engine::read(const boost::asio::mutable_buffer& data,
boost::system::error_code& ec, std::size_t& bytes_transferred)
{
if (boost::asio::buffer_size(data) == 0)
if (data.size() == 0)
{
ec = boost::system::error_code();
return engine::want_nothing;
}
return perform(&engine::do_read,
boost::asio::buffer_cast<void*>(data),
boost::asio::buffer_size(data), ec, &bytes_transferred);
return perform(&engine::do_read, data.data(),
data.size(), ec, &bytes_transferred);
}
boost::asio::mutable_buffers_1 engine::get_output(
boost::asio::mutable_buffer engine::get_output(
const boost::asio::mutable_buffer& data)
{
int length = ::BIO_read(ext_bio_,
boost::asio::buffer_cast<void*>(data),
static_cast<int>(boost::asio::buffer_size(data)));
data.data(), static_cast<int>(data.size()));
return boost::asio::buffer(data,
length > 0 ? static_cast<std::size_t>(length) : 0);
@@ -186,8 +182,7 @@ boost::asio::const_buffer engine::put_input(
const boost::asio::const_buffer& data)
{
int length = ::BIO_write(ext_bio_,
boost::asio::buffer_cast<const void*>(data),
static_cast<int>(boost::asio::buffer_size(data)));
data.data(), static_cast<int>(data.size()));
return boost::asio::buffer(data +
(length > 0 ? static_cast<std::size_t>(length) : 0));
@@ -210,7 +205,7 @@ const boost::system::error_code& engine::map_error_code(
// SSL v2 doesn't provide a protocol-level shutdown, so an eof on the
// underlying transport is passed through.
#if (OPENSSL_VERSION_NUMBER < 0x10100000L)
if (ssl_->version == SSL2_VERSION)
if (SSL_version(ssl_) == SSL2_VERSION)
return ec;
#endif // (OPENSSL_VERSION_NUMBER < 0x10100000L)
@@ -223,11 +218,13 @@ const boost::system::error_code& engine::map_error_code(
return ec;
}
#if (OPENSSL_VERSION_NUMBER < 0x10000000L)
boost::asio::detail::static_mutex& engine::accept_mutex()
{
static boost::asio::detail::static_mutex mutex = BOOST_ASIO_STATIC_MUTEX_INIT;
return mutex;
}
#endif // (OPENSSL_VERSION_NUMBER < 0x10000000L)
engine::want engine::perform(int (engine::* op)(void*, std::size_t),
void* data, std::size_t length, boost::system::error_code& ec,
@@ -244,14 +241,23 @@ engine::want engine::perform(int (engine::* op)(void*, std::size_t),
{
ec = boost::system::error_code(sys_error,
boost::asio::error::get_ssl_category());
return want_nothing;
return pending_output_after > pending_output_before
? want_output : want_nothing;
}
if (ssl_error == SSL_ERROR_SYSCALL)
{
ec = boost::system::error_code(sys_error,
boost::asio::error::get_system_category());
return want_nothing;
if (sys_error == 0)
{
ec = boost::asio::ssl::error::unspecified_system_error;
}
else
{
ec = boost::system::error_code(sys_error,
boost::asio::error::get_ssl_category());
}
return pending_output_after > pending_output_before
? want_output : want_nothing;
}
if (result > 0 && bytes_transferred)
@@ -272,21 +278,28 @@ engine::want engine::perform(int (engine::* op)(void*, std::size_t),
ec = boost::system::error_code();
return want_input_and_retry;
}
else if (::SSL_get_shutdown(ssl_) & SSL_RECEIVED_SHUTDOWN)
else if (ssl_error == SSL_ERROR_ZERO_RETURN)
{
ec = boost::asio::error::eof;
return want_nothing;
}
else
else if (ssl_error == SSL_ERROR_NONE)
{
ec = boost::system::error_code();
return want_nothing;
}
else
{
ec = boost::asio::ssl::error::unexpected_result;
return want_nothing;
}
}
int engine::do_accept(void*, std::size_t)
{
#if (OPENSSL_VERSION_NUMBER < 0x10000000L)
boost::asio::detail::static_mutex::scoped_lock lock(accept_mutex());
#endif // (OPENSSL_VERSION_NUMBER < 0x10000000L)
return ::SSL_accept(ssl_);
}
@@ -315,8 +328,6 @@ int engine::do_write(void* data, std::size_t length)
length < INT_MAX ? static_cast<int>(length) : INT_MAX);
}
#endif // !defined(BOOST_ASIO_ENABLE_OLD_SSL)
} // namespace detail
} // namespace ssl
} // namespace asio

View File

@@ -3,7 +3,7 @@
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2005 Voipster / Indrek dot Juhani at voipster dot com
// Copyright (c) 2005-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
// Copyright (c) 2005-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
@@ -79,12 +79,13 @@ public:
#elif (OPENSSL_VERSION_NUMBER < 0x10100000L)
::ERR_remove_thread_state(NULL);
#endif // (OPENSSL_VERSION_NUMBER < 0x10000000L)
#if !defined(SSL_OP_NO_COMPRESSION) \
&& (OPENSSL_VERSION_NUMBER >= 0x10002000L) \
&& (OPENSSL_VERSION_NUMBER < 0x10100000L)
#if (OPENSSL_VERSION_NUMBER >= 0x10002000L) \
&& (OPENSSL_VERSION_NUMBER < 0x10100000L) \
&& !defined(SSL_OP_NO_COMPRESSION)
::SSL_COMP_free_compression_methods();
#endif // (OPENSSL_VERSION_NUMBER >= 0x10002000L)
// && (OPENSSL_VERSION_NUMBER < 0x10100000L)
// && !defined(SSL_OP_NO_COMPRESSION)
#if !defined(OPENSSL_IS_BORINGSSL)
::CONF_modules_unload(1);
#endif // !defined(OPENSSL_IS_BORINGSSL)

View File

@@ -2,7 +2,7 @@
// ssl/detail/io.hpp
// ~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
@@ -17,11 +17,9 @@
#include <boost/asio/detail/config.hpp>
#if !defined(BOOST_ASIO_ENABLE_OLD_SSL)
# include <boost/asio/ssl/detail/engine.hpp>
# include <boost/asio/ssl/detail/stream_core.hpp>
# include <boost/asio/write.hpp>
#endif // !defined(BOOST_ASIO_ENABLE_OLD_SSL)
#include <boost/asio/ssl/detail/engine.hpp>
#include <boost/asio/ssl/detail/stream_core.hpp>
#include <boost/asio/write.hpp>
#include <boost/asio/detail/push_options.hpp>
@@ -30,12 +28,11 @@ namespace asio {
namespace ssl {
namespace detail {
#if !defined(BOOST_ASIO_ENABLE_OLD_SSL)
template <typename Stream, typename Operation>
std::size_t io(Stream& next_layer, stream_core& core,
const Operation& op, boost::system::error_code& ec)
{
boost::system::error_code io_ec;
std::size_t bytes_transferred = 0;
do switch (op(core.engine_, ec, bytes_transferred))
{
@@ -43,9 +40,13 @@ std::size_t io(Stream& next_layer, stream_core& core,
// If the input buffer is empty then we need to read some more data from
// the underlying transport.
if (boost::asio::buffer_size(core.input_) == 0)
if (core.input_.size() == 0)
{
core.input_ = boost::asio::buffer(core.input_buffer_,
next_layer.read_some(core.input_buffer_, ec));
next_layer.read_some(core.input_buffer_, io_ec));
if (!ec)
ec = io_ec;
}
// Pass the new input data to the engine.
core.input_ = core.engine_.put_input(core.input_);
@@ -58,7 +59,9 @@ std::size_t io(Stream& next_layer, stream_core& core,
// Get output data from the engine and write it to the underlying
// transport.
boost::asio::write(next_layer,
core.engine_.get_output(core.output_buffer_), ec);
core.engine_.get_output(core.output_buffer_), io_ec);
if (!ec)
ec = io_ec;
// Try the operation again.
continue;
@@ -68,7 +71,9 @@ std::size_t io(Stream& next_layer, stream_core& core,
// Get output data from the engine and write it to the underlying
// transport.
boost::asio::write(next_layer,
core.engine_.get_output(core.output_buffer_), ec);
core.engine_.get_output(core.output_buffer_), io_ec);
if (!ec)
ec = io_ec;
// Operation is complete. Return result to caller.
core.engine_.map_error_code(ec);
@@ -119,7 +124,7 @@ public:
io_op(io_op&& other)
: next_layer_(other.next_layer_),
core_(other.core_),
op_(other.op_),
op_(BOOST_ASIO_MOVE_CAST(Operation)(other.op_)),
start_(other.start_),
want_(other.want_),
ec_(other.ec_),
@@ -143,7 +148,7 @@ public:
// If the input buffer already has data in it we can pass it to the
// engine and then retry the operation immediately.
if (boost::asio::buffer_size(core_.input_) != 0)
if (core_.input_.size() != 0)
{
core_.input_ = core_.engine_.put_input(core_.input_);
continue;
@@ -153,7 +158,7 @@ public:
// cannot allow more than one read operation at a time on the
// underlying transport. The pending_read_ timer's expiry is set to
// pos_infin if a read is in progress, and neg_infin otherwise.
if (core_.pending_read_.expires_at() == core_.neg_infin())
if (core_.expiry(core_.pending_read_) == core_.neg_infin())
{
// Prevent other read operations from being started.
core_.pending_read_.expires_at(core_.pos_infin());
@@ -180,7 +185,7 @@ public:
// cannot allow more than one write operation at a time on the
// underlying transport. The pending_write_ timer's expiry is set to
// pos_infin if a write is in progress, and neg_infin otherwise.
if (core_.pending_write_.expires_at() == core_.neg_infin())
if (core_.expiry(core_.pending_write_) == core_.neg_infin())
{
// Prevent other write operations from being started.
core_.pending_write_.expires_at(core_.pos_infin());
@@ -206,7 +211,7 @@ public:
// have to keep in mind that this function might be being called from
// the async operation's initiating function. In this case we're not
// allowed to call the handler directly. Instead, issue a zero-sized
// read so the handler runs "as-if" posted using io_service::post().
// read so the handler runs "as-if" posted using io_context::post().
if (start)
{
next_layer_.async_read_some(
@@ -288,7 +293,7 @@ public:
Handler handler_;
};
template <typename Stream, typename Operation, typename Handler>
template <typename Stream, typename Operation, typename Handler>
inline void* asio_handler_allocate(std::size_t size,
io_op<Stream, Operation, Handler>* this_handler)
{
@@ -339,10 +344,37 @@ inline void async_io(Stream& next_layer, stream_core& core,
boost::system::error_code(), 0, 1);
}
#endif // !defined(BOOST_ASIO_ENABLE_OLD_SSL)
} // namespace detail
} // namespace ssl
template <typename Stream, typename Operation,
typename Handler, typename Allocator>
struct associated_allocator<
ssl::detail::io_op<Stream, Operation, Handler>, Allocator>
{
typedef typename associated_allocator<Handler, Allocator>::type type;
static type get(const ssl::detail::io_op<Stream, Operation, Handler>& h,
const Allocator& a = Allocator()) BOOST_ASIO_NOEXCEPT
{
return associated_allocator<Handler, Allocator>::get(h.handler_, a);
}
};
template <typename Stream, typename Operation,
typename Handler, typename Executor>
struct associated_executor<
ssl::detail::io_op<Stream, Operation, Handler>, Executor>
{
typedef typename associated_executor<Handler, Executor>::type type;
static type get(const ssl::detail::io_op<Stream, Operation, Handler>& h,
const Executor& ex = Executor()) BOOST_ASIO_NOEXCEPT
{
return associated_executor<Handler, Executor>::get(h.handler_, ex);
}
};
} // namespace asio
} // namespace boost

View File

@@ -2,7 +2,7 @@
// ssl/detail/openssl_init.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
@@ -17,8 +17,8 @@
#include <boost/asio/detail/config.hpp>
#include <cstring>
#include <boost/asio/detail/memory.hpp>
#include <boost/asio/detail/noncopyable.hpp>
#include <boost/asio/detail/shared_ptr.hpp>
#include <boost/asio/ssl/detail/openssl_types.hpp>
#include <boost/asio/detail/push_options.hpp>

View File

@@ -2,7 +2,7 @@
// ssl/detail/openssl_types.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

View File

@@ -2,7 +2,7 @@
// ssl/detail/password_callback.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
@@ -17,11 +17,9 @@
#include <boost/asio/detail/config.hpp>
#if !defined(BOOST_ASIO_ENABLE_OLD_SSL)
# include <cstddef>
# include <string>
# include <boost/asio/ssl/context_base.hpp>
#endif // !defined(BOOST_ASIO_ENABLE_OLD_SSL)
#include <cstddef>
#include <string>
#include <boost/asio/ssl/context_base.hpp>
#include <boost/asio/detail/push_options.hpp>
@@ -30,8 +28,6 @@ namespace asio {
namespace ssl {
namespace detail {
#if !defined(BOOST_ASIO_ENABLE_OLD_SSL)
class password_callback_base
{
public:
@@ -62,8 +58,6 @@ private:
PasswordCallback callback_;
};
#endif // !defined(BOOST_ASIO_ENABLE_OLD_SSL)
} // namespace detail
} // namespace ssl
} // namespace asio

View File

@@ -2,7 +2,7 @@
// ssl/detail/read_op.hpp
// ~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
@@ -17,10 +17,8 @@
#include <boost/asio/detail/config.hpp>
#if !defined(BOOST_ASIO_ENABLE_OLD_SSL)
# include <boost/asio/detail/buffer_sequence_adapter.hpp>
# include <boost/asio/ssl/detail/engine.hpp>
#endif // !defined(BOOST_ASIO_ENABLE_OLD_SSL)
#include <boost/asio/detail/buffer_sequence_adapter.hpp>
#include <boost/asio/ssl/detail/engine.hpp>
#include <boost/asio/detail/push_options.hpp>
@@ -29,8 +27,6 @@ namespace asio {
namespace ssl {
namespace detail {
#if !defined(BOOST_ASIO_ENABLE_OLD_SSL)
template <typename MutableBufferSequence>
class read_op
{
@@ -63,8 +59,6 @@ private:
MutableBufferSequence buffers_;
};
#endif // !defined(BOOST_ASIO_ENABLE_OLD_SSL)
} // namespace detail
} // namespace ssl
} // namespace asio

View File

@@ -2,7 +2,7 @@
// ssl/detail/shutdown_op.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
@@ -17,9 +17,7 @@
#include <boost/asio/detail/config.hpp>
#if !defined(BOOST_ASIO_ENABLE_OLD_SSL)
# include <boost/asio/ssl/detail/engine.hpp>
#endif // !defined(BOOST_ASIO_ENABLE_OLD_SSL)
#include <boost/asio/ssl/detail/engine.hpp>
#include <boost/asio/detail/push_options.hpp>
@@ -28,8 +26,6 @@ namespace asio {
namespace ssl {
namespace detail {
#if !defined(BOOST_ASIO_ENABLE_OLD_SSL)
class shutdown_op
{
public:
@@ -46,12 +42,20 @@ public:
const boost::system::error_code& ec,
const std::size_t&) const
{
handler(ec);
if (ec == boost::asio::error::eof)
{
// The engine only generates an eof when the shutdown notification has
// been received from the peer. This indicates that the shutdown has
// completed successfully, and thus need not be passed on to the handler.
handler(boost::system::error_code());
}
else
{
handler(ec);
}
}
};
#endif // !defined(BOOST_ASIO_ENABLE_OLD_SSL)
} // namespace detail
} // namespace ssl
} // namespace asio

View File

@@ -2,7 +2,7 @@
// ssl/detail/stream_core.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
@@ -17,15 +17,13 @@
#include <boost/asio/detail/config.hpp>
#if !defined(BOOST_ASIO_ENABLE_OLD_SSL)
# if defined(BOOST_ASIO_HAS_BOOST_DATE_TIME)
# include <boost/asio/deadline_timer.hpp>
# else // defined(BOOST_ASIO_HAS_BOOST_DATE_TIME)
# include <boost/asio/steady_timer.hpp>
# endif // defined(BOOST_ASIO_HAS_BOOST_DATE_TIME)
# include <boost/asio/ssl/detail/engine.hpp>
# include <boost/asio/buffer.hpp>
#endif // !defined(BOOST_ASIO_ENABLE_OLD_SSL)
#if defined(BOOST_ASIO_HAS_BOOST_DATE_TIME)
# include <boost/asio/deadline_timer.hpp>
#else // defined(BOOST_ASIO_HAS_BOOST_DATE_TIME)
# include <boost/asio/steady_timer.hpp>
#endif // defined(BOOST_ASIO_HAS_BOOST_DATE_TIME)
#include <boost/asio/ssl/detail/engine.hpp>
#include <boost/asio/buffer.hpp>
#include <boost/asio/detail/push_options.hpp>
@@ -34,18 +32,17 @@ namespace asio {
namespace ssl {
namespace detail {
#if !defined(BOOST_ASIO_ENABLE_OLD_SSL)
struct stream_core
{
// According to the OpenSSL documentation, this is the buffer size that is
// sufficient to hold the largest possible TLS record.
enum { max_tls_record_size = 17 * 1024 };
stream_core(SSL_CTX* context, boost::asio::io_service& io_service)
template <typename Executor>
stream_core(SSL_CTX* context, const Executor& ex)
: engine_(context),
pending_read_(io_service),
pending_write_(io_service),
pending_read_(ex),
pending_write_(ex),
output_buffer_space_(max_tls_record_size),
output_buffer_(boost::asio::buffer(output_buffer_space_)),
input_buffer_space_(max_tls_record_size),
@@ -80,6 +77,13 @@ struct stream_core
{
return boost::posix_time::pos_infin;
}
// Helper function to get a timer's expiry time.
static boost::asio::deadline_timer::time_type expiry(
const boost::asio::deadline_timer& timer)
{
return timer.expires_at();
}
#else // defined(BOOST_ASIO_HAS_BOOST_DATE_TIME)
// Timer used for storing queued read operations.
boost::asio::steady_timer pending_read_;
@@ -98,26 +102,31 @@ struct stream_core
{
return (boost::asio::steady_timer::time_point::max)();
}
// Helper function to get a timer's expiry time.
static boost::asio::steady_timer::time_point expiry(
const boost::asio::steady_timer& timer)
{
return timer.expiry();
}
#endif // defined(BOOST_ASIO_HAS_BOOST_DATE_TIME)
// Buffer space used to prepare output intended for the transport.
std::vector<unsigned char> output_buffer_space_;
// A buffer that may be used to prepare output intended for the transport.
const boost::asio::mutable_buffers_1 output_buffer_;
const boost::asio::mutable_buffer output_buffer_;
// Buffer space used to read input intended for the engine.
std::vector<unsigned char> input_buffer_space_;
// A buffer that may be used to read input intended for the engine.
const boost::asio::mutable_buffers_1 input_buffer_;
const boost::asio::mutable_buffer input_buffer_;
// The buffer pointing to the engine's unconsumed input.
boost::asio::const_buffer input_;
};
#endif // !defined(BOOST_ASIO_ENABLE_OLD_SSL)
} // namespace detail
} // namespace ssl
} // namespace asio

View File

@@ -2,7 +2,7 @@
// ssl/detail/verify_callback.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
@@ -17,9 +17,7 @@
#include <boost/asio/detail/config.hpp>
#if !defined(BOOST_ASIO_ENABLE_OLD_SSL)
# include <boost/asio/ssl/verify_context.hpp>
#endif // !defined(BOOST_ASIO_ENABLE_OLD_SSL)
#include <boost/asio/ssl/verify_context.hpp>
#include <boost/asio/detail/push_options.hpp>
@@ -28,8 +26,6 @@ namespace asio {
namespace ssl {
namespace detail {
#if !defined(BOOST_ASIO_ENABLE_OLD_SSL)
class verify_callback_base
{
public:
@@ -58,8 +54,6 @@ private:
VerifyCallback callback_;
};
#endif // !defined(BOOST_ASIO_ENABLE_OLD_SSL)
} // namespace detail
} // namespace ssl
} // namespace asio

View File

@@ -2,7 +2,7 @@
// ssl/detail/write_op.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
@@ -17,10 +17,8 @@
#include <boost/asio/detail/config.hpp>
#if !defined(BOOST_ASIO_ENABLE_OLD_SSL)
# include <boost/asio/detail/buffer_sequence_adapter.hpp>
# include <boost/asio/ssl/detail/engine.hpp>
#endif // !defined(BOOST_ASIO_ENABLE_OLD_SSL)
#include <boost/asio/detail/buffer_sequence_adapter.hpp>
#include <boost/asio/ssl/detail/engine.hpp>
#include <boost/asio/detail/push_options.hpp>
@@ -29,8 +27,6 @@ namespace asio {
namespace ssl {
namespace detail {
#if !defined(BOOST_ASIO_ENABLE_OLD_SSL)
template <typename ConstBufferSequence>
class write_op
{
@@ -63,8 +59,6 @@ private:
ConstBufferSequence buffers_;
};
#endif // !defined(BOOST_ASIO_ENABLE_OLD_SSL)
} // namespace detail
} // namespace ssl
} // namespace asio

View File

@@ -2,7 +2,7 @@
// ssl/error.hpp
// ~~~~~~~~~~~~~
//
// Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
@@ -45,12 +45,24 @@ enum stream_errors
{
#if defined(GENERATING_DOCUMENTATION)
/// The underlying stream closed before the ssl stream gracefully shut down.
stream_truncated
#elif (OPENSSL_VERSION_NUMBER < 0x10100000L) && !defined(OPENSSL_IS_BORINGSSL)
stream_truncated = ERR_PACK(ERR_LIB_SSL, 0, SSL_R_SHORT_READ)
#else
stream_truncated = 1
#endif
stream_truncated,
/// The underlying SSL library returned a system error without providing
/// further information.
unspecified_system_error,
/// The underlying SSL library generated an unexpected result from a function
/// call.
unexpected_result
#else // defined(GENERATING_DOCUMENTATION)
# if (OPENSSL_VERSION_NUMBER < 0x10100000L) && !defined(OPENSSL_IS_BORINGSSL)
stream_truncated = ERR_PACK(ERR_LIB_SSL, 0, SSL_R_SHORT_READ),
# else
stream_truncated = 1,
# endif
unspecified_system_error = 2,
unexpected_result = 3
#endif // defined(GENERATING_DOCUMENTATION)
};
extern BOOST_ASIO_DECL

View File

@@ -3,7 +3,7 @@
// ~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2005 Voipster / Indrek dot Juhani at voipster dot com
// Copyright (c) 2005-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
// Copyright (c) 2005-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
@@ -18,9 +18,7 @@
#include <boost/asio/detail/config.hpp>
#if !defined(BOOST_ASIO_ENABLE_OLD_SSL)
# include <boost/asio/detail/throw_error.hpp>
#endif // !defined(BOOST_ASIO_ENABLE_OLD_SSL)
#include <boost/asio/detail/throw_error.hpp>
#include <boost/asio/detail/push_options.hpp>
@@ -28,8 +26,6 @@ namespace boost {
namespace asio {
namespace ssl {
#if !defined(BOOST_ASIO_ENABLE_OLD_SSL)
template <typename VerifyCallback>
void context::set_verify_callback(VerifyCallback callback)
{
@@ -39,11 +35,12 @@ void context::set_verify_callback(VerifyCallback callback)
}
template <typename VerifyCallback>
boost::system::error_code context::set_verify_callback(
BOOST_ASIO_SYNC_OP_VOID context::set_verify_callback(
VerifyCallback callback, boost::system::error_code& ec)
{
return do_set_verify_callback(
do_set_verify_callback(
new detail::verify_callback<VerifyCallback>(callback), ec);
BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
}
template <typename PasswordCallback>
@@ -55,15 +52,14 @@ void context::set_password_callback(PasswordCallback callback)
}
template <typename PasswordCallback>
boost::system::error_code context::set_password_callback(
BOOST_ASIO_SYNC_OP_VOID context::set_password_callback(
PasswordCallback callback, boost::system::error_code& ec)
{
return do_set_password_callback(
do_set_password_callback(
new detail::password_callback<PasswordCallback>(callback), ec);
BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
}
#endif // !defined(BOOST_ASIO_ENABLE_OLD_SSL)
} // namespace ssl
} // namespace asio
} // namespace boost

View File

@@ -3,7 +3,7 @@
// ~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2005 Voipster / Indrek dot Juhani at voipster dot com
// Copyright (c) 2005-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
// Copyright (c) 2005-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
@@ -18,13 +18,11 @@
#include <boost/asio/detail/config.hpp>
#if !defined(BOOST_ASIO_ENABLE_OLD_SSL)
# include <cstring>
# include <boost/asio/detail/throw_error.hpp>
# include <boost/asio/error.hpp>
# include <boost/asio/ssl/context.hpp>
# include <boost/asio/ssl/error.hpp>
#endif // !defined(BOOST_ASIO_ENABLE_OLD_SSL)
#include <cstring>
#include <boost/asio/detail/throw_error.hpp>
#include <boost/asio/error.hpp>
#include <boost/asio/ssl/context.hpp>
#include <boost/asio/ssl/error.hpp>
#include <boost/asio/detail/push_options.hpp>
@@ -32,8 +30,6 @@ namespace boost {
namespace asio {
namespace ssl {
#if !defined(BOOST_ASIO_ENABLE_OLD_SSL)
struct context::bio_cleanup
{
BIO* p;
@@ -162,7 +158,7 @@ context::context(context::method m)
SSL_CTX_set_max_proto_version(handle_, TLS1_VERSION);
}
break;
#else // (OPENSSL_VERSION_NUMBER >= 0x10100000L)
#elif defined(SSL_TXT_TLSV1)
case context::tlsv1:
handle_ = ::SSL_CTX_new(::TLSv1_method());
break;
@@ -172,7 +168,14 @@ context::context(context::method m)
case context::tlsv1_server:
handle_ = ::SSL_CTX_new(::TLSv1_server_method());
break;
#endif // (OPENSSL_VERSION_NUMBER >= 0x10100000L)
#else // defined(SSL_TXT_TLSV1)
case context::tlsv1:
case context::tlsv1_client:
case context::tlsv1_server:
boost::asio::detail::throw_error(
boost::asio::error::invalid_argument, "context");
break;
#endif // defined(SSL_TXT_TLSV1)
// TLS v1.1.
#if (OPENSSL_VERSION_NUMBER >= 0x10100000L) && !defined(LIBRESSL_VERSION_NUMBER)
@@ -245,7 +248,7 @@ context::context(context::method m)
SSL_CTX_set_max_proto_version(handle_, TLS1_2_VERSION);
}
break;
#elif defined(SSL_TXT_TLSV1_1)
#elif defined(SSL_TXT_TLSV1_2)
case context::tlsv12:
handle_ = ::SSL_CTX_new(::TLSv1_2_method());
break;
@@ -255,14 +258,52 @@ context::context(context::method m)
case context::tlsv12_server:
handle_ = ::SSL_CTX_new(::TLSv1_2_server_method());
break;
#else // defined(SSL_TXT_TLSV1_1)
#else // defined(SSL_TXT_TLSV1_2)
case context::tlsv12:
case context::tlsv12_client:
case context::tlsv12_server:
boost::asio::detail::throw_error(
boost::asio::error::invalid_argument, "context");
break;
#endif // defined(SSL_TXT_TLSV1_1)
#endif // defined(SSL_TXT_TLSV1_2)
// TLS v1.3.
#if (OPENSSL_VERSION_NUMBER >= 0x10101000L) \
&& !defined(LIBRESSL_VERSION_NUMBER)
case context::tlsv13:
handle_ = ::SSL_CTX_new(::TLS_method());
if (handle_)
{
SSL_CTX_set_min_proto_version(handle_, TLS1_3_VERSION);
SSL_CTX_set_max_proto_version(handle_, TLS1_3_VERSION);
}
break;
case context::tlsv13_client:
handle_ = ::SSL_CTX_new(::TLS_client_method());
if (handle_)
{
SSL_CTX_set_min_proto_version(handle_, TLS1_3_VERSION);
SSL_CTX_set_max_proto_version(handle_, TLS1_3_VERSION);
}
break;
case context::tlsv13_server:
handle_ = ::SSL_CTX_new(::TLS_server_method());
if (handle_)
{
SSL_CTX_set_min_proto_version(handle_, TLS1_3_VERSION);
SSL_CTX_set_max_proto_version(handle_, TLS1_3_VERSION);
}
break;
#else // (OPENSSL_VERSION_NUMBER >= 0x10101000L)
// && !defined(LIBRESSL_VERSION_NUMBER)
case context::tlsv13:
case context::tlsv13_client:
case context::tlsv13_server:
boost::asio::detail::throw_error(
boost::asio::error::invalid_argument, "context");
break;
#endif // (OPENSSL_VERSION_NUMBER >= 0x10101000L)
// && !defined(LIBRESSL_VERSION_NUMBER)
// Any supported SSL/TLS version.
case context::sslv23:
@@ -326,14 +367,6 @@ context::context(context::method m)
set_options(no_compression);
}
context::context(boost::asio::io_service&, context::method m)
: handle_(0)
{
context tmp(m);
handle_ = tmp.handle_;
tmp.handle_ = 0;
}
#if defined(BOOST_ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
context::context(context&& other)
{
@@ -390,11 +423,6 @@ context::native_handle_type context::native_handle()
return handle_;
}
context::impl_type context::impl()
{
return handle_;
}
void context::clear_options(context::options o)
{
boost::system::error_code ec;
@@ -402,7 +430,7 @@ void context::clear_options(context::options o)
boost::asio::detail::throw_error(ec, "clear_options");
}
boost::system::error_code context::clear_options(
BOOST_ASIO_SYNC_OP_VOID context::clear_options(
context::options o, boost::system::error_code& ec)
{
#if (OPENSSL_VERSION_NUMBER >= 0x009080DFL) \
@@ -426,7 +454,7 @@ boost::system::error_code context::clear_options(
ec = boost::asio::error::operation_not_supported;
#endif // (OPENSSL_VERSION_NUMBER >= 0x009080DFL)
// && (OPENSSL_VERSION_NUMBER != 0x00909000L)
return ec;
BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
}
void context::set_options(context::options o)
@@ -436,7 +464,7 @@ void context::set_options(context::options o)
boost::asio::detail::throw_error(ec, "set_options");
}
boost::system::error_code context::set_options(
BOOST_ASIO_SYNC_OP_VOID context::set_options(
context::options o, boost::system::error_code& ec)
{
#if !defined(SSL_OP_NO_COMPRESSION)
@@ -453,7 +481,7 @@ boost::system::error_code context::set_options(
::SSL_CTX_set_options(handle_, o);
ec = boost::system::error_code();
return ec;
BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
}
void context::set_verify_mode(verify_mode v)
@@ -463,13 +491,13 @@ void context::set_verify_mode(verify_mode v)
boost::asio::detail::throw_error(ec, "set_verify_mode");
}
boost::system::error_code context::set_verify_mode(
BOOST_ASIO_SYNC_OP_VOID context::set_verify_mode(
verify_mode v, boost::system::error_code& ec)
{
::SSL_CTX_set_verify(handle_, v, ::SSL_CTX_get_verify_callback(handle_));
ec = boost::system::error_code();
return ec;
BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
}
void context::set_verify_depth(int depth)
@@ -479,13 +507,13 @@ void context::set_verify_depth(int depth)
boost::asio::detail::throw_error(ec, "set_verify_depth");
}
boost::system::error_code context::set_verify_depth(
BOOST_ASIO_SYNC_OP_VOID context::set_verify_depth(
int depth, boost::system::error_code& ec)
{
::SSL_CTX_set_verify_depth(handle_, depth);
ec = boost::system::error_code();
return ec;
BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
}
void context::load_verify_file(const std::string& filename)
@@ -495,7 +523,7 @@ void context::load_verify_file(const std::string& filename)
boost::asio::detail::throw_error(ec, "load_verify_file");
}
boost::system::error_code context::load_verify_file(
BOOST_ASIO_SYNC_OP_VOID context::load_verify_file(
const std::string& filename, boost::system::error_code& ec)
{
::ERR_clear_error();
@@ -505,11 +533,11 @@ boost::system::error_code context::load_verify_file(
ec = boost::system::error_code(
static_cast<int>(::ERR_get_error()),
boost::asio::error::get_ssl_category());
return ec;
BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
}
ec = boost::system::error_code();
return ec;
BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
}
void context::add_certificate_authority(const const_buffer& ca)
@@ -519,7 +547,7 @@ void context::add_certificate_authority(const const_buffer& ca)
boost::asio::detail::throw_error(ec, "add_certificate_authority");
}
boost::system::error_code context::add_certificate_authority(
BOOST_ASIO_SYNC_OP_VOID context::add_certificate_authority(
const const_buffer& ca, boost::system::error_code& ec)
{
::ERR_clear_error();
@@ -527,24 +555,27 @@ boost::system::error_code context::add_certificate_authority(
bio_cleanup bio = { make_buffer_bio(ca) };
if (bio.p)
{
x509_cleanup cert = { ::PEM_read_bio_X509(bio.p, 0, 0, 0) };
if (cert.p)
if (X509_STORE* store = ::SSL_CTX_get_cert_store(handle_))
{
if (X509_STORE* store = ::SSL_CTX_get_cert_store(handle_))
for (;;)
{
if (::X509_STORE_add_cert(store, cert.p) == 1)
x509_cleanup cert = { ::PEM_read_bio_X509(bio.p, 0, 0, 0) };
if (!cert.p)
break;
if (::X509_STORE_add_cert(store, cert.p) != 1)
{
ec = boost::system::error_code();
return ec;
ec = boost::system::error_code(
static_cast<int>(::ERR_get_error()),
boost::asio::error::get_ssl_category());
BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
}
}
}
}
ec = boost::system::error_code(
static_cast<int>(::ERR_get_error()),
boost::asio::error::get_ssl_category());
return ec;
ec = boost::system::error_code();
BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
}
void context::set_default_verify_paths()
@@ -554,7 +585,7 @@ void context::set_default_verify_paths()
boost::asio::detail::throw_error(ec, "set_default_verify_paths");
}
boost::system::error_code context::set_default_verify_paths(
BOOST_ASIO_SYNC_OP_VOID context::set_default_verify_paths(
boost::system::error_code& ec)
{
::ERR_clear_error();
@@ -564,11 +595,11 @@ boost::system::error_code context::set_default_verify_paths(
ec = boost::system::error_code(
static_cast<int>(::ERR_get_error()),
boost::asio::error::get_ssl_category());
return ec;
BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
}
ec = boost::system::error_code();
return ec;
BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
}
void context::add_verify_path(const std::string& path)
@@ -578,7 +609,7 @@ void context::add_verify_path(const std::string& path)
boost::asio::detail::throw_error(ec, "add_verify_path");
}
boost::system::error_code context::add_verify_path(
BOOST_ASIO_SYNC_OP_VOID context::add_verify_path(
const std::string& path, boost::system::error_code& ec)
{
::ERR_clear_error();
@@ -588,11 +619,11 @@ boost::system::error_code context::add_verify_path(
ec = boost::system::error_code(
static_cast<int>(::ERR_get_error()),
boost::asio::error::get_ssl_category());
return ec;
BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
}
ec = boost::system::error_code();
return ec;
BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
}
void context::use_certificate(
@@ -603,7 +634,7 @@ void context::use_certificate(
boost::asio::detail::throw_error(ec, "use_certificate");
}
boost::system::error_code context::use_certificate(
BOOST_ASIO_SYNC_OP_VOID context::use_certificate(
const const_buffer& certificate, file_format format,
boost::system::error_code& ec)
{
@@ -612,11 +643,11 @@ boost::system::error_code context::use_certificate(
if (format == context_base::asn1)
{
if (::SSL_CTX_use_certificate_ASN1(handle_,
static_cast<int>(buffer_size(certificate)),
buffer_cast<const unsigned char*>(certificate)) == 1)
static_cast<int>(certificate.size()),
static_cast<const unsigned char*>(certificate.data())) == 1)
{
ec = boost::system::error_code();
return ec;
BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
}
}
else if (format == context_base::pem)
@@ -630,7 +661,7 @@ boost::system::error_code context::use_certificate(
if (::SSL_CTX_use_certificate(handle_, cert.p) == 1)
{
ec = boost::system::error_code();
return ec;
BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
}
}
}
@@ -638,13 +669,13 @@ boost::system::error_code context::use_certificate(
else
{
ec = boost::asio::error::invalid_argument;
return ec;
BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
}
ec = boost::system::error_code(
static_cast<int>(::ERR_get_error()),
boost::asio::error::get_ssl_category());
return ec;
BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
}
void context::use_certificate_file(
@@ -655,7 +686,7 @@ void context::use_certificate_file(
boost::asio::detail::throw_error(ec, "use_certificate_file");
}
boost::system::error_code context::use_certificate_file(
BOOST_ASIO_SYNC_OP_VOID context::use_certificate_file(
const std::string& filename, file_format format,
boost::system::error_code& ec)
{
@@ -671,7 +702,7 @@ boost::system::error_code context::use_certificate_file(
default:
{
ec = boost::asio::error::invalid_argument;
return ec;
BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
}
}
@@ -682,11 +713,11 @@ boost::system::error_code context::use_certificate_file(
ec = boost::system::error_code(
static_cast<int>(::ERR_get_error()),
boost::asio::error::get_ssl_category());
return ec;
BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
}
ec = boost::system::error_code();
return ec;
BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
}
void context::use_certificate_chain(const const_buffer& chain)
@@ -696,7 +727,7 @@ void context::use_certificate_chain(const const_buffer& chain)
boost::asio::detail::throw_error(ec, "use_certificate_chain");
}
boost::system::error_code context::use_certificate_chain(
BOOST_ASIO_SYNC_OP_VOID context::use_certificate_chain(
const const_buffer& chain, boost::system::error_code& ec)
{
::ERR_clear_error();
@@ -719,7 +750,7 @@ boost::system::error_code context::use_certificate_chain(
{
ec = boost::system::error_code(ERR_R_PEM_LIB,
boost::asio::error::get_ssl_category());
return ec;
BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
}
int result = ::SSL_CTX_use_certificate(handle_, cert.p);
@@ -728,7 +759,7 @@ boost::system::error_code context::use_certificate_chain(
ec = boost::system::error_code(
static_cast<int>(::ERR_get_error()),
boost::asio::error::get_ssl_category());
return ec;
BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
}
#if (OPENSSL_VERSION_NUMBER >= 0x10002000L) && !defined(LIBRESSL_VERSION_NUMBER)
@@ -750,7 +781,7 @@ boost::system::error_code context::use_certificate_chain(
ec = boost::system::error_code(
static_cast<int>(::ERR_get_error()),
boost::asio::error::get_ssl_category());
return ec;
BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
}
}
@@ -760,14 +791,14 @@ boost::system::error_code context::use_certificate_chain(
{
::ERR_clear_error();
ec = boost::system::error_code();
return ec;
BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
}
}
ec = boost::system::error_code(
static_cast<int>(::ERR_get_error()),
boost::asio::error::get_ssl_category());
return ec;
BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
}
void context::use_certificate_chain_file(const std::string& filename)
@@ -777,7 +808,7 @@ void context::use_certificate_chain_file(const std::string& filename)
boost::asio::detail::throw_error(ec, "use_certificate_chain_file");
}
boost::system::error_code context::use_certificate_chain_file(
BOOST_ASIO_SYNC_OP_VOID context::use_certificate_chain_file(
const std::string& filename, boost::system::error_code& ec)
{
::ERR_clear_error();
@@ -787,11 +818,11 @@ boost::system::error_code context::use_certificate_chain_file(
ec = boost::system::error_code(
static_cast<int>(::ERR_get_error()),
boost::asio::error::get_ssl_category());
return ec;
BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
}
ec = boost::system::error_code();
return ec;
BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
}
void context::use_private_key(
@@ -802,7 +833,7 @@ void context::use_private_key(
boost::asio::detail::throw_error(ec, "use_private_key");
}
boost::system::error_code context::use_private_key(
BOOST_ASIO_SYNC_OP_VOID context::use_private_key(
const const_buffer& private_key, context::file_format format,
boost::system::error_code& ec)
{
@@ -833,7 +864,7 @@ boost::system::error_code context::use_private_key(
default:
{
ec = boost::asio::error::invalid_argument;
return ec;
BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
}
}
@@ -842,7 +873,7 @@ boost::system::error_code context::use_private_key(
if (::SSL_CTX_use_PrivateKey(handle_, evp_private_key.p) == 1)
{
ec = boost::system::error_code();
return ec;
BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
}
}
}
@@ -850,7 +881,7 @@ boost::system::error_code context::use_private_key(
ec = boost::system::error_code(
static_cast<int>(::ERR_get_error()),
boost::asio::error::get_ssl_category());
return ec;
BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
}
void context::use_private_key_file(
@@ -869,7 +900,7 @@ void context::use_rsa_private_key(
boost::asio::detail::throw_error(ec, "use_rsa_private_key");
}
boost::system::error_code context::use_rsa_private_key(
BOOST_ASIO_SYNC_OP_VOID context::use_rsa_private_key(
const const_buffer& private_key, context::file_format format,
boost::system::error_code& ec)
{
@@ -900,7 +931,7 @@ boost::system::error_code context::use_rsa_private_key(
default:
{
ec = boost::asio::error::invalid_argument;
return ec;
BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
}
}
@@ -909,7 +940,7 @@ boost::system::error_code context::use_rsa_private_key(
if (::SSL_CTX_use_RSAPrivateKey(handle_, rsa_private_key.p) == 1)
{
ec = boost::system::error_code();
return ec;
BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
}
}
}
@@ -917,10 +948,10 @@ boost::system::error_code context::use_rsa_private_key(
ec = boost::system::error_code(
static_cast<int>(::ERR_get_error()),
boost::asio::error::get_ssl_category());
return ec;
BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
}
boost::system::error_code context::use_private_key_file(
BOOST_ASIO_SYNC_OP_VOID context::use_private_key_file(
const std::string& filename, context::file_format format,
boost::system::error_code& ec)
{
@@ -936,7 +967,7 @@ boost::system::error_code context::use_private_key_file(
default:
{
ec = boost::asio::error::invalid_argument;
return ec;
BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
}
}
@@ -947,11 +978,11 @@ boost::system::error_code context::use_private_key_file(
ec = boost::system::error_code(
static_cast<int>(::ERR_get_error()),
boost::asio::error::get_ssl_category());
return ec;
BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
}
ec = boost::system::error_code();
return ec;
BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
}
void context::use_rsa_private_key_file(
@@ -962,7 +993,7 @@ void context::use_rsa_private_key_file(
boost::asio::detail::throw_error(ec, "use_rsa_private_key_file");
}
boost::system::error_code context::use_rsa_private_key_file(
BOOST_ASIO_SYNC_OP_VOID context::use_rsa_private_key_file(
const std::string& filename, context::file_format format,
boost::system::error_code& ec)
{
@@ -978,7 +1009,7 @@ boost::system::error_code context::use_rsa_private_key_file(
default:
{
ec = boost::asio::error::invalid_argument;
return ec;
BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
}
}
@@ -990,11 +1021,11 @@ boost::system::error_code context::use_rsa_private_key_file(
ec = boost::system::error_code(
static_cast<int>(::ERR_get_error()),
boost::asio::error::get_ssl_category());
return ec;
BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
}
ec = boost::system::error_code();
return ec;
BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
}
void context::use_tmp_dh(const const_buffer& dh)
@@ -1004,7 +1035,7 @@ void context::use_tmp_dh(const const_buffer& dh)
boost::asio::detail::throw_error(ec, "use_tmp_dh");
}
boost::system::error_code context::use_tmp_dh(
BOOST_ASIO_SYNC_OP_VOID context::use_tmp_dh(
const const_buffer& dh, boost::system::error_code& ec)
{
::ERR_clear_error();
@@ -1018,7 +1049,7 @@ boost::system::error_code context::use_tmp_dh(
ec = boost::system::error_code(
static_cast<int>(::ERR_get_error()),
boost::asio::error::get_ssl_category());
return ec;
BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
}
void context::use_tmp_dh_file(const std::string& filename)
@@ -1028,7 +1059,7 @@ void context::use_tmp_dh_file(const std::string& filename)
boost::asio::detail::throw_error(ec, "use_tmp_dh_file");
}
boost::system::error_code context::use_tmp_dh_file(
BOOST_ASIO_SYNC_OP_VOID context::use_tmp_dh_file(
const std::string& filename, boost::system::error_code& ec)
{
::ERR_clear_error();
@@ -1042,10 +1073,10 @@ boost::system::error_code context::use_tmp_dh_file(
ec = boost::system::error_code(
static_cast<int>(::ERR_get_error()),
boost::asio::error::get_ssl_category());
return ec;
BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
}
boost::system::error_code context::do_use_tmp_dh(
BOOST_ASIO_SYNC_OP_VOID context::do_use_tmp_dh(
BIO* bio, boost::system::error_code& ec)
{
::ERR_clear_error();
@@ -1056,17 +1087,17 @@ boost::system::error_code context::do_use_tmp_dh(
if (::SSL_CTX_set_tmp_dh(handle_, dh.p) == 1)
{
ec = boost::system::error_code();
return ec;
BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
}
}
ec = boost::system::error_code(
static_cast<int>(::ERR_get_error()),
boost::asio::error::get_ssl_category());
return ec;
BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
}
boost::system::error_code context::do_set_verify_callback(
BOOST_ASIO_SYNC_OP_VOID context::do_set_verify_callback(
detail::verify_callback_base* callback, boost::system::error_code& ec)
{
if (SSL_CTX_get_app_data(handle_))
@@ -1082,7 +1113,7 @@ boost::system::error_code context::do_set_verify_callback(
&context::verify_callback_function);
ec = boost::system::error_code();
return ec;
BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
}
int context::verify_callback_function(int preverified, X509_STORE_CTX* ctx)
@@ -1111,7 +1142,7 @@ int context::verify_callback_function(int preverified, X509_STORE_CTX* ctx)
return 0;
}
boost::system::error_code context::do_set_password_callback(
BOOST_ASIO_SYNC_OP_VOID context::do_set_password_callback(
detail::password_callback_base* callback, boost::system::error_code& ec)
{
#if (OPENSSL_VERSION_NUMBER >= 0x10100000L) && !defined(LIBRESSL_VERSION_NUMBER)
@@ -1129,7 +1160,7 @@ boost::system::error_code context::do_set_password_callback(
SSL_CTX_set_default_passwd_cb(handle_, &context::password_callback_function);
ec = boost::system::error_code();
return ec;
BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
}
int context::password_callback_function(
@@ -1162,12 +1193,10 @@ int context::password_callback_function(
BIO* context::make_buffer_bio(const const_buffer& b)
{
return ::BIO_new_mem_buf(
const_cast<void*>(buffer_cast<const void*>(b)),
static_cast<int>(buffer_size(b)));
const_cast<void*>(b.data()),
static_cast<int>(b.size()));
}
#endif // !defined(BOOST_ASIO_ENABLE_OLD_SSL)
} // namespace ssl
} // namespace asio
} // namespace boost

View File

@@ -2,7 +2,7 @@
// ssl/impl/error.ipp
// ~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
@@ -77,6 +77,8 @@ public:
switch (value)
{
case stream_truncated: return "stream truncated";
case unspecified_system_error: return "unspecified system error";
case unexpected_result: return "unexpected result";
default: return "asio.ssl.stream error";
}
}

View File

@@ -2,7 +2,7 @@
// ssl/impl/rfc2818_verification.ipp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
@@ -17,13 +17,11 @@
#include <boost/asio/detail/config.hpp>
#if !defined(BOOST_ASIO_ENABLE_OLD_SSL)
# include <cctype>
# include <cstring>
# include <boost/asio/ip/address.hpp>
# include <boost/asio/ssl/rfc2818_verification.hpp>
# include <boost/asio/ssl/detail/openssl_types.hpp>
#endif // !defined(BOOST_ASIO_ENABLE_OLD_SSL)
#include <cctype>
#include <cstring>
#include <boost/asio/ip/address.hpp>
#include <boost/asio/ssl/rfc2818_verification.hpp>
#include <boost/asio/ssl/detail/openssl_types.hpp>
#include <boost/asio/detail/push_options.hpp>
@@ -31,8 +29,6 @@ namespace boost {
namespace asio {
namespace ssl {
#if !defined(BOOST_ASIO_ENABLE_OLD_SSL)
bool rfc2818_verification::operator()(
bool preverified, verify_context& ctx) const
{
@@ -50,7 +46,7 @@ bool rfc2818_verification::operator()(
// Try converting the host name to an address. If it is an address then we
// need to look for an IP address in the certificate rather than a host name.
boost::system::error_code ec;
ip::address address = ip::address::from_string(host_, ec);
ip::address address = ip::make_address(host_, ec);
bool is_address = !ec;
X509* cert = X509_STORE_CTX_get_current_cert(ctx.native_handle());
@@ -157,8 +153,6 @@ bool rfc2818_verification::match_pattern(const char* pattern,
return p == p_end && !*h;
}
#endif // !defined(BOOST_ASIO_ENABLE_OLD_SSL)
} // namespace ssl
} // namespace asio
} // namespace boost

View File

@@ -2,7 +2,7 @@
// impl/ssl/src.hpp
// ~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

View File

@@ -1,436 +0,0 @@
//
// ssl/old/basic_context.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2005 Voipster / Indrek dot Juhani at voipster dot com
// Copyright (c) 2005-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef BOOST_ASIO_SSL_OLD_BASIC_CONTEXT_HPP
#define BOOST_ASIO_SSL_OLD_BASIC_CONTEXT_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/config.hpp>
#include <string>
#include <boost/noncopyable.hpp>
#include <boost/asio/detail/throw_error.hpp>
#include <boost/asio/error.hpp>
#include <boost/asio/io_service.hpp>
#include <boost/asio/ssl/context_base.hpp>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
namespace ssl {
namespace old {
/// SSL context.
template <typename Service>
class basic_context
: public context_base,
private boost::noncopyable
{
public:
/// The type of the service that will be used to provide context operations.
typedef Service service_type;
/// The native implementation type of the SSL context.
typedef typename service_type::impl_type impl_type;
/// Constructor.
basic_context(boost::asio::io_service& io_service, method m)
: service_(boost::asio::use_service<Service>(io_service)),
impl_(service_.null())
{
service_.create(impl_, m);
}
/// Destructor.
~basic_context()
{
service_.destroy(impl_);
}
/// Get the underlying implementation in the native type.
/**
* This function may be used to obtain the underlying implementation of the
* context. This is intended to allow access to context functionality that is
* not otherwise provided.
*/
impl_type impl()
{
return impl_;
}
/// Set options on the context.
/**
* This function may be used to configure the SSL options used by the context.
*
* @param o A bitmask of options. The available option values are defined in
* the context_base class. The options are bitwise-ored with any existing
* value for the options.
*
* @throws boost::system::system_error Thrown on failure.
*/
void set_options(options o)
{
boost::system::error_code ec;
service_.set_options(impl_, o, ec);
boost::asio::detail::throw_error(ec);
}
/// Set options on the context.
/**
* This function may be used to configure the SSL options used by the context.
*
* @param o A bitmask of options. The available option values are defined in
* the context_base class. The options are bitwise-ored with any existing
* value for the options.
*
* @param ec Set to indicate what error occurred, if any.
*/
boost::system::error_code set_options(options o,
boost::system::error_code& ec)
{
return service_.set_options(impl_, o, ec);
}
/// Set the peer verification mode.
/**
* This function may be used to configure the peer verification mode used by
* the context.
*
* @param v A bitmask of peer verification modes. The available verify_mode
* values are defined in the context_base class.
*
* @throws boost::system::system_error Thrown on failure.
*/
void set_verify_mode(verify_mode v)
{
boost::system::error_code ec;
service_.set_verify_mode(impl_, v, ec);
boost::asio::detail::throw_error(ec);
}
/// Set the peer verification mode.
/**
* This function may be used to configure the peer verification mode used by
* the context.
*
* @param v A bitmask of peer verification modes. The available verify_mode
* values are defined in the context_base class.
*
* @param ec Set to indicate what error occurred, if any.
*/
boost::system::error_code set_verify_mode(verify_mode v,
boost::system::error_code& ec)
{
return service_.set_verify_mode(impl_, v, ec);
}
/// Load a certification authority file for performing verification.
/**
* This function is used to load one or more trusted certification authorities
* from a file.
*
* @param filename The name of a file containing certification authority
* certificates in PEM format.
*
* @throws boost::system::system_error Thrown on failure.
*/
void load_verify_file(const std::string& filename)
{
boost::system::error_code ec;
service_.load_verify_file(impl_, filename, ec);
boost::asio::detail::throw_error(ec);
}
/// Load a certification authority file for performing verification.
/**
* This function is used to load the certificates for one or more trusted
* certification authorities from a file.
*
* @param filename The name of a file containing certification authority
* certificates in PEM format.
*
* @param ec Set to indicate what error occurred, if any.
*/
boost::system::error_code load_verify_file(const std::string& filename,
boost::system::error_code& ec)
{
return service_.load_verify_file(impl_, filename, ec);
}
/// Add a directory containing certificate authority files to be used for
/// performing verification.
/**
* This function is used to specify the name of a directory containing
* certification authority certificates. Each file in the directory must
* contain a single certificate. The files must be named using the subject
* name's hash and an extension of ".0".
*
* @param path The name of a directory containing the certificates.
*
* @throws boost::system::system_error Thrown on failure.
*/
void add_verify_path(const std::string& path)
{
boost::system::error_code ec;
service_.add_verify_path(impl_, path, ec);
boost::asio::detail::throw_error(ec);
}
/// Add a directory containing certificate authority files to be used for
/// performing verification.
/**
* This function is used to specify the name of a directory containing
* certification authority certificates. Each file in the directory must
* contain a single certificate. The files must be named using the subject
* name's hash and an extension of ".0".
*
* @param path The name of a directory containing the certificates.
*
* @param ec Set to indicate what error occurred, if any.
*/
boost::system::error_code add_verify_path(const std::string& path,
boost::system::error_code& ec)
{
return service_.add_verify_path(impl_, path, ec);
}
/// Use a certificate from a file.
/**
* This function is used to load a certificate into the context from a file.
*
* @param filename The name of the file containing the certificate.
*
* @param format The file format (ASN.1 or PEM).
*
* @throws boost::system::system_error Thrown on failure.
*/
void use_certificate_file(const std::string& filename, file_format format)
{
boost::system::error_code ec;
service_.use_certificate_file(impl_, filename, format, ec);
boost::asio::detail::throw_error(ec);
}
/// Use a certificate from a file.
/**
* This function is used to load a certificate into the context from a file.
*
* @param filename The name of the file containing the certificate.
*
* @param format The file format (ASN.1 or PEM).
*
* @param ec Set to indicate what error occurred, if any.
*/
boost::system::error_code use_certificate_file(const std::string& filename,
file_format format, boost::system::error_code& ec)
{
return service_.use_certificate_file(impl_, filename, format, ec);
}
/// Use a certificate chain from a file.
/**
* This function is used to load a certificate chain into the context from a
* file.
*
* @param filename The name of the file containing the certificate. The file
* must use the PEM format.
*
* @throws boost::system::system_error Thrown on failure.
*/
void use_certificate_chain_file(const std::string& filename)
{
boost::system::error_code ec;
service_.use_certificate_chain_file(impl_, filename, ec);
boost::asio::detail::throw_error(ec);
}
/// Use a certificate chain from a file.
/**
* This function is used to load a certificate chain into the context from a
* file.
*
* @param filename The name of the file containing the certificate. The file
* must use the PEM format.
*
* @param ec Set to indicate what error occurred, if any.
*/
boost::system::error_code use_certificate_chain_file(
const std::string& filename, boost::system::error_code& ec)
{
return service_.use_certificate_chain_file(impl_, filename, ec);
}
/// Use a private key from a file.
/**
* This function is used to load a private key into the context from a file.
*
* @param filename The name of the file containing the private key.
*
* @param format The file format (ASN.1 or PEM).
*
* @throws boost::system::system_error Thrown on failure.
*/
void use_private_key_file(const std::string& filename, file_format format)
{
boost::system::error_code ec;
service_.use_private_key_file(impl_, filename, format, ec);
boost::asio::detail::throw_error(ec);
}
/// Use a private key from a file.
/**
* This function is used to load a private key into the context from a file.
*
* @param filename The name of the file containing the private key.
*
* @param format The file format (ASN.1 or PEM).
*
* @param ec Set to indicate what error occurred, if any.
*/
boost::system::error_code use_private_key_file(const std::string& filename,
file_format format, boost::system::error_code& ec)
{
return service_.use_private_key_file(impl_, filename, format, ec);
}
/// Use an RSA private key from a file.
/**
* This function is used to load an RSA private key into the context from a
* file.
*
* @param filename The name of the file containing the RSA private key.
*
* @param format The file format (ASN.1 or PEM).
*
* @throws boost::system::system_error Thrown on failure.
*/
void use_rsa_private_key_file(const std::string& filename, file_format format)
{
boost::system::error_code ec;
service_.use_rsa_private_key_file(impl_, filename, format, ec);
boost::asio::detail::throw_error(ec);
}
/// Use an RSA private key from a file.
/**
* This function is used to load an RSA private key into the context from a
* file.
*
* @param filename The name of the file containing the RSA private key.
*
* @param format The file format (ASN.1 or PEM).
*
* @param ec Set to indicate what error occurred, if any.
*/
boost::system::error_code use_rsa_private_key_file(
const std::string& filename, file_format format,
boost::system::error_code& ec)
{
return service_.use_rsa_private_key_file(impl_, filename, format, ec);
}
/// Use the specified file to obtain the temporary Diffie-Hellman parameters.
/**
* This function is used to load Diffie-Hellman parameters into the context
* from a file.
*
* @param filename The name of the file containing the Diffie-Hellman
* parameters. The file must use the PEM format.
*
* @throws boost::system::system_error Thrown on failure.
*/
void use_tmp_dh_file(const std::string& filename)
{
boost::system::error_code ec;
service_.use_tmp_dh_file(impl_, filename, ec);
boost::asio::detail::throw_error(ec);
}
/// Use the specified file to obtain the temporary Diffie-Hellman parameters.
/**
* This function is used to load Diffie-Hellman parameters into the context
* from a file.
*
* @param filename The name of the file containing the Diffie-Hellman
* parameters. The file must use the PEM format.
*
* @param ec Set to indicate what error occurred, if any.
*/
boost::system::error_code use_tmp_dh_file(const std::string& filename,
boost::system::error_code& ec)
{
return service_.use_tmp_dh_file(impl_, filename, ec);
}
/// Set the password callback.
/**
* This function is used to specify a callback function to obtain password
* information about an encrypted key in PEM format.
*
* @param callback The function object to be used for obtaining the password.
* The function signature of the handler must be:
* @code std::string password_callback(
* std::size_t max_length, // The maximum size for a password.
* password_purpose purpose // Whether password is for reading or writing.
* ); @endcode
* The return value of the callback is a string containing the password.
*
* @throws boost::system::system_error Thrown on failure.
*/
template <typename PasswordCallback>
void set_password_callback(PasswordCallback callback)
{
boost::system::error_code ec;
service_.set_password_callback(impl_, callback, ec);
boost::asio::detail::throw_error(ec);
}
/// Set the password callback.
/**
* This function is used to specify a callback function to obtain password
* information about an encrypted key in PEM format.
*
* @param callback The function object to be used for obtaining the password.
* The function signature of the handler must be:
* @code std::string password_callback(
* std::size_t max_length, // The maximum size for a password.
* password_purpose purpose // Whether password is for reading or writing.
* ); @endcode
* The return value of the callback is a string containing the password.
*
* @param ec Set to indicate what error occurred, if any.
*/
template <typename PasswordCallback>
boost::system::error_code set_password_callback(PasswordCallback callback,
boost::system::error_code& ec)
{
return service_.set_password_callback(impl_, callback, ec);
}
private:
/// The backend service implementation.
service_type& service_;
/// The underlying native implementation.
impl_type impl_;
};
} // namespace old
} // namespace ssl
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_SSL_OLD_BASIC_CONTEXT_HPP

View File

@@ -1,176 +0,0 @@
//
// ssl/old/context_service.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2005 Voipster / Indrek dot Juhani at voipster dot com
// Copyright (c) 2005-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef BOOST_ASIO_SSL_OLD_CONTEXT_SERVICE_HPP
#define BOOST_ASIO_SSL_OLD_CONTEXT_SERVICE_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/config.hpp>
#include <string>
#include <boost/noncopyable.hpp>
#include <boost/asio/error.hpp>
#include <boost/asio/io_service.hpp>
#include <boost/asio/ssl/context_base.hpp>
#include <boost/asio/ssl/old/detail/openssl_context_service.hpp>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
namespace ssl {
namespace old {
/// Default service implementation for a context.
class context_service
#if defined(GENERATING_DOCUMENTATION)
: public boost::asio::io_service::service
#else
: public boost::asio::detail::service_base<context_service>
#endif
{
private:
// The type of the platform-specific implementation.
typedef old::detail::openssl_context_service service_impl_type;
public:
#if defined(GENERATING_DOCUMENTATION)
/// The unique service identifier.
static boost::asio::io_service::id id;
#endif
/// The type of the context.
#if defined(GENERATING_DOCUMENTATION)
typedef implementation_defined impl_type;
#else
typedef service_impl_type::impl_type impl_type;
#endif
/// Constructor.
explicit context_service(boost::asio::io_service& io_service)
: boost::asio::detail::service_base<context_service>(io_service),
service_impl_(boost::asio::use_service<service_impl_type>(io_service))
{
}
/// Return a null context implementation.
impl_type null() const
{
return service_impl_.null();
}
/// Create a new context implementation.
void create(impl_type& impl, context_base::method m)
{
service_impl_.create(impl, m);
}
/// Destroy a context implementation.
void destroy(impl_type& impl)
{
service_impl_.destroy(impl);
}
/// Set options on the context.
boost::system::error_code set_options(impl_type& impl,
context_base::options o, boost::system::error_code& ec)
{
return service_impl_.set_options(impl, o, ec);
}
/// Set peer verification mode.
boost::system::error_code set_verify_mode(impl_type& impl,
context_base::verify_mode v, boost::system::error_code& ec)
{
return service_impl_.set_verify_mode(impl, v, ec);
}
/// Load a certification authority file for performing verification.
boost::system::error_code load_verify_file(impl_type& impl,
const std::string& filename, boost::system::error_code& ec)
{
return service_impl_.load_verify_file(impl, filename, ec);
}
/// Add a directory containing certification authority files to be used for
/// performing verification.
boost::system::error_code add_verify_path(impl_type& impl,
const std::string& path, boost::system::error_code& ec)
{
return service_impl_.add_verify_path(impl, path, ec);
}
/// Use a certificate from a file.
boost::system::error_code use_certificate_file(impl_type& impl,
const std::string& filename, context_base::file_format format,
boost::system::error_code& ec)
{
return service_impl_.use_certificate_file(impl, filename, format, ec);
}
/// Use a certificate chain from a file.
boost::system::error_code use_certificate_chain_file(impl_type& impl,
const std::string& filename, boost::system::error_code& ec)
{
return service_impl_.use_certificate_chain_file(impl, filename, ec);
}
/// Use a private key from a file.
boost::system::error_code use_private_key_file(impl_type& impl,
const std::string& filename, context_base::file_format format,
boost::system::error_code& ec)
{
return service_impl_.use_private_key_file(impl, filename, format, ec);
}
/// Use an RSA private key from a file.
boost::system::error_code use_rsa_private_key_file(impl_type& impl,
const std::string& filename, context_base::file_format format,
boost::system::error_code& ec)
{
return service_impl_.use_rsa_private_key_file(impl, filename, format, ec);
}
/// Use the specified file to obtain the temporary Diffie-Hellman parameters.
boost::system::error_code use_tmp_dh_file(impl_type& impl,
const std::string& filename, boost::system::error_code& ec)
{
return service_impl_.use_tmp_dh_file(impl, filename, ec);
}
/// Set the password callback.
template <typename PasswordCallback>
boost::system::error_code set_password_callback(impl_type& impl,
PasswordCallback callback, boost::system::error_code& ec)
{
return service_impl_.set_password_callback(impl, callback, ec);
}
private:
// Destroy all user-defined handler objects owned by the service.
void shutdown_service()
{
}
// The service that provides the platform-specific implementation.
service_impl_type& service_impl_;
};
} // namespace old
} // namespace ssl
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_SSL_OLD_CONTEXT_SERVICE_HPP

View File

@@ -1,396 +0,0 @@
//
// ssl/old/detail/openssl_context_service.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2005 Voipster / Indrek dot Juhani at voipster dot com
// Copyright (c) 2005-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef BOOST_ASIO_SSL_OLD_DETAIL_OPENSSL_CONTEXT_SERVICE_HPP
#define BOOST_ASIO_SSL_OLD_DETAIL_OPENSSL_CONTEXT_SERVICE_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/config.hpp>
#include <cstring>
#include <string>
#include <boost/function.hpp>
#include <boost/asio/detail/throw_error.hpp>
#include <boost/asio/error.hpp>
#include <boost/asio/io_service.hpp>
#include <boost/asio/ssl/context_base.hpp>
#include <boost/asio/ssl/detail/openssl_init.hpp>
#include <boost/asio/ssl/detail/openssl_types.hpp>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
namespace ssl {
namespace old {
namespace detail {
class openssl_context_service
: public boost::asio::detail::service_base<openssl_context_service>
{
public:
// The native type of the context.
typedef ::SSL_CTX* impl_type;
// The type for the password callback function object.
typedef boost::function<std::string(std::size_t,
context_base::password_purpose)> password_callback_type;
// Constructor.
openssl_context_service(boost::asio::io_service& io_service)
: boost::asio::detail::service_base<openssl_context_service>(io_service)
{
}
// Destroy all user-defined handler objects owned by the service.
void shutdown_service()
{
}
// Return a null context implementation.
static impl_type null()
{
return 0;
}
// Create a new context implementation.
void create(impl_type& impl, context_base::method m)
{
switch (m)
{
#if defined(OPENSSL_NO_SSL2)
case context_base::sslv2:
case context_base::sslv2_client:
case context_base::sslv2_server:
boost::asio::detail::throw_error(boost::asio::error::invalid_argument);
break;
#else // defined(OPENSSL_NO_SSL2)
case context_base::sslv2:
impl = ::SSL_CTX_new(::SSLv2_method());
break;
case context_base::sslv2_client:
impl = ::SSL_CTX_new(::SSLv2_client_method());
break;
case context_base::sslv2_server:
impl = ::SSL_CTX_new(::SSLv2_server_method());
break;
#endif // defined(OPENSSL_NO_SSL2)
#if defined(OPENSSL_NO_SSL3)
case context_base::sslv3:
case context_base::sslv3_client:
case context_base::sslv3_server:
boost::asio::detail::throw_error(boost::asio::error::invalid_argument);
break;
#else // defined(OPENSSL_NO_SSL3)
case context_base::sslv3:
impl = ::SSL_CTX_new(::SSLv3_method());
break;
case context_base::sslv3_client:
impl = ::SSL_CTX_new(::SSLv3_client_method());
break;
case context_base::sslv3_server:
impl = ::SSL_CTX_new(::SSLv3_server_method());
break;
#endif // defined(OPENSSL_NO_SSL3)
case context_base::tlsv1:
impl = ::SSL_CTX_new(::TLSv1_method());
break;
case context_base::tlsv1_client:
impl = ::SSL_CTX_new(::TLSv1_client_method());
break;
case context_base::tlsv1_server:
impl = ::SSL_CTX_new(::TLSv1_server_method());
break;
case context_base::sslv23:
impl = ::SSL_CTX_new(::SSLv23_method());
break;
case context_base::sslv23_client:
impl = ::SSL_CTX_new(::SSLv23_client_method());
break;
case context_base::sslv23_server:
impl = ::SSL_CTX_new(::SSLv23_server_method());
break;
default:
impl = ::SSL_CTX_new(0);
break;
}
}
// Destroy a context implementation.
void destroy(impl_type& impl)
{
if (impl != null())
{
if (impl->default_passwd_callback_userdata)
{
password_callback_type* callback =
static_cast<password_callback_type*>(
impl->default_passwd_callback_userdata);
delete callback;
impl->default_passwd_callback_userdata = 0;
}
::SSL_CTX_free(impl);
impl = null();
}
}
// Set options on the context.
boost::system::error_code set_options(impl_type& impl,
context_base::options o, boost::system::error_code& ec)
{
::SSL_CTX_set_options(impl, o);
ec = boost::system::error_code();
return ec;
}
// Set peer verification mode.
boost::system::error_code set_verify_mode(impl_type& impl,
context_base::verify_mode v, boost::system::error_code& ec)
{
::SSL_CTX_set_verify(impl, v, 0);
ec = boost::system::error_code();
return ec;
}
// Load a certification authority file for performing verification.
boost::system::error_code load_verify_file(impl_type& impl,
const std::string& filename, boost::system::error_code& ec)
{
if (::SSL_CTX_load_verify_locations(impl, filename.c_str(), 0) != 1)
{
ec = boost::asio::error::invalid_argument;
return ec;
}
ec = boost::system::error_code();
return ec;
}
// Add a directory containing certification authority files to be used for
// performing verification.
boost::system::error_code add_verify_path(impl_type& impl,
const std::string& path, boost::system::error_code& ec)
{
if (::SSL_CTX_load_verify_locations(impl, 0, path.c_str()) != 1)
{
ec = boost::asio::error::invalid_argument;
return ec;
}
ec = boost::system::error_code();
return ec;
}
// Use a certificate from a file.
boost::system::error_code use_certificate_file(impl_type& impl,
const std::string& filename, context_base::file_format format,
boost::system::error_code& ec)
{
int file_type;
switch (format)
{
case context_base::asn1:
file_type = SSL_FILETYPE_ASN1;
break;
case context_base::pem:
file_type = SSL_FILETYPE_PEM;
break;
default:
{
ec = boost::asio::error::invalid_argument;
return ec;
}
}
if (::SSL_CTX_use_certificate_file(impl, filename.c_str(), file_type) != 1)
{
ec = boost::asio::error::invalid_argument;
return ec;
}
ec = boost::system::error_code();
return ec;
}
// Use a certificate chain from a file.
boost::system::error_code use_certificate_chain_file(impl_type& impl,
const std::string& filename, boost::system::error_code& ec)
{
if (::SSL_CTX_use_certificate_chain_file(impl, filename.c_str()) != 1)
{
ec = boost::asio::error::invalid_argument;
return ec;
}
ec = boost::system::error_code();
return ec;
}
// Use a private key from a file.
boost::system::error_code use_private_key_file(impl_type& impl,
const std::string& filename, context_base::file_format format,
boost::system::error_code& ec)
{
int file_type;
switch (format)
{
case context_base::asn1:
file_type = SSL_FILETYPE_ASN1;
break;
case context_base::pem:
file_type = SSL_FILETYPE_PEM;
break;
default:
{
ec = boost::asio::error::invalid_argument;
return ec;
}
}
if (::SSL_CTX_use_PrivateKey_file(impl, filename.c_str(), file_type) != 1)
{
ec = boost::asio::error::invalid_argument;
return ec;
}
ec = boost::system::error_code();
return ec;
}
// Use an RSA private key from a file.
boost::system::error_code use_rsa_private_key_file(impl_type& impl,
const std::string& filename, context_base::file_format format,
boost::system::error_code& ec)
{
int file_type;
switch (format)
{
case context_base::asn1:
file_type = SSL_FILETYPE_ASN1;
break;
case context_base::pem:
file_type = SSL_FILETYPE_PEM;
break;
default:
{
ec = boost::asio::error::invalid_argument;
return ec;
}
}
if (::SSL_CTX_use_RSAPrivateKey_file(
impl, filename.c_str(), file_type) != 1)
{
ec = boost::asio::error::invalid_argument;
return ec;
}
ec = boost::system::error_code();
return ec;
}
// Use the specified file to obtain the temporary Diffie-Hellman parameters.
boost::system::error_code use_tmp_dh_file(impl_type& impl,
const std::string& filename, boost::system::error_code& ec)
{
::BIO* bio = ::BIO_new_file(filename.c_str(), "r");
if (!bio)
{
ec = boost::asio::error::invalid_argument;
return ec;
}
::DH* dh = ::PEM_read_bio_DHparams(bio, 0, 0, 0);
if (!dh)
{
::BIO_free(bio);
ec = boost::asio::error::invalid_argument;
return ec;
}
::BIO_free(bio);
int result = ::SSL_CTX_set_tmp_dh(impl, dh);
::DH_free(dh);
if (result != 1)
{
ec = boost::asio::error::invalid_argument;
return ec;
}
ec = boost::system::error_code();
return ec;
}
static int password_callback(char* buf, int size, int purpose, void* data)
{
using namespace std; // For strncat and strlen.
if (data)
{
password_callback_type* callback =
static_cast<password_callback_type*>(data);
std::string passwd = (*callback)(static_cast<std::size_t>(size),
purpose ? context_base::for_writing : context_base::for_reading);
*buf = '\0';
strncat(buf, passwd.c_str(), size);
return strlen(buf);
}
return 0;
}
// Set the password callback.
template <typename Password_Callback>
boost::system::error_code set_password_callback(impl_type& impl,
Password_Callback callback, boost::system::error_code& ec)
{
// Allocate callback function object if not already present.
if (impl->default_passwd_callback_userdata)
{
password_callback_type* callback_function =
static_cast<password_callback_type*>(
impl->default_passwd_callback_userdata);
*callback_function = callback;
}
else
{
password_callback_type* callback_function =
new password_callback_type(callback);
impl->default_passwd_callback_userdata = callback_function;
}
// Set the password callback.
SSL_CTX_set_default_passwd_cb(impl,
&openssl_context_service::password_callback);
ec = boost::system::error_code();
return ec;
}
private:
// Ensure openssl is initialised.
boost::asio::ssl::detail::openssl_init<> init_;
};
} // namespace detail
} // namespace old
} // namespace ssl
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_SSL_OLD_DETAIL_OPENSSL_CONTEXT_SERVICE_HPP

View File

@@ -1,526 +0,0 @@
//
// ssl/old/detail/openssl_operation.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2005 Voipster / Indrek dot Juhani at voipster dot com
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef BOOST_ASIO_SSL_OLD_DETAIL_OPENSSL_OPERATION_HPP
#define BOOST_ASIO_SSL_OLD_DETAIL_OPENSSL_OPERATION_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/config.hpp>
#include <boost/function.hpp>
#include <boost/bind.hpp>
#include <boost/asio/buffer.hpp>
#include <boost/asio/detail/assert.hpp>
#include <boost/asio/detail/socket_ops.hpp>
#include <boost/asio/placeholders.hpp>
#include <boost/asio/ssl/detail/openssl_types.hpp>
#include <boost/asio/ssl/error.hpp>
#include <boost/asio/strand.hpp>
#include <boost/system/system_error.hpp>
#include <boost/asio/write.hpp>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
namespace ssl {
namespace old {
namespace detail {
typedef boost::function<int (::SSL*)> ssl_primitive_func;
typedef boost::function<void (const boost::system::error_code&, int)>
user_handler_func;
// Network send_/recv buffer implementation
//
//
class net_buffer
{
static const int NET_BUF_SIZE = 16*1024 + 256; // SSL record size + spare
unsigned char buf_[NET_BUF_SIZE];
unsigned char* data_start_;
unsigned char* data_end_;
public:
net_buffer()
{
data_start_ = data_end_ = buf_;
}
unsigned char* get_unused_start() { return data_end_; }
unsigned char* get_data_start() { return data_start_; }
size_t get_unused_len() { return (NET_BUF_SIZE - (data_end_ - buf_)); }
size_t get_data_len() { return (data_end_ - data_start_); }
void data_added(size_t count)
{
data_end_ += count;
data_end_ = data_end_ > (buf_ + NET_BUF_SIZE)?
(buf_ + NET_BUF_SIZE):
data_end_;
}
void data_removed(size_t count)
{
data_start_ += count;
if (data_start_ >= data_end_) reset();
}
void reset() { data_start_ = buf_; data_end_ = buf_; }
bool has_data() { return (data_start_ < data_end_); }
}; // class net_buffer
//
// Operation class
//
//
template <typename Stream>
class openssl_operation
{
public:
// Constructor for asynchronous operations
openssl_operation(ssl_primitive_func primitive,
Stream& socket,
net_buffer& recv_buf,
SSL* session,
BIO* ssl_bio,
user_handler_func handler,
boost::asio::io_service::strand& strand
)
: primitive_(primitive)
, user_handler_(handler)
, strand_(&strand)
, recv_buf_(recv_buf)
, socket_(socket)
, ssl_bio_(ssl_bio)
, session_(session)
{
write_ = boost::bind(
&openssl_operation::do_async_write,
this, boost::arg<1>(), boost::arg<2>()
);
read_ = boost::bind(
&openssl_operation::do_async_read,
this
);
handler_= boost::bind(
&openssl_operation::async_user_handler,
this, boost::arg<1>(), boost::arg<2>()
);
}
// Constructor for synchronous operations
openssl_operation(ssl_primitive_func primitive,
Stream& socket,
net_buffer& recv_buf,
SSL* session,
BIO* ssl_bio)
: primitive_(primitive)
, strand_(0)
, recv_buf_(recv_buf)
, socket_(socket)
, ssl_bio_(ssl_bio)
, session_(session)
{
write_ = boost::bind(
&openssl_operation::do_sync_write,
this, boost::arg<1>(), boost::arg<2>()
);
read_ = boost::bind(
&openssl_operation::do_sync_read,
this
);
handler_ = boost::bind(
&openssl_operation::sync_user_handler,
this, boost::arg<1>(), boost::arg<2>()
);
}
// Start operation
// In case of asynchronous it returns 0, in sync mode returns success code
// or throws an error...
int start()
{
int rc = primitive_( session_ );
bool is_operation_done = (rc > 0);
// For connect/accept/shutdown, the operation
// is done, when return code is 1
// for write, it is done, when is retcode > 0
// for read, it is done when retcode > 0
int error_code = !is_operation_done ?
::SSL_get_error( session_, rc ) :
0;
int sys_error_code = ERR_get_error();
if (error_code == SSL_ERROR_SSL)
return handler_(boost::system::error_code(
sys_error_code, boost::asio::error::get_ssl_category()), rc);
bool is_read_needed = (error_code == SSL_ERROR_WANT_READ);
bool is_write_needed = (error_code == SSL_ERROR_WANT_WRITE ||
::BIO_ctrl_pending( ssl_bio_ ));
bool is_shut_down_received =
((::SSL_get_shutdown( session_ ) & SSL_RECEIVED_SHUTDOWN) ==
SSL_RECEIVED_SHUTDOWN);
bool is_shut_down_sent =
((::SSL_get_shutdown( session_ ) & SSL_SENT_SHUTDOWN) ==
SSL_SENT_SHUTDOWN);
if (is_shut_down_sent && is_shut_down_received
&& is_operation_done && !is_write_needed)
// SSL connection is shut down cleanly
return handler_(boost::system::error_code(), 1);
if (is_shut_down_received && !is_operation_done)
// Shutdown has been requested, while we were reading or writing...
// abort our action...
return handler_(boost::asio::error::shut_down, 0);
if (!is_operation_done && !is_read_needed && !is_write_needed
&& !is_shut_down_sent)
{
// The operation has failed... It is not completed and does
// not want network communication nor does want to send shutdown out...
if (error_code == SSL_ERROR_SYSCALL)
{
return handler_(boost::system::error_code(
sys_error_code, boost::asio::error::system_category), rc);
}
else
{
return handler_(boost::system::error_code(
sys_error_code, boost::asio::error::get_ssl_category()), rc);
}
}
if (!is_operation_done && !is_write_needed)
{
// We may have left over data that we can pass to SSL immediately
if (recv_buf_.get_data_len() > 0)
{
// Pass the buffered data to SSL
int written = ::BIO_write
(
ssl_bio_,
recv_buf_.get_data_start(),
recv_buf_.get_data_len()
);
if (written > 0)
{
recv_buf_.data_removed(written);
}
else if (written < 0)
{
if (!BIO_should_retry(ssl_bio_))
{
// Some serios error with BIO....
return handler_(boost::asio::error::no_recovery, 0);
}
}
return start();
}
else if (is_read_needed || (is_shut_down_sent && !is_shut_down_received))
{
return read_();
}
}
// Continue with operation, flush any SSL data out to network...
return write_(is_operation_done, rc);
}
// Private implementation
private:
typedef boost::function<int (const boost::system::error_code&, int)>
int_handler_func;
typedef boost::function<int (bool, int)> write_func;
typedef boost::function<int ()> read_func;
ssl_primitive_func primitive_;
user_handler_func user_handler_;
boost::asio::io_service::strand* strand_;
write_func write_;
read_func read_;
int_handler_func handler_;
net_buffer send_buf_; // buffers for network IO
// The recv buffer is owned by the stream, not the operation, since there can
// be left over bytes after passing the data up to the application, and these
// bytes need to be kept around for the next read operation issued by the
// application.
net_buffer& recv_buf_;
Stream& socket_;
BIO* ssl_bio_;
SSL* session_;
//
int sync_user_handler(const boost::system::error_code& error, int rc)
{
if (!error)
return rc;
throw boost::system::system_error(error);
}
int async_user_handler(boost::system::error_code error, int rc)
{
if (rc < 0)
{
if (!error)
error = boost::asio::error::no_recovery;
rc = 0;
}
user_handler_(error, rc);
return 0;
}
// Writes bytes asynchronously from SSL to NET
int do_async_write(bool is_operation_done, int rc)
{
int len = ::BIO_ctrl_pending( ssl_bio_ );
if ( len )
{
// There is something to write into net, do it...
len = (int)send_buf_.get_unused_len() > len?
len:
send_buf_.get_unused_len();
if (len == 0)
{
// In case our send buffer is full, we have just to wait until
// previous send to complete...
return 0;
}
// Read outgoing data from bio
len = ::BIO_read( ssl_bio_, send_buf_.get_unused_start(), len);
if (len > 0)
{
unsigned char *data_start = send_buf_.get_unused_start();
send_buf_.data_added(len);
BOOST_ASIO_ASSERT(strand_);
boost::asio::async_write
(
socket_,
boost::asio::buffer(data_start, len),
strand_->wrap
(
boost::bind
(
&openssl_operation::async_write_handler,
this,
is_operation_done,
rc,
boost::asio::placeholders::error,
boost::asio::placeholders::bytes_transferred
)
)
);
return 0;
}
else if (!BIO_should_retry(ssl_bio_))
{
// Seems like fatal error
// reading from SSL BIO has failed...
handler_(boost::asio::error::no_recovery, 0);
return 0;
}
}
if (is_operation_done)
{
// Finish the operation, with success
handler_(boost::system::error_code(), rc);
return 0;
}
// OPeration is not done and writing to net has been made...
// start operation again
start();
return 0;
}
void async_write_handler(bool is_operation_done, int rc,
const boost::system::error_code& error, size_t bytes_sent)
{
if (!error)
{
// Remove data from send buffer
send_buf_.data_removed(bytes_sent);
if (is_operation_done)
handler_(boost::system::error_code(), rc);
else
// Since the operation was not completed, try it again...
start();
}
else
handler_(error, rc);
}
int do_async_read()
{
// Wait for new data
BOOST_ASIO_ASSERT(strand_);
socket_.async_read_some
(
boost::asio::buffer(recv_buf_.get_unused_start(),
recv_buf_.get_unused_len()),
strand_->wrap
(
boost::bind
(
&openssl_operation::async_read_handler,
this,
boost::asio::placeholders::error,
boost::asio::placeholders::bytes_transferred
)
)
);
return 0;
}
void async_read_handler(const boost::system::error_code& error,
size_t bytes_recvd)
{
if (!error)
{
recv_buf_.data_added(bytes_recvd);
// Pass the received data to SSL
int written = ::BIO_write
(
ssl_bio_,
recv_buf_.get_data_start(),
recv_buf_.get_data_len()
);
if (written > 0)
{
recv_buf_.data_removed(written);
}
else if (written < 0)
{
if (!BIO_should_retry(ssl_bio_))
{
// Some serios error with BIO....
handler_(boost::asio::error::no_recovery, 0);
return;
}
}
// and try the SSL primitive again
start();
}
else
{
// Error in network level...
// SSL can't continue either...
handler_(error, 0);
}
}
// Syncronous functions...
int do_sync_write(bool is_operation_done, int rc)
{
int len = ::BIO_ctrl_pending( ssl_bio_ );
if ( len )
{
// There is something to write into net, do it...
len = (int)send_buf_.get_unused_len() > len?
len:
send_buf_.get_unused_len();
// Read outgoing data from bio
len = ::BIO_read( ssl_bio_, send_buf_.get_unused_start(), len);
if (len > 0)
{
size_t sent_len = boost::asio::write(
socket_,
boost::asio::buffer(send_buf_.get_unused_start(), len)
);
send_buf_.data_added(len);
send_buf_.data_removed(sent_len);
}
else if (!BIO_should_retry(ssl_bio_))
{
// Seems like fatal error
// reading from SSL BIO has failed...
throw boost::system::system_error(boost::asio::error::no_recovery);
}
}
if (is_operation_done)
// Finish the operation, with success
return rc;
// Operation is not finished, start again.
return start();
}
int do_sync_read()
{
size_t len = socket_.read_some
(
boost::asio::buffer(recv_buf_.get_unused_start(),
recv_buf_.get_unused_len())
);
// Write data to ssl
recv_buf_.data_added(len);
// Pass the received data to SSL
int written = ::BIO_write
(
ssl_bio_,
recv_buf_.get_data_start(),
recv_buf_.get_data_len()
);
if (written > 0)
{
recv_buf_.data_removed(written);
}
else if (written < 0)
{
if (!BIO_should_retry(ssl_bio_))
{
// Some serios error with BIO....
throw boost::system::system_error(boost::asio::error::no_recovery);
}
}
// Try the operation again
return start();
}
}; // class openssl_operation
} // namespace detail
} // namespace old
} // namespace ssl
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_SSL_OLD_DETAIL_OPENSSL_OPERATION_HPP

View File

@@ -1,573 +0,0 @@
//
// ssl/old/detail/stream_service.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2005 Voipster / Indrek dot Juhani at voipster dot com
// Copyright (c) 2005-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef BOOST_ASIO_SSL_OLD_DETAIL_OPENSSL_STREAM_SERVICE_HPP
#define BOOST_ASIO_SSL_OLD_DETAIL_OPENSSL_STREAM_SERVICE_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/config.hpp>
#include <cstddef>
#include <climits>
#include <memory>
#include <boost/config.hpp>
#include <boost/noncopyable.hpp>
#include <boost/function.hpp>
#include <boost/bind.hpp>
#include <boost/asio/detail/buffer_sequence_adapter.hpp>
#include <boost/asio/error.hpp>
#include <boost/asio/io_service.hpp>
#include <boost/asio/ssl/basic_context.hpp>
#include <boost/asio/ssl/stream_base.hpp>
#include <boost/asio/ssl/old/detail/openssl_operation.hpp>
#include <boost/asio/ssl/detail/openssl_types.hpp>
#include <boost/asio/strand.hpp>
#include <boost/system/system_error.hpp>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
namespace ssl {
namespace old {
namespace detail {
class openssl_stream_service
: public boost::asio::detail::service_base<openssl_stream_service>
{
private:
enum { max_buffer_size = INT_MAX };
//Base handler for asyncrhonous operations
template <typename Stream>
class base_handler
{
public:
typedef boost::function<
void (const boost::system::error_code&, size_t)> func_t;
base_handler(boost::asio::io_service& io_service)
: op_(NULL)
, io_service_(io_service)
, work_(io_service)
{}
void do_func(const boost::system::error_code& error, size_t size)
{
func_(error, size);
}
void set_operation(openssl_operation<Stream>* op) { op_ = op; }
void set_func(func_t func) { func_ = func; }
~base_handler()
{
delete op_;
}
private:
func_t func_;
openssl_operation<Stream>* op_;
boost::asio::io_service& io_service_;
boost::asio::io_service::work work_;
}; // class base_handler
// Handler for asynchronous IO (write/read) operations
template<typename Stream, typename Handler>
class io_handler
: public base_handler<Stream>
{
public:
io_handler(Handler handler, boost::asio::io_service& io_service)
: base_handler<Stream>(io_service)
, handler_(handler)
{
this->set_func(boost::bind(
&io_handler<Stream, Handler>::handler_impl,
this, boost::arg<1>(), boost::arg<2>() ));
}
private:
Handler handler_;
void handler_impl(const boost::system::error_code& error, size_t size)
{
std::auto_ptr<io_handler<Stream, Handler> > this_ptr(this);
handler_(error, size);
}
}; // class io_handler
// Handler for asyncrhonous handshake (connect, accept) functions
template <typename Stream, typename Handler>
class handshake_handler
: public base_handler<Stream>
{
public:
handshake_handler(Handler handler, boost::asio::io_service& io_service)
: base_handler<Stream>(io_service)
, handler_(handler)
{
this->set_func(boost::bind(
&handshake_handler<Stream, Handler>::handler_impl,
this, boost::arg<1>(), boost::arg<2>() ));
}
private:
Handler handler_;
void handler_impl(const boost::system::error_code& error, size_t)
{
std::auto_ptr<handshake_handler<Stream, Handler> > this_ptr(this);
handler_(error);
}
}; // class handshake_handler
// Handler for asyncrhonous shutdown
template <typename Stream, typename Handler>
class shutdown_handler
: public base_handler<Stream>
{
public:
shutdown_handler(Handler handler, boost::asio::io_service& io_service)
: base_handler<Stream>(io_service),
handler_(handler)
{
this->set_func(boost::bind(
&shutdown_handler<Stream, Handler>::handler_impl,
this, boost::arg<1>(), boost::arg<2>() ));
}
private:
Handler handler_;
void handler_impl(const boost::system::error_code& error, size_t)
{
std::auto_ptr<shutdown_handler<Stream, Handler> > this_ptr(this);
handler_(error);
}
}; // class shutdown_handler
public:
// The implementation type.
typedef struct impl_struct
{
::SSL* ssl;
::BIO* ext_bio;
net_buffer recv_buf;
} * impl_type;
// Construct a new stream socket service for the specified io_service.
explicit openssl_stream_service(boost::asio::io_service& io_service)
: boost::asio::detail::service_base<openssl_stream_service>(io_service),
strand_(io_service)
{
}
// Destroy all user-defined handler objects owned by the service.
void shutdown_service()
{
}
// Return a null stream implementation.
impl_type null() const
{
return 0;
}
// Create a new stream implementation.
template <typename Stream, typename Context_Service>
void create(impl_type& impl, Stream& /*next_layer*/,
basic_context<Context_Service>& context)
{
impl = new impl_struct;
impl->ssl = ::SSL_new(context.impl());
::SSL_set_mode(impl->ssl, SSL_MODE_ENABLE_PARTIAL_WRITE);
::SSL_set_mode(impl->ssl, SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER);
::BIO* int_bio = 0;
impl->ext_bio = 0;
::BIO_new_bio_pair(&int_bio, 8192, &impl->ext_bio, 8192);
::SSL_set_bio(impl->ssl, int_bio, int_bio);
}
// Destroy a stream implementation.
template <typename Stream>
void destroy(impl_type& impl, Stream& /*next_layer*/)
{
if (impl != 0)
{
::BIO_free(impl->ext_bio);
::SSL_free(impl->ssl);
delete impl;
impl = 0;
}
}
// Perform SSL handshaking.
template <typename Stream>
boost::system::error_code handshake(impl_type& impl, Stream& next_layer,
stream_base::handshake_type type, boost::system::error_code& ec)
{
try
{
openssl_operation<Stream> op(
type == stream_base::client ?
&ssl_wrap<mutex_type>::SSL_connect:
&ssl_wrap<mutex_type>::SSL_accept,
next_layer,
impl->recv_buf,
impl->ssl,
impl->ext_bio);
op.start();
}
catch (boost::system::system_error& e)
{
ec = e.code();
return ec;
}
ec = boost::system::error_code();
return ec;
}
// Start an asynchronous SSL handshake.
template <typename Stream, typename Handler>
void async_handshake(impl_type& impl, Stream& next_layer,
stream_base::handshake_type type, Handler handler)
{
typedef handshake_handler<Stream, Handler> connect_handler;
connect_handler* local_handler =
new connect_handler(handler, get_io_service());
openssl_operation<Stream>* op = new openssl_operation<Stream>
(
type == stream_base::client ?
&ssl_wrap<mutex_type>::SSL_connect:
&ssl_wrap<mutex_type>::SSL_accept,
next_layer,
impl->recv_buf,
impl->ssl,
impl->ext_bio,
boost::bind
(
&base_handler<Stream>::do_func,
local_handler,
boost::arg<1>(),
boost::arg<2>()
),
strand_
);
local_handler->set_operation(op);
strand_.post(boost::bind(&openssl_operation<Stream>::start, op));
}
// Shut down SSL on the stream.
template <typename Stream>
boost::system::error_code shutdown(impl_type& impl, Stream& next_layer,
boost::system::error_code& ec)
{
try
{
openssl_operation<Stream> op(
&ssl_wrap<mutex_type>::SSL_shutdown,
next_layer,
impl->recv_buf,
impl->ssl,
impl->ext_bio);
op.start();
}
catch (boost::system::system_error& e)
{
ec = e.code();
return ec;
}
ec = boost::system::error_code();
return ec;
}
// Asynchronously shut down SSL on the stream.
template <typename Stream, typename Handler>
void async_shutdown(impl_type& impl, Stream& next_layer, Handler handler)
{
typedef shutdown_handler<Stream, Handler> disconnect_handler;
disconnect_handler* local_handler =
new disconnect_handler(handler, get_io_service());
openssl_operation<Stream>* op = new openssl_operation<Stream>
(
&ssl_wrap<mutex_type>::SSL_shutdown,
next_layer,
impl->recv_buf,
impl->ssl,
impl->ext_bio,
boost::bind
(
&base_handler<Stream>::do_func,
local_handler,
boost::arg<1>(),
boost::arg<2>()
),
strand_
);
local_handler->set_operation(op);
strand_.post(boost::bind(&openssl_operation<Stream>::start, op));
}
// Write some data to the stream.
template <typename Stream, typename Const_Buffers>
std::size_t write_some(impl_type& impl, Stream& next_layer,
const Const_Buffers& buffers, boost::system::error_code& ec)
{
size_t bytes_transferred = 0;
try
{
boost::asio::const_buffer buffer =
boost::asio::detail::buffer_sequence_adapter<
boost::asio::const_buffer, Const_Buffers>::first(buffers);
std::size_t buffer_size = boost::asio::buffer_size(buffer);
if (buffer_size > max_buffer_size)
buffer_size = max_buffer_size;
else if (buffer_size == 0)
{
ec = boost::system::error_code();
return 0;
}
boost::function<int (SSL*)> send_func =
boost::bind(boost::type<int>(), &::SSL_write, boost::arg<1>(),
boost::asio::buffer_cast<const void*>(buffer),
static_cast<int>(buffer_size));
openssl_operation<Stream> op(
send_func,
next_layer,
impl->recv_buf,
impl->ssl,
impl->ext_bio
);
bytes_transferred = static_cast<size_t>(op.start());
}
catch (boost::system::system_error& e)
{
ec = e.code();
return 0;
}
ec = boost::system::error_code();
return bytes_transferred;
}
// Start an asynchronous write.
template <typename Stream, typename Const_Buffers, typename Handler>
void async_write_some(impl_type& impl, Stream& next_layer,
const Const_Buffers& buffers, Handler handler)
{
typedef io_handler<Stream, Handler> send_handler;
boost::asio::const_buffer buffer =
boost::asio::detail::buffer_sequence_adapter<
boost::asio::const_buffer, Const_Buffers>::first(buffers);
std::size_t buffer_size = boost::asio::buffer_size(buffer);
if (buffer_size > max_buffer_size)
buffer_size = max_buffer_size;
else if (buffer_size == 0)
{
get_io_service().post(boost::asio::detail::bind_handler(
handler, boost::system::error_code(), 0));
return;
}
send_handler* local_handler = new send_handler(handler, get_io_service());
boost::function<int (SSL*)> send_func =
boost::bind(boost::type<int>(), &::SSL_write, boost::arg<1>(),
boost::asio::buffer_cast<const void*>(buffer),
static_cast<int>(buffer_size));
openssl_operation<Stream>* op = new openssl_operation<Stream>
(
send_func,
next_layer,
impl->recv_buf,
impl->ssl,
impl->ext_bio,
boost::bind
(
&base_handler<Stream>::do_func,
local_handler,
boost::arg<1>(),
boost::arg<2>()
),
strand_
);
local_handler->set_operation(op);
strand_.post(boost::bind(&openssl_operation<Stream>::start, op));
}
// Read some data from the stream.
template <typename Stream, typename Mutable_Buffers>
std::size_t read_some(impl_type& impl, Stream& next_layer,
const Mutable_Buffers& buffers, boost::system::error_code& ec)
{
size_t bytes_transferred = 0;
try
{
boost::asio::mutable_buffer buffer =
boost::asio::detail::buffer_sequence_adapter<
boost::asio::mutable_buffer, Mutable_Buffers>::first(buffers);
std::size_t buffer_size = boost::asio::buffer_size(buffer);
if (buffer_size > max_buffer_size)
buffer_size = max_buffer_size;
else if (buffer_size == 0)
{
ec = boost::system::error_code();
return 0;
}
boost::function<int (SSL*)> recv_func =
boost::bind(boost::type<int>(), &::SSL_read, boost::arg<1>(),
boost::asio::buffer_cast<void*>(buffer),
static_cast<int>(buffer_size));
openssl_operation<Stream> op(recv_func,
next_layer,
impl->recv_buf,
impl->ssl,
impl->ext_bio
);
bytes_transferred = static_cast<size_t>(op.start());
}
catch (boost::system::system_error& e)
{
ec = e.code();
return 0;
}
ec = boost::system::error_code();
return bytes_transferred;
}
// Start an asynchronous read.
template <typename Stream, typename Mutable_Buffers, typename Handler>
void async_read_some(impl_type& impl, Stream& next_layer,
const Mutable_Buffers& buffers, Handler handler)
{
typedef io_handler<Stream, Handler> recv_handler;
boost::asio::mutable_buffer buffer =
boost::asio::detail::buffer_sequence_adapter<
boost::asio::mutable_buffer, Mutable_Buffers>::first(buffers);
std::size_t buffer_size = boost::asio::buffer_size(buffer);
if (buffer_size > max_buffer_size)
buffer_size = max_buffer_size;
else if (buffer_size == 0)
{
get_io_service().post(boost::asio::detail::bind_handler(
handler, boost::system::error_code(), 0));
return;
}
recv_handler* local_handler = new recv_handler(handler, get_io_service());
boost::function<int (SSL*)> recv_func =
boost::bind(boost::type<int>(), &::SSL_read, boost::arg<1>(),
boost::asio::buffer_cast<void*>(buffer),
static_cast<int>(buffer_size));
openssl_operation<Stream>* op = new openssl_operation<Stream>
(
recv_func,
next_layer,
impl->recv_buf,
impl->ssl,
impl->ext_bio,
boost::bind
(
&base_handler<Stream>::do_func,
local_handler,
boost::arg<1>(),
boost::arg<2>()
),
strand_
);
local_handler->set_operation(op);
strand_.post(boost::bind(&openssl_operation<Stream>::start, op));
}
// Peek at the incoming data on the stream.
template <typename Stream, typename Mutable_Buffers>
std::size_t peek(impl_type& /*impl*/, Stream& /*next_layer*/,
const Mutable_Buffers& /*buffers*/, boost::system::error_code& ec)
{
ec = boost::system::error_code();
return 0;
}
// Determine the amount of data that may be read without blocking.
template <typename Stream>
std::size_t in_avail(impl_type& /*impl*/, Stream& /*next_layer*/,
boost::system::error_code& ec)
{
ec = boost::system::error_code();
return 0;
}
private:
boost::asio::io_service::strand strand_;
typedef boost::asio::detail::mutex mutex_type;
template<typename Mutex>
struct ssl_wrap
{
static Mutex ssl_mutex_;
static int SSL_accept(SSL *ssl)
{
typename Mutex::scoped_lock lock(ssl_mutex_);
return ::SSL_accept(ssl);
}
static int SSL_connect(SSL *ssl)
{
typename Mutex::scoped_lock lock(ssl_mutex_);
return ::SSL_connect(ssl);
}
static int SSL_shutdown(SSL *ssl)
{
typename Mutex::scoped_lock lock(ssl_mutex_);
return ::SSL_shutdown(ssl);
}
};
};
template<typename Mutex>
Mutex openssl_stream_service::ssl_wrap<Mutex>::ssl_mutex_;
} // namespace detail
} // namespace old
} // namespace ssl
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_SSL_OLD_DETAIL_OPENSSL_STREAM_SERVICE_HPP

View File

@@ -1,503 +0,0 @@
//
// ssl/old/stream.hpp
// ~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2005 Voipster / Indrek dot Juhani at voipster dot com
// Copyright (c) 2005-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef BOOST_ASIO_SSL_OLD_STREAM_HPP
#define BOOST_ASIO_SSL_OLD_STREAM_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/config.hpp>
#include <cstddef>
#include <boost/noncopyable.hpp>
#include <boost/asio/detail/throw_error.hpp>
#include <boost/asio/detail/type_traits.hpp>
#include <boost/asio/error.hpp>
#include <boost/asio/ssl/basic_context.hpp>
#include <boost/asio/ssl/stream_base.hpp>
#include <boost/asio/ssl/stream_service.hpp>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
namespace ssl {
namespace old {
/// Provides stream-oriented functionality using SSL.
/**
* The stream class template provides asynchronous and blocking stream-oriented
* functionality using SSL.
*
* @par Thread Safety
* @e Distinct @e objects: Safe.@n
* @e Shared @e objects: Unsafe.
*
* @par Example
* To use the SSL stream template with an ip::tcp::socket, you would write:
* @code
* boost::asio::io_service io_service;
* boost::asio::ssl::context context(io_service, boost::asio::ssl::context::sslv23);
* boost::asio::ssl::stream<boost::asio::ip::tcp::socket> sock(io_service, context);
* @endcode
*
* @par Concepts:
* AsyncReadStream, AsyncWriteStream, Stream, SyncRead_Stream, SyncWriteStream.
*/
template <typename Stream, typename Service = old::stream_service>
class stream
: public stream_base,
private boost::noncopyable
{
public:
/// The type of the next layer.
typedef typename remove_reference<Stream>::type next_layer_type;
/// The type of the lowest layer.
typedef typename next_layer_type::lowest_layer_type lowest_layer_type;
/// The type of the service that will be used to provide stream operations.
typedef Service service_type;
/// The native implementation type of the stream.
typedef typename service_type::impl_type impl_type;
/// Construct a stream.
/**
* This constructor creates a stream and initialises the underlying stream
* object.
*
* @param arg The argument to be passed to initialise the underlying stream.
*
* @param context The SSL context to be used for the stream.
*/
template <typename Arg, typename Context_Service>
explicit stream(Arg& arg, basic_context<Context_Service>& context)
: next_layer_(arg),
service_(boost::asio::use_service<Service>(next_layer_.get_io_service())),
impl_(service_.null())
{
service_.create(impl_, next_layer_, context);
}
/// Destructor.
~stream()
{
service_.destroy(impl_, next_layer_);
}
/// Get the io_service associated with the object.
/**
* This function may be used to obtain the io_service object that the stream
* uses to dispatch handlers for asynchronous operations.
*
* @return A reference to the io_service object that stream will use to
* dispatch handlers. Ownership is not transferred to the caller.
*/
boost::asio::io_service& get_io_service()
{
return next_layer_.get_io_service();
}
/// Get a reference to the next layer.
/**
* This function returns a reference to the next layer in a stack of stream
* layers.
*
* @return A reference to the next layer in the stack of stream layers.
* Ownership is not transferred to the caller.
*/
next_layer_type& next_layer()
{
return next_layer_;
}
/// Get a reference to the lowest layer.
/**
* This function returns a reference to the lowest layer in a stack of
* stream layers.
*
* @return A reference to the lowest layer in the stack of stream layers.
* Ownership is not transferred to the caller.
*/
lowest_layer_type& lowest_layer()
{
return next_layer_.lowest_layer();
}
/// Get a const reference to the lowest layer.
/**
* This function returns a const reference to the lowest layer in a stack of
* stream layers.
*
* @return A const reference to the lowest layer in the stack of stream
* layers. Ownership is not transferred to the caller.
*/
const lowest_layer_type& lowest_layer() const
{
return next_layer_.lowest_layer();
}
/// Get the underlying implementation in the native type.
/**
* This function may be used to obtain the underlying implementation of the
* context. This is intended to allow access to stream functionality that is
* not otherwise provided.
*/
impl_type impl()
{
return impl_;
}
/// Perform SSL handshaking.
/**
* This function is used to perform SSL handshaking on the stream. The
* function call will block until handshaking is complete or an error occurs.
*
* @param type The type of handshaking to be performed, i.e. as a client or as
* a server.
*
* @throws boost::system::system_error Thrown on failure.
*/
void handshake(handshake_type type)
{
boost::system::error_code ec;
service_.handshake(impl_, next_layer_, type, ec);
boost::asio::detail::throw_error(ec);
}
/// Perform SSL handshaking.
/**
* This function is used to perform SSL handshaking on the stream. The
* function call will block until handshaking is complete or an error occurs.
*
* @param type The type of handshaking to be performed, i.e. as a client or as
* a server.
*
* @param ec Set to indicate what error occurred, if any.
*/
boost::system::error_code handshake(handshake_type type,
boost::system::error_code& ec)
{
return service_.handshake(impl_, next_layer_, type, ec);
}
/// Start an asynchronous SSL handshake.
/**
* This function is used to asynchronously perform an SSL handshake on the
* stream. This function call always returns immediately.
*
* @param type The type of handshaking to be performed, i.e. as a client or as
* a server.
*
* @param handler The handler to be called when the handshake operation
* completes. Copies will be made of the handler as required. The equivalent
* function signature of the handler must be:
* @code void handler(
* const boost::system::error_code& error // Result of operation.
* ); @endcode
*/
template <typename HandshakeHandler>
void async_handshake(handshake_type type, HandshakeHandler handler)
{
service_.async_handshake(impl_, next_layer_, type, handler);
}
/// Shut down SSL on the stream.
/**
* This function is used to shut down SSL on the stream. The function call
* will block until SSL has been shut down or an error occurs.
*
* @throws boost::system::system_error Thrown on failure.
*/
void shutdown()
{
boost::system::error_code ec;
service_.shutdown(impl_, next_layer_, ec);
boost::asio::detail::throw_error(ec);
}
/// Shut down SSL on the stream.
/**
* This function is used to shut down SSL on the stream. The function call
* will block until SSL has been shut down or an error occurs.
*
* @param ec Set to indicate what error occurred, if any.
*/
boost::system::error_code shutdown(boost::system::error_code& ec)
{
return service_.shutdown(impl_, next_layer_, ec);
}
/// Asynchronously shut down SSL on the stream.
/**
* This function is used to asynchronously shut down SSL on the stream. This
* function call always returns immediately.
*
* @param handler The handler to be called when the handshake operation
* completes. Copies will be made of the handler as required. The equivalent
* function signature of the handler must be:
* @code void handler(
* const boost::system::error_code& error // Result of operation.
* ); @endcode
*/
template <typename ShutdownHandler>
void async_shutdown(ShutdownHandler handler)
{
service_.async_shutdown(impl_, next_layer_, handler);
}
/// Write some data to the stream.
/**
* This function is used to write data on the stream. The function call will
* block until one or more bytes of data has been written successfully, or
* until an error occurs.
*
* @param buffers The data to be written.
*
* @returns The number of bytes written.
*
* @throws boost::system::system_error Thrown on failure.
*
* @note The write_some operation may not transmit all of the data to the
* peer. Consider using the @ref write function if you need to ensure that all
* data is written before the blocking operation completes.
*/
template <typename ConstBufferSequence>
std::size_t write_some(const ConstBufferSequence& buffers)
{
boost::system::error_code ec;
std::size_t s = service_.write_some(impl_, next_layer_, buffers, ec);
boost::asio::detail::throw_error(ec);
return s;
}
/// Write some data to the stream.
/**
* This function is used to write data on the stream. The function call will
* block until one or more bytes of data has been written successfully, or
* until an error occurs.
*
* @param buffers The data to be written to the stream.
*
* @param ec Set to indicate what error occurred, if any.
*
* @returns The number of bytes written. Returns 0 if an error occurred.
*
* @note The write_some operation may not transmit all of the data to the
* peer. Consider using the @ref write function if you need to ensure that all
* data is written before the blocking operation completes.
*/
template <typename ConstBufferSequence>
std::size_t write_some(const ConstBufferSequence& buffers,
boost::system::error_code& ec)
{
return service_.write_some(impl_, next_layer_, buffers, ec);
}
/// Start an asynchronous write.
/**
* This function is used to asynchronously write one or more bytes of data to
* the stream. The function call always returns immediately.
*
* @param buffers The data to be written to the stream. Although the buffers
* object may be copied as necessary, ownership of the underlying buffers is
* retained by the caller, which must guarantee that they remain valid until
* the handler is called.
*
* @param handler The handler to be called when the write operation completes.
* Copies will be made of the handler as required. The equivalent function
* signature of the handler must be:
* @code void handler(
* const boost::system::error_code& error, // Result of operation.
* std::size_t bytes_transferred // Number of bytes written.
* ); @endcode
*
* @note The async_write_some operation may not transmit all of the data to
* the peer. Consider using the @ref async_write function if you need to
* ensure that all data is written before the blocking operation completes.
*/
template <typename ConstBufferSequence, typename WriteHandler>
void async_write_some(const ConstBufferSequence& buffers,
WriteHandler handler)
{
service_.async_write_some(impl_, next_layer_, buffers, handler);
}
/// Read some data from the stream.
/**
* This function is used to read data from the stream. The function call will
* block until one or more bytes of data has been read successfully, or until
* an error occurs.
*
* @param buffers The buffers into which the data will be read.
*
* @returns The number of bytes read.
*
* @throws boost::system::system_error Thrown on failure.
*
* @note The read_some operation may not read all of the requested number of
* bytes. Consider using the @ref read function if you need to ensure that the
* requested amount of data is read before the blocking operation completes.
*/
template <typename MutableBufferSequence>
std::size_t read_some(const MutableBufferSequence& buffers)
{
boost::system::error_code ec;
std::size_t s = service_.read_some(impl_, next_layer_, buffers, ec);
boost::asio::detail::throw_error(ec);
return s;
}
/// Read some data from the stream.
/**
* This function is used to read data from the stream. The function call will
* block until one or more bytes of data has been read successfully, or until
* an error occurs.
*
* @param buffers The buffers into which the data will be read.
*
* @param ec Set to indicate what error occurred, if any.
*
* @returns The number of bytes read. Returns 0 if an error occurred.
*
* @note The read_some operation may not read all of the requested number of
* bytes. Consider using the @ref read function if you need to ensure that the
* requested amount of data is read before the blocking operation completes.
*/
template <typename MutableBufferSequence>
std::size_t read_some(const MutableBufferSequence& buffers,
boost::system::error_code& ec)
{
return service_.read_some(impl_, next_layer_, buffers, ec);
}
/// Start an asynchronous read.
/**
* This function is used to asynchronously read one or more bytes of data from
* the stream. The function call always returns immediately.
*
* @param buffers The buffers into which the data will be read. Although the
* buffers object may be copied as necessary, ownership of the underlying
* buffers is retained by the caller, which must guarantee that they remain
* valid until the handler is called.
*
* @param handler The handler to be called when the read operation completes.
* Copies will be made of the handler as required. The equivalent function
* signature of the handler must be:
* @code void handler(
* const boost::system::error_code& error, // Result of operation.
* std::size_t bytes_transferred // Number of bytes read.
* ); @endcode
*
* @note The async_read_some operation may not read all of the requested
* number of bytes. Consider using the @ref async_read function if you need to
* ensure that the requested amount of data is read before the asynchronous
* operation completes.
*/
template <typename MutableBufferSequence, typename ReadHandler>
void async_read_some(const MutableBufferSequence& buffers,
ReadHandler handler)
{
service_.async_read_some(impl_, next_layer_, buffers, handler);
}
/// Peek at the incoming data on the stream.
/**
* This function is used to peek at the incoming data on the stream, without
* removing it from the input queue. The function call will block until data
* has been read successfully or an error occurs.
*
* @param buffers The buffers into which the data will be read.
*
* @returns The number of bytes read.
*
* @throws boost::system::system_error Thrown on failure.
*/
template <typename MutableBufferSequence>
std::size_t peek(const MutableBufferSequence& buffers)
{
boost::system::error_code ec;
std::size_t s = service_.peek(impl_, next_layer_, buffers, ec);
boost::asio::detail::throw_error(ec);
return s;
}
/// Peek at the incoming data on the stream.
/**
* This function is used to peek at the incoming data on the stream, withoutxi
* removing it from the input queue. The function call will block until data
* has been read successfully or an error occurs.
*
* @param buffers The buffers into which the data will be read.
*
* @param ec Set to indicate what error occurred, if any.
*
* @returns The number of bytes read. Returns 0 if an error occurred.
*/
template <typename MutableBufferSequence>
std::size_t peek(const MutableBufferSequence& buffers,
boost::system::error_code& ec)
{
return service_.peek(impl_, next_layer_, buffers, ec);
}
/// Determine the amount of data that may be read without blocking.
/**
* This function is used to determine the amount of data, in bytes, that may
* be read from the stream without blocking.
*
* @returns The number of bytes of data that can be read without blocking.
*
* @throws boost::system::system_error Thrown on failure.
*/
std::size_t in_avail()
{
boost::system::error_code ec;
std::size_t s = service_.in_avail(impl_, next_layer_, ec);
boost::asio::detail::throw_error(ec);
return s;
}
/// Determine the amount of data that may be read without blocking.
/**
* This function is used to determine the amount of data, in bytes, that may
* be read from the stream without blocking.
*
* @param ec Set to indicate what error occurred, if any.
*
* @returns The number of bytes of data that can be read without blocking.
*/
std::size_t in_avail(boost::system::error_code& ec)
{
return service_.in_avail(impl_, next_layer_, ec);
}
private:
/// The next layer.
Stream next_layer_;
/// The backend service implementation.
service_type& service_;
/// The underlying native implementation.
impl_type impl_;
};
} // namespace old
} // namespace ssl
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_SSL_OLD_STREAM_HPP

View File

@@ -1,186 +0,0 @@
//
// ssl/old/stream_service.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2005 Voipster / Indrek dot Juhani at voipster dot com
// Copyright (c) 2005-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef BOOST_ASIO_SSL_OLD_STREAM_SERVICE_HPP
#define BOOST_ASIO_SSL_OLD_STREAM_SERVICE_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/config.hpp>
#include <cstddef>
#include <boost/noncopyable.hpp>
#include <boost/asio/io_service.hpp>
#include <boost/asio/ssl/basic_context.hpp>
#include <boost/asio/ssl/old/detail/openssl_stream_service.hpp>
#include <boost/asio/ssl/stream_base.hpp>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
namespace ssl {
namespace old {
/// Default service implementation for an SSL stream.
class stream_service
#if defined(GENERATING_DOCUMENTATION)
: public boost::asio::io_service::service
#else
: public boost::asio::detail::service_base<stream_service>
#endif
{
private:
// The type of the platform-specific implementation.
typedef old::detail::openssl_stream_service service_impl_type;
public:
#if defined(GENERATING_DOCUMENTATION)
/// The unique service identifier.
static boost::asio::io_service::id id;
#endif
/// The type of a stream implementation.
#if defined(GENERATING_DOCUMENTATION)
typedef implementation_defined impl_type;
#else
typedef service_impl_type::impl_type impl_type;
#endif
/// Construct a new stream service for the specified io_service.
explicit stream_service(boost::asio::io_service& io_service)
: boost::asio::detail::service_base<stream_service>(io_service),
service_impl_(boost::asio::use_service<service_impl_type>(io_service))
{
}
/// Return a null stream implementation.
impl_type null() const
{
return service_impl_.null();
}
/// Create a new stream implementation.
template <typename Stream, typename Context_Service>
void create(impl_type& impl, Stream& next_layer,
basic_context<Context_Service>& context)
{
service_impl_.create(impl, next_layer, context);
}
/// Destroy a stream implementation.
template <typename Stream>
void destroy(impl_type& impl, Stream& next_layer)
{
service_impl_.destroy(impl, next_layer);
}
/// Perform SSL handshaking.
template <typename Stream>
boost::system::error_code handshake(impl_type& impl, Stream& next_layer,
stream_base::handshake_type type, boost::system::error_code& ec)
{
return service_impl_.handshake(impl, next_layer, type, ec);
}
/// Start an asynchronous SSL handshake.
template <typename Stream, typename HandshakeHandler>
void async_handshake(impl_type& impl, Stream& next_layer,
stream_base::handshake_type type, HandshakeHandler handler)
{
service_impl_.async_handshake(impl, next_layer, type, handler);
}
/// Shut down SSL on the stream.
template <typename Stream>
boost::system::error_code shutdown(impl_type& impl, Stream& next_layer,
boost::system::error_code& ec)
{
return service_impl_.shutdown(impl, next_layer, ec);
}
/// Asynchronously shut down SSL on the stream.
template <typename Stream, typename ShutdownHandler>
void async_shutdown(impl_type& impl, Stream& next_layer,
ShutdownHandler handler)
{
service_impl_.async_shutdown(impl, next_layer, handler);
}
/// Write some data to the stream.
template <typename Stream, typename ConstBufferSequence>
std::size_t write_some(impl_type& impl, Stream& next_layer,
const ConstBufferSequence& buffers, boost::system::error_code& ec)
{
return service_impl_.write_some(impl, next_layer, buffers, ec);
}
/// Start an asynchronous write.
template <typename Stream, typename ConstBufferSequence,
typename WriteHandler>
void async_write_some(impl_type& impl, Stream& next_layer,
const ConstBufferSequence& buffers, WriteHandler handler)
{
service_impl_.async_write_some(impl, next_layer, buffers, handler);
}
/// Read some data from the stream.
template <typename Stream, typename MutableBufferSequence>
std::size_t read_some(impl_type& impl, Stream& next_layer,
const MutableBufferSequence& buffers, boost::system::error_code& ec)
{
return service_impl_.read_some(impl, next_layer, buffers, ec);
}
/// Start an asynchronous read.
template <typename Stream, typename MutableBufferSequence,
typename ReadHandler>
void async_read_some(impl_type& impl, Stream& next_layer,
const MutableBufferSequence& buffers, ReadHandler handler)
{
service_impl_.async_read_some(impl, next_layer, buffers, handler);
}
/// Peek at the incoming data on the stream.
template <typename Stream, typename MutableBufferSequence>
std::size_t peek(impl_type& impl, Stream& next_layer,
const MutableBufferSequence& buffers, boost::system::error_code& ec)
{
return service_impl_.peek(impl, next_layer, buffers, ec);
}
/// Determine the amount of data that may be read without blocking.
template <typename Stream>
std::size_t in_avail(impl_type& impl, Stream& next_layer,
boost::system::error_code& ec)
{
return service_impl_.in_avail(impl, next_layer, ec);
}
private:
// Destroy all user-defined handler objects owned by the service.
void shutdown_service()
{
}
// The service that provides the platform-specific implementation.
service_impl_type& service_impl_;
};
} // namespace old
} // namespace ssl
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_SSL_OLD_STREAM_SERVICE_HPP

View File

@@ -2,7 +2,7 @@
// ssl/rfc2818_verification.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
@@ -17,11 +17,9 @@
#include <boost/asio/detail/config.hpp>
#if !defined(BOOST_ASIO_ENABLE_OLD_SSL)
# include <string>
# include <boost/asio/ssl/detail/openssl_types.hpp>
# include <boost/asio/ssl/verify_context.hpp>
#endif // !defined(BOOST_ASIO_ENABLE_OLD_SSL)
#include <string>
#include <boost/asio/ssl/detail/openssl_types.hpp>
#include <boost/asio/ssl/verify_context.hpp>
#include <boost/asio/detail/push_options.hpp>
@@ -29,8 +27,6 @@ namespace boost {
namespace asio {
namespace ssl {
#if !defined(BOOST_ASIO_ENABLE_OLD_SSL)
/// Verifies a certificate against a hostname according to the rules described
/// in RFC 2818.
/**
@@ -47,9 +43,9 @@ namespace ssl {
* ctx.set_default_verify_paths();
*
* // Open a socket and connect it to the remote host.
* boost::asio::io_service io_service;
* ssl_socket sock(io_service, ctx);
* tcp::resolver resolver(io_service);
* boost::asio::io_context io_context;
* ssl_socket sock(io_context, ctx);
* tcp::resolver resolver(io_context);
* tcp::resolver::query query("host.name", "https");
* boost::asio::connect(sock.lowest_layer(), resolver.resolve(query));
* sock.lowest_layer().set_option(tcp::no_delay(true));
@@ -87,8 +83,6 @@ private:
std::string host_;
};
#endif // defined(BOOST_ASIO_ENABLE_OLD_SSL)
} // namespace ssl
} // namespace asio
} // namespace boost

View File

@@ -2,7 +2,7 @@
// ssl/stream.hpp
// ~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
@@ -17,24 +17,21 @@
#include <boost/asio/detail/config.hpp>
#if defined(BOOST_ASIO_ENABLE_OLD_SSL)
# include <boost/asio/ssl/old/stream.hpp>
#else // defined(BOOST_ASIO_ENABLE_OLD_SSL)
# include <boost/asio/async_result.hpp>
# include <boost/asio/detail/buffer_sequence_adapter.hpp>
# include <boost/asio/detail/handler_type_requirements.hpp>
# include <boost/asio/detail/noncopyable.hpp>
# include <boost/asio/detail/type_traits.hpp>
# include <boost/asio/ssl/context.hpp>
# include <boost/asio/ssl/detail/buffered_handshake_op.hpp>
# include <boost/asio/ssl/detail/handshake_op.hpp>
# include <boost/asio/ssl/detail/io.hpp>
# include <boost/asio/ssl/detail/read_op.hpp>
# include <boost/asio/ssl/detail/shutdown_op.hpp>
# include <boost/asio/ssl/detail/stream_core.hpp>
# include <boost/asio/ssl/detail/write_op.hpp>
# include <boost/asio/ssl/stream_base.hpp>
#endif // defined(BOOST_ASIO_ENABLE_OLD_SSL)
#include <boost/asio/async_result.hpp>
#include <boost/asio/detail/buffer_sequence_adapter.hpp>
#include <boost/asio/detail/handler_type_requirements.hpp>
#include <boost/asio/detail/non_const_lvalue.hpp>
#include <boost/asio/detail/noncopyable.hpp>
#include <boost/asio/detail/type_traits.hpp>
#include <boost/asio/ssl/context.hpp>
#include <boost/asio/ssl/detail/buffered_handshake_op.hpp>
#include <boost/asio/ssl/detail/handshake_op.hpp>
#include <boost/asio/ssl/detail/io.hpp>
#include <boost/asio/ssl/detail/read_op.hpp>
#include <boost/asio/ssl/detail/shutdown_op.hpp>
#include <boost/asio/ssl/detail/stream_core.hpp>
#include <boost/asio/ssl/detail/write_op.hpp>
#include <boost/asio/ssl/stream_base.hpp>
#include <boost/asio/detail/push_options.hpp>
@@ -42,12 +39,6 @@ namespace boost {
namespace asio {
namespace ssl {
#if defined(BOOST_ASIO_ENABLE_OLD_SSL)
using boost::asio::ssl::old::stream;
#else // defined(BOOST_ASIO_ENABLE_OLD_SSL)
/// Provides stream-oriented functionality using SSL.
/**
* The stream class template provides asynchronous and blocking stream-oriented
@@ -62,9 +53,9 @@ using boost::asio::ssl::old::stream;
* @par Example
* To use the SSL stream template with an ip::tcp::socket, you would write:
* @code
* boost::asio::io_service io_service;
* boost::asio::io_context my_context;
* boost::asio::ssl::context ctx(boost::asio::ssl::context::sslv23);
* boost::asio::ssl::stream<asio:ip::tcp::socket> sock(io_service, ctx);
* boost::asio::ssl::stream<asio:ip::tcp::socket> sock(my_context, ctx);
* @endcode
*
* @par Concepts:
@@ -85,15 +76,16 @@ public:
SSL* ssl;
};
/// (Deprecated: Use native_handle_type.) The underlying implementation type.
typedef impl_struct* impl_type;
/// The type of the next layer.
typedef typename remove_reference<Stream>::type next_layer_type;
/// The type of the lowest layer.
typedef typename next_layer_type::lowest_layer_type lowest_layer_type;
/// The type of the executor associated with the object.
typedef typename lowest_layer_type::executor_type executor_type;
#if defined(BOOST_ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
/// Construct a stream.
/**
* This constructor creates a stream and initialises the underlying stream
@@ -104,29 +96,39 @@ public:
* @param ctx The SSL context to be used for the stream.
*/
template <typename Arg>
stream(Arg&& arg, context& ctx)
: next_layer_(BOOST_ASIO_MOVE_CAST(Arg)(arg)),
core_(ctx.native_handle(), next_layer_.lowest_layer().get_executor())
{
}
#else // defined(BOOST_ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
template <typename Arg>
stream(Arg& arg, context& ctx)
: next_layer_(arg),
core_(ctx.native_handle(), next_layer_.lowest_layer().get_io_service())
core_(ctx.native_handle(), next_layer_.lowest_layer().get_executor())
{
backwards_compatible_impl_.ssl = core_.engine_.native_handle();
}
#endif // defined(BOOST_ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
/// Destructor.
/**
* @note A @c stream object must not be destroyed while there are pending
* asynchronous operations associated with it.
*/
~stream()
{
}
/// Get the io_service associated with the object.
/// Get the executor associated with the object.
/**
* This function may be used to obtain the io_service object that the stream
* This function may be used to obtain the executor object that the stream
* uses to dispatch handlers for asynchronous operations.
*
* @return A reference to the io_service object that stream will use to
* dispatch handlers. Ownership is not transferred to the caller.
* @return A copy of the executor that stream will use to dispatch handlers.
*/
boost::asio::io_service& get_io_service()
executor_type get_executor() BOOST_ASIO_NOEXCEPT
{
return next_layer_.lowest_layer().get_io_service();
return next_layer_.lowest_layer().get_executor();
}
/// Get the underlying implementation in the native type.
@@ -140,7 +142,7 @@ public:
* suitable for passing to functions such as @c SSL_get_verify_result and
* @c SSL_get_peer_certificate:
* @code
* boost::asio::ssl::stream<asio:ip::tcp::socket> sock(io_service, ctx);
* boost::asio::ssl::stream<asio:ip::tcp::socket> sock(my_context, ctx);
*
* // ... establish connection and perform handshake ...
*
@@ -158,18 +160,6 @@ public:
return core_.engine_.native_handle();
}
/// (Deprecated: Use native_handle().) Get the underlying implementation in
/// the native type.
/**
* This function may be used to obtain the underlying implementation of the
* context. This is intended to allow access to stream functionality that is
* not otherwise provided.
*/
impl_type impl()
{
return &backwards_compatible_impl_;
}
/// Get a reference to the next layer.
/**
* This function returns a reference to the next layer in a stack of stream
@@ -253,10 +243,11 @@ public:
*
* @note Calls @c SSL_set_verify.
*/
boost::system::error_code set_verify_mode(
BOOST_ASIO_SYNC_OP_VOID set_verify_mode(
verify_mode v, boost::system::error_code& ec)
{
return core_.engine_.set_verify_mode(v, ec);
core_.engine_.set_verify_mode(v, ec);
BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
}
/// Set the peer verification depth.
@@ -290,10 +281,11 @@ public:
*
* @note Calls @c SSL_set_verify_depth.
*/
boost::system::error_code set_verify_depth(
BOOST_ASIO_SYNC_OP_VOID set_verify_depth(
int depth, boost::system::error_code& ec)
{
return core_.engine_.set_verify_depth(depth, ec);
core_.engine_.set_verify_depth(depth, ec);
BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
}
/// Set the callback used to verify peer certificates.
@@ -341,11 +333,12 @@ public:
* @note Calls @c SSL_set_verify.
*/
template <typename VerifyCallback>
boost::system::error_code set_verify_callback(VerifyCallback callback,
BOOST_ASIO_SYNC_OP_VOID set_verify_callback(VerifyCallback callback,
boost::system::error_code& ec)
{
return core_.engine_.set_verify_callback(
core_.engine_.set_verify_callback(
new detail::verify_callback<VerifyCallback>(callback), ec);
BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
}
/// Perform SSL handshaking.
@@ -375,11 +368,11 @@ public:
*
* @param ec Set to indicate what error occurred, if any.
*/
boost::system::error_code handshake(handshake_type type,
BOOST_ASIO_SYNC_OP_VOID handshake(handshake_type type,
boost::system::error_code& ec)
{
detail::io(next_layer_, core_, detail::handshake_op(type), ec);
return ec;
BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
}
/// Perform SSL handshaking.
@@ -415,12 +408,12 @@ public:
* @param ec Set to indicate what error occurred, if any.
*/
template <typename ConstBufferSequence>
boost::system::error_code handshake(handshake_type type,
BOOST_ASIO_SYNC_OP_VOID handshake(handshake_type type,
const ConstBufferSequence& buffers, boost::system::error_code& ec)
{
detail::io(next_layer_, core_,
detail::buffered_handshake_op<ConstBufferSequence>(type, buffers), ec);
return ec;
BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
}
/// Start an asynchronous SSL handshake.
@@ -444,18 +437,9 @@ public:
async_handshake(handshake_type type,
BOOST_ASIO_MOVE_ARG(HandshakeHandler) handler)
{
// If you get an error on the following line it means that your handler does
// not meet the documented type requirements for a HandshakeHandler.
BOOST_ASIO_HANDSHAKE_HANDLER_CHECK(HandshakeHandler, handler) type_check;
boost::asio::detail::async_result_init<
HandshakeHandler, void (boost::system::error_code)> init(
BOOST_ASIO_MOVE_CAST(HandshakeHandler)(handler));
detail::async_io(next_layer_, core_,
detail::handshake_op(type), init.handler);
return init.result.get();
return async_initiate<HandshakeHandler,
void (boost::system::error_code)>(
initiate_async_handshake(), handler, this, type);
}
/// Start an asynchronous SSL handshake.
@@ -485,20 +469,9 @@ public:
async_handshake(handshake_type type, const ConstBufferSequence& buffers,
BOOST_ASIO_MOVE_ARG(BufferedHandshakeHandler) handler)
{
// If you get an error on the following line it means that your handler does
// not meet the documented type requirements for a BufferedHandshakeHandler.
BOOST_ASIO_BUFFERED_HANDSHAKE_HANDLER_CHECK(
BufferedHandshakeHandler, handler) type_check;
boost::asio::detail::async_result_init<BufferedHandshakeHandler,
void (boost::system::error_code, std::size_t)> init(
BOOST_ASIO_MOVE_CAST(BufferedHandshakeHandler)(handler));
detail::async_io(next_layer_, core_,
detail::buffered_handshake_op<ConstBufferSequence>(type, buffers),
init.handler);
return init.result.get();
return async_initiate<BufferedHandshakeHandler,
void (boost::system::error_code, std::size_t)>(
initiate_async_buffered_handshake(), handler, this, type, buffers);
}
/// Shut down SSL on the stream.
@@ -522,10 +495,10 @@ public:
*
* @param ec Set to indicate what error occurred, if any.
*/
boost::system::error_code shutdown(boost::system::error_code& ec)
BOOST_ASIO_SYNC_OP_VOID shutdown(boost::system::error_code& ec)
{
detail::io(next_layer_, core_, detail::shutdown_op(), ec);
return ec;
BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
}
/// Asynchronously shut down SSL on the stream.
@@ -545,17 +518,9 @@ public:
void (boost::system::error_code))
async_shutdown(BOOST_ASIO_MOVE_ARG(ShutdownHandler) handler)
{
// If you get an error on the following line it means that your handler does
// not meet the documented type requirements for a ShutdownHandler.
BOOST_ASIO_SHUTDOWN_HANDLER_CHECK(ShutdownHandler, handler) type_check;
boost::asio::detail::async_result_init<
ShutdownHandler, void (boost::system::error_code)> init(
BOOST_ASIO_MOVE_CAST(ShutdownHandler)(handler));
detail::async_io(next_layer_, core_, detail::shutdown_op(), init.handler);
return init.result.get();
return async_initiate<ShutdownHandler,
void (boost::system::error_code)>(
initiate_async_shutdown(), handler, this);
}
/// Write some data to the stream.
@@ -627,7 +592,8 @@ public:
*
* @note The async_write_some operation may not transmit all of the data to
* the peer. Consider using the @ref async_write function if you need to
* ensure that all data is written before the blocking operation completes.
* ensure that all data is written before the asynchronous operation
* completes.
*/
template <typename ConstBufferSequence, typename WriteHandler>
BOOST_ASIO_INITFN_RESULT_TYPE(WriteHandler,
@@ -635,18 +601,9 @@ public:
async_write_some(const ConstBufferSequence& buffers,
BOOST_ASIO_MOVE_ARG(WriteHandler) handler)
{
// If you get an error on the following line it means that your handler does
// not meet the documented type requirements for a WriteHandler.
BOOST_ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check;
boost::asio::detail::async_result_init<
WriteHandler, void (boost::system::error_code, std::size_t)> init(
BOOST_ASIO_MOVE_CAST(WriteHandler)(handler));
detail::async_io(next_layer_, core_,
detail::write_op<ConstBufferSequence>(buffers), init.handler);
return init.result.get();
return async_initiate<WriteHandler,
void (boost::system::error_code, std::size_t)>(
initiate_async_write_some(), handler, this, buffers);
}
/// Read some data from the stream.
@@ -727,28 +684,101 @@ public:
async_read_some(const MutableBufferSequence& buffers,
BOOST_ASIO_MOVE_ARG(ReadHandler) handler)
{
// If you get an error on the following line it means that your handler does
// not meet the documented type requirements for a ReadHandler.
BOOST_ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check;
boost::asio::detail::async_result_init<
ReadHandler, void (boost::system::error_code, std::size_t)> init(
BOOST_ASIO_MOVE_CAST(ReadHandler)(handler));
detail::async_io(next_layer_, core_,
detail::read_op<MutableBufferSequence>(buffers), init.handler);
return init.result.get();
return async_initiate<ReadHandler,
void (boost::system::error_code, std::size_t)>(
initiate_async_read_some(), handler, this, buffers);
}
private:
struct initiate_async_handshake
{
template <typename HandshakeHandler>
void operator()(BOOST_ASIO_MOVE_ARG(HandshakeHandler) handler,
stream* self, handshake_type type) const
{
// If you get an error on the following line it means that your handler
// does not meet the documented type requirements for a HandshakeHandler.
BOOST_ASIO_HANDSHAKE_HANDLER_CHECK(HandshakeHandler, handler) type_check;
boost::asio::detail::non_const_lvalue<HandshakeHandler> handler2(handler);
detail::async_io(self->next_layer_, self->core_,
detail::handshake_op(type), handler2.value);
}
};
struct initiate_async_buffered_handshake
{
template <typename BufferedHandshakeHandler, typename ConstBufferSequence>
void operator()(BOOST_ASIO_MOVE_ARG(BufferedHandshakeHandler) handler,
stream* self, handshake_type type,
const ConstBufferSequence& buffers) const
{
// If you get an error on the following line it means that your
// handler does not meet the documented type requirements for a
// BufferedHandshakeHandler.
BOOST_ASIO_BUFFERED_HANDSHAKE_HANDLER_CHECK(
BufferedHandshakeHandler, handler) type_check;
boost::asio::detail::non_const_lvalue<
BufferedHandshakeHandler> handler2(handler);
detail::async_io(self->next_layer_, self->core_,
detail::buffered_handshake_op<ConstBufferSequence>(type, buffers),
handler2.value);
}
};
struct initiate_async_shutdown
{
template <typename ShutdownHandler>
void operator()(BOOST_ASIO_MOVE_ARG(ShutdownHandler) handler,
stream* self) const
{
// If you get an error on the following line it means that your handler
// does not meet the documented type requirements for a ShutdownHandler.
BOOST_ASIO_HANDSHAKE_HANDLER_CHECK(ShutdownHandler, handler) type_check;
boost::asio::detail::non_const_lvalue<ShutdownHandler> handler2(handler);
detail::async_io(self->next_layer_, self->core_,
detail::shutdown_op(), handler2.value);
}
};
struct initiate_async_write_some
{
template <typename WriteHandler, typename ConstBufferSequence>
void operator()(BOOST_ASIO_MOVE_ARG(WriteHandler) handler,
stream* self, const ConstBufferSequence& buffers) const
{
// If you get an error on the following line it means that your handler
// does not meet the documented type requirements for a WriteHandler.
BOOST_ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check;
boost::asio::detail::non_const_lvalue<WriteHandler> handler2(handler);
detail::async_io(self->next_layer_, self->core_,
detail::write_op<ConstBufferSequence>(buffers), handler2.value);
}
};
struct initiate_async_read_some
{
template <typename ReadHandler, typename MutableBufferSequence>
void operator()(BOOST_ASIO_MOVE_ARG(ReadHandler) handler,
stream* self, const MutableBufferSequence& buffers) const
{
// If you get an error on the following line it means that your handler
// does not meet the documented type requirements for a ReadHandler.
BOOST_ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check;
boost::asio::detail::non_const_lvalue<ReadHandler> handler2(handler);
detail::async_io(self->next_layer_, self->core_,
detail::read_op<MutableBufferSequence>(buffers), handler2.value);
}
};
Stream next_layer_;
detail::stream_core core_;
impl_struct backwards_compatible_impl_;
};
#endif // defined(BOOST_ASIO_ENABLE_OLD_SSL)
} // namespace ssl
} // namespace asio
} // namespace boost

View File

@@ -2,7 +2,7 @@
// ssl/stream_base.hpp
// ~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

View File

@@ -1,42 +0,0 @@
//
// ssl/stream_service.hpp
// ~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef BOOST_ASIO_SSL_STREAM_SERVICE_HPP
#define BOOST_ASIO_SSL_STREAM_SERVICE_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/config.hpp>
#if defined(BOOST_ASIO_ENABLE_OLD_SSL)
# include <boost/asio/ssl/old/stream_service.hpp>
#endif // defined(BOOST_ASIO_ENABLE_OLD_SSL)
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
namespace ssl {
#if defined(BOOST_ASIO_ENABLE_OLD_SSL)
using boost::asio::ssl::old::stream_service;
#endif // defined(BOOST_ASIO_ENABLE_OLD_SSL)
} // namespace ssl
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_SSL_STREAM_SERVICE_HPP

View File

@@ -2,7 +2,7 @@
// ssl/verify_context.hpp
// ~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
@@ -17,10 +17,8 @@
#include <boost/asio/detail/config.hpp>
#if !defined(BOOST_ASIO_ENABLE_OLD_SSL)
# include <boost/asio/detail/noncopyable.hpp>
# include <boost/asio/ssl/detail/openssl_types.hpp>
#endif // !defined(BOOST_ASIO_ENABLE_OLD_SSL)
#include <boost/asio/detail/noncopyable.hpp>
#include <boost/asio/ssl/detail/openssl_types.hpp>
#include <boost/asio/detail/push_options.hpp>
@@ -28,8 +26,6 @@ namespace boost {
namespace asio {
namespace ssl {
#if !defined(BOOST_ASIO_ENABLE_OLD_SSL)
/// A simple wrapper around the X509_STORE_CTX type, used during verification of
/// a peer certificate.
/**
@@ -64,8 +60,6 @@ private:
native_handle_type handle_;
};
#endif // defined(BOOST_ASIO_ENABLE_OLD_SSL)
} // namespace ssl
} // namespace asio
} // namespace boost

View File

@@ -2,7 +2,7 @@
// ssl/verify_mode.hpp
// ~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)