File indexing completed on 2025-01-18 09:29:02
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef BOOST_ASIO_SSL_IMPL_HOST_NAME_VERIFICATION_IPP
0012 #define BOOST_ASIO_SSL_IMPL_HOST_NAME_VERIFICATION_IPP
0013
0014 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
0015 # pragma once
0016 #endif
0017
0018 #include <boost/asio/detail/config.hpp>
0019
0020 #include <cctype>
0021 #include <cstring>
0022 #include <boost/asio/ip/address.hpp>
0023 #include <boost/asio/ssl/host_name_verification.hpp>
0024 #include <boost/asio/ssl/detail/openssl_types.hpp>
0025
0026 #include <boost/asio/detail/push_options.hpp>
0027
0028 namespace boost {
0029 namespace asio {
0030 namespace ssl {
0031
0032 bool host_name_verification::operator()(
0033 bool preverified, verify_context& ctx) const
0034 {
0035 using namespace std;
0036
0037
0038 if (!preverified)
0039 return false;
0040
0041
0042 int depth = X509_STORE_CTX_get_error_depth(ctx.native_handle());
0043 if (depth > 0)
0044 return true;
0045
0046
0047
0048 boost::system::error_code ec;
0049 ip::address address = ip::make_address(host_, ec);
0050 const bool is_address = !ec;
0051 (void)address;
0052
0053 X509* cert = X509_STORE_CTX_get_current_cert(ctx.native_handle());
0054
0055 if (is_address)
0056 {
0057 return X509_check_ip_asc(cert, host_.c_str(), 0) == 1;
0058 }
0059 else
0060 {
0061 char* peername = 0;
0062 const int result = X509_check_host(cert,
0063 host_.c_str(), host_.size(), 0, &peername);
0064 OPENSSL_free(peername);
0065 return result == 1;
0066 }
0067 }
0068
0069 }
0070 }
0071 }
0072
0073 #include <boost/asio/detail/pop_options.hpp>
0074
0075 #endif