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