context_base.hpp 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. //
  2. // ssl/context_base.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2021 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/config.hpp>
  16. #include <boost/asio/ssl/detail/openssl_types.hpp>
  17. #include <boost/asio/detail/push_options.hpp>
  18. namespace boost {
  19. namespace asio {
  20. namespace ssl {
  21. /// The context_base class is used as a base for the basic_context class
  22. /// template so that we have a common place to define various enums.
  23. class context_base
  24. {
  25. public:
  26. /// Different methods supported by a context.
  27. enum method
  28. {
  29. /// Generic SSL version 2.
  30. sslv2,
  31. /// SSL version 2 client.
  32. sslv2_client,
  33. /// SSL version 2 server.
  34. sslv2_server,
  35. /// Generic SSL version 3.
  36. sslv3,
  37. /// SSL version 3 client.
  38. sslv3_client,
  39. /// SSL version 3 server.
  40. sslv3_server,
  41. /// Generic TLS version 1.
  42. tlsv1,
  43. /// TLS version 1 client.
  44. tlsv1_client,
  45. /// TLS version 1 server.
  46. tlsv1_server,
  47. /// Generic SSL/TLS.
  48. sslv23,
  49. /// SSL/TLS client.
  50. sslv23_client,
  51. /// SSL/TLS server.
  52. sslv23_server,
  53. /// Generic TLS version 1.1.
  54. tlsv11,
  55. /// TLS version 1.1 client.
  56. tlsv11_client,
  57. /// TLS version 1.1 server.
  58. tlsv11_server,
  59. /// Generic TLS version 1.2.
  60. tlsv12,
  61. /// TLS version 1.2 client.
  62. tlsv12_client,
  63. /// TLS version 1.2 server.
  64. tlsv12_server,
  65. /// Generic TLS version 1.3.
  66. tlsv13,
  67. /// TLS version 1.3 client.
  68. tlsv13_client,
  69. /// TLS version 1.3 server.
  70. tlsv13_server,
  71. /// Generic TLS.
  72. tls,
  73. /// TLS client.
  74. tls_client,
  75. /// TLS server.
  76. tls_server
  77. };
  78. /// Bitmask type for SSL options.
  79. typedef long options;
  80. #if defined(GENERATING_DOCUMENTATION)
  81. /// Implement various bug workarounds.
  82. static const long default_workarounds = implementation_defined;
  83. /// Always create a new key when using tmp_dh parameters.
  84. static const long single_dh_use = implementation_defined;
  85. /// Disable SSL v2.
  86. static const long no_sslv2 = implementation_defined;
  87. /// Disable SSL v3.
  88. static const long no_sslv3 = implementation_defined;
  89. /// Disable TLS v1.
  90. static const long no_tlsv1 = implementation_defined;
  91. /// Disable TLS v1.1.
  92. static const long no_tlsv1_1 = implementation_defined;
  93. /// Disable TLS v1.2.
  94. static const long no_tlsv1_2 = implementation_defined;
  95. /// Disable TLS v1.3.
  96. static const long no_tlsv1_3 = implementation_defined;
  97. /// Disable compression. Compression is disabled by default.
  98. static const long no_compression = implementation_defined;
  99. #else
  100. BOOST_ASIO_STATIC_CONSTANT(long, default_workarounds = SSL_OP_ALL);
  101. BOOST_ASIO_STATIC_CONSTANT(long, single_dh_use = SSL_OP_SINGLE_DH_USE);
  102. BOOST_ASIO_STATIC_CONSTANT(long, no_sslv2 = SSL_OP_NO_SSLv2);
  103. BOOST_ASIO_STATIC_CONSTANT(long, no_sslv3 = SSL_OP_NO_SSLv3);
  104. BOOST_ASIO_STATIC_CONSTANT(long, no_tlsv1 = SSL_OP_NO_TLSv1);
  105. # if defined(SSL_OP_NO_TLSv1_1)
  106. BOOST_ASIO_STATIC_CONSTANT(long, no_tlsv1_1 = SSL_OP_NO_TLSv1_1);
  107. # else // defined(SSL_OP_NO_TLSv1_1)
  108. BOOST_ASIO_STATIC_CONSTANT(long, no_tlsv1_1 = 0x10000000L);
  109. # endif // defined(SSL_OP_NO_TLSv1_1)
  110. # if defined(SSL_OP_NO_TLSv1_2)
  111. BOOST_ASIO_STATIC_CONSTANT(long, no_tlsv1_2 = SSL_OP_NO_TLSv1_2);
  112. # else // defined(SSL_OP_NO_TLSv1_2)
  113. BOOST_ASIO_STATIC_CONSTANT(long, no_tlsv1_2 = 0x08000000L);
  114. # endif // defined(SSL_OP_NO_TLSv1_2)
  115. # if defined(SSL_OP_NO_TLSv1_3)
  116. BOOST_ASIO_STATIC_CONSTANT(long, no_tlsv1_3 = SSL_OP_NO_TLSv1_3);
  117. # else // defined(SSL_OP_NO_TLSv1_3)
  118. BOOST_ASIO_STATIC_CONSTANT(long, no_tlsv1_3 = 0x20000000L);
  119. # endif // defined(SSL_OP_NO_TLSv1_3)
  120. # if defined(SSL_OP_NO_COMPRESSION)
  121. BOOST_ASIO_STATIC_CONSTANT(long, no_compression = SSL_OP_NO_COMPRESSION);
  122. # else // defined(SSL_OP_NO_COMPRESSION)
  123. BOOST_ASIO_STATIC_CONSTANT(long, no_compression = 0x20000L);
  124. # endif // defined(SSL_OP_NO_COMPRESSION)
  125. #endif
  126. /// File format types.
  127. enum file_format
  128. {
  129. /// ASN.1 file.
  130. asn1,
  131. /// PEM file.
  132. pem
  133. };
  134. #if !defined(GENERATING_DOCUMENTATION)
  135. // The following types and constants are preserved for backward compatibility.
  136. // New programs should use the equivalents of the same names that are defined
  137. // in the boost::asio::ssl namespace.
  138. typedef int verify_mode;
  139. BOOST_ASIO_STATIC_CONSTANT(int, verify_none = SSL_VERIFY_NONE);
  140. BOOST_ASIO_STATIC_CONSTANT(int, verify_peer = SSL_VERIFY_PEER);
  141. BOOST_ASIO_STATIC_CONSTANT(int,
  142. verify_fail_if_no_peer_cert = SSL_VERIFY_FAIL_IF_NO_PEER_CERT);
  143. BOOST_ASIO_STATIC_CONSTANT(int, verify_client_once = SSL_VERIFY_CLIENT_ONCE);
  144. #endif
  145. /// Purpose of PEM password.
  146. enum password_purpose
  147. {
  148. /// The password is needed for reading/decryption.
  149. for_reading,
  150. /// The password is needed for writing/encryption.
  151. for_writing
  152. };
  153. protected:
  154. /// Protected destructor to prevent deletion through this type.
  155. ~context_base()
  156. {
  157. }
  158. };
  159. } // namespace ssl
  160. } // namespace asio
  161. } // namespace boost
  162. #include <boost/asio/detail/pop_options.hpp>
  163. #endif // BOOST_ASIO_SSL_CONTEXT_BASE_HPP