context_base.hpp 3.9 KB

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