delete lock;
}
+void SSLContext::setSSLLockTypesLocked(std::map<int, SSLLockType> inLockTypes) {
+ lockTypes() = inLockTypes;
+}
+
void SSLContext::setSSLLockTypes(std::map<int, SSLLockType> inLockTypes) {
+ std::lock_guard<std::mutex> g(initMutex());
if (initialized_) {
// We set the locks on initialization, so if we are already initialized
// this would have no affect.
LOG(INFO) << "Ignoring setSSLLockTypes after initialization";
return;
}
+ setSSLLockTypesLocked(std::move(inLockTypes));
+}
- lockTypes() = inLockTypes;
+void SSLContext::setSSLLockTypesAndInitOpenSSL(
+ std::map<int, SSLLockType> inLockTypes) {
+ std::lock_guard<std::mutex> g(initMutex());
+ CHECK(!initialized_) << "OpenSSL is already initialized";
+ setSSLLockTypesLocked(std::move(inLockTypes));
+ initializeOpenSSLLocked();
}
bool SSLContext::isSSLLockDisabled(int lockId) {
+ std::lock_guard<std::mutex> g(initMutex());
+ CHECK(initialized_) << "OpenSSL is not initialized yet";
const auto& sslLocks = lockTypes();
const auto it = sslLocks.find(lockId);
return it != sslLocks.end() &&
*/
static void setSSLLockTypes(std::map<int, SSLLockType> lockTypes);
+ /**
+ * Set the lock types and initialize OpenSSL in an atomic fashion. This
+ * aborts if the library has already been initialized.
+ */
+ static void setSSLLockTypesAndInitOpenSSL(
+ std::map<int, SSLLockType> lockTypes);
+
/**
* Determine if the SSL lock with the specified id (i.e.
* CRYPTO_LOCK_SSL_SESSION) is disabled. This should be called after
// Functions are called when locked by the calling function.
static void initializeOpenSSLLocked();
static void cleanupOpenSSLLocked();
+ static void setSSLLockTypesLocked(std::map<int, SSLLockType> inLockTypes);
};
typedef std::shared_ptr<SSLContext> SSLContextPtr;
#endif
}
+TEST(AsyncSSLSocketTest2, SSLContextSetLocksAndInitialize) {
+ SSLContext::cleanupOpenSSL();
+ SSLContext::setSSLLockTypesAndInitOpenSSL({});
+ EXPECT_DEATH(
+ SSLContext::setSSLLockTypesAndInitOpenSSL({}),
+ "OpenSSL is already initialized");
+
+ SSLContext::cleanupOpenSSL();
+ SSLContext::initializeOpenSSL();
+ EXPECT_DEATH(
+ SSLContext::setSSLLockTypesAndInitOpenSSL({}),
+ "OpenSSL is already initialized");
+}
} // folly
int main(int argc, char *argv[]) {