[Mono.Security]: Cleanup Mono.Security.Interface.CertificateValidationHelper.
[mono.git] / mcs / class / System / Mono.Net.Security / MonoSslStreamImpl.cs
1 //
2 // MonoSslStream.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
27 #if SECURITY_DEP
28
29 #if MONO_SECURITY_ALIAS
30 extern alias MonoSecurity;
31 #endif
32
33 #if MONO_SECURITY_ALIAS
34 using MSI = MonoSecurity::Mono.Security.Interface;
35 #else
36 using MSI = Mono.Security.Interface;
37 #endif
38
39 using System;
40 using System.IO;
41 using System.Net;
42 using System.Net.Security;
43 using System.Threading.Tasks;
44 using System.Security.Authentication;
45 using System.Security.Cryptography.X509Certificates;
46 using System.Security.Principal;
47 using System.Security.Cryptography;
48
49 namespace Mono.Net.Security.Private
50 {
51         /*
52          * Strictly private - do not use outside the Mono.Net.Security directory.
53          */
54         class MonoSslStreamImpl : MSI.IMonoSslStream
55         {
56                 IMonoSslStream impl;
57
58                 internal IMonoSslStream Impl {
59                         get {
60                                 CheckDisposed ();
61                                 return impl;
62                         }
63                 }
64
65                 public MonoSslStreamImpl (IMonoSslStream impl)
66                 {
67                         this.impl = impl;
68                 }
69
70                 public void AuthenticateAsClient (string targetHost)
71                 {
72                         Impl.AuthenticateAsClient (targetHost);
73                 }
74
75                 public void AuthenticateAsClient (string targetHost, X509CertificateCollection clientCertificates, SslProtocols enabledSslProtocols, bool checkCertificateRevocation)
76                 {
77                         Impl.AuthenticateAsClient (targetHost, clientCertificates, enabledSslProtocols, checkCertificateRevocation);
78                 }
79
80                 public IAsyncResult BeginAuthenticateAsClient (string targetHost, AsyncCallback asyncCallback, object asyncState)
81                 {
82                         return Impl.BeginAuthenticateAsClient (targetHost, asyncCallback, asyncState);
83                 }
84
85                 public IAsyncResult BeginAuthenticateAsClient (string targetHost, X509CertificateCollection clientCertificates, SslProtocols enabledSslProtocols, bool checkCertificateRevocation, AsyncCallback asyncCallback, object asyncState)
86                 {
87                         return Impl.BeginAuthenticateAsClient (targetHost, clientCertificates, enabledSslProtocols, checkCertificateRevocation, asyncCallback, asyncState);
88                 }
89
90                 public void EndAuthenticateAsClient (IAsyncResult asyncResult)
91                 {
92                         Impl.EndAuthenticateAsClient (asyncResult);
93                 }
94
95                 public void AuthenticateAsServer (X509Certificate serverCertificate)
96                 {
97                         Impl.AuthenticateAsServer (serverCertificate);
98                 }
99
100                 public void AuthenticateAsServer (X509Certificate serverCertificate, bool clientCertificateRequired, SslProtocols enabledSslProtocols, bool checkCertificateRevocation)
101                 {
102                         Impl.AuthenticateAsServer (serverCertificate, clientCertificateRequired, enabledSslProtocols, checkCertificateRevocation);
103                 }
104
105                 public IAsyncResult BeginAuthenticateAsServer (X509Certificate serverCertificate, AsyncCallback asyncCallback, object asyncState)
106                 {
107                         return Impl.BeginAuthenticateAsServer (serverCertificate, asyncCallback, asyncState);
108                 }
109
110                 public IAsyncResult BeginAuthenticateAsServer (X509Certificate serverCertificate, bool clientCertificateRequired, SslProtocols enabledSslProtocols, bool checkCertificateRevocation, AsyncCallback asyncCallback, object asyncState)
111                 {
112                         return Impl.BeginAuthenticateAsServer (serverCertificate, clientCertificateRequired, enabledSslProtocols, checkCertificateRevocation, asyncCallback, asyncState);
113                 }
114
115                 public void EndAuthenticateAsServer (IAsyncResult asyncResult)
116                 {
117                         Impl.EndAuthenticateAsServer (asyncResult);
118                 }
119
120                 public Task AuthenticateAsClientAsync (string targetHost)
121                 {
122                         return Impl.AuthenticateAsClientAsync (targetHost);
123                 }
124
125                 public Task AuthenticateAsClientAsync (string targetHost, X509CertificateCollection clientCertificates, SslProtocols enabledSslProtocols, bool checkCertificateRevocation)
126                 {
127                         return Impl.AuthenticateAsClientAsync (targetHost, clientCertificates, enabledSslProtocols, checkCertificateRevocation);
128                 }
129
130                 public Task AuthenticateAsServerAsync (X509Certificate serverCertificate)
131                 {
132                         return Impl.AuthenticateAsServerAsync (serverCertificate);
133                 }
134
135                 public Task AuthenticateAsServerAsync (X509Certificate serverCertificate, bool clientCertificateRequired, SslProtocols enabledSslProtocols, bool checkCertificateRevocation)
136                 {
137                         return Impl.AuthenticateAsServerAsync (serverCertificate, clientCertificateRequired, enabledSslProtocols, checkCertificateRevocation);
138                 }
139
140                 public void Flush ()
141                 {
142                         Impl.Flush ();
143                 }
144
145                 public int Read (byte[] buffer, int offset, int count)
146                 {
147                         return Impl.Read (buffer, offset, count);
148                 }
149
150                 public void Write (byte[] buffer)
151                 {
152                         Impl.Write (buffer);
153                 }
154
155                 public void Write (byte[] buffer, int offset, int count)
156                 {
157                         Impl.Write (buffer, offset, count);
158                 }
159
160                 public IAsyncResult BeginRead (byte[] buffer, int offset, int count, AsyncCallback asyncCallback, object asyncState)
161                 {
162                         return Impl.BeginRead (buffer, offset, count, asyncCallback, asyncState);
163                 }
164
165                 public int EndRead (IAsyncResult asyncResult)
166                 {
167                         return Impl.EndRead (asyncResult);
168                 }
169
170                 public IAsyncResult BeginWrite (byte[] buffer, int offset, int count, AsyncCallback asyncCallback, object asyncState)
171                 {
172                         return Impl.BeginWrite (buffer, offset, count, asyncCallback, asyncState);
173                 }
174
175                 public void EndWrite (IAsyncResult asyncResult)
176                 {
177                         Impl.EndWrite (asyncResult);
178                 }
179
180                 public TransportContext TransportContext {
181                         get { return Impl.TransportContext; }
182                 }
183
184                 public bool IsAuthenticated {
185                         get { return Impl.IsAuthenticated; }
186                 }
187
188                 public bool IsMutuallyAuthenticated {
189                         get { return Impl.IsMutuallyAuthenticated; }
190                 }
191
192                 public bool IsEncrypted {
193                         get { return Impl.IsEncrypted; }
194                 }
195
196                 public bool IsSigned {
197                         get { return Impl.IsSigned; }
198                 }
199
200                 public bool IsServer {
201                         get { return Impl.IsServer; }
202                 }
203
204                 public CipherAlgorithmType CipherAlgorithm {
205                         get { return Impl.CipherAlgorithm; }
206                 }
207
208                 public int CipherStrength {
209                         get { return Impl.CipherStrength; }
210                 }
211
212                 public HashAlgorithmType HashAlgorithm {
213                         get { return Impl.HashAlgorithm; }
214                 }
215
216                 public int HashStrength {
217                         get { return Impl.HashStrength; }
218                 }
219
220                 public ExchangeAlgorithmType KeyExchangeAlgorithm {
221                         get { return Impl.KeyExchangeAlgorithm; }
222                 }
223
224                 public int KeyExchangeStrength {
225                         get { return Impl.KeyExchangeStrength; }
226                 }
227
228                 public bool CanRead {
229                         get { return Impl.CanRead; }
230                 }
231
232                 public bool CanTimeout {
233                         get { return Impl.CanTimeout; }
234                 }
235
236                 public bool CanWrite {
237                         get { return Impl.CanWrite; }
238                 }
239
240                 public long Length {
241                         get { return Impl.Length; }
242                 }
243
244                 public long Position {
245                         get { return Impl.Position; }
246                 }
247
248                 public void SetLength (long value)
249                 {
250                         Impl.SetLength (value);
251                 }
252
253                 public AuthenticatedStream AuthenticatedStream {
254                         get { return Impl.AuthenticatedStream; }
255                 }
256
257                 public int ReadTimeout {
258                         get { return Impl.ReadTimeout; }
259                         set { Impl.ReadTimeout = value; }
260                 }
261
262                 public int WriteTimeout {
263                         get { return Impl.WriteTimeout; }
264                         set { Impl.WriteTimeout = value; }
265                 }
266
267                 public bool CheckCertRevocationStatus {
268                         get { return Impl.CheckCertRevocationStatus; }
269                 }
270
271                 public X509Certificate InternalLocalCertificate {
272                         get { return Impl.InternalLocalCertificate; }
273                 }
274
275                 public X509Certificate LocalCertificate {
276                         get { return Impl.LocalCertificate; }
277                 }
278
279                 public X509Certificate RemoteCertificate {
280                         get { return Impl.RemoteCertificate; }
281                 }
282
283                 public SslProtocols SslProtocol {
284                         get { return Impl.SslProtocol; }
285                 }
286
287                 public MSI.MonoTlsProvider Provider {
288                         get { return Impl.Provider; }
289                 }
290
291                 public MSI.MonoTlsConnectionInfo GetConnectionInfo ()
292                 {
293                         return Impl.GetConnectionInfo ();
294                 }
295
296                 void CheckDisposed ()
297                 {
298                         if (impl == null)
299                                 throw new ObjectDisposedException ("MonoSslStream");
300                 }
301
302                 public void Dispose ()
303                 {
304                         Dispose (true);
305                         GC.SuppressFinalize (this);
306                 }
307
308                 protected virtual void Dispose (bool disposing)
309                 {
310                         if (impl != null && disposing) {
311                                 impl.Dispose ();
312                                 impl = null;
313                         }
314                 }
315         }
316 }
317 #endif
318