@@ -74,16 +74,6 @@ class SslCtx {
7474 }
7575 }
7676
77- /* *
78- * @brief Sets the path to trusted certificate file.
79- * @throws `std::runtime_error` on failure.
80- */
81- void load_verify_file (const char *path) {
82- if (!SSL_CTX_load_verify_file (m_ctx.get (), path)) {
83- throw_ssl_err (" Failed to set default trusted certificate file `" , path, " `." );
84- }
85- }
86-
8777 /* *
8878 * @brief Sets the path to trusted certificates directory.
8979 *
@@ -98,35 +88,50 @@ class SslCtx {
9888 }
9989
10090 /* *
101- * @brief Sets the path to trusted certificates directory.
102- * @throws `std::runtime_error` on failure.
91+ * @brief Sets the path for trusted certificate file and directory.
92+ * @param file Path to trusted certificate file.
93+ * @param dir Path to trusted certificate directory.
10394 */
104- void load_verify_dir (const char *path ) {
105- if (!SSL_CTX_load_verify_dir (m_ctx.get (), path )) {
106- throw_ssl_err (" Failed to set default trusted certificate directory ` " , path, " ` ." );
95+ void load_verify_locations (const char *file, const char *dir ) {
96+ if (!SSL_CTX_load_verify_locations (m_ctx.get (), file, dir )) {
97+ throw_ssl_err (" Failed to set default trusted certificate locations ." );
10798 }
10899 }
109100
110101 /* *
111102 * @brief Sets the path to trusted certificates store.
112103 *
113104 * It will use the OS defaults.
105+ *
106+ * This is not available before openssl 3.
114107 * @throws `std::runtime_error` on failure.
115108 */
116109 void set_default_verify_store () {
110+ // Available only from OpenSSL 3.0.0-0 release
111+ #if OPENSSL_VERSION_NUMBER >= 0x03000000f
117112 if (!SSL_CTX_set_default_verify_store (m_ctx.get ())) {
118113 throw_ssl_err (" Failed to set default trusted certificate store." );
119114 }
115+ #else // OPENSSL_VERSION_NUMBER >= 0x03000000f
116+ throw std::runtime_error (" `set_default_verify_store` is not available before OpenSSL 3." );
117+ #endif // OPENSSL_VERSION_NUMBER >= 0x03000000f
120118 }
121119
122120 /* *
123121 * @brief Sets the path to trusted certificates store.
122+ *
123+ * This is not available before openssl 3.
124124 * @throws `std::runtime_error` on failure.
125125 */
126126 void load_verify_store (const char *path) {
127+ // Available only from OpenSSL 3.0.0-0 release
128+ #if OPENSSL_VERSION_NUMBER >= 0x03000000f
127129 if (!SSL_CTX_load_verify_store (m_ctx.get (), path)) {
128130 throw_ssl_err (" Failed to set default trusted certificate store `" , path, " `." );
129131 }
132+ #else // OPENSSL_VERSION_NUMBER >= 0x03000000f
133+ throw std::runtime_error (" `load_verify_store` is not available before OpenSSL 3." );
134+ #endif // OPENSSL_VERSION_NUMBER >= 0x03000000f
130135 }
131136
132137 /* *
0 commit comments