12 #ifndef ASIO_SSL_OLD_DETAIL_OPENSSL_CONTEXT_SERVICE_HPP 13 #define ASIO_SSL_OLD_DETAIL_OPENSSL_CONTEXT_SERVICE_HPP 15 #if defined(_MSC_VER) && (_MSC_VER >= 1200) 17 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) 22 #include <boost/function.hpp> 45 typedef boost::function<std::string(std::size_t,
70 #if defined(OPENSSL_NO_SSL2) 76 #else // defined(OPENSSL_NO_SSL2) 78 impl = ::SSL_CTX_new(::SSLv2_method());
81 impl = ::SSL_CTX_new(::SSLv2_client_method());
84 impl = ::SSL_CTX_new(::SSLv2_server_method());
86 #endif // defined(OPENSSL_NO_SSL2) 88 impl = ::SSL_CTX_new(::SSLv3_method());
91 impl = ::SSL_CTX_new(::SSLv3_client_method());
94 impl = ::SSL_CTX_new(::SSLv3_server_method());
97 impl = ::SSL_CTX_new(::TLSv1_method());
100 impl = ::SSL_CTX_new(::TLSv1_client_method());
103 impl = ::SSL_CTX_new(::TLSv1_server_method());
106 impl = ::SSL_CTX_new(::SSLv23_method());
109 impl = ::SSL_CTX_new(::SSLv23_client_method());
112 impl = ::SSL_CTX_new(::SSLv23_server_method());
115 impl = ::SSL_CTX_new(0);
125 if (impl->default_passwd_callback_userdata)
127 password_callback_type* callback =
128 static_cast<password_callback_type*
>(
129 impl->default_passwd_callback_userdata);
131 impl->default_passwd_callback_userdata = 0;
134 ::SSL_CTX_free(impl);
143 ::SSL_CTX_set_options(impl, o);
153 ::SSL_CTX_set_verify(impl, v, 0);
163 if (::SSL_CTX_load_verify_locations(impl, filename.c_str(), 0) != 1)
178 if (::SSL_CTX_load_verify_locations(impl, 0, path.c_str()) != 1)
197 file_type = SSL_FILETYPE_ASN1;
200 file_type = SSL_FILETYPE_PEM;
209 if (::SSL_CTX_use_certificate_file(impl, filename.c_str(), file_type) != 1)
223 if (::SSL_CTX_use_certificate_chain_file(impl, filename.c_str()) != 1)
242 file_type = SSL_FILETYPE_ASN1;
245 file_type = SSL_FILETYPE_PEM;
254 if (::SSL_CTX_use_PrivateKey_file(impl, filename.c_str(), file_type) != 1)
273 file_type = SSL_FILETYPE_ASN1;
276 file_type = SSL_FILETYPE_PEM;
285 if (::SSL_CTX_use_RSAPrivateKey_file(
286 impl, filename.c_str(), file_type) != 1)
300 ::BIO* bio = ::BIO_new_file(filename.c_str(),
"r");
307 ::DH* dh = ::PEM_read_bio_DHparams(bio, 0, 0, 0);
316 int result = ::SSL_CTX_set_tmp_dh(impl, dh);
334 password_callback_type* callback =
335 static_cast<password_callback_type*
>(data);
336 std::string passwd = (*callback)(
static_cast<std::size_t
>(size),
339 strncat(buf, passwd.c_str(), size);
347 template <
typename Password_Callback>
352 if (impl->default_passwd_callback_userdata)
354 password_callback_type* callback_function =
355 static_cast<password_callback_type*
>(
356 impl->default_passwd_callback_userdata);
357 *callback_function = callback;
361 password_callback_type* callback_function =
363 impl->default_passwd_callback_userdata = callback_function;
367 SSL_CTX_set_default_passwd_cb(impl,
386 #endif // ASIO_SSL_OLD_DETAIL_OPENSSL_CONTEXT_SERVICE_HPP The password is needed for reading/decryption.
asio::error_code set_verify_mode(impl_type &impl, context_base::verify_mode v, asio::error_code &ec)
asio::error_code load_verify_file(impl_type &impl, const std::string &filename, asio::error_code &ec)
void throw_error(const asio::error_code &err)
void destroy(impl_type &impl)
boost::function< std::string(std::size_t, context_base::password_purpose)> password_callback_type
Provides core I/O functionality.
asio::error_code set_password_callback(impl_type &impl, Password_Callback callback, asio::error_code &ec)
openssl_context_service(asio::io_service &io_service)
static int password_callback(char *buf, int size, int purpose, void *data)
asio::error_code use_tmp_dh_file(impl_type &impl, const std::string &filename, asio::error_code &ec)
asio::error_code use_certificate_chain_file(impl_type &impl, const std::string &filename, asio::error_code &ec)
method
Different methods supported by a context.
asio::error_code use_private_key_file(impl_type &impl, const std::string &filename, context_base::file_format format, asio::error_code &ec)
asio::error_code use_rsa_private_key_file(impl_type &impl, const std::string &filename, context_base::file_format format, asio::error_code &ec)
asio::error_code set_options(impl_type &impl, context_base::options o, asio::error_code &ec)
asio::error_code use_certificate_file(impl_type &impl, const std::string &filename, context_base::file_format format, asio::error_code &ec)
Class to represent an error code value.
void create(impl_type &impl, context_base::method m)
password_purpose
Purpose of PEM password.
void shutdown_service()
Destroy all user-defined handler objects owned by the service.
asio::error_code add_verify_path(impl_type &impl, const std::string &path, asio::error_code &ec)
The password is needed for writing/encryption.
service_base(asio::io_service &io_service)
long options
Bitmask type for SSL options.
file_format
File format types.