@@ -32,6 +32,7 @@ namespace MongoDB.Driver
3232 public class MongoServerSettings : IEquatable < MongoServerSettings > , IInheritableMongoClientSettings
3333 {
3434 // private fields
35+ private bool _allowInsecureTls ;
3536 private string _applicationName ;
3637 private Action < ClusterBuilder > _clusterConfigurator ;
3738 private IReadOnlyList < CompressorConfiguration > _compressors ;
@@ -60,8 +61,7 @@ public class MongoServerSettings : IEquatable<MongoServerSettings>, IInheritable
6061 private TimeSpan _serverSelectionTimeout ;
6162 private TimeSpan _socketTimeout ;
6263 private SslSettings _sslSettings ;
63- private bool _useSsl ;
64- private bool _verifySslCertificate ;
64+ private bool _useTls ;
6565 private int _waitQueueSize ;
6666 private TimeSpan _waitQueueTimeout ;
6767 private WriteConcern _writeConcern ;
@@ -78,6 +78,7 @@ public class MongoServerSettings : IEquatable<MongoServerSettings>, IInheritable
7878 /// </summary>
7979 public MongoServerSettings ( )
8080 {
81+ _allowInsecureTls = false ;
8182 _applicationName = null ;
8283 _compressors = new CompressorConfiguration [ 0 ] ;
8384 _connectionMode = ConnectionMode . Automatic ;
@@ -105,8 +106,7 @@ public MongoServerSettings()
105106 _serverSelectionTimeout = MongoDefaults . ServerSelectionTimeout ;
106107 _socketTimeout = MongoDefaults . SocketTimeout ;
107108 _sslSettings = null ;
108- _useSsl = false ;
109- _verifySslCertificate = true ;
109+ _useTls = false ;
110110 _waitQueueSize = MongoDefaults . ComputedWaitQueueSize ;
111111 _waitQueueTimeout = MongoDefaults . WaitQueueTimeout ;
112112 _writeConcern = WriteConcern . Unacknowledged ;
@@ -123,6 +123,19 @@ public AddressFamily AddressFamily
123123 get { return _ipv6 ? AddressFamily . InterNetworkV6 : AddressFamily . InterNetwork ; }
124124 }
125125
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+
126139 /// <summary>
127140 /// Gets or sets the application name.
128141 /// </summary>
@@ -552,26 +565,41 @@ public SslSettings SslSettings
552565 /// <summary>
553566 /// Gets or sets a value indicating whether to use SSL.
554567 /// </summary>
568+ [ Obsolete ( "Use UseTls instead." ) ]
555569 public bool UseSsl
556570 {
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 ; }
558585 set
559586 {
560587 if ( _isFrozen ) { throw new InvalidOperationException ( "MongoServerSettings is frozen." ) ; }
561- _useSsl = value ;
588+ _useTls = value ;
562589 }
563590 }
564591
565592 /// <summary>
566593 /// Gets or sets a value indicating whether to verify an SSL certificate.
567594 /// </summary>
595+ [ Obsolete ( "Use AllowInsecureTls instead." ) ]
568596 public bool VerifySslCertificate
569597 {
570- get { return _verifySslCertificate ; }
598+ get { return ! _allowInsecureTls ; }
571599 set
572600 {
573601 if ( _isFrozen ) { throw new InvalidOperationException ( "MongoServerSettings is frozen." ) ; }
574- _verifySslCertificate = value ;
602+ _allowInsecureTls = ! value ;
575603 }
576604 }
577605
@@ -667,6 +695,7 @@ public UTF8Encoding WriteEncoding
667695 public static MongoServerSettings FromClientSettings ( MongoClientSettings clientSettings )
668696 {
669697 var serverSettings = new MongoServerSettings ( ) ;
698+ serverSettings . AllowInsecureTls = clientSettings . AllowInsecureTls ;
670699 serverSettings . ApplicationName = clientSettings . ApplicationName ;
671700 serverSettings . ClusterConfigurator = clientSettings . ClusterConfigurator ;
672701 serverSettings . Compressors = clientSettings . Compressors ;
@@ -696,8 +725,7 @@ public static MongoServerSettings FromClientSettings(MongoClientSettings clientS
696725 serverSettings . ServerSelectionTimeout = clientSettings . ServerSelectionTimeout ;
697726 serverSettings . SocketTimeout = clientSettings . SocketTimeout ;
698727 serverSettings . SslSettings = ( clientSettings . SslSettings == null ) ? null : clientSettings . SslSettings . Clone ( ) ;
699- serverSettings . UseSsl = clientSettings . UseSsl ;
700- serverSettings . VerifySslCertificate = clientSettings . VerifySslCertificate ;
728+ serverSettings . UseTls = clientSettings . UseTls ;
701729 serverSettings . WaitQueueSize = clientSettings . WaitQueueSize ;
702730 serverSettings . WaitQueueTimeout = clientSettings . WaitQueueTimeout ;
703731 serverSettings . WriteConcern = clientSettings . WriteConcern ;
@@ -715,6 +743,7 @@ public static MongoServerSettings FromUrl(MongoUrl url)
715743 var credential = url . GetCredential ( ) ;
716744
717745 var serverSettings = new MongoServerSettings ( ) ;
746+ serverSettings . AllowInsecureTls = url . AllowInsecureTls ;
718747 serverSettings . ApplicationName = url . ApplicationName ;
719748 serverSettings . Compressors = url . Compressors ;
720749 serverSettings . ConnectionMode = url . ConnectionMode ;
@@ -755,8 +784,7 @@ public static MongoServerSettings FromUrl(MongoUrl url)
755784 serverSettings . ServerSelectionTimeout = url . ServerSelectionTimeout ;
756785 serverSettings . SocketTimeout = url . SocketTimeout ;
757786 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 ;
760788 serverSettings . WaitQueueSize = url . ComputedWaitQueueSize ;
761789 serverSettings . WaitQueueTimeout = url . WaitQueueTimeout ;
762790 serverSettings . WriteConcern = url . GetWriteConcern ( false ) ;
@@ -772,6 +800,7 @@ public static MongoServerSettings FromUrl(MongoUrl url)
772800 public MongoServerSettings Clone ( )
773801 {
774802 var clone = new MongoServerSettings ( ) ;
803+ clone . _allowInsecureTls = _allowInsecureTls ;
775804 clone . _applicationName = _applicationName ;
776805 clone . _clusterConfigurator = _clusterConfigurator ;
777806 clone . _compressors = _compressors ;
@@ -800,8 +829,7 @@ public MongoServerSettings Clone()
800829 clone . _serverSelectionTimeout = _serverSelectionTimeout ;
801830 clone . _socketTimeout = _socketTimeout ;
802831 clone . _sslSettings = ( _sslSettings == null ) ? null : _sslSettings . Clone ( ) ;
803- clone . _useSsl = _useSsl ;
804- clone . _verifySslCertificate = _verifySslCertificate ;
832+ clone . _useTls = _useTls ;
805833 clone . _waitQueueSize = _waitQueueSize ;
806834 clone . _waitQueueTimeout = _waitQueueTimeout ;
807835 clone . _writeConcern = _writeConcern ;
@@ -833,6 +861,7 @@ public override bool Equals(object obj)
833861 if ( object . ReferenceEquals ( obj , null ) || GetType ( ) != obj . GetType ( ) ) { return false ; }
834862 var rhs = ( MongoServerSettings ) obj ;
835863 return
864+ _allowInsecureTls == rhs . _allowInsecureTls &&
836865 _applicationName == rhs . _applicationName &&
837866 object . ReferenceEquals ( _clusterConfigurator , rhs . _clusterConfigurator ) &&
838867 _compressors . SequenceEqual ( rhs . _compressors ) &&
@@ -861,8 +890,7 @@ public override bool Equals(object obj)
861890 _serverSelectionTimeout == rhs . _serverSelectionTimeout &&
862891 _socketTimeout == rhs . _socketTimeout &&
863892 _sslSettings == rhs . _sslSettings &&
864- _useSsl == rhs . _useSsl &&
865- _verifySslCertificate == rhs . _verifySslCertificate &&
893+ _useTls == rhs . _useTls &&
866894 _waitQueueSize == rhs . _waitQueueSize &&
867895 _waitQueueTimeout == rhs . _waitQueueTimeout &&
868896 _writeConcern . Equals ( rhs . _writeConcern ) &&
@@ -912,6 +940,7 @@ public override int GetHashCode()
912940 }
913941
914942 return new Hasher ( )
943+ . Hash ( _allowInsecureTls )
915944 . Hash ( _applicationName )
916945 . Hash ( _clusterConfigurator )
917946 . HashElements ( _compressors )
@@ -940,8 +969,7 @@ public override int GetHashCode()
940969 . Hash ( _serverSelectionTimeout )
941970 . Hash ( _socketTimeout )
942971 . Hash ( _sslSettings )
943- . Hash ( _useSsl )
944- . Hash ( _verifySslCertificate )
972+ . Hash ( _useTls )
945973 . Hash ( _waitQueueSize )
946974 . Hash ( _waitQueueTimeout )
947975 . Hash ( _writeConcern )
@@ -1008,8 +1036,8 @@ public override string ToString()
10081036 {
10091037 parts . Add ( string . Format ( "SslSettings={0}" , _sslSettings ) ) ;
10101038 }
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 ) ) ;
10131041 parts . Add ( string . Format ( "WaitQueueSize={0}" , _waitQueueSize ) ) ;
10141042 parts . Add ( string . Format ( "WaitQueueTimeout={0}" , _waitQueueTimeout ) ) ;
10151043 parts . Add ( string . Format ( "WriteConcern={0}" , _writeConcern ) ) ;
@@ -1024,6 +1052,7 @@ public override string ToString()
10241052 internal ClusterKey ToClusterKey ( )
10251053 {
10261054 return new ClusterKey (
1055+ _allowInsecureTls ,
10271056 _applicationName ,
10281057 _clusterConfigurator ,
10291058 _compressors ,
@@ -1047,8 +1076,7 @@ internal ClusterKey ToClusterKey()
10471076 _serverSelectionTimeout ,
10481077 _socketTimeout ,
10491078 _sslSettings ,
1050- _useSsl ,
1051- _verifySslCertificate ,
1079+ _useTls ,
10521080 _waitQueueSize ,
10531081 _waitQueueTimeout ) ;
10541082 }
0 commit comments