annotate DEPENDENCIES/generic/include/boost/asio/ssl/rfc2818_verification.hpp @ 133:4acb5d8d80b6 tip

Don't fail environmental check if README.md exists (but .txt and no-suffix don't)
author Chris Cannam
date Tue, 30 Jul 2019 12:25:44 +0100
parents c530137014c0
children
rev   line source
Chris@16 1 //
Chris@16 2 // ssl/rfc2818_verification.hpp
Chris@16 3 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Chris@16 4 //
Chris@101 5 // Copyright (c) 2003-2015 Christopher M. Kohlhoff (chris at kohlhoff dot com)
Chris@16 6 //
Chris@16 7 // Distributed under the Boost Software License, Version 1.0. (See accompanying
Chris@16 8 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
Chris@16 9 //
Chris@16 10
Chris@16 11 #ifndef BOOST_ASIO_SSL_RFC2818_VERIFICATION_HPP
Chris@16 12 #define BOOST_ASIO_SSL_RFC2818_VERIFICATION_HPP
Chris@16 13
Chris@16 14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
Chris@16 15 # pragma once
Chris@16 16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
Chris@16 17
Chris@16 18 #include <boost/asio/detail/config.hpp>
Chris@16 19
Chris@16 20 #if !defined(BOOST_ASIO_ENABLE_OLD_SSL)
Chris@16 21 # include <string>
Chris@16 22 # include <boost/asio/ssl/detail/openssl_types.hpp>
Chris@16 23 # include <boost/asio/ssl/verify_context.hpp>
Chris@16 24 #endif // !defined(BOOST_ASIO_ENABLE_OLD_SSL)
Chris@16 25
Chris@16 26 #include <boost/asio/detail/push_options.hpp>
Chris@16 27
Chris@16 28 namespace boost {
Chris@16 29 namespace asio {
Chris@16 30 namespace ssl {
Chris@16 31
Chris@16 32 #if !defined(BOOST_ASIO_ENABLE_OLD_SSL)
Chris@16 33
Chris@16 34 /// Verifies a certificate against a hostname according to the rules described
Chris@16 35 /// in RFC 2818.
Chris@16 36 /**
Chris@16 37 * @par Example
Chris@16 38 * The following example shows how to synchronously open a secure connection to
Chris@16 39 * a given host name:
Chris@16 40 * @code
Chris@16 41 * using boost::asio::ip::tcp;
Chris@16 42 * namespace ssl = boost::asio::ssl;
Chris@16 43 * typedef ssl::stream<tcp::socket> ssl_socket;
Chris@16 44 *
Chris@16 45 * // Create a context that uses the default paths for finding CA certificates.
Chris@16 46 * ssl::context ctx(ssl::context::sslv23);
Chris@16 47 * ctx.set_default_verify_paths();
Chris@16 48 *
Chris@16 49 * // Open a socket and connect it to the remote host.
Chris@16 50 * boost::asio::io_service io_service;
Chris@16 51 * ssl_socket sock(io_service, ctx);
Chris@16 52 * tcp::resolver resolver(io_service);
Chris@16 53 * tcp::resolver::query query("host.name", "https");
Chris@16 54 * boost::asio::connect(sock.lowest_layer(), resolver.resolve(query));
Chris@16 55 * sock.lowest_layer().set_option(tcp::no_delay(true));
Chris@16 56 *
Chris@16 57 * // Perform SSL handshake and verify the remote host's certificate.
Chris@16 58 * sock.set_verify_mode(ssl::verify_peer);
Chris@16 59 * sock.set_verify_callback(ssl::rfc2818_verification("host.name"));
Chris@16 60 * sock.handshake(ssl_socket::client);
Chris@16 61 *
Chris@16 62 * // ... read and write as normal ...
Chris@16 63 * @endcode
Chris@16 64 */
Chris@16 65 class rfc2818_verification
Chris@16 66 {
Chris@16 67 public:
Chris@16 68 /// The type of the function object's result.
Chris@16 69 typedef bool result_type;
Chris@16 70
Chris@16 71 /// Constructor.
Chris@16 72 explicit rfc2818_verification(const std::string& host)
Chris@16 73 : host_(host)
Chris@16 74 {
Chris@16 75 }
Chris@16 76
Chris@16 77 /// Perform certificate verification.
Chris@16 78 BOOST_ASIO_DECL bool operator()(bool preverified, verify_context& ctx) const;
Chris@16 79
Chris@16 80 private:
Chris@16 81 // Helper function to check a host name against a pattern.
Chris@16 82 BOOST_ASIO_DECL static bool match_pattern(const char* pattern,
Chris@16 83 std::size_t pattern_length, const char* host);
Chris@16 84
Chris@16 85 // Helper function to check a host name against an IPv4 address
Chris@16 86 // The host name to be checked.
Chris@16 87 std::string host_;
Chris@16 88 };
Chris@16 89
Chris@16 90 #endif // defined(BOOST_ASIO_ENABLE_OLD_SSL)
Chris@16 91
Chris@16 92 } // namespace ssl
Chris@16 93 } // namespace asio
Chris@16 94 } // namespace boost
Chris@16 95
Chris@16 96 #include <boost/asio/detail/pop_options.hpp>
Chris@16 97
Chris@16 98 #if defined(BOOST_ASIO_HEADER_ONLY)
Chris@16 99 # include <boost/asio/ssl/impl/rfc2818_verification.ipp>
Chris@16 100 #endif // defined(BOOST_ASIO_HEADER_ONLY)
Chris@16 101
Chris@16 102 #endif // BOOST_ASIO_SSL_RFC2818_VERIFICATION_HPP