annotate DEPENDENCIES/generic/include/boost/asio/ssl/context.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/context.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_CONTEXT_HPP
Chris@16 12 #define BOOST_ASIO_SSL_CONTEXT_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 <boost/asio/ssl/basic_context.hpp>
Chris@16 22 # include <boost/asio/ssl/context_service.hpp>
Chris@16 23 #else // defined(BOOST_ASIO_ENABLE_OLD_SSL)
Chris@16 24 # include <string>
Chris@16 25 # include <boost/asio/buffer.hpp>
Chris@16 26 # include <boost/asio/io_service.hpp>
Chris@16 27 # include <boost/asio/ssl/context_base.hpp>
Chris@16 28 # include <boost/asio/ssl/detail/openssl_types.hpp>
Chris@16 29 # include <boost/asio/ssl/detail/openssl_init.hpp>
Chris@16 30 # include <boost/asio/ssl/detail/password_callback.hpp>
Chris@16 31 # include <boost/asio/ssl/detail/verify_callback.hpp>
Chris@16 32 # include <boost/asio/ssl/verify_mode.hpp>
Chris@16 33 #endif // defined(BOOST_ASIO_ENABLE_OLD_SSL)
Chris@16 34
Chris@16 35 #include <boost/asio/detail/push_options.hpp>
Chris@16 36
Chris@16 37 namespace boost {
Chris@16 38 namespace asio {
Chris@16 39 namespace ssl {
Chris@16 40
Chris@16 41 #if defined(BOOST_ASIO_ENABLE_OLD_SSL)
Chris@16 42
Chris@16 43 /// Typedef for the typical usage of context.
Chris@16 44 typedef basic_context<context_service> context;
Chris@16 45
Chris@16 46 #else // defined(BOOST_ASIO_ENABLE_OLD_SSL)
Chris@16 47
Chris@16 48 class context
Chris@16 49 : public context_base,
Chris@16 50 private noncopyable
Chris@16 51 {
Chris@16 52 public:
Chris@16 53 /// The native handle type of the SSL context.
Chris@16 54 typedef SSL_CTX* native_handle_type;
Chris@16 55
Chris@16 56 /// (Deprecated: Use native_handle_type.) The native type of the SSL context.
Chris@16 57 typedef SSL_CTX* impl_type;
Chris@16 58
Chris@16 59 /// Constructor.
Chris@16 60 BOOST_ASIO_DECL explicit context(method m);
Chris@16 61
Chris@16 62 /// Deprecated constructor taking a reference to an io_service object.
Chris@16 63 BOOST_ASIO_DECL context(boost::asio::io_service&, method m);
Chris@16 64
Chris@16 65 #if defined(BOOST_ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
Chris@16 66 /// Move-construct a context from another.
Chris@16 67 /**
Chris@16 68 * This constructor moves an SSL context from one object to another.
Chris@16 69 *
Chris@16 70 * @param other The other context object from which the move will occur.
Chris@16 71 *
Chris@16 72 * @note Following the move, the following operations only are valid for the
Chris@16 73 * moved-from object:
Chris@16 74 * @li Destruction.
Chris@16 75 * @li As a target for move-assignment.
Chris@16 76 */
Chris@16 77 BOOST_ASIO_DECL context(context&& other);
Chris@16 78
Chris@16 79 /// Move-assign a context from another.
Chris@16 80 /**
Chris@16 81 * This assignment operator moves an SSL context from one object to another.
Chris@16 82 *
Chris@16 83 * @param other The other context object from which the move will occur.
Chris@16 84 *
Chris@16 85 * @note Following the move, the following operations only are valid for the
Chris@16 86 * moved-from object:
Chris@16 87 * @li Destruction.
Chris@16 88 * @li As a target for move-assignment.
Chris@16 89 */
Chris@16 90 BOOST_ASIO_DECL context& operator=(context&& other);
Chris@16 91 #endif // defined(BOOST_ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
Chris@16 92
Chris@16 93 /// Destructor.
Chris@16 94 BOOST_ASIO_DECL ~context();
Chris@16 95
Chris@16 96 /// Get the underlying implementation in the native type.
Chris@16 97 /**
Chris@16 98 * This function may be used to obtain the underlying implementation of the
Chris@16 99 * context. This is intended to allow access to context functionality that is
Chris@16 100 * not otherwise provided.
Chris@16 101 */
Chris@16 102 BOOST_ASIO_DECL native_handle_type native_handle();
Chris@16 103
Chris@16 104 /// (Deprecated: Use native_handle().) Get the underlying implementation in
Chris@16 105 /// the native type.
Chris@16 106 /**
Chris@16 107 * This function may be used to obtain the underlying implementation of the
Chris@16 108 * context. This is intended to allow access to context functionality that is
Chris@16 109 * not otherwise provided.
Chris@16 110 */
Chris@16 111 BOOST_ASIO_DECL impl_type impl();
Chris@16 112
Chris@16 113 /// Clear options on the context.
Chris@16 114 /**
Chris@16 115 * This function may be used to configure the SSL options used by the context.
Chris@16 116 *
Chris@16 117 * @param o A bitmask of options. The available option values are defined in
Chris@16 118 * the context_base class. The specified options, if currently enabled on the
Chris@16 119 * context, are cleared.
Chris@16 120 *
Chris@16 121 * @throws boost::system::system_error Thrown on failure.
Chris@16 122 *
Chris@16 123 * @note Calls @c SSL_CTX_clear_options.
Chris@16 124 */
Chris@16 125 BOOST_ASIO_DECL void clear_options(options o);
Chris@16 126
Chris@16 127 /// Clear options on the context.
Chris@16 128 /**
Chris@16 129 * This function may be used to configure the SSL options used by the context.
Chris@16 130 *
Chris@16 131 * @param o A bitmask of options. The available option values are defined in
Chris@16 132 * the context_base class. The specified options, if currently enabled on the
Chris@16 133 * context, are cleared.
Chris@16 134 *
Chris@16 135 * @param ec Set to indicate what error occurred, if any.
Chris@16 136 *
Chris@16 137 * @note Calls @c SSL_CTX_clear_options.
Chris@16 138 */
Chris@16 139 BOOST_ASIO_DECL boost::system::error_code clear_options(options o,
Chris@16 140 boost::system::error_code& ec);
Chris@16 141
Chris@16 142 /// Set options on the context.
Chris@16 143 /**
Chris@16 144 * This function may be used to configure the SSL options used by the context.
Chris@16 145 *
Chris@16 146 * @param o A bitmask of options. The available option values are defined in
Chris@16 147 * the context_base class. The options are bitwise-ored with any existing
Chris@16 148 * value for the options.
Chris@16 149 *
Chris@16 150 * @throws boost::system::system_error Thrown on failure.
Chris@16 151 *
Chris@16 152 * @note Calls @c SSL_CTX_set_options.
Chris@16 153 */
Chris@16 154 BOOST_ASIO_DECL void set_options(options o);
Chris@16 155
Chris@16 156 /// Set options on the context.
Chris@16 157 /**
Chris@16 158 * This function may be used to configure the SSL options used by the context.
Chris@16 159 *
Chris@16 160 * @param o A bitmask of options. The available option values are defined in
Chris@16 161 * the context_base class. The options are bitwise-ored with any existing
Chris@16 162 * value for the options.
Chris@16 163 *
Chris@16 164 * @param ec Set to indicate what error occurred, if any.
Chris@16 165 *
Chris@16 166 * @note Calls @c SSL_CTX_set_options.
Chris@16 167 */
Chris@16 168 BOOST_ASIO_DECL boost::system::error_code set_options(options o,
Chris@16 169 boost::system::error_code& ec);
Chris@16 170
Chris@16 171 /// Set the peer verification mode.
Chris@16 172 /**
Chris@16 173 * This function may be used to configure the peer verification mode used by
Chris@16 174 * the context.
Chris@16 175 *
Chris@16 176 * @param v A bitmask of peer verification modes. See @ref verify_mode for
Chris@16 177 * available values.
Chris@16 178 *
Chris@16 179 * @throws boost::system::system_error Thrown on failure.
Chris@16 180 *
Chris@16 181 * @note Calls @c SSL_CTX_set_verify.
Chris@16 182 */
Chris@16 183 BOOST_ASIO_DECL void set_verify_mode(verify_mode v);
Chris@16 184
Chris@16 185 /// Set the peer verification mode.
Chris@16 186 /**
Chris@16 187 * This function may be used to configure the peer verification mode used by
Chris@16 188 * the context.
Chris@16 189 *
Chris@16 190 * @param v A bitmask of peer verification modes. See @ref verify_mode for
Chris@16 191 * available values.
Chris@16 192 *
Chris@16 193 * @param ec Set to indicate what error occurred, if any.
Chris@16 194 *
Chris@16 195 * @note Calls @c SSL_CTX_set_verify.
Chris@16 196 */
Chris@16 197 BOOST_ASIO_DECL boost::system::error_code set_verify_mode(
Chris@16 198 verify_mode v, boost::system::error_code& ec);
Chris@16 199
Chris@16 200 /// Set the peer verification depth.
Chris@16 201 /**
Chris@16 202 * This function may be used to configure the maximum verification depth
Chris@16 203 * allowed by the context.
Chris@16 204 *
Chris@16 205 * @param depth Maximum depth for the certificate chain verification that
Chris@16 206 * shall be allowed.
Chris@16 207 *
Chris@16 208 * @throws boost::system::system_error Thrown on failure.
Chris@16 209 *
Chris@16 210 * @note Calls @c SSL_CTX_set_verify_depth.
Chris@16 211 */
Chris@16 212 BOOST_ASIO_DECL void set_verify_depth(int depth);
Chris@16 213
Chris@16 214 /// Set the peer verification depth.
Chris@16 215 /**
Chris@16 216 * This function may be used to configure the maximum verification depth
Chris@16 217 * allowed by the context.
Chris@16 218 *
Chris@16 219 * @param depth Maximum depth for the certificate chain verification that
Chris@16 220 * shall be allowed.
Chris@16 221 *
Chris@16 222 * @param ec Set to indicate what error occurred, if any.
Chris@16 223 *
Chris@16 224 * @note Calls @c SSL_CTX_set_verify_depth.
Chris@16 225 */
Chris@16 226 BOOST_ASIO_DECL boost::system::error_code set_verify_depth(
Chris@16 227 int depth, boost::system::error_code& ec);
Chris@16 228
Chris@16 229 /// Set the callback used to verify peer certificates.
Chris@16 230 /**
Chris@16 231 * This function is used to specify a callback function that will be called
Chris@16 232 * by the implementation when it needs to verify a peer certificate.
Chris@16 233 *
Chris@16 234 * @param callback The function object to be used for verifying a certificate.
Chris@16 235 * The function signature of the handler must be:
Chris@16 236 * @code bool verify_callback(
Chris@16 237 * bool preverified, // True if the certificate passed pre-verification.
Chris@16 238 * verify_context& ctx // The peer certificate and other context.
Chris@16 239 * ); @endcode
Chris@16 240 * The return value of the callback is true if the certificate has passed
Chris@16 241 * verification, false otherwise.
Chris@16 242 *
Chris@16 243 * @throws boost::system::system_error Thrown on failure.
Chris@16 244 *
Chris@16 245 * @note Calls @c SSL_CTX_set_verify.
Chris@16 246 */
Chris@16 247 template <typename VerifyCallback>
Chris@16 248 void set_verify_callback(VerifyCallback callback);
Chris@16 249
Chris@16 250 /// Set the callback used to verify peer certificates.
Chris@16 251 /**
Chris@16 252 * This function is used to specify a callback function that will be called
Chris@16 253 * by the implementation when it needs to verify a peer certificate.
Chris@16 254 *
Chris@16 255 * @param callback The function object to be used for verifying a certificate.
Chris@16 256 * The function signature of the handler must be:
Chris@16 257 * @code bool verify_callback(
Chris@16 258 * bool preverified, // True if the certificate passed pre-verification.
Chris@16 259 * verify_context& ctx // The peer certificate and other context.
Chris@16 260 * ); @endcode
Chris@16 261 * The return value of the callback is true if the certificate has passed
Chris@16 262 * verification, false otherwise.
Chris@16 263 *
Chris@16 264 * @param ec Set to indicate what error occurred, if any.
Chris@16 265 *
Chris@16 266 * @note Calls @c SSL_CTX_set_verify.
Chris@16 267 */
Chris@16 268 template <typename VerifyCallback>
Chris@16 269 boost::system::error_code set_verify_callback(VerifyCallback callback,
Chris@16 270 boost::system::error_code& ec);
Chris@16 271
Chris@16 272 /// Load a certification authority file for performing verification.
Chris@16 273 /**
Chris@16 274 * This function is used to load one or more trusted certification authorities
Chris@16 275 * from a file.
Chris@16 276 *
Chris@16 277 * @param filename The name of a file containing certification authority
Chris@16 278 * certificates in PEM format.
Chris@16 279 *
Chris@16 280 * @throws boost::system::system_error Thrown on failure.
Chris@16 281 *
Chris@16 282 * @note Calls @c SSL_CTX_load_verify_locations.
Chris@16 283 */
Chris@16 284 BOOST_ASIO_DECL void load_verify_file(const std::string& filename);
Chris@16 285
Chris@16 286 /// Load a certification authority file for performing verification.
Chris@16 287 /**
Chris@16 288 * This function is used to load the certificates for one or more trusted
Chris@16 289 * certification authorities from a file.
Chris@16 290 *
Chris@16 291 * @param filename The name of a file containing certification authority
Chris@16 292 * certificates in PEM format.
Chris@16 293 *
Chris@16 294 * @param ec Set to indicate what error occurred, if any.
Chris@16 295 *
Chris@16 296 * @note Calls @c SSL_CTX_load_verify_locations.
Chris@16 297 */
Chris@16 298 BOOST_ASIO_DECL boost::system::error_code load_verify_file(
Chris@16 299 const std::string& filename, boost::system::error_code& ec);
Chris@16 300
Chris@16 301 /// Add certification authority for performing verification.
Chris@16 302 /**
Chris@16 303 * This function is used to add one trusted certification authority
Chris@16 304 * from a memory buffer.
Chris@16 305 *
Chris@16 306 * @param ca The buffer containing the certification authority certificate.
Chris@16 307 * The certificate must use the PEM format.
Chris@16 308 *
Chris@16 309 * @throws boost::system::system_error Thrown on failure.
Chris@16 310 *
Chris@16 311 * @note Calls @c SSL_CTX_get_cert_store and @c X509_STORE_add_cert.
Chris@16 312 */
Chris@16 313 BOOST_ASIO_DECL void add_certificate_authority(const const_buffer& ca);
Chris@16 314
Chris@16 315 /// Add certification authority for performing verification.
Chris@16 316 /**
Chris@16 317 * This function is used to add one trusted certification authority
Chris@16 318 * from a memory buffer.
Chris@16 319 *
Chris@16 320 * @param ca The buffer containing the certification authority certificate.
Chris@16 321 * The certificate must use the PEM format.
Chris@16 322 *
Chris@16 323 * @param ec Set to indicate what error occurred, if any.
Chris@16 324 *
Chris@16 325 * @note Calls @c SSL_CTX_get_cert_store and @c X509_STORE_add_cert.
Chris@16 326 */
Chris@16 327 BOOST_ASIO_DECL boost::system::error_code add_certificate_authority(
Chris@16 328 const const_buffer& ca, boost::system::error_code& ec);
Chris@16 329
Chris@16 330 /// Configures the context to use the default directories for finding
Chris@16 331 /// certification authority certificates.
Chris@16 332 /**
Chris@16 333 * This function specifies that the context should use the default,
Chris@16 334 * system-dependent directories for locating certification authority
Chris@16 335 * certificates.
Chris@16 336 *
Chris@16 337 * @throws boost::system::system_error Thrown on failure.
Chris@16 338 *
Chris@16 339 * @note Calls @c SSL_CTX_set_default_verify_paths.
Chris@16 340 */
Chris@16 341 BOOST_ASIO_DECL void set_default_verify_paths();
Chris@16 342
Chris@16 343 /// Configures the context to use the default directories for finding
Chris@16 344 /// certification authority certificates.
Chris@16 345 /**
Chris@16 346 * This function specifies that the context should use the default,
Chris@16 347 * system-dependent directories for locating certification authority
Chris@16 348 * certificates.
Chris@16 349 *
Chris@16 350 * @param ec Set to indicate what error occurred, if any.
Chris@16 351 *
Chris@16 352 * @note Calls @c SSL_CTX_set_default_verify_paths.
Chris@16 353 */
Chris@16 354 BOOST_ASIO_DECL boost::system::error_code set_default_verify_paths(
Chris@16 355 boost::system::error_code& ec);
Chris@16 356
Chris@16 357 /// Add a directory containing certificate authority files to be used for
Chris@16 358 /// performing verification.
Chris@16 359 /**
Chris@16 360 * This function is used to specify the name of a directory containing
Chris@16 361 * certification authority certificates. Each file in the directory must
Chris@16 362 * contain a single certificate. The files must be named using the subject
Chris@16 363 * name's hash and an extension of ".0".
Chris@16 364 *
Chris@16 365 * @param path The name of a directory containing the certificates.
Chris@16 366 *
Chris@16 367 * @throws boost::system::system_error Thrown on failure.
Chris@16 368 *
Chris@16 369 * @note Calls @c SSL_CTX_load_verify_locations.
Chris@16 370 */
Chris@16 371 BOOST_ASIO_DECL void add_verify_path(const std::string& path);
Chris@16 372
Chris@16 373 /// Add a directory containing certificate authority files to be used for
Chris@16 374 /// performing verification.
Chris@16 375 /**
Chris@16 376 * This function is used to specify the name of a directory containing
Chris@16 377 * certification authority certificates. Each file in the directory must
Chris@16 378 * contain a single certificate. The files must be named using the subject
Chris@16 379 * name's hash and an extension of ".0".
Chris@16 380 *
Chris@16 381 * @param path The name of a directory containing the certificates.
Chris@16 382 *
Chris@16 383 * @param ec Set to indicate what error occurred, if any.
Chris@16 384 *
Chris@16 385 * @note Calls @c SSL_CTX_load_verify_locations.
Chris@16 386 */
Chris@16 387 BOOST_ASIO_DECL boost::system::error_code add_verify_path(
Chris@16 388 const std::string& path, boost::system::error_code& ec);
Chris@16 389
Chris@16 390 /// Use a certificate from a memory buffer.
Chris@16 391 /**
Chris@16 392 * This function is used to load a certificate into the context from a buffer.
Chris@16 393 *
Chris@16 394 * @param certificate The buffer containing the certificate.
Chris@16 395 *
Chris@16 396 * @param format The certificate format (ASN.1 or PEM).
Chris@16 397 *
Chris@16 398 * @throws boost::system::system_error Thrown on failure.
Chris@16 399 *
Chris@16 400 * @note Calls @c SSL_CTX_use_certificate or SSL_CTX_use_certificate_ASN1.
Chris@16 401 */
Chris@16 402 BOOST_ASIO_DECL void use_certificate(
Chris@16 403 const const_buffer& certificate, file_format format);
Chris@16 404
Chris@16 405 /// Use a certificate from a memory buffer.
Chris@16 406 /**
Chris@16 407 * This function is used to load a certificate into the context from a buffer.
Chris@16 408 *
Chris@16 409 * @param certificate The buffer containing the certificate.
Chris@16 410 *
Chris@16 411 * @param format The certificate format (ASN.1 or PEM).
Chris@16 412 *
Chris@16 413 * @param ec Set to indicate what error occurred, if any.
Chris@16 414 *
Chris@16 415 * @note Calls @c SSL_CTX_use_certificate or SSL_CTX_use_certificate_ASN1.
Chris@16 416 */
Chris@16 417 BOOST_ASIO_DECL boost::system::error_code use_certificate(
Chris@16 418 const const_buffer& certificate, file_format format,
Chris@16 419 boost::system::error_code& ec);
Chris@16 420
Chris@16 421 /// Use a certificate from a file.
Chris@16 422 /**
Chris@16 423 * This function is used to load a certificate into the context from a file.
Chris@16 424 *
Chris@16 425 * @param filename The name of the file containing the certificate.
Chris@16 426 *
Chris@16 427 * @param format The file format (ASN.1 or PEM).
Chris@16 428 *
Chris@16 429 * @throws boost::system::system_error Thrown on failure.
Chris@16 430 *
Chris@16 431 * @note Calls @c SSL_CTX_use_certificate_file.
Chris@16 432 */
Chris@16 433 BOOST_ASIO_DECL void use_certificate_file(
Chris@16 434 const std::string& filename, file_format format);
Chris@16 435
Chris@16 436 /// Use a certificate from a file.
Chris@16 437 /**
Chris@16 438 * This function is used to load a certificate into the context from a file.
Chris@16 439 *
Chris@16 440 * @param filename The name of the file containing the certificate.
Chris@16 441 *
Chris@16 442 * @param format The file format (ASN.1 or PEM).
Chris@16 443 *
Chris@16 444 * @param ec Set to indicate what error occurred, if any.
Chris@16 445 *
Chris@16 446 * @note Calls @c SSL_CTX_use_certificate_file.
Chris@16 447 */
Chris@16 448 BOOST_ASIO_DECL boost::system::error_code use_certificate_file(
Chris@16 449 const std::string& filename, file_format format,
Chris@16 450 boost::system::error_code& ec);
Chris@16 451
Chris@16 452 /// Use a certificate chain from a memory buffer.
Chris@16 453 /**
Chris@16 454 * This function is used to load a certificate chain into the context from a
Chris@16 455 * buffer.
Chris@16 456 *
Chris@16 457 * @param chain The buffer containing the certificate chain. The certificate
Chris@16 458 * chain must use the PEM format.
Chris@16 459 *
Chris@16 460 * @throws boost::system::system_error Thrown on failure.
Chris@16 461 *
Chris@16 462 * @note Calls @c SSL_CTX_use_certificate and SSL_CTX_add_extra_chain_cert.
Chris@16 463 */
Chris@16 464 BOOST_ASIO_DECL void use_certificate_chain(const const_buffer& chain);
Chris@16 465
Chris@16 466 /// Use a certificate chain from a memory buffer.
Chris@16 467 /**
Chris@16 468 * This function is used to load a certificate chain into the context from a
Chris@16 469 * buffer.
Chris@16 470 *
Chris@16 471 * @param chain The buffer containing the certificate chain. The certificate
Chris@16 472 * chain must use the PEM format.
Chris@16 473 *
Chris@16 474 * @param ec Set to indicate what error occurred, if any.
Chris@16 475 *
Chris@16 476 * @note Calls @c SSL_CTX_use_certificate and SSL_CTX_add_extra_chain_cert.
Chris@16 477 */
Chris@16 478 BOOST_ASIO_DECL boost::system::error_code use_certificate_chain(
Chris@16 479 const const_buffer& chain, boost::system::error_code& ec);
Chris@16 480
Chris@16 481 /// Use a certificate chain from a file.
Chris@16 482 /**
Chris@16 483 * This function is used to load a certificate chain into the context from a
Chris@16 484 * file.
Chris@16 485 *
Chris@16 486 * @param filename The name of the file containing the certificate. The file
Chris@16 487 * must use the PEM format.
Chris@16 488 *
Chris@16 489 * @throws boost::system::system_error Thrown on failure.
Chris@16 490 *
Chris@16 491 * @note Calls @c SSL_CTX_use_certificate_chain_file.
Chris@16 492 */
Chris@16 493 BOOST_ASIO_DECL void use_certificate_chain_file(const std::string& filename);
Chris@16 494
Chris@16 495 /// Use a certificate chain from a file.
Chris@16 496 /**
Chris@16 497 * This function is used to load a certificate chain into the context from a
Chris@16 498 * file.
Chris@16 499 *
Chris@16 500 * @param filename The name of the file containing the certificate. The file
Chris@16 501 * must use the PEM format.
Chris@16 502 *
Chris@16 503 * @param ec Set to indicate what error occurred, if any.
Chris@16 504 *
Chris@16 505 * @note Calls @c SSL_CTX_use_certificate_chain_file.
Chris@16 506 */
Chris@16 507 BOOST_ASIO_DECL boost::system::error_code use_certificate_chain_file(
Chris@16 508 const std::string& filename, boost::system::error_code& ec);
Chris@16 509
Chris@16 510 /// Use a private key from a memory buffer.
Chris@16 511 /**
Chris@16 512 * This function is used to load a private key into the context from a buffer.
Chris@16 513 *
Chris@16 514 * @param private_key The buffer containing the private key.
Chris@16 515 *
Chris@16 516 * @param format The private key format (ASN.1 or PEM).
Chris@16 517 *
Chris@16 518 * @throws boost::system::system_error Thrown on failure.
Chris@16 519 *
Chris@16 520 * @note Calls @c SSL_CTX_use_PrivateKey or SSL_CTX_use_PrivateKey_ASN1.
Chris@16 521 */
Chris@16 522 BOOST_ASIO_DECL void use_private_key(
Chris@16 523 const const_buffer& private_key, file_format format);
Chris@16 524
Chris@16 525 /// Use a private key from a memory buffer.
Chris@16 526 /**
Chris@16 527 * This function is used to load a private key into the context from a buffer.
Chris@16 528 *
Chris@16 529 * @param private_key The buffer containing the private key.
Chris@16 530 *
Chris@16 531 * @param format The private key format (ASN.1 or PEM).
Chris@16 532 *
Chris@16 533 * @param ec Set to indicate what error occurred, if any.
Chris@16 534 *
Chris@16 535 * @note Calls @c SSL_CTX_use_PrivateKey or SSL_CTX_use_PrivateKey_ASN1.
Chris@16 536 */
Chris@16 537 BOOST_ASIO_DECL boost::system::error_code use_private_key(
Chris@16 538 const const_buffer& private_key, file_format format,
Chris@16 539 boost::system::error_code& ec);
Chris@16 540
Chris@16 541 /// Use a private key from a file.
Chris@16 542 /**
Chris@16 543 * This function is used to load a private key into the context from a file.
Chris@16 544 *
Chris@16 545 * @param filename The name of the file containing the private key.
Chris@16 546 *
Chris@16 547 * @param format The file format (ASN.1 or PEM).
Chris@16 548 *
Chris@16 549 * @throws boost::system::system_error Thrown on failure.
Chris@16 550 *
Chris@16 551 * @note Calls @c SSL_CTX_use_PrivateKey_file.
Chris@16 552 */
Chris@16 553 BOOST_ASIO_DECL void use_private_key_file(
Chris@16 554 const std::string& filename, file_format format);
Chris@16 555
Chris@16 556 /// Use a private key from a file.
Chris@16 557 /**
Chris@16 558 * This function is used to load a private key into the context from a file.
Chris@16 559 *
Chris@16 560 * @param filename The name of the file containing the private key.
Chris@16 561 *
Chris@16 562 * @param format The file format (ASN.1 or PEM).
Chris@16 563 *
Chris@16 564 * @param ec Set to indicate what error occurred, if any.
Chris@16 565 *
Chris@16 566 * @note Calls @c SSL_CTX_use_PrivateKey_file.
Chris@16 567 */
Chris@16 568 BOOST_ASIO_DECL boost::system::error_code use_private_key_file(
Chris@16 569 const std::string& filename, file_format format,
Chris@16 570 boost::system::error_code& ec);
Chris@16 571
Chris@16 572 /// Use an RSA private key from a memory buffer.
Chris@16 573 /**
Chris@16 574 * This function is used to load an RSA private key into the context from a
Chris@16 575 * buffer.
Chris@16 576 *
Chris@16 577 * @param private_key The buffer containing the RSA private key.
Chris@16 578 *
Chris@16 579 * @param format The private key format (ASN.1 or PEM).
Chris@16 580 *
Chris@16 581 * @throws boost::system::system_error Thrown on failure.
Chris@16 582 *
Chris@16 583 * @note Calls @c SSL_CTX_use_RSAPrivateKey or SSL_CTX_use_RSAPrivateKey_ASN1.
Chris@16 584 */
Chris@16 585 BOOST_ASIO_DECL void use_rsa_private_key(
Chris@16 586 const const_buffer& private_key, file_format format);
Chris@16 587
Chris@16 588 /// Use an RSA private key from a memory buffer.
Chris@16 589 /**
Chris@16 590 * This function is used to load an RSA private key into the context from a
Chris@16 591 * buffer.
Chris@16 592 *
Chris@16 593 * @param private_key The buffer containing the RSA private key.
Chris@16 594 *
Chris@16 595 * @param format The private key format (ASN.1 or PEM).
Chris@16 596 *
Chris@16 597 * @param ec Set to indicate what error occurred, if any.
Chris@16 598 *
Chris@16 599 * @note Calls @c SSL_CTX_use_RSAPrivateKey or SSL_CTX_use_RSAPrivateKey_ASN1.
Chris@16 600 */
Chris@16 601 BOOST_ASIO_DECL boost::system::error_code use_rsa_private_key(
Chris@16 602 const const_buffer& private_key, file_format format,
Chris@16 603 boost::system::error_code& ec);
Chris@16 604
Chris@16 605 /// Use an RSA private key from a file.
Chris@16 606 /**
Chris@16 607 * This function is used to load an RSA private key into the context from a
Chris@16 608 * file.
Chris@16 609 *
Chris@16 610 * @param filename The name of the file containing the RSA private key.
Chris@16 611 *
Chris@16 612 * @param format The file format (ASN.1 or PEM).
Chris@16 613 *
Chris@16 614 * @throws boost::system::system_error Thrown on failure.
Chris@16 615 *
Chris@16 616 * @note Calls @c SSL_CTX_use_RSAPrivateKey_file.
Chris@16 617 */
Chris@16 618 BOOST_ASIO_DECL void use_rsa_private_key_file(
Chris@16 619 const std::string& filename, file_format format);
Chris@16 620
Chris@16 621 /// Use an RSA private key from a file.
Chris@16 622 /**
Chris@16 623 * This function is used to load an RSA private key into the context from a
Chris@16 624 * file.
Chris@16 625 *
Chris@16 626 * @param filename The name of the file containing the RSA private key.
Chris@16 627 *
Chris@16 628 * @param format The file format (ASN.1 or PEM).
Chris@16 629 *
Chris@16 630 * @param ec Set to indicate what error occurred, if any.
Chris@16 631 *
Chris@16 632 * @note Calls @c SSL_CTX_use_RSAPrivateKey_file.
Chris@16 633 */
Chris@16 634 BOOST_ASIO_DECL boost::system::error_code use_rsa_private_key_file(
Chris@16 635 const std::string& filename, file_format format,
Chris@16 636 boost::system::error_code& ec);
Chris@16 637
Chris@16 638 /// Use the specified memory buffer to obtain the temporary Diffie-Hellman
Chris@16 639 /// parameters.
Chris@16 640 /**
Chris@16 641 * This function is used to load Diffie-Hellman parameters into the context
Chris@16 642 * from a buffer.
Chris@16 643 *
Chris@16 644 * @param dh The memory buffer containing the Diffie-Hellman parameters. The
Chris@16 645 * buffer must use the PEM format.
Chris@16 646 *
Chris@16 647 * @throws boost::system::system_error Thrown on failure.
Chris@16 648 *
Chris@16 649 * @note Calls @c SSL_CTX_set_tmp_dh.
Chris@16 650 */
Chris@16 651 BOOST_ASIO_DECL void use_tmp_dh(const const_buffer& dh);
Chris@16 652
Chris@16 653 /// Use the specified memory buffer to obtain the temporary Diffie-Hellman
Chris@16 654 /// parameters.
Chris@16 655 /**
Chris@16 656 * This function is used to load Diffie-Hellman parameters into the context
Chris@16 657 * from a buffer.
Chris@16 658 *
Chris@16 659 * @param dh The memory buffer containing the Diffie-Hellman parameters. The
Chris@16 660 * buffer must use the PEM format.
Chris@16 661 *
Chris@16 662 * @param ec Set to indicate what error occurred, if any.
Chris@16 663 *
Chris@16 664 * @note Calls @c SSL_CTX_set_tmp_dh.
Chris@16 665 */
Chris@16 666 BOOST_ASIO_DECL boost::system::error_code use_tmp_dh(
Chris@16 667 const const_buffer& dh, boost::system::error_code& ec);
Chris@16 668
Chris@16 669 /// Use the specified file to obtain the temporary Diffie-Hellman parameters.
Chris@16 670 /**
Chris@16 671 * This function is used to load Diffie-Hellman parameters into the context
Chris@16 672 * from a file.
Chris@16 673 *
Chris@16 674 * @param filename The name of the file containing the Diffie-Hellman
Chris@16 675 * parameters. The file must use the PEM format.
Chris@16 676 *
Chris@16 677 * @throws boost::system::system_error Thrown on failure.
Chris@16 678 *
Chris@16 679 * @note Calls @c SSL_CTX_set_tmp_dh.
Chris@16 680 */
Chris@16 681 BOOST_ASIO_DECL void use_tmp_dh_file(const std::string& filename);
Chris@16 682
Chris@16 683 /// Use the specified file to obtain the temporary Diffie-Hellman parameters.
Chris@16 684 /**
Chris@16 685 * This function is used to load Diffie-Hellman parameters into the context
Chris@16 686 * from a file.
Chris@16 687 *
Chris@16 688 * @param filename The name of the file containing the Diffie-Hellman
Chris@16 689 * parameters. The file must use the PEM format.
Chris@16 690 *
Chris@16 691 * @param ec Set to indicate what error occurred, if any.
Chris@16 692 *
Chris@16 693 * @note Calls @c SSL_CTX_set_tmp_dh.
Chris@16 694 */
Chris@16 695 BOOST_ASIO_DECL boost::system::error_code use_tmp_dh_file(
Chris@16 696 const std::string& filename, boost::system::error_code& ec);
Chris@16 697
Chris@16 698 /// Set the password callback.
Chris@16 699 /**
Chris@16 700 * This function is used to specify a callback function to obtain password
Chris@16 701 * information about an encrypted key in PEM format.
Chris@16 702 *
Chris@16 703 * @param callback The function object to be used for obtaining the password.
Chris@16 704 * The function signature of the handler must be:
Chris@16 705 * @code std::string password_callback(
Chris@16 706 * std::size_t max_length, // The maximum size for a password.
Chris@16 707 * password_purpose purpose // Whether password is for reading or writing.
Chris@16 708 * ); @endcode
Chris@16 709 * The return value of the callback is a string containing the password.
Chris@16 710 *
Chris@16 711 * @throws boost::system::system_error Thrown on failure.
Chris@16 712 *
Chris@16 713 * @note Calls @c SSL_CTX_set_default_passwd_cb.
Chris@16 714 */
Chris@16 715 template <typename PasswordCallback>
Chris@16 716 void set_password_callback(PasswordCallback callback);
Chris@16 717
Chris@16 718 /// Set the password callback.
Chris@16 719 /**
Chris@16 720 * This function is used to specify a callback function to obtain password
Chris@16 721 * information about an encrypted key in PEM format.
Chris@16 722 *
Chris@16 723 * @param callback The function object to be used for obtaining the password.
Chris@16 724 * The function signature of the handler must be:
Chris@16 725 * @code std::string password_callback(
Chris@16 726 * std::size_t max_length, // The maximum size for a password.
Chris@16 727 * password_purpose purpose // Whether password is for reading or writing.
Chris@16 728 * ); @endcode
Chris@16 729 * The return value of the callback is a string containing the password.
Chris@16 730 *
Chris@16 731 * @param ec Set to indicate what error occurred, if any.
Chris@16 732 *
Chris@16 733 * @note Calls @c SSL_CTX_set_default_passwd_cb.
Chris@16 734 */
Chris@16 735 template <typename PasswordCallback>
Chris@16 736 boost::system::error_code set_password_callback(PasswordCallback callback,
Chris@16 737 boost::system::error_code& ec);
Chris@16 738
Chris@16 739 private:
Chris@16 740 struct bio_cleanup;
Chris@16 741 struct x509_cleanup;
Chris@16 742 struct evp_pkey_cleanup;
Chris@16 743 struct rsa_cleanup;
Chris@16 744 struct dh_cleanup;
Chris@16 745
Chris@16 746 // Helper function used to set a peer certificate verification callback.
Chris@16 747 BOOST_ASIO_DECL boost::system::error_code do_set_verify_callback(
Chris@16 748 detail::verify_callback_base* callback, boost::system::error_code& ec);
Chris@16 749
Chris@16 750 // Callback used when the SSL implementation wants to verify a certificate.
Chris@16 751 BOOST_ASIO_DECL static int verify_callback_function(
Chris@16 752 int preverified, X509_STORE_CTX* ctx);
Chris@16 753
Chris@16 754 // Helper function used to set a password callback.
Chris@16 755 BOOST_ASIO_DECL boost::system::error_code do_set_password_callback(
Chris@16 756 detail::password_callback_base* callback, boost::system::error_code& ec);
Chris@16 757
Chris@16 758 // Callback used when the SSL implementation wants a password.
Chris@16 759 BOOST_ASIO_DECL static int password_callback_function(
Chris@16 760 char* buf, int size, int purpose, void* data);
Chris@16 761
Chris@16 762 // Helper function to set the temporary Diffie-Hellman parameters from a BIO.
Chris@16 763 BOOST_ASIO_DECL boost::system::error_code do_use_tmp_dh(
Chris@16 764 BIO* bio, boost::system::error_code& ec);
Chris@16 765
Chris@16 766 // Helper function to make a BIO from a memory buffer.
Chris@16 767 BOOST_ASIO_DECL BIO* make_buffer_bio(const const_buffer& b);
Chris@16 768
Chris@16 769 // The underlying native implementation.
Chris@16 770 native_handle_type handle_;
Chris@16 771
Chris@16 772 // Ensure openssl is initialised.
Chris@16 773 boost::asio::ssl::detail::openssl_init<> init_;
Chris@16 774 };
Chris@16 775
Chris@16 776 #endif // defined(BOOST_ASIO_ENABLE_OLD_SSL)
Chris@16 777
Chris@16 778 } // namespace ssl
Chris@16 779 } // namespace asio
Chris@16 780 } // namespace boost
Chris@16 781
Chris@16 782 #include <boost/asio/detail/pop_options.hpp>
Chris@16 783
Chris@16 784 #include <boost/asio/ssl/impl/context.hpp>
Chris@16 785 #if defined(BOOST_ASIO_HEADER_ONLY)
Chris@16 786 # include <boost/asio/ssl/impl/context.ipp>
Chris@16 787 #endif // defined(BOOST_ASIO_HEADER_ONLY)
Chris@16 788
Chris@16 789 #endif // BOOST_ASIO_SSL_CONTEXT_HPP