summaryrefslogtreecommitdiff
path: root/src/mongo/util/net
diff options
context:
space:
mode:
authorIsabella Siu <isabella.siu@10gen.com>2019-01-04 16:04:27 -0500
committerIsabella Siu <isabella.siu@10gen.com>2019-01-09 11:10:11 -0500
commit0e237325a508f3c49eb6a19ea4a9dbb7c6053058 (patch)
treeadd0173dfb7aa76504b1d0cd18c251fcbfeb099f /src/mongo/util/net
parent5d0f13334445fca6e2c5bfc496b5d5b1cb7e0f8a (diff)
downloadmongo-0e237325a508f3c49eb6a19ea4a9dbb7c6053058.tar.gz
SERVER-38738 collapse all getSSLManager() to one implementation and remove mutex
Diffstat (limited to 'src/mongo/util/net')
-rw-r--r--src/mongo/util/net/ssl_manager.cpp9
-rw-r--r--src/mongo/util/net/ssl_manager_apple.cpp14
-rw-r--r--src/mongo/util/net/ssl_manager_openssl.cpp11
-rw-r--r--src/mongo/util/net/ssl_manager_windows.cpp13
4 files changed, 12 insertions, 35 deletions
diff --git a/src/mongo/util/net/ssl_manager.cpp b/src/mongo/util/net/ssl_manager.cpp
index ac772a97a01..7035053b51f 100644
--- a/src/mongo/util/net/ssl_manager.cpp
+++ b/src/mongo/util/net/ssl_manager.cpp
@@ -53,6 +53,9 @@
#include "mongo/util/text.h"
namespace mongo {
+
+SSLManagerInterface* theSSLManager = nullptr;
+
namespace {
// Some of these duplicate the std::isalpha/std::isxdigit because we don't want them to be
@@ -575,7 +578,7 @@ TLSVersionCounts& TLSVersionCounts::get(ServiceContext* serviceContext) {
MONGO_INITIALIZER_WITH_PREREQUISITES(SSLManagerLogger, ("SSLManager", "GlobalLogManager"))
(InitializerContext*) {
if (!isSSLServer || (sslGlobalParams.sslMode.load() != SSLParams::SSLMode_disabled)) {
- const auto& config = getSSLManager()->getSSLConfiguration();
+ const auto& config = theSSLManager->getSSLConfiguration();
if (!config.clientSubjectName.empty()) {
LOG(1) << "Client Certificate Name: " << config.clientSubjectName;
}
@@ -1159,6 +1162,10 @@ void recordTLSVersion(TLSVersion version, const HostAndPort& hostForLogging) {
}
}
+SSLManagerInterface* getSSLManager() {
+ return theSSLManager;
+}
+
} // namespace mongo
// TODO SERVER-11601 Use NFC Unicode canonicalization
diff --git a/src/mongo/util/net/ssl_manager_apple.cpp b/src/mongo/util/net/ssl_manager_apple.cpp
index 084c3369f2e..6d16d98fae0 100644
--- a/src/mongo/util/net/ssl_manager_apple.cpp
+++ b/src/mongo/util/net/ssl_manager_apple.cpp
@@ -1559,10 +1559,7 @@ int SSLManagerApple::SSL_shutdown(SSLConnectionInterface* conn) {
// Global variable indicating if this is a server or a client instance
bool isSSLServer = false;
-namespace {
-SimpleMutex sslManagerMtx;
-SSLManagerInterface* theSSLManager = nullptr;
-} // namespace
+extern SSLManagerInterface* theSSLManager;
std::unique_ptr<SSLManagerInterface> SSLManagerInterface::create(const SSLParams& params,
bool isServer) {
@@ -1574,7 +1571,6 @@ MONGO_INITIALIZER_WITH_PREREQUISITES(SSLManager, ("EndStartupOptionHandling"))
kMongoDBRolesOID = ::CFStringCreateWithCString(
nullptr, mongodbRolesOID.identifier.c_str(), ::kCFStringEncodingUTF8);
- stdx::lock_guard<SimpleMutex> lck(sslManagerMtx);
if (!isSSLServer || (sslGlobalParams.sslMode.load() != SSLParams::SSLMode_disabled)) {
theSSLManager = new SSLManagerApple(sslGlobalParams, isSSLServer);
}
@@ -1582,11 +1578,3 @@ MONGO_INITIALIZER_WITH_PREREQUISITES(SSLManager, ("EndStartupOptionHandling"))
}
} // namespace mongo
-
-mongo::SSLManagerInterface* mongo::getSSLManager() {
- stdx::lock_guard<SimpleMutex> lck(sslManagerMtx);
- if (theSSLManager) {
- return theSSLManager;
- }
- return nullptr;
-}
diff --git a/src/mongo/util/net/ssl_manager_openssl.cpp b/src/mongo/util/net/ssl_manager_openssl.cpp
index e3eab7cbe6d..44521e0115c 100644
--- a/src/mongo/util/net/ssl_manager_openssl.cpp
+++ b/src/mongo/util/net/ssl_manager_openssl.cpp
@@ -416,8 +416,6 @@ public:
////////////////////////////////////////////////////////////////
-SimpleMutex sslManagerMtx;
-SSLManagerInterface* theSSLManager = NULL;
using UniqueSSLContext = std::unique_ptr<SSL_CTX, decltype(&free_ssl_context)>;
static const int BUFFER_SIZE = 8 * 1024;
static const int DATE_LEN = 128;
@@ -642,6 +640,7 @@ void setupFIPS() {
// Global variable indicating if this is a server or a client instance
bool isSSLServer = false;
+extern SSLManagerInterface* theSSLManager;
MONGO_INITIALIZER(SetupOpenSSL)(InitializerContext*) {
SSL_library_init();
@@ -664,7 +663,6 @@ MONGO_INITIALIZER(SetupOpenSSL)(InitializerContext*) {
MONGO_INITIALIZER_WITH_PREREQUISITES(SSLManager, ("SetupOpenSSL", "EndStartupOptionHandling"))
(InitializerContext*) {
- stdx::lock_guard<SimpleMutex> lck(sslManagerMtx);
if (!isSSLServer || (sslGlobalParams.sslMode.load() != SSLParams::SSLMode_disabled)) {
theSSLManager = new SSLManagerOpenSSL(sslGlobalParams, isSSLServer);
}
@@ -676,13 +674,6 @@ std::unique_ptr<SSLManagerInterface> SSLManagerInterface::create(const SSLParams
return stdx::make_unique<SSLManagerOpenSSL>(params, isServer);
}
-SSLManagerInterface* getSSLManager() {
- stdx::lock_guard<SimpleMutex> lck(sslManagerMtx);
- if (theSSLManager)
- return theSSLManager;
- return NULL;
-}
-
SSLX509Name getCertificateSubjectX509Name(X509* cert) {
std::vector<std::vector<SSLX509Name::Entry>> entries;
diff --git a/src/mongo/util/net/ssl_manager_windows.cpp b/src/mongo/util/net/ssl_manager_windows.cpp
index 111d38157c8..e5f88e026e7 100644
--- a/src/mongo/util/net/ssl_manager_windows.cpp
+++ b/src/mongo/util/net/ssl_manager_windows.cpp
@@ -66,10 +66,9 @@
namespace mongo {
-namespace {
+extern SSLManagerInterface* theSSLManager;
-SimpleMutex sslManagerMtx;
-SSLManagerInterface* theSSLManager = NULL;
+namespace {
/**
* Free a Certificate Context.
@@ -346,7 +345,6 @@ private:
MONGO_INITIALIZER_WITH_PREREQUISITES(SSLManager, ("EndStartupOptionHandling"))
(InitializerContext*) {
- stdx::lock_guard<SimpleMutex> lck(sslManagerMtx);
if (!isSSLServer || (sslGlobalParams.sslMode.load() != SSLParams::SSLMode_disabled)) {
theSSLManager = new SSLManagerWindows(sslGlobalParams, isSSLServer);
}
@@ -379,13 +377,6 @@ std::unique_ptr<SSLManagerInterface> SSLManagerInterface::create(const SSLParams
return stdx::make_unique<SSLManagerWindows>(params, isServer);
}
-SSLManagerInterface* getSSLManager() {
- stdx::lock_guard<SimpleMutex> lck(sslManagerMtx);
- if (theSSLManager)
- return theSSLManager;
- return NULL;
-}
-
namespace {
SSLManagerWindows::SSLManagerWindows(const SSLParams& params, bool isServer)