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