Changed link from GUID to URL
[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 using System.Security.Cryptography.X509Certificates;
28
29 namespace Mono.Security.Interface
30 {
31         public sealed class MonoTlsSettings
32         {
33                 public MonoRemoteCertificateValidationCallback RemoteCertificateValidationCallback {
34                         get; set;
35                 }
36
37                 public MonoLocalCertificateSelectionCallback ClientCertificateSelectionCallback {
38                         get; set;
39                 }
40
41                 public bool CheckCertificateName {
42                         get { return checkCertName; }
43                         set { checkCertName = value; }
44                 }
45
46                 public bool CheckCertificateRevocationStatus {
47                         get { return checkCertRevocationStatus; }
48                         set { checkCertRevocationStatus = value; }
49                 }
50
51                 public bool UseServicePointManagerCallback {
52                         get { return useServicePointManagerCallback; }
53                         set { useServicePointManagerCallback = value; }
54                 }
55
56                 public bool SkipSystemValidators {
57                         get { return skipSystemValidators; }
58                         set { skipSystemValidators = value; }
59                 }
60
61                 public bool CallbackNeedsCertificateChain {
62                         get { return callbackNeedsChain; }
63                         set { callbackNeedsChain = value; }
64                 }
65
66                 /*
67                  * This is only supported if CertificateValidationHelper.SupportsTrustAnchors is true.
68                  */
69                 public X509CertificateCollection TrustAnchors {
70                         get; set;
71                 }
72
73                 public object UserSettings {
74                         get; set;
75                 }
76
77                 /*
78                  * If you set this here, then it will override 'ServicePointManager.SecurityProtocol'.
79                  */
80                 public TlsProtocols? EnabledProtocols {
81                         get; set;
82                 }
83
84                 bool cloned = false;
85                 bool checkCertName = true;
86                 bool checkCertRevocationStatus = false;
87                 bool useServicePointManagerCallback = false;
88                 bool skipSystemValidators = false;
89                 bool callbackNeedsChain = true;
90                 ICertificateValidator certificateValidator;
91
92                 public MonoTlsSettings ()
93                 {
94                 }
95
96                 #region Private APIs
97
98                 /*
99                  * Private APIs - do not use!
100                  * 
101                  * This is only public to avoid making our internals visible to System.dll.
102                  * 
103                  */
104
105                 [Obsolete ("Do not use outside System.dll!")]
106                 public ICertificateValidator CertificateValidator {
107                         get { return certificateValidator; }
108                 }
109
110                 [Obsolete ("Do not use outside System.dll!")]
111                 public MonoTlsSettings CloneWithValidator (ICertificateValidator validator)
112                 {
113                         if (cloned) {
114                                 this.certificateValidator = validator;
115                                 return this;
116                         }
117
118                         var copy = new MonoTlsSettings (this);
119                         copy.certificateValidator = validator;
120                         return copy;
121                 }
122
123                 MonoTlsSettings (MonoTlsSettings other)
124                 {
125                         RemoteCertificateValidationCallback = other.RemoteCertificateValidationCallback;
126                         ClientCertificateSelectionCallback = other.ClientCertificateSelectionCallback;
127                         checkCertName = other.checkCertName;
128                         checkCertRevocationStatus = other.checkCertRevocationStatus;
129                         UseServicePointManagerCallback = other.useServicePointManagerCallback;
130                         skipSystemValidators = other.skipSystemValidators;
131                         callbackNeedsChain = other.callbackNeedsChain;
132                         UserSettings = other.UserSettings;
133                         EnabledProtocols = other.EnabledProtocols;
134                         TrustAnchors = other.TrustAnchors;
135                         cloned = true;
136                 }
137
138                 #endregion
139         }
140 }
141