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