Fix to checked-build reference auditing
[mono.git] / mcs / class / Mono.Security / Mono.Security.Interface / MonoTlsSettings.cs
1 //
2 // MonoTlsSettings.cs
3 //
4 // Author:
5 //       Martin Baulig <martin.baulig@xamarin.com>
6 //
7 // Copyright (c) 2015 Xamarin, Inc.
8 //
9 // Permission is hereby granted, free of charge, to any person obtaining a copy
10 // of this software and associated documentation files (the "Software"), to deal
11 // in the Software without restriction, including without limitation the rights
12 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 // copies of the Software, and to permit persons to whom the Software is
14 // furnished to do so, subject to the following conditions:
15 //
16 // The above copyright notice and this permission notice shall be included in
17 // all copies or substantial portions of the Software.
18 //
19 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 // THE SOFTWARE.
26 using System;
27
28 namespace Mono.Security.Interface
29 {
30         public sealed class MonoTlsSettings
31         {
32                 public MonoRemoteCertificateValidationCallback ServerCertificateValidationCallback {
33                         get; set;
34                 }
35
36                 public MonoLocalCertificateSelectionCallback ClientCertificateSelectionCallback {
37                         get; set;
38                 }
39
40                 public bool CheckCertificateName {
41                         get { return checkCertName; }
42                         set { checkCertName = value; }
43                 }
44
45                 public bool CheckCertificateRevocationStatus {
46                         get { return checkCertRevocationStatus; }
47                         set { checkCertRevocationStatus = value; }
48                 }
49
50                 public bool UseServicePointManagerCallback {
51                         get { return useServicePointManagerCallback; }
52                         set { useServicePointManagerCallback = value; }
53                 }
54
55                 public bool SkipSystemValidators {
56                         get { return skipSystemValidators; }
57                         set { skipSystemValidators = value; }
58                 }
59
60                 public bool CallbackNeedsCertificateChain {
61                         get { return callbackNeedsChain; }
62                         set { callbackNeedsChain = value; }
63                 }
64
65                 public object UserSettings {
66                         get; set;
67                 }
68
69                 bool cloned = false;
70                 bool checkCertName = true;
71                 bool checkCertRevocationStatus = false;
72                 bool useServicePointManagerCallback = false;
73                 bool skipSystemValidators = false;
74                 bool callbackNeedsChain = true;
75                 ICertificateValidator certificateValidator;
76
77                 #region Private APIs
78
79                 /*
80                  * Private APIs - do not use!
81                  * 
82                  * This is only public to avoid making our internals visible to System.dll.
83                  * 
84                  */
85
86                 [Obsolete ("Do not use outside System.dll!")]
87                 public ICertificateValidator CertificateValidator {
88                         get { return certificateValidator; }
89                         set { certificateValidator = value; }
90                 }
91
92                 [Obsolete ("Do not use outside System.dll!")]
93                 public MonoTlsSettings CloneWithValidator (ICertificateValidator validator)
94                 {
95                         if (cloned) {
96                                 this.certificateValidator = validator;
97                                 return this;
98                         }
99
100                         var copy = new MonoTlsSettings ();
101                         copy.ServerCertificateValidationCallback = ServerCertificateValidationCallback;
102                         copy.ClientCertificateSelectionCallback = ClientCertificateSelectionCallback;
103                         copy.checkCertName = checkCertName;
104                         copy.checkCertRevocationStatus = checkCertRevocationStatus;
105                         copy.UseServicePointManagerCallback = useServicePointManagerCallback;
106                         copy.skipSystemValidators = skipSystemValidators;
107                         copy.callbackNeedsChain = callbackNeedsChain;
108                         copy.UserSettings = UserSettings;
109                         copy.certificateValidator = validator;
110                         copy.cloned = true;
111                         return copy;
112                 }
113
114                 #endregion
115         }
116 }
117