#include <pthread.h>
#include <openssl/conf.h>
+#ifndef OPENSSL_NO_ENGINE
#include <openssl/engine.h>
+#endif
#include <openssl/err.h>
#include <openssl/ocsp.h>
#include <openssl/rand.h>
#endif /* (OPENSSL_VERSION_NUMBER < 0x1010000fL || (defined LIBRESSL_VERSION_NUMBER) && LIBRESSL_VERSION_NUMBER < 0x2090100fL) */
static std::atomic<uint64_t> s_users;
+#ifndef OPENSSL_NO_ENGINE
static LockGuarded<std::unordered_map<std::string, std::unique_ptr<ENGINE, int(*)(ENGINE*)>>> s_engines;
+#endif
static int s_ticketsKeyIndex{-1};
static int s_countersIndex{-1};
static int s_keyLogIndex{-1};
void unregisterOpenSSLUser()
{
if (s_users.fetch_sub(1) == 1) {
+#ifndef OPENSSL_NO_ENGINE
for (auto& [name, engine] : *s_engines.lock()) {
ENGINE_finish(engine.get());
engine.reset();
}
s_engines.lock()->clear();
+#endif
#if (OPENSSL_VERSION_NUMBER < 0x1010000fL || (defined LIBRESSL_VERSION_NUMBER && LIBRESSL_VERSION_NUMBER < 0x2090100fL))
ERR_free_strings();
std::pair<bool, std::string> libssl_load_engine(const std::string& engineName, const std::optional<std::string>& defaultString)
{
+#ifdef OPENSSL_NO_ENGINE
+ return { false, "OpenSSL has been built without engine support" };
+#else
if (s_users.load() == 0) {
/* We need to make sure that OpenSSL has been properly initialized before loading an engine.
This messes up our accounting a bit, so some memory might not be properly released when
engines->insert({engineName, std::move(engine)});
return { true, "" };
+#endif
}
void* libssl_get_ticket_key_callback_data(SSL* s)
std::vector<int> getAsyncFDs() override
{
+ std::vector<int> results;
+#ifdef SSL_MODE_ASYNC
if (SSL_waiting_for_async(d_conn.get()) != 1) {
- return {};
+ return results;
}
OSSL_ASYNC_FD fds[32];
size_t numfds = sizeof(fds)/sizeof(*fds);
SSL_get_all_async_fds(d_conn.get(), nullptr, &numfds);
if (numfds == 0) {
- return {};
+ return results;
}
SSL_get_all_async_fds(d_conn.get(), fds, &numfds);
- std::vector<int> results;
results.reserve(numfds);
for (size_t idx = 0; idx < numfds; idx++) {
results.push_back(fds[idx]);
}
+#endif
return results;
}
else if (error == SSL_ERROR_ZERO_RETURN) {
throw std::runtime_error("TLS connection closed by remote end");
}
+#ifdef SSL_MODE_ASYNC
else if (error == SSL_ERROR_WANT_ASYNC) {
return IOState::Async;
}
+#endif
else {
if (g_verbose) {
throw std::runtime_error("Error while processing TLS connection: (" + std::to_string(error) + ") " + libssl_get_error_string());