context_service.hpp 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. //
  2. // ssl/old/context_service.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2005 Voipster / Indrek dot Juhani at voipster dot com
  6. // Copyright (c) 2005-2015 Christopher M. Kohlhoff (chris at kohlhoff dot com)
  7. //
  8. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  9. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  10. //
  11. #ifndef ASIO_SSL_OLD_CONTEXT_SERVICE_HPP
  12. #define ASIO_SSL_OLD_CONTEXT_SERVICE_HPP
  13. #if defined(_MSC_VER) && (_MSC_VER >= 1200)
  14. # pragma once
  15. #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
  16. #include "asio/detail/config.hpp"
  17. #include <string>
  18. #include <boost/noncopyable.hpp>
  19. #include "asio/error.hpp"
  20. #include "asio/io_service.hpp"
  21. #include "asio/ssl/context_base.hpp"
  22. #include "asio/ssl/old/detail/openssl_context_service.hpp"
  23. #include "asio/detail/push_options.hpp"
  24. namespace asio {
  25. namespace ssl {
  26. namespace old {
  27. /// Default service implementation for a context.
  28. class context_service
  29. #if defined(GENERATING_DOCUMENTATION)
  30. : public asio::io_service::service
  31. #else
  32. : public asio::detail::service_base<context_service>
  33. #endif
  34. {
  35. private:
  36. // The type of the platform-specific implementation.
  37. typedef old::detail::openssl_context_service service_impl_type;
  38. public:
  39. #if defined(GENERATING_DOCUMENTATION)
  40. /// The unique service identifier.
  41. static asio::io_service::id id;
  42. #endif
  43. /// The type of the context.
  44. #if defined(GENERATING_DOCUMENTATION)
  45. typedef implementation_defined impl_type;
  46. #else
  47. typedef service_impl_type::impl_type impl_type;
  48. #endif
  49. /// Constructor.
  50. explicit context_service(asio::io_service& io_service)
  51. : asio::detail::service_base<context_service>(io_service),
  52. service_impl_(asio::use_service<service_impl_type>(io_service))
  53. {
  54. }
  55. /// Return a null context implementation.
  56. impl_type null() const
  57. {
  58. return service_impl_.null();
  59. }
  60. /// Create a new context implementation.
  61. void create(impl_type& impl, context_base::method m)
  62. {
  63. service_impl_.create(impl, m);
  64. }
  65. /// Destroy a context implementation.
  66. void destroy(impl_type& impl)
  67. {
  68. service_impl_.destroy(impl);
  69. }
  70. /// Set options on the context.
  71. asio::error_code set_options(impl_type& impl,
  72. context_base::options o, asio::error_code& ec)
  73. {
  74. return service_impl_.set_options(impl, o, ec);
  75. }
  76. /// Set peer verification mode.
  77. asio::error_code set_verify_mode(impl_type& impl,
  78. context_base::verify_mode v, asio::error_code& ec)
  79. {
  80. return service_impl_.set_verify_mode(impl, v, ec);
  81. }
  82. /// Load a certification authority file for performing verification.
  83. asio::error_code load_verify_file(impl_type& impl,
  84. const std::string& filename, asio::error_code& ec)
  85. {
  86. return service_impl_.load_verify_file(impl, filename, ec);
  87. }
  88. /// Add a directory containing certification authority files to be used for
  89. /// performing verification.
  90. asio::error_code add_verify_path(impl_type& impl,
  91. const std::string& path, asio::error_code& ec)
  92. {
  93. return service_impl_.add_verify_path(impl, path, ec);
  94. }
  95. /// Use a certificate from a file.
  96. asio::error_code use_certificate_file(impl_type& impl,
  97. const std::string& filename, context_base::file_format format,
  98. asio::error_code& ec)
  99. {
  100. return service_impl_.use_certificate_file(impl, filename, format, ec);
  101. }
  102. /// Use a certificate chain from a file.
  103. asio::error_code use_certificate_chain_file(impl_type& impl,
  104. const std::string& filename, asio::error_code& ec)
  105. {
  106. return service_impl_.use_certificate_chain_file(impl, filename, ec);
  107. }
  108. /// Use a private key from a file.
  109. asio::error_code use_private_key_file(impl_type& impl,
  110. const std::string& filename, context_base::file_format format,
  111. asio::error_code& ec)
  112. {
  113. return service_impl_.use_private_key_file(impl, filename, format, ec);
  114. }
  115. /// Use an RSA private key from a file.
  116. asio::error_code use_rsa_private_key_file(impl_type& impl,
  117. const std::string& filename, context_base::file_format format,
  118. asio::error_code& ec)
  119. {
  120. return service_impl_.use_rsa_private_key_file(impl, filename, format, ec);
  121. }
  122. /// Use the specified file to obtain the temporary Diffie-Hellman parameters.
  123. asio::error_code use_tmp_dh_file(impl_type& impl,
  124. const std::string& filename, asio::error_code& ec)
  125. {
  126. return service_impl_.use_tmp_dh_file(impl, filename, ec);
  127. }
  128. /// Set the password callback.
  129. template <typename PasswordCallback>
  130. asio::error_code set_password_callback(impl_type& impl,
  131. PasswordCallback callback, asio::error_code& ec)
  132. {
  133. return service_impl_.set_password_callback(impl, callback, ec);
  134. }
  135. private:
  136. // Destroy all user-defined handler objects owned by the service.
  137. void shutdown_service()
  138. {
  139. }
  140. // The service that provides the platform-specific implementation.
  141. service_impl_type& service_impl_;
  142. };
  143. } // namespace old
  144. } // namespace ssl
  145. } // namespace asio
  146. #include "asio/detail/pop_options.hpp"
  147. #endif // ASIO_SSL_OLD_CONTEXT_SERVICE_HPP