context_base.hpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. //
  2. // context_base.hpp
  3. // ~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2005-2008 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. #ifndef BOOST_ASIO_SSL_CONTEXT_BASE_HPP
  11. #define BOOST_ASIO_SSL_CONTEXT_BASE_HPP
  12. #if defined(_MSC_VER) && (_MSC_VER >= 1200)
  13. # pragma once
  14. #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
  15. #include <boost/asio/detail/push_options.hpp>
  16. #include <boost/asio/detail/push_options.hpp>
  17. #include <boost/config.hpp>
  18. #include <boost/detail/workaround.hpp>
  19. #include <boost/asio/detail/pop_options.hpp>
  20. #include <boost/asio/ssl/detail/openssl_types.hpp>
  21. namespace boost {
  22. namespace asio {
  23. namespace ssl {
  24. /// The context_base class is used as a base for the basic_context class
  25. /// template so that we have a common place to define various enums.
  26. class context_base
  27. {
  28. public:
  29. /// Different methods supported by a context.
  30. enum method
  31. {
  32. /// Generic SSL version 2.
  33. sslv2,
  34. /// SSL version 2 client.
  35. sslv2_client,
  36. /// SSL version 2 server.
  37. sslv2_server,
  38. /// Generic SSL version 3.
  39. sslv3,
  40. /// SSL version 3 client.
  41. sslv3_client,
  42. /// SSL version 3 server.
  43. sslv3_server,
  44. /// Generic TLS version 1.
  45. tlsv1,
  46. /// TLS version 1 client.
  47. tlsv1_client,
  48. /// TLS version 1 server.
  49. tlsv1_server,
  50. /// Generic SSL/TLS.
  51. sslv23,
  52. /// SSL/TLS client.
  53. sslv23_client,
  54. /// SSL/TLS server.
  55. sslv23_server
  56. };
  57. /// Bitmask type for SSL options.
  58. typedef int options;
  59. #if defined(GENERATING_DOCUMENTATION)
  60. /// Implement various bug workarounds.
  61. static const int default_workarounds = implementation_defined;
  62. /// Always create a new key when using tmp_dh parameters.
  63. static const int single_dh_use = implementation_defined;
  64. /// Disable SSL v2.
  65. static const int no_sslv2 = implementation_defined;
  66. /// Disable SSL v3.
  67. static const int no_sslv3 = implementation_defined;
  68. /// Disable TLS v1.
  69. static const int no_tlsv1 = implementation_defined;
  70. #else
  71. BOOST_STATIC_CONSTANT(int, default_workarounds = SSL_OP_ALL);
  72. BOOST_STATIC_CONSTANT(int, single_dh_use = SSL_OP_SINGLE_DH_USE);
  73. BOOST_STATIC_CONSTANT(int, no_sslv2 = SSL_OP_NO_SSLv2);
  74. BOOST_STATIC_CONSTANT(int, no_sslv3 = SSL_OP_NO_SSLv3);
  75. BOOST_STATIC_CONSTANT(int, no_tlsv1 = SSL_OP_NO_TLSv1);
  76. #endif
  77. /// File format types.
  78. enum file_format
  79. {
  80. /// ASN.1 file.
  81. asn1,
  82. /// PEM file.
  83. pem
  84. };
  85. /// Bitmask type for peer verification.
  86. typedef int verify_mode;
  87. #if defined(GENERATING_DOCUMENTATION)
  88. /// No verification.
  89. static const int verify_none = implementation_defined;
  90. /// Verify the peer.
  91. static const int verify_peer = implementation_defined;
  92. /// Fail verification if the peer has no certificate. Ignored unless
  93. /// verify_peer is set.
  94. static const int verify_fail_if_no_peer_cert = implementation_defined;
  95. /// Do not request client certificate on renegotiation. Ignored unless
  96. /// verify_peer is set.
  97. static const int verify_client_once = implementation_defined;
  98. #else
  99. BOOST_STATIC_CONSTANT(int, verify_none = SSL_VERIFY_NONE);
  100. BOOST_STATIC_CONSTANT(int, verify_peer = SSL_VERIFY_PEER);
  101. BOOST_STATIC_CONSTANT(int,
  102. verify_fail_if_no_peer_cert = SSL_VERIFY_FAIL_IF_NO_PEER_CERT);
  103. BOOST_STATIC_CONSTANT(int, verify_client_once = SSL_VERIFY_CLIENT_ONCE);
  104. #endif
  105. /// Purpose of PEM password.
  106. enum password_purpose
  107. {
  108. /// The password is needed for reading/decryption.
  109. for_reading,
  110. /// The password is needed for writing/encryption.
  111. for_writing
  112. };
  113. protected:
  114. /// Protected destructor to prevent deletion through this type.
  115. ~context_base()
  116. {
  117. }
  118. #if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
  119. private:
  120. // Workaround to enable the empty base optimisation with Borland C++.
  121. char dummy_;
  122. #endif
  123. };
  124. } // namespace ssl
  125. } // namespace asio
  126. } // namespace boost
  127. #include <boost/asio/detail/pop_options.hpp>
  128. #endif // BOOST_ASIO_SSL_CONTEXT_BASE_HPP