| 142 | } |
| 143 | |
| 144 | void cleanupOpenSSL() { |
| 145 | if (!openSSLInitialized) { |
| 146 | return; |
| 147 | } |
| 148 | openSSLInitialized = false; |
| 149 | |
| 150 | // https://wiki.openssl.org/index.php/Library_Initialization#Cleanup |
| 151 | // we purposefully do NOT call FIPS_mode_set(0) and leave it up to the enclosing application to manage FIPS entirely |
| 152 | #if (OPENSSL_VERSION_NUMBER < OPENSSL_ENGINE_CLEANUP_REQUIRED_BEFORE) |
| 153 | ENGINE_cleanup(); // https://www.openssl.org/docs/man1.1.0/crypto/ENGINE_cleanup.html - cleanup call is needed before 1.1.0 |
| 154 | #endif |
| 155 | #if !defined(OPENSSL_IS_BORINGSSL) && !defined(OPENSSL_IS_AWSLC) |
| 156 | CONF_modules_unload(1); |
| 157 | #endif |
| 158 | EVP_cleanup(); |
| 159 | CRYPTO_cleanup_all_ex_data(); |
| 160 | #if OPENSSL_VERSION_NUMBER >= 0x10100000 |
| 161 | // Do nothing unless an openssl derivative is detected |
| 162 | # if !defined(OPENSSL_IS_BORINGSSL) && !defined(OPENSSL_IS_AWSLC) |
| 163 | // https://www.openssl.org/docs/man1.1.1/man3/OPENSSL_thread_stop.html |
| 164 | OPENSSL_thread_stop(); |
| 165 | # endif |
| 166 | #else |
| 167 | // ERR_remove_state() was deprecated in OpenSSL 1.0.0 and ERR_remove_thread_state() |
| 168 | // was deprecated in OpenSSL 1.1.0; these functions and should not be used. |
| 169 | // https://www.openssl.org/docs/manmaster/man3/ERR_remove_state.html |
| 170 | ERR_remove_state(0); |
| 171 | #endif |
| 172 | ERR_free_strings(); |
| 173 | |
| 174 | mutexes.reset(); |
| 175 | } |
| 176 | |
| 177 | static void buildErrors(string& message, int errno_copy = 0, int sslerrno = 0); |
| 178 | static bool matchName(const char* host, const char* pattern, int size); |