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