@@ -43,6 +43,18 @@ namespace mongo {
43
43
return " " ;
44
44
}
45
45
#else
46
+
47
+ // Old copies of OpenSSL will not have constants to disable protocols they don't support.
48
+ // Define them to values we can OR together safely to generically disable these protocols across
49
+ // all versions of OpenSSL.
50
+ #ifndef SSL_OP_NO_TLSv1_1
51
+ #define SSL_OP_NO_TLSv1_1 0
52
+ #endif
53
+ #ifndef SSL_OP_NO_TLSv1_2
54
+ #define SSL_OP_NO_TLSv1_2 0
55
+ #endif
56
+
57
+
46
58
const std::string getSSLVersion (const std::string &prefix, const std::string &suffix) {
47
59
return prefix + SSLeay_version (SSLEAY_VERSION) + suffix;
48
60
}
@@ -132,6 +144,7 @@ namespace mongo {
132
144
const std::string& pempwd,
133
145
const std::string& clusterfile,
134
146
const std::string& clusterpwd,
147
+ const std::vector<SSLGlobalParams::Protocols>& disabledProtocols,
135
148
const std::string& cafile = " " ,
136
149
const std::string& crlfile = " " ,
137
150
const std::string& cipherConfig = " " ,
@@ -146,6 +159,7 @@ namespace mongo {
146
159
cafile (cafile),
147
160
crlfile (crlfile),
148
161
cipherConfig (cipherConfig),
162
+ disabledProtocols (disabledProtocols),
149
163
weakCertificateValidation (weakCertificateValidation),
150
164
allowInvalidCertificates (allowInvalidCertificates),
151
165
allowInvalidHostnames (allowInvalidHostnames),
@@ -158,6 +172,7 @@ namespace mongo {
158
172
std::string cafile;
159
173
std::string crlfile;
160
174
std::string cipherConfig;
175
+ std::vector<SSLGlobalParams::Protocols> disabledProtocols;
161
176
bool weakCertificateValidation;
162
177
bool allowInvalidCertificates;
163
178
bool allowInvalidHostnames;
@@ -294,6 +309,7 @@ namespace mongo {
294
309
sslGlobalParams.sslPEMKeyPassword ,
295
310
sslGlobalParams.sslClusterFile ,
296
311
sslGlobalParams.sslClusterPassword ,
312
+ sslGlobalParams.sslDisabledProtocols ,
297
313
sslGlobalParams.sslCAFile ,
298
314
sslGlobalParams.sslCRLFile ,
299
315
sslGlobalParams.sslCipherConfig ,
@@ -538,7 +554,22 @@ namespace mongo {
538
554
// SSL_OP_ALL - Activate all bug workaround options, to support buggy client SSL's.
539
555
// SSL_OP_NO_SSLv2 - Disable SSL v2 support
540
556
// SSL_OP_NO_SSLv3 - Disable SSL v3 support
541
- SSL_CTX_set_options (*context, SSL_OP_ALL|SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3);
557
+ long supportedProtocols = SSL_OP_ALL|SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3;
558
+
559
+ // Set the supported TLS protocols. Allow --disabledProtocols to disable selected ciphers.
560
+ if (!params.disabledProtocols .empty ()) {
561
+ for (std::vector<SSLGlobalParams::Protocols>::const_iterator it =
562
+ params.disabledProtocols .begin (); it != params.disabledProtocols .end (); ++it) {
563
+ if (*it == SSLGlobalParams::TLS1_0) {
564
+ supportedProtocols |= SSL_OP_NO_TLSv1;
565
+ } else if (*it == SSLGlobalParams::TLS1_1) {
566
+ supportedProtocols |= SSL_OP_NO_TLSv1_1;
567
+ } else if (*it == SSLGlobalParams::TLS1_2) {
568
+ supportedProtocols |= SSL_OP_NO_TLSv1_2;
569
+ }
570
+ }
571
+ }
572
+ SSL_CTX_set_options (*context, supportedProtocols);
542
573
543
574
// HIGH - Enable strong ciphers
544
575
// !EXPORT - Disable export ciphers (40/56 bit)
@@ -769,39 +800,31 @@ namespace mongo {
769
800
}
770
801
771
802
SSLConnection* SSLManager::connect (Socket* socket) {
772
- SSLConnection* sslConn = new SSLConnection (_clientContext, socket, NULL , 0 );
773
- ScopeGuard sslGuard = MakeGuard (::SSL_free, sslConn->ssl );
774
- ScopeGuard bioGuard = MakeGuard (::BIO_free, sslConn->networkBIO );
803
+ std::auto_ptr<SSLConnection> sslConn (new SSLConnection (_clientContext, socket, NULL , 0 ));
775
804
776
805
int ret;
777
806
do {
778
807
ret = ::SSL_connect (sslConn->ssl );
779
- } while (!_doneWithSSLOp (sslConn, ret));
808
+ } while (!_doneWithSSLOp (sslConn. get () , ret));
780
809
781
810
if (ret != 1 )
782
- _handleSSLError (SSL_get_error (sslConn, ret), ret);
811
+ _handleSSLError (SSL_get_error (sslConn. get () , ret), ret);
783
812
784
- sslGuard.Dismiss ();
785
- bioGuard.Dismiss ();
786
- return sslConn;
813
+ return sslConn.release ();
787
814
}
788
815
789
816
SSLConnection* SSLManager::accept (Socket* socket, const char * initialBytes, int len) {
790
- SSLConnection* sslConn = new SSLConnection (_serverContext, socket, initialBytes, len);
791
- ScopeGuard sslGuard = MakeGuard (::SSL_free, sslConn->ssl );
792
- ScopeGuard bioGuard = MakeGuard (::BIO_free, sslConn->networkBIO );
817
+ std::auto_ptr<SSLConnection> sslConn (new SSLConnection (_serverContext, socket, initialBytes, len));
793
818
794
819
int ret;
795
820
do {
796
821
ret = ::SSL_accept (sslConn->ssl );
797
- } while (!_doneWithSSLOp (sslConn, ret));
822
+ } while (!_doneWithSSLOp (sslConn. get () , ret));
798
823
799
824
if (ret != 1 )
800
- _handleSSLError (SSL_get_error (sslConn, ret), ret);
825
+ _handleSSLError (SSL_get_error (sslConn. get () , ret), ret);
801
826
802
- sslGuard.Dismiss ();
803
- bioGuard.Dismiss ();
804
- return sslConn;
827
+ return sslConn.release ();
805
828
}
806
829
807
830
// TODO SERVER-11601 Use NFC Unicode canonicalization
0 commit comments