context_base.hpp 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. //
  2. // ssl/context_base.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2018 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.
  66. tls,
  67. /// TLS client.
  68. tls_client,
  69. /// TLS server.
  70. tls_server
  71. };
  72. /// Bitmask type for SSL options.
  73. typedef long options;
  74. #if defined(GENERATING_DOCUMENTATION)
  75. /// Implement various bug workarounds.
  76. static const long default_workarounds = implementation_defined;
  77. /// Always create a new key when using tmp_dh parameters.
  78. static const long single_dh_use = implementation_defined;
  79. /// Disable SSL v2.
  80. static const long no_sslv2 = implementation_defined;
  81. /// Disable SSL v3.
  82. static const long no_sslv3 = implementation_defined;
  83. /// Disable TLS v1.
  84. static const long no_tlsv1 = implementation_defined;
  85. /// Disable TLS v1.1.
  86. static const long no_tlsv1_1 = implementation_defined;
  87. /// Disable TLS v1.2.
  88. static const long no_tlsv1_2 = implementation_defined;
  89. /// Disable compression. Compression is disabled by default.
  90. static const long no_compression = implementation_defined;
  91. #else
  92. BOOST_ASIO_STATIC_CONSTANT(long, default_workarounds = SSL_OP_ALL);
  93. BOOST_ASIO_STATIC_CONSTANT(long, single_dh_use = SSL_OP_SINGLE_DH_USE);
  94. BOOST_ASIO_STATIC_CONSTANT(long, no_sslv2 = SSL_OP_NO_SSLv2);
  95. BOOST_ASIO_STATIC_CONSTANT(long, no_sslv3 = SSL_OP_NO_SSLv3);
  96. BOOST_ASIO_STATIC_CONSTANT(long, no_tlsv1 = SSL_OP_NO_TLSv1);
  97. # if defined(SSL_OP_NO_TLSv1_1)
  98. BOOST_ASIO_STATIC_CONSTANT(long, no_tlsv1_1 = SSL_OP_NO_TLSv1_1);
  99. # else // defined(SSL_OP_NO_TLSv1_1)
  100. BOOST_ASIO_STATIC_CONSTANT(long, no_tlsv1_1 = 0x10000000L);
  101. # endif // defined(SSL_OP_NO_TLSv1_1)
  102. # if defined(SSL_OP_NO_TLSv1_2)
  103. BOOST_ASIO_STATIC_CONSTANT(long, no_tlsv1_2 = SSL_OP_NO_TLSv1_2);
  104. # else // defined(SSL_OP_NO_TLSv1_2)
  105. BOOST_ASIO_STATIC_CONSTANT(long, no_tlsv1_2 = 0x08000000L);
  106. # endif // defined(SSL_OP_NO_TLSv1_2)
  107. # if defined(SSL_OP_NO_COMPRESSION)
  108. BOOST_ASIO_STATIC_CONSTANT(long, no_compression = SSL_OP_NO_COMPRESSION);
  109. # else // defined(SSL_OP_NO_COMPRESSION)
  110. BOOST_ASIO_STATIC_CONSTANT(long, no_compression = 0x20000L);
  111. # endif // defined(SSL_OP_NO_COMPRESSION)
  112. #endif
  113. /// File format types.
  114. enum file_format
  115. {
  116. /// ASN.1 file.
  117. asn1,
  118. /// PEM file.
  119. pem
  120. };
  121. #if !defined(GENERATING_DOCUMENTATION)
  122. // The following types and constants are preserved for backward compatibility.
  123. // New programs should use the equivalents of the same names that are defined
  124. // in the boost::asio::ssl namespace.
  125. typedef int verify_mode;
  126. BOOST_ASIO_STATIC_CONSTANT(int, verify_none = SSL_VERIFY_NONE);
  127. BOOST_ASIO_STATIC_CONSTANT(int, verify_peer = SSL_VERIFY_PEER);
  128. BOOST_ASIO_STATIC_CONSTANT(int,
  129. verify_fail_if_no_peer_cert = SSL_VERIFY_FAIL_IF_NO_PEER_CERT);
  130. BOOST_ASIO_STATIC_CONSTANT(int, verify_client_once = SSL_VERIFY_CLIENT_ONCE);
  131. #endif
  132. /// Purpose of PEM password.
  133. enum password_purpose
  134. {
  135. /// The password is needed for reading/decryption.
  136. for_reading,
  137. /// The password is needed for writing/encryption.
  138. for_writing
  139. };
  140. protected:
  141. /// Protected destructor to prevent deletion through this type.
  142. ~context_base()
  143. {
  144. }
  145. };
  146. } // namespace ssl
  147. } // namespace asio
  148. } // namespace boost
  149. #include <boost/asio/detail/pop_options.hpp>
  150. #endif // BOOST_ASIO_SSL_CONTEXT_BASE_HPP