@@ -32,6 +32,7 @@ namespace MongoDB.Driver
32
32
public class MongoServerSettings : IEquatable < MongoServerSettings > , IInheritableMongoClientSettings
33
33
{
34
34
// private fields
35
+ private bool _allowInsecureTls ;
35
36
private string _applicationName ;
36
37
private Action < ClusterBuilder > _clusterConfigurator ;
37
38
private IReadOnlyList < CompressorConfiguration > _compressors ;
@@ -60,8 +61,7 @@ public class MongoServerSettings : IEquatable<MongoServerSettings>, IInheritable
60
61
private TimeSpan _serverSelectionTimeout ;
61
62
private TimeSpan _socketTimeout ;
62
63
private SslSettings _sslSettings ;
63
- private bool _useSsl ;
64
- private bool _verifySslCertificate ;
64
+ private bool _useTls ;
65
65
private int _waitQueueSize ;
66
66
private TimeSpan _waitQueueTimeout ;
67
67
private WriteConcern _writeConcern ;
@@ -78,6 +78,7 @@ public class MongoServerSettings : IEquatable<MongoServerSettings>, IInheritable
78
78
/// </summary>
79
79
public MongoServerSettings ( )
80
80
{
81
+ _allowInsecureTls = false ;
81
82
_applicationName = null ;
82
83
_compressors = new CompressorConfiguration [ 0 ] ;
83
84
_connectionMode = ConnectionMode . Automatic ;
@@ -105,8 +106,7 @@ public MongoServerSettings()
105
106
_serverSelectionTimeout = MongoDefaults . ServerSelectionTimeout ;
106
107
_socketTimeout = MongoDefaults . SocketTimeout ;
107
108
_sslSettings = null ;
108
- _useSsl = false ;
109
- _verifySslCertificate = true ;
109
+ _useTls = false ;
110
110
_waitQueueSize = MongoDefaults . ComputedWaitQueueSize ;
111
111
_waitQueueTimeout = MongoDefaults . WaitQueueTimeout ;
112
112
_writeConcern = WriteConcern . Unacknowledged ;
@@ -123,6 +123,19 @@ public AddressFamily AddressFamily
123
123
get { return _ipv6 ? AddressFamily . InterNetworkV6 : AddressFamily . InterNetwork ; }
124
124
}
125
125
126
+ /// <summary>
127
+ /// Gets or sets whether to relax TLS constraints as much as possible.
128
+ /// </summary>
129
+ public bool AllowInsecureTls
130
+ {
131
+ get { return _allowInsecureTls ; }
132
+ set
133
+ {
134
+ if ( _isFrozen ) { throw new InvalidOperationException ( "MongoServerSettings is frozen." ) ; }
135
+ _allowInsecureTls = value ;
136
+ }
137
+ }
138
+
126
139
/// <summary>
127
140
/// Gets or sets the application name.
128
141
/// </summary>
@@ -552,26 +565,41 @@ public SslSettings SslSettings
552
565
/// <summary>
553
566
/// Gets or sets a value indicating whether to use SSL.
554
567
/// </summary>
568
+ [ Obsolete ( "Use UseTls instead." ) ]
555
569
public bool UseSsl
556
570
{
557
- get { return _useSsl ; }
571
+ get { return _useTls ; }
572
+ set
573
+ {
574
+ if ( _isFrozen ) { throw new InvalidOperationException ( "MongoServerSettings is frozen." ) ; }
575
+ _useTls = value ;
576
+ }
577
+ }
578
+
579
+ /// <summary>
580
+ /// Gets or sets a value indicating whether to use TLS.
581
+ /// </summary>
582
+ public bool UseTls
583
+ {
584
+ get { return _useTls ; }
558
585
set
559
586
{
560
587
if ( _isFrozen ) { throw new InvalidOperationException ( "MongoServerSettings is frozen." ) ; }
561
- _useSsl = value ;
588
+ _useTls = value ;
562
589
}
563
590
}
564
591
565
592
/// <summary>
566
593
/// Gets or sets a value indicating whether to verify an SSL certificate.
567
594
/// </summary>
595
+ [ Obsolete ( "Use AllowInsecureTls instead." ) ]
568
596
public bool VerifySslCertificate
569
597
{
570
- get { return _verifySslCertificate ; }
598
+ get { return ! _allowInsecureTls ; }
571
599
set
572
600
{
573
601
if ( _isFrozen ) { throw new InvalidOperationException ( "MongoServerSettings is frozen." ) ; }
574
- _verifySslCertificate = value ;
602
+ _allowInsecureTls = ! value ;
575
603
}
576
604
}
577
605
@@ -667,6 +695,7 @@ public UTF8Encoding WriteEncoding
667
695
public static MongoServerSettings FromClientSettings ( MongoClientSettings clientSettings )
668
696
{
669
697
var serverSettings = new MongoServerSettings ( ) ;
698
+ serverSettings . AllowInsecureTls = clientSettings . AllowInsecureTls ;
670
699
serverSettings . ApplicationName = clientSettings . ApplicationName ;
671
700
serverSettings . ClusterConfigurator = clientSettings . ClusterConfigurator ;
672
701
serverSettings . Compressors = clientSettings . Compressors ;
@@ -696,8 +725,7 @@ public static MongoServerSettings FromClientSettings(MongoClientSettings clientS
696
725
serverSettings . ServerSelectionTimeout = clientSettings . ServerSelectionTimeout ;
697
726
serverSettings . SocketTimeout = clientSettings . SocketTimeout ;
698
727
serverSettings . SslSettings = ( clientSettings . SslSettings == null ) ? null : clientSettings . SslSettings . Clone ( ) ;
699
- serverSettings . UseSsl = clientSettings . UseSsl ;
700
- serverSettings . VerifySslCertificate = clientSettings . VerifySslCertificate ;
728
+ serverSettings . UseTls = clientSettings . UseTls ;
701
729
serverSettings . WaitQueueSize = clientSettings . WaitQueueSize ;
702
730
serverSettings . WaitQueueTimeout = clientSettings . WaitQueueTimeout ;
703
731
serverSettings . WriteConcern = clientSettings . WriteConcern ;
@@ -715,6 +743,7 @@ public static MongoServerSettings FromUrl(MongoUrl url)
715
743
var credential = url . GetCredential ( ) ;
716
744
717
745
var serverSettings = new MongoServerSettings ( ) ;
746
+ serverSettings . AllowInsecureTls = url . AllowInsecureTls ;
718
747
serverSettings . ApplicationName = url . ApplicationName ;
719
748
serverSettings . Compressors = url . Compressors ;
720
749
serverSettings . ConnectionMode = url . ConnectionMode ;
@@ -755,8 +784,7 @@ public static MongoServerSettings FromUrl(MongoUrl url)
755
784
serverSettings . ServerSelectionTimeout = url . ServerSelectionTimeout ;
756
785
serverSettings . SocketTimeout = url . SocketTimeout ;
757
786
serverSettings . SslSettings = null ; // SSL settings must be provided in code
758
- serverSettings . UseSsl = url . UseSsl ;
759
- serverSettings . VerifySslCertificate = url . VerifySslCertificate ;
787
+ serverSettings . UseTls = url . UseTls ;
760
788
serverSettings . WaitQueueSize = url . ComputedWaitQueueSize ;
761
789
serverSettings . WaitQueueTimeout = url . WaitQueueTimeout ;
762
790
serverSettings . WriteConcern = url . GetWriteConcern ( false ) ;
@@ -772,6 +800,7 @@ public static MongoServerSettings FromUrl(MongoUrl url)
772
800
public MongoServerSettings Clone ( )
773
801
{
774
802
var clone = new MongoServerSettings ( ) ;
803
+ clone . _allowInsecureTls = _allowInsecureTls ;
775
804
clone . _applicationName = _applicationName ;
776
805
clone . _clusterConfigurator = _clusterConfigurator ;
777
806
clone . _compressors = _compressors ;
@@ -800,8 +829,7 @@ public MongoServerSettings Clone()
800
829
clone . _serverSelectionTimeout = _serverSelectionTimeout ;
801
830
clone . _socketTimeout = _socketTimeout ;
802
831
clone . _sslSettings = ( _sslSettings == null ) ? null : _sslSettings . Clone ( ) ;
803
- clone . _useSsl = _useSsl ;
804
- clone . _verifySslCertificate = _verifySslCertificate ;
832
+ clone . _useTls = _useTls ;
805
833
clone . _waitQueueSize = _waitQueueSize ;
806
834
clone . _waitQueueTimeout = _waitQueueTimeout ;
807
835
clone . _writeConcern = _writeConcern ;
@@ -833,6 +861,7 @@ public override bool Equals(object obj)
833
861
if ( object . ReferenceEquals ( obj , null ) || GetType ( ) != obj . GetType ( ) ) { return false ; }
834
862
var rhs = ( MongoServerSettings ) obj ;
835
863
return
864
+ _allowInsecureTls == rhs . _allowInsecureTls &&
836
865
_applicationName == rhs . _applicationName &&
837
866
object . ReferenceEquals ( _clusterConfigurator , rhs . _clusterConfigurator ) &&
838
867
_compressors . SequenceEqual ( rhs . _compressors ) &&
@@ -861,8 +890,7 @@ public override bool Equals(object obj)
861
890
_serverSelectionTimeout == rhs . _serverSelectionTimeout &&
862
891
_socketTimeout == rhs . _socketTimeout &&
863
892
_sslSettings == rhs . _sslSettings &&
864
- _useSsl == rhs . _useSsl &&
865
- _verifySslCertificate == rhs . _verifySslCertificate &&
893
+ _useTls == rhs . _useTls &&
866
894
_waitQueueSize == rhs . _waitQueueSize &&
867
895
_waitQueueTimeout == rhs . _waitQueueTimeout &&
868
896
_writeConcern . Equals ( rhs . _writeConcern ) &&
@@ -912,6 +940,7 @@ public override int GetHashCode()
912
940
}
913
941
914
942
return new Hasher ( )
943
+ . Hash ( _allowInsecureTls )
915
944
. Hash ( _applicationName )
916
945
. Hash ( _clusterConfigurator )
917
946
. HashElements ( _compressors )
@@ -940,8 +969,7 @@ public override int GetHashCode()
940
969
. Hash ( _serverSelectionTimeout )
941
970
. Hash ( _socketTimeout )
942
971
. Hash ( _sslSettings )
943
- . Hash ( _useSsl )
944
- . Hash ( _verifySslCertificate )
972
+ . Hash ( _useTls )
945
973
. Hash ( _waitQueueSize )
946
974
. Hash ( _waitQueueTimeout )
947
975
. Hash ( _writeConcern )
@@ -1008,8 +1036,8 @@ public override string ToString()
1008
1036
{
1009
1037
parts . Add ( string . Format ( "SslSettings={0}" , _sslSettings ) ) ;
1010
1038
}
1011
- parts . Add ( string . Format ( "Ssl ={0}" , _useSsl ) ) ;
1012
- parts . Add ( string . Format ( "SslVerifyCertificate ={0}" , _verifySslCertificate ) ) ;
1039
+ parts . Add ( string . Format ( "Tls ={0}" , _useTls ) ) ;
1040
+ parts . Add ( string . Format ( "TlsInsecure ={0}" , _allowInsecureTls ) ) ;
1013
1041
parts . Add ( string . Format ( "WaitQueueSize={0}" , _waitQueueSize ) ) ;
1014
1042
parts . Add ( string . Format ( "WaitQueueTimeout={0}" , _waitQueueTimeout ) ) ;
1015
1043
parts . Add ( string . Format ( "WriteConcern={0}" , _writeConcern ) ) ;
@@ -1024,6 +1052,7 @@ public override string ToString()
1024
1052
internal ClusterKey ToClusterKey ( )
1025
1053
{
1026
1054
return new ClusterKey (
1055
+ _allowInsecureTls ,
1027
1056
_applicationName ,
1028
1057
_clusterConfigurator ,
1029
1058
_compressors ,
@@ -1047,8 +1076,7 @@ internal ClusterKey ToClusterKey()
1047
1076
_serverSelectionTimeout ,
1048
1077
_socketTimeout ,
1049
1078
_sslSettings ,
1050
- _useSsl ,
1051
- _verifySslCertificate ,
1079
+ _useTls ,
1052
1080
_waitQueueSize ,
1053
1081
_waitQueueTimeout ) ;
1054
1082
}
0 commit comments