context_base.hpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. //
  2. // ssl/context_base.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2005-2011 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/config.hpp"
  16. #include <boost/detail/workaround.hpp>
  17. #include "asio/ssl/detail/openssl_types.hpp"
  18. #include "asio/detail/push_options.hpp"
  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. };
  54. /// Bitmask type for SSL options.
  55. typedef int options;
  56. #if defined(GENERATING_DOCUMENTATION)
  57. /// Implement various bug workarounds.
  58. static const int default_workarounds = implementation_defined;
  59. /// Always create a new key when using tmp_dh parameters.
  60. static const int single_dh_use = implementation_defined;
  61. /// Disable SSL v2.
  62. static const int no_sslv2 = implementation_defined;
  63. /// Disable SSL v3.
  64. static const int no_sslv3 = implementation_defined;
  65. /// Disable TLS v1.
  66. static const int no_tlsv1 = implementation_defined;
  67. #else
  68. BOOST_STATIC_CONSTANT(int, default_workarounds = SSL_OP_ALL);
  69. BOOST_STATIC_CONSTANT(int, single_dh_use = SSL_OP_SINGLE_DH_USE);
  70. BOOST_STATIC_CONSTANT(int, no_sslv2 = SSL_OP_NO_SSLv2);
  71. BOOST_STATIC_CONSTANT(int, no_sslv3 = SSL_OP_NO_SSLv3);
  72. BOOST_STATIC_CONSTANT(int, no_tlsv1 = SSL_OP_NO_TLSv1);
  73. #endif
  74. /// File format types.
  75. enum file_format
  76. {
  77. /// ASN.1 file.
  78. asn1,
  79. /// PEM file.
  80. pem
  81. };
  82. /// Bitmask type for peer verification.
  83. typedef int verify_mode;
  84. #if defined(GENERATING_DOCUMENTATION)
  85. /// No verification.
  86. static const int verify_none = implementation_defined;
  87. /// Verify the peer.
  88. static const int verify_peer = implementation_defined;
  89. /// Fail verification if the peer has no certificate. Ignored unless
  90. /// verify_peer is set.
  91. static const int verify_fail_if_no_peer_cert = implementation_defined;
  92. /// Do not request client certificate on renegotiation. Ignored unless
  93. /// verify_peer is set.
  94. static const int verify_client_once = implementation_defined;
  95. #else
  96. BOOST_STATIC_CONSTANT(int, verify_none = SSL_VERIFY_NONE);
  97. BOOST_STATIC_CONSTANT(int, verify_peer = SSL_VERIFY_PEER);
  98. BOOST_STATIC_CONSTANT(int,
  99. verify_fail_if_no_peer_cert = SSL_VERIFY_FAIL_IF_NO_PEER_CERT);
  100. BOOST_STATIC_CONSTANT(int, verify_client_once = SSL_VERIFY_CLIENT_ONCE);
  101. #endif
  102. /// Purpose of PEM password.
  103. enum password_purpose
  104. {
  105. /// The password is needed for reading/decryption.
  106. for_reading,
  107. /// The password is needed for writing/encryption.
  108. for_writing
  109. };
  110. protected:
  111. /// Protected destructor to prevent deletion through this type.
  112. ~context_base()
  113. {
  114. }
  115. #if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
  116. private:
  117. // Workaround to enable the empty base optimisation with Borland C++.
  118. char dummy_;
  119. #endif
  120. };
  121. } // namespace ssl
  122. } // namespace asio
  123. #include "asio/detail/pop_options.hpp"
  124. #endif // ASIO_SSL_CONTEXT_BASE_HPP