Realistic 3D camera system
3D camera system components
context.hpp
Go to the documentation of this file.
1 //
2 // ssl/context.hpp
3 // ~~~~~~~~~~~~~~~
4 //
5 // Copyright (c) 2003-2015 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 ASIO_SSL_CONTEXT_HPP
12 #define 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 "asio/detail/config.hpp"
19 
20 #if defined(ASIO_ENABLE_OLD_SSL)
23 #else // defined(ASIO_ENABLE_OLD_SSL)
24 # include <string>
25 # include "asio/buffer.hpp"
26 # include "asio/io_service.hpp"
27 # include "asio/ssl/context_base.hpp"
32 # include "asio/ssl/verify_mode.hpp"
33 #endif // defined(ASIO_ENABLE_OLD_SSL)
34 
36 
37 namespace asio {
38 namespace ssl {
39 
40 #if defined(ASIO_ENABLE_OLD_SSL)
41 
43 typedef basic_context<context_service> context;
44 
45 #else // defined(ASIO_ENABLE_OLD_SSL)
46 
47 class context
48  : public context_base,
49  private noncopyable
50 {
51 public:
53  typedef SSL_CTX* native_handle_type;
54 
56  typedef SSL_CTX* impl_type;
57 
59  ASIO_DECL explicit context(method m);
60 
63 
64 #if defined(ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
65 
76  ASIO_DECL context(context&& other);
77 
79 
89  ASIO_DECL context& operator=(context&& other);
90 #endif // defined(ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
91 
94 
96 
101  ASIO_DECL native_handle_type native_handle();
102 
105 
110  ASIO_DECL impl_type impl();
111 
113 
125 
127 
139  asio::error_code& ec);
140 
142 
153  ASIO_DECL void set_options(options o);
154 
156 
168  asio::error_code& ec);
169 
171 
183 
185 
198 
200 
211  ASIO_DECL void set_verify_depth(int depth);
212 
214 
226  int depth, asio::error_code& ec);
227 
229 
246  template <typename VerifyCallback>
247  void set_verify_callback(VerifyCallback callback);
248 
250 
267  template <typename VerifyCallback>
268  asio::error_code set_verify_callback(VerifyCallback callback,
269  asio::error_code& ec);
270 
272 
283  ASIO_DECL void load_verify_file(const std::string& filename);
284 
286 
298  const std::string& filename, asio::error_code& ec);
299 
301 
313 
315 
327  const const_buffer& ca, asio::error_code& ec);
328 
331 
341 
344 
354  asio::error_code& ec);
355 
358 
370  ASIO_DECL void add_verify_path(const std::string& path);
371 
374 
387  const std::string& path, asio::error_code& ec);
388 
390 
402  const const_buffer& certificate, file_format format);
403 
405 
417  const const_buffer& certificate, file_format format,
418  asio::error_code& ec);
419 
421 
433  const std::string& filename, file_format format);
434 
436 
448  const std::string& filename, file_format format,
449  asio::error_code& ec);
450 
452 
463  ASIO_DECL void use_certificate_chain(const const_buffer& chain);
464 
466 
478  const const_buffer& chain, asio::error_code& ec);
479 
481 
492  ASIO_DECL void use_certificate_chain_file(const std::string& filename);
493 
495 
507  const std::string& filename, asio::error_code& ec);
508 
510 
522  const const_buffer& private_key, file_format format);
523 
525 
537  const const_buffer& private_key, file_format format,
538  asio::error_code& ec);
539 
541 
553  const std::string& filename, file_format format);
554 
556 
568  const std::string& filename, file_format format,
569  asio::error_code& ec);
570 
572 
585  const const_buffer& private_key, file_format format);
586 
588 
601  const const_buffer& private_key, file_format format,
602  asio::error_code& ec);
603 
605 
618  const std::string& filename, file_format format);
619 
621 
634  const std::string& filename, file_format format,
635  asio::error_code& ec);
636 
639 
650  ASIO_DECL void use_tmp_dh(const const_buffer& dh);
651 
654 
666  const const_buffer& dh, asio::error_code& ec);
667 
669 
680  ASIO_DECL void use_tmp_dh_file(const std::string& filename);
681 
683 
695  const std::string& filename, asio::error_code& ec);
696 
698 
714  template <typename PasswordCallback>
715  void set_password_callback(PasswordCallback callback);
716 
718 
734  template <typename PasswordCallback>
735  asio::error_code set_password_callback(PasswordCallback callback,
736  asio::error_code& ec);
737 
738 private:
739  struct bio_cleanup;
740  struct x509_cleanup;
741  struct evp_pkey_cleanup;
742  struct rsa_cleanup;
743  struct dh_cleanup;
744 
745  // Helper function used to set a peer certificate verification callback.
746  ASIO_DECL asio::error_code do_set_verify_callback(
748 
749  // Callback used when the SSL implementation wants to verify a certificate.
750  ASIO_DECL static int verify_callback_function(
751  int preverified, X509_STORE_CTX* ctx);
752 
753  // Helper function used to set a password callback.
754  ASIO_DECL asio::error_code do_set_password_callback(
756 
757  // Callback used when the SSL implementation wants a password.
758  ASIO_DECL static int password_callback_function(
759  char* buf, int size, int purpose, void* data);
760 
761  // Helper function to set the temporary Diffie-Hellman parameters from a BIO.
762  ASIO_DECL asio::error_code do_use_tmp_dh(
763  BIO* bio, asio::error_code& ec);
764 
765  // Helper function to make a BIO from a memory buffer.
766  ASIO_DECL BIO* make_buffer_bio(const const_buffer& b);
767 
768  // The underlying native implementation.
769  native_handle_type handle_;
770 
771  // Ensure openssl is initialised.
773 };
774 
775 #endif // defined(ASIO_ENABLE_OLD_SSL)
776 
777 } // namespace ssl
778 } // namespace asio
779 
781 
782 #include "asio/ssl/impl/context.hpp"
783 #if defined(ASIO_HEADER_ONLY)
784 # include "asio/ssl/impl/context.ipp"
785 #endif // defined(ASIO_HEADER_ONLY)
786 
787 #endif // ASIO_SSL_CONTEXT_HPP
ASIO_DECL void use_tmp_dh_file(const std::string &filename)
Use the specified file to obtain the temporary Diffie-Hellman parameters.
Definition: context.ipp:829
void set_password_callback(PasswordCallback callback)
Set the password callback.
Definition: context.hpp:49
ASIO_DECL void set_default_verify_paths()
Definition: context.ipp:382
SSL_CTX * native_handle_type
The native handle type of the SSL context.
Definition: context.hpp:53
SSL_CTX * impl_type
(Deprecated: Use native_handle_type.) The native type of the SSL context.
Definition: context.hpp:56
ASIO_DECL void clear_options(options o)
Clear options on the context.
Definition: context.ipp:230
ASIO_DECL void use_rsa_private_key_file(const std::string &filename, file_format format)
Use an RSA private key from a file.
Definition: context.ipp:762
Provides core I/O functionality.
Definition: io_service.hpp:184
ASIO_DECL void use_private_key(const const_buffer &private_key, file_format format)
Use a private key from a memory buffer.
Definition: context.ipp:618
Holds a buffer that cannot be modified.
Definition: buffer.hpp:211
ASIO_DECL void load_verify_file(const std::string &filename)
Load a certification authority file for performing verification.
Definition: context.ipp:323
ASIO_DECL void use_rsa_private_key(const const_buffer &private_key, file_format format)
Use an RSA private key from a memory buffer.
Definition: context.ipp:677
ASIO_DECL void use_certificate(const const_buffer &certificate, file_format format)
Use a certificate from a memory buffer.
Definition: context.ipp:430
asio::basic_streambuf< Allocator > & b
Definition: read.hpp:702
ASIO_DECL void use_certificate_chain_file(const std::string &filename)
Use a certificate chain from a file.
Definition: context.ipp:594
ASIO_DECL void set_verify_depth(int depth)
Set the peer verification depth.
Definition: context.ipp:307
ASIO_DECL void use_private_key_file(const std::string &filename, file_format format)
Use a private key from a file.
Definition: context.ipp:669
method
Different methods supported by a context.
ASIO_DECL context(method m)
Constructor.
Definition: context.ipp:66
ASIO_DECL void set_options(options o)
Set options on the context.
Definition: context.ipp:264
void set_verify_callback(VerifyCallback callback)
Set the callback used to verify peer certificates.
Definition: context.hpp:33
ASIO_DECL native_handle_type native_handle()
Get the underlying implementation in the native type.
Definition: context.ipp:220
ASIO_DECL void add_certificate_authority(const const_buffer &ca)
Add certification authority for performing verification.
Definition: context.ipp:347
Class to represent an error code value.
Definition: error_code.hpp:80
#define ASIO_DECL
Definition: config.hpp:43
ASIO_DECL impl_type impl()
Definition: context.ipp:225
ASIO_DECL void use_certificate_file(const std::string &filename, file_format format)
Use a certificate from a file.
Definition: context.ipp:482
ASIO_DECL void set_verify_mode(verify_mode v)
Set the peer verification mode.
Definition: context.ipp:291
long options
Bitmask type for SSL options.
ASIO_DECL void use_certificate_chain(const const_buffer &chain)
Use a certificate chain from a memory buffer.
Definition: context.ipp:524
ASIO_DECL ~context()
Destructor.
Definition: context.ipp:194
file_format
File format types.
ASIO_DECL void use_tmp_dh(const const_buffer &dh)
Definition: context.ipp:805
ASIO_DECL void add_verify_path(const std::string &path)
Definition: context.ipp:406