Initial Commit
This commit is contained in:
67
include/asio/ssl/impl/context.hpp
Normal file
67
include/asio/ssl/impl/context.hpp
Normal file
@@ -0,0 +1,67 @@
|
||||
//
|
||||
// ssl/impl/context.hpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2005 Voipster / Indrek dot Juhani at voipster dot com
|
||||
// Copyright (c) 2005-2025 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 ASIO_SSL_IMPL_CONTEXT_HPP
|
||||
#define ASIO_SSL_IMPL_CONTEXT_HPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
#include "asio/detail/config.hpp"
|
||||
|
||||
#include "asio/detail/throw_error.hpp"
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
|
||||
namespace asio {
|
||||
namespace ssl {
|
||||
|
||||
template <typename VerifyCallback>
|
||||
void context::set_verify_callback(VerifyCallback callback)
|
||||
{
|
||||
asio::error_code ec;
|
||||
this->set_verify_callback(callback, ec);
|
||||
asio::detail::throw_error(ec, "set_verify_callback");
|
||||
}
|
||||
|
||||
template <typename VerifyCallback>
|
||||
ASIO_SYNC_OP_VOID context::set_verify_callback(
|
||||
VerifyCallback callback, asio::error_code& ec)
|
||||
{
|
||||
do_set_verify_callback(
|
||||
new detail::verify_callback<VerifyCallback>(callback), ec);
|
||||
ASIO_SYNC_OP_VOID_RETURN(ec);
|
||||
}
|
||||
|
||||
template <typename PasswordCallback>
|
||||
void context::set_password_callback(PasswordCallback callback)
|
||||
{
|
||||
asio::error_code ec;
|
||||
this->set_password_callback(callback, ec);
|
||||
asio::detail::throw_error(ec, "set_password_callback");
|
||||
}
|
||||
|
||||
template <typename PasswordCallback>
|
||||
ASIO_SYNC_OP_VOID context::set_password_callback(
|
||||
PasswordCallback callback, asio::error_code& ec)
|
||||
{
|
||||
do_set_password_callback(
|
||||
new detail::password_callback<PasswordCallback>(callback), ec);
|
||||
ASIO_SYNC_OP_VOID_RETURN(ec);
|
||||
}
|
||||
|
||||
} // namespace ssl
|
||||
} // namespace asio
|
||||
|
||||
#include "asio/detail/pop_options.hpp"
|
||||
|
||||
#endif // ASIO_SSL_IMPL_CONTEXT_HPP
|
||||
1322
include/asio/ssl/impl/context.ipp
Normal file
1322
include/asio/ssl/impl/context.ipp
Normal file
File diff suppressed because it is too large
Load Diff
124
include/asio/ssl/impl/error.ipp
Normal file
124
include/asio/ssl/impl/error.ipp
Normal file
@@ -0,0 +1,124 @@
|
||||
//
|
||||
// ssl/impl/error.ipp
|
||||
// ~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2025 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 ASIO_SSL_IMPL_ERROR_IPP
|
||||
#define ASIO_SSL_IMPL_ERROR_IPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
#include "asio/detail/config.hpp"
|
||||
#include "asio/ssl/error.hpp"
|
||||
#include "asio/ssl/detail/openssl_init.hpp"
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
|
||||
namespace asio {
|
||||
namespace error {
|
||||
namespace detail {
|
||||
|
||||
class ssl_category : public asio::error_category
|
||||
{
|
||||
public:
|
||||
const char* name() const noexcept
|
||||
{
|
||||
return "asio.ssl";
|
||||
}
|
||||
|
||||
std::string message(int value) const
|
||||
{
|
||||
const char* reason = ::ERR_reason_error_string(value);
|
||||
if (reason)
|
||||
{
|
||||
const char* lib = ::ERR_lib_error_string(value);
|
||||
#if (OPENSSL_VERSION_NUMBER < 0x30000000L)
|
||||
const char* func = ::ERR_func_error_string(value);
|
||||
#else // (OPENSSL_VERSION_NUMBER < 0x30000000L)
|
||||
const char* func = 0;
|
||||
#endif // (OPENSSL_VERSION_NUMBER < 0x30000000L)
|
||||
std::string result(reason);
|
||||
if (lib || func)
|
||||
{
|
||||
result += " (";
|
||||
if (lib)
|
||||
result += lib;
|
||||
if (lib && func)
|
||||
result += ", ";
|
||||
if (func)
|
||||
result += func;
|
||||
result += ")";
|
||||
}
|
||||
return result;
|
||||
}
|
||||
return "asio.ssl error";
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
const asio::error_category& get_ssl_category()
|
||||
{
|
||||
static detail::ssl_category instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
} // namespace error
|
||||
namespace ssl {
|
||||
namespace error {
|
||||
|
||||
#if (OPENSSL_VERSION_NUMBER < 0x10100000L) && !defined(OPENSSL_IS_BORINGSSL)
|
||||
|
||||
const asio::error_category& get_stream_category()
|
||||
{
|
||||
return asio::error::get_ssl_category();
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
namespace detail {
|
||||
|
||||
class stream_category : public asio::error_category
|
||||
{
|
||||
public:
|
||||
const char* name() const noexcept
|
||||
{
|
||||
return "asio.ssl.stream";
|
||||
}
|
||||
|
||||
std::string message(int value) const
|
||||
{
|
||||
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";
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
const asio::error_category& get_stream_category()
|
||||
{
|
||||
static detail::stream_category instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
} // namespace error
|
||||
} // namespace ssl
|
||||
} // namespace asio
|
||||
|
||||
#include "asio/detail/pop_options.hpp"
|
||||
|
||||
#endif // ASIO_SSL_IMPL_ERROR_IPP
|
||||
73
include/asio/ssl/impl/host_name_verification.ipp
Normal file
73
include/asio/ssl/impl/host_name_verification.ipp
Normal file
@@ -0,0 +1,73 @@
|
||||
//
|
||||
// ssl/impl/host_name_verification.ipp
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2025 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 ASIO_SSL_IMPL_HOST_NAME_VERIFICATION_IPP
|
||||
#define ASIO_SSL_IMPL_HOST_NAME_VERIFICATION_IPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
#include "asio/detail/config.hpp"
|
||||
|
||||
#include <cctype>
|
||||
#include <cstring>
|
||||
#include "asio/ip/address.hpp"
|
||||
#include "asio/ssl/host_name_verification.hpp"
|
||||
#include "asio/ssl/detail/openssl_types.hpp"
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
|
||||
namespace asio {
|
||||
namespace ssl {
|
||||
|
||||
bool host_name_verification::operator()(
|
||||
bool preverified, verify_context& ctx) const
|
||||
{
|
||||
using namespace std; // For memcmp.
|
||||
|
||||
// Don't bother looking at certificates that have failed pre-verification.
|
||||
if (!preverified)
|
||||
return false;
|
||||
|
||||
// We're only interested in checking the certificate at the end of the chain.
|
||||
int depth = X509_STORE_CTX_get_error_depth(ctx.native_handle());
|
||||
if (depth > 0)
|
||||
return true;
|
||||
|
||||
// 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.
|
||||
asio::error_code ec;
|
||||
ip::address address = ip::make_address(host_, ec);
|
||||
const bool is_address = !ec;
|
||||
(void)address;
|
||||
|
||||
X509* cert = X509_STORE_CTX_get_current_cert(ctx.native_handle());
|
||||
|
||||
if (is_address)
|
||||
{
|
||||
return X509_check_ip_asc(cert, host_.c_str(), 0) == 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
char* peername = 0;
|
||||
const int result = X509_check_host(cert,
|
||||
host_.c_str(), host_.size(), 0, &peername);
|
||||
OPENSSL_free(peername);
|
||||
return result == 1;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace ssl
|
||||
} // namespace asio
|
||||
|
||||
#include "asio/detail/pop_options.hpp"
|
||||
|
||||
#endif // ASIO_SSL_IMPL_HOST_NAME_VERIFICATION_IPP
|
||||
28
include/asio/ssl/impl/src.hpp
Normal file
28
include/asio/ssl/impl/src.hpp
Normal file
@@ -0,0 +1,28 @@
|
||||
//
|
||||
// impl/ssl/src.hpp
|
||||
// ~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2025 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 ASIO_SSL_IMPL_SRC_HPP
|
||||
#define ASIO_SSL_IMPL_SRC_HPP
|
||||
|
||||
#define ASIO_SOURCE
|
||||
|
||||
#include "asio/detail/config.hpp"
|
||||
|
||||
#if defined(ASIO_HEADER_ONLY)
|
||||
# error Do not compile Asio library source with ASIO_HEADER_ONLY defined
|
||||
#endif
|
||||
|
||||
#include "asio/ssl/impl/context.ipp"
|
||||
#include "asio/ssl/impl/error.ipp"
|
||||
#include "asio/ssl/detail/impl/engine.ipp"
|
||||
#include "asio/ssl/detail/impl/openssl_init.ipp"
|
||||
#include "asio/ssl/impl/host_name_verification.ipp"
|
||||
|
||||
#endif // ASIO_SSL_IMPL_SRC_HPP
|
||||
Reference in New Issue
Block a user