context_base.hpp 4.1 KB

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