tls.hpp 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. // Copyright 2019 MongoDB Inc.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #pragma once
  15. #include <string>
  16. #include <bsoncxx/stdx/optional.hpp>
  17. #include <bsoncxx/string/view_or_value.hpp>
  18. #include <mongocxx/stdx.hpp>
  19. #include <mongocxx/config/prelude.hpp>
  20. namespace mongocxx {
  21. MONGOCXX_INLINE_NAMESPACE_BEGIN
  22. namespace options {
  23. ///
  24. /// Class representing the optional arguments to a MongoDB driver client (TLS)
  25. ///
  26. class MONGOCXX_API tls {
  27. public:
  28. ///
  29. /// The path to the .pem file containing a public key certificate and its associated private
  30. /// key.
  31. ///
  32. /// @param pem_file
  33. /// The path to the .pem file.
  34. ///
  35. /// @return
  36. /// A reference to the object on which this member function is being called. This facilitates
  37. /// method chaining.
  38. ///
  39. tls& pem_file(bsoncxx::string::view_or_value pem_file);
  40. ///
  41. /// Retrieves the current path to the .pem file.
  42. ///
  43. /// @return The path to the .pem file.
  44. ///
  45. const stdx::optional<bsoncxx::string::view_or_value>& pem_file() const;
  46. ///
  47. /// The pass phrase used to decrypt an encrypted PEM file.
  48. ///
  49. /// @param pem_password
  50. /// The pass phrase.
  51. ///
  52. /// @return
  53. /// A reference to the object on which this member function is being called. This facilitates
  54. /// method chaining.
  55. ///
  56. tls& pem_password(bsoncxx::string::view_or_value pem_password);
  57. ///
  58. /// Retrieves the current decryption pass phrase.
  59. ///
  60. /// @return The pass phrase.
  61. ///
  62. const stdx::optional<bsoncxx::string::view_or_value>& pem_password() const;
  63. ///
  64. /// The path to the .pem file that contains the root certificate chain from the Certificate
  65. /// Authority.
  66. ///
  67. /// @param ca_file
  68. /// The path to the CA file.
  69. ///
  70. /// @return
  71. /// A reference to the object on which this member function is being called. This facilitates
  72. /// method chaining.
  73. ///
  74. tls& ca_file(bsoncxx::string::view_or_value ca_file);
  75. ///
  76. /// Retrieves the current path to the CA file.
  77. ///
  78. /// @return The path to the CA file.
  79. ///
  80. const stdx::optional<bsoncxx::string::view_or_value>& ca_file() const;
  81. ///
  82. /// The path to the Certificate Authority directory.
  83. ///
  84. /// @param ca_dir
  85. /// The path to the CA directory.
  86. ///
  87. /// @return
  88. /// A reference to the object on which this member function is being called. This facilitates
  89. /// method chaining.
  90. ///
  91. tls& ca_dir(bsoncxx::string::view_or_value ca_dir);
  92. ///
  93. /// Retrieves the current path to the CA directory.
  94. ///
  95. /// @return The path to the CA directory.
  96. ///
  97. const stdx::optional<bsoncxx::string::view_or_value>& ca_dir() const;
  98. ///
  99. /// The path to the .pem file that contains revoked certificates.
  100. ///
  101. /// @param crl_file
  102. /// The path to the PEM file.
  103. ///
  104. /// @return
  105. /// A reference to the object on which this member function is being called. This facilitates
  106. /// method chaining.
  107. ///
  108. tls& crl_file(bsoncxx::string::view_or_value crl_file);
  109. ///
  110. /// Retrieves the current path to the .pem file that contains revoked certificates.
  111. ///
  112. /// @return The path to the revoked certificates file.
  113. ///
  114. const stdx::optional<bsoncxx::string::view_or_value>& crl_file() const;
  115. ///
  116. /// If true, the driver will not verify the server's CA file.
  117. ///
  118. /// @param allow_invalid_certificates
  119. /// Whether or not to check the server's CA file.
  120. ///
  121. /// @return
  122. /// A reference to the object on which this member function is being called. This facilitates
  123. /// method chaining.
  124. ///
  125. tls& allow_invalid_certificates(bool allow_invalid_certificates);
  126. ///
  127. /// Retrieves whether or not the driver will check the server's CA file.
  128. ///
  129. /// @return Whether or not the driver will check the server's CA file.
  130. ///
  131. const stdx::optional<bool>& allow_invalid_certificates() const;
  132. private:
  133. stdx::optional<bsoncxx::string::view_or_value> _pem_file;
  134. stdx::optional<bsoncxx::string::view_or_value> _pem_password;
  135. stdx::optional<bsoncxx::string::view_or_value> _ca_file;
  136. stdx::optional<bsoncxx::string::view_or_value> _ca_dir;
  137. stdx::optional<bsoncxx::string::view_or_value> _crl_file;
  138. stdx::optional<bool> _allow_invalid_certificates;
  139. };
  140. } // namespace options
  141. MONGOCXX_INLINE_NAMESPACE_END
  142. } // namespace mongocxx
  143. #include <mongocxx/config/postlude.hpp>