Verifies a certificate against a host_name according to the rules described in RFC 6125.
class host_name_verification
Name |
Description |
---|---|
The type of the function object's result. |
Name |
Description |
---|---|
host_name_verification [constructor] |
Constructor. |
Perform certificate verification. |
The following example shows how to synchronously open a secure connection to a given host name:
using asio::ip::tcp; namespace ssl = asio::ssl; typedef ssl::stream<tcp::socket> ssl_socket; // Create a context that uses the default paths for finding CA certificates. ssl::context ctx(ssl::context::sslv23); ctx.set_default_verify_paths(); // Open a socket and connect it to the remote host. asio::io_context io_context; ssl_socket sock(io_context, ctx); tcp::resolver resolver(io_context); tcp::resolver::query query("host.name", "https"); asio::connect(sock.lowest_layer(), resolver.resolve(query)); sock.lowest_layer().set_option(tcp::no_delay(true)); // Perform SSL handshake and verify the remote host's certificate. sock.set_verify_mode(ssl::verify_peer); sock.set_verify_callback(ssl::host_name_verification("host.name")); sock.handshake(ssl_socket::client); // ... read and write as normal ...
Header: asio/ssl/host_name_verification.hpp
Convenience header: asio/ssl.hpp