c0b702fde1b2f92798271fdf943402e1460eb27a
[mono.git] / mcs / class / System / System.Net.Security / SslStream.cs
1 //
2 // SslStream.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 MonoSecurity::Mono.Security.Interface;
35 #else
36 using Mono.Security.Interface;
37 #endif
38
39 using CipherAlgorithmType = System.Security.Authentication.CipherAlgorithmType;
40 using HashAlgorithmType = System.Security.Authentication.HashAlgorithmType;
41 using ExchangeAlgorithmType = System.Security.Authentication.ExchangeAlgorithmType;
42 #endif
43
44 using System.IO;
45 using System.Net;
46 using System.Net.Security;
47 using System.Security.Authentication;
48 using System.Security.Cryptography.X509Certificates;
49 using System.Security.Permissions;
50 using System.Security.Principal;
51 using System.Security.Cryptography;
52 using System.Threading.Tasks;
53
54 using MNS = Mono.Net.Security;
55
56 namespace System.Net.Security
57 {
58         /*
59          * These two are defined by the referencesource; add them heere to make
60          * it easy to switch between the two implementations.
61          */
62
63         internal delegate bool RemoteCertValidationCallback (
64                 string host,
65                 X509Certificate certificate,
66                 X509Chain chain,
67                 SslPolicyErrors sslPolicyErrors);
68
69         internal delegate X509Certificate LocalCertSelectionCallback (
70                 string targetHost,
71                 X509CertificateCollection localCertificates,
72                 X509Certificate remoteCertificate,
73                 string[] acceptableIssuers);
74
75         public class SslStream : AuthenticatedStream
76         {
77 #if SECURITY_DEP
78                 MonoTlsProvider provider;
79                 IMonoSslStream impl;
80
81                 internal IMonoSslStream Impl {
82                         get {
83                                 CheckDisposed ();
84                                 return impl;
85                         }
86                 }
87
88                 internal MonoTlsProvider Provider {
89                         get {
90                                 CheckDisposed ();
91                                 return provider;
92                         }
93                 }
94
95                 static MonoTlsProvider GetProvider ()
96                 {
97                         return MonoTlsProviderFactory.GetProvider ();
98                 }
99
100                 public SslStream (Stream innerStream)
101                         : this (innerStream, false)
102                 {
103                 }
104
105                 public SslStream (Stream innerStream, bool leaveInnerStreamOpen)
106                         : base (innerStream, leaveInnerStreamOpen)
107                 {
108                         provider = GetProvider ();
109                         impl = provider.CreateSslStreamInternal (this, innerStream, leaveInnerStreamOpen, null);
110                 }
111
112                 public SslStream (Stream innerStream, bool leaveInnerStreamOpen, RemoteCertificateValidationCallback userCertificateValidationCallback)
113                         : this (innerStream, leaveInnerStreamOpen, userCertificateValidationCallback, null)
114                 {
115                 }
116
117                 public SslStream (Stream innerStream, bool leaveInnerStreamOpen, RemoteCertificateValidationCallback userCertificateValidationCallback, LocalCertificateSelectionCallback userCertificateSelectionCallback)
118                         : base (innerStream, leaveInnerStreamOpen)
119                 {
120                         provider = GetProvider ();
121                         var settings = MonoTlsSettings.CopyDefaultSettings ();
122                         settings.RemoteCertificateValidationCallback = MNS.Private.CallbackHelpers.PublicToMono (userCertificateValidationCallback);
123                         settings.ClientCertificateSelectionCallback = MNS.Private.CallbackHelpers.PublicToMono (userCertificateSelectionCallback);
124                         impl = provider.CreateSslStream (innerStream, leaveInnerStreamOpen, settings);
125                 }
126
127                 [MonoLimitation ("encryptionPolicy is ignored")]
128                 public SslStream (Stream innerStream, bool leaveInnerStreamOpen, RemoteCertificateValidationCallback userCertificateValidationCallback, LocalCertificateSelectionCallback userCertificateSelectionCallback, EncryptionPolicy encryptionPolicy)
129                 : this (innerStream, leaveInnerStreamOpen, userCertificateValidationCallback, userCertificateSelectionCallback)
130                 {
131                 }
132
133                 internal SslStream (Stream innerStream, bool leaveInnerStreamOpen, MonoTlsProvider provider, MonoTlsSettings settings)
134                         : base (innerStream, leaveInnerStreamOpen)
135                 {
136                         this.provider = provider;
137                         impl = provider.CreateSslStreamInternal (this, innerStream, leaveInnerStreamOpen, settings);
138                 }
139
140                 internal static IMonoSslStream CreateMonoSslStream (Stream innerStream, bool leaveInnerStreamOpen, MonoTlsProvider provider, MonoTlsSettings settings)
141                 {
142                         var sslStream = new SslStream (innerStream, leaveInnerStreamOpen, provider, settings);
143                         return sslStream.Impl;
144                 }
145
146                 public virtual void AuthenticateAsClient (string targetHost)
147                 {
148                         Impl.AuthenticateAsClient (targetHost);
149                 }
150
151                 public virtual void AuthenticateAsClient (string targetHost, X509CertificateCollection clientCertificates, SslProtocols enabledSslProtocols, bool checkCertificateRevocation)
152                 {
153                         Impl.AuthenticateAsClient (targetHost, clientCertificates, enabledSslProtocols, checkCertificateRevocation);
154                 }
155
156                 // [HostProtection (ExternalThreading=true)]
157                 public virtual IAsyncResult BeginAuthenticateAsClient (string targetHost, AsyncCallback asyncCallback, object asyncState)
158                 {
159                         return Impl.BeginAuthenticateAsClient (targetHost, asyncCallback, asyncState);
160                 }
161
162                 // [HostProtection (ExternalThreading=true)]
163                 public virtual IAsyncResult BeginAuthenticateAsClient (string targetHost, X509CertificateCollection clientCertificates, SslProtocols enabledSslProtocols, bool checkCertificateRevocation, AsyncCallback asyncCallback, object asyncState)
164                 {
165                         return Impl.BeginAuthenticateAsClient (targetHost, clientCertificates, enabledSslProtocols, checkCertificateRevocation, asyncCallback, asyncState);
166                 }
167
168                 public virtual void EndAuthenticateAsClient (IAsyncResult asyncResult)
169                 {
170                         Impl.EndAuthenticateAsClient (asyncResult);
171                 }
172
173                 public virtual void AuthenticateAsServer (X509Certificate serverCertificate)
174                 {
175                         Impl.AuthenticateAsServer (serverCertificate);
176                 }
177
178                 public virtual void AuthenticateAsServer (X509Certificate serverCertificate, bool clientCertificateRequired, SslProtocols enabledSslProtocols, bool checkCertificateRevocation)
179                 {
180                         Impl.AuthenticateAsServer (serverCertificate, clientCertificateRequired, enabledSslProtocols, checkCertificateRevocation);
181                 }
182
183                 // [HostProtection (ExternalThreading=true)]
184                 public virtual IAsyncResult BeginAuthenticateAsServer (X509Certificate serverCertificate, AsyncCallback asyncCallback, object asyncState)
185                 {
186                         return Impl.BeginAuthenticateAsServer (serverCertificate, asyncCallback, asyncState);
187                 }
188
189                 public virtual IAsyncResult BeginAuthenticateAsServer (X509Certificate serverCertificate, bool clientCertificateRequired, SslProtocols enabledSslProtocols, bool checkCertificateRevocation, AsyncCallback asyncCallback, object asyncState)
190                 {
191                         return Impl.BeginAuthenticateAsServer (serverCertificate, clientCertificateRequired, enabledSslProtocols, checkCertificateRevocation, asyncCallback, asyncState);
192                 }
193
194                 public virtual void EndAuthenticateAsServer (IAsyncResult asyncResult)
195                 {
196                         Impl.EndAuthenticateAsServer (asyncResult);
197                 }
198
199                 public TransportContext TransportContext {
200                         get {
201                                 throw new NotSupportedException();
202                         }
203                 }
204
205                 // [HostProtection (ExternalThreading=true)]
206                 public virtual Task AuthenticateAsClientAsync (string targetHost)
207                 {
208                         return Impl.AuthenticateAsClientAsync (targetHost);
209                 }
210
211                 public virtual Task AuthenticateAsClientAsync (string targetHost, X509CertificateCollection clientCertificates, SslProtocols enabledSslProtocols, bool checkCertificateRevocation)
212                 {
213                         return Impl.AuthenticateAsClientAsync (targetHost, clientCertificates, enabledSslProtocols, checkCertificateRevocation);
214                 }
215
216                 public virtual Task AuthenticateAsServerAsync (X509Certificate serverCertificate)
217                 {
218                         return Impl.AuthenticateAsServerAsync (serverCertificate);
219                 }
220
221                 public virtual Task AuthenticateAsServerAsync (X509Certificate serverCertificate, bool clientCertificateRequired, SslProtocols enabledSslProtocols, bool checkCertificateRevocation)
222                 {
223                         return Impl.AuthenticateAsServerAsync (serverCertificate, clientCertificateRequired, enabledSslProtocols, checkCertificateRevocation);
224                 }
225
226                 public virtual Task ShutdownAsync ()
227                 {
228                         return Impl.ShutdownAsync ();
229                 }
230
231                 public override bool IsAuthenticated {
232                         get { return Impl.IsAuthenticated; }
233                 }
234
235                 public override bool IsMutuallyAuthenticated {
236                         get { return Impl.IsMutuallyAuthenticated; }
237                 }
238
239                 public override bool IsEncrypted {
240                         get { return Impl.IsEncrypted; }
241                 }
242
243                 public override bool IsSigned {
244                         get { return Impl.IsSigned; }
245                 }
246
247                 public override bool IsServer {
248                         get { return Impl.IsServer; }
249                 }
250
251                 public virtual SslProtocols SslProtocol {
252                         get { return (SslProtocols)Impl.SslProtocol; }
253                 }
254
255                 public virtual bool CheckCertRevocationStatus {
256                         get { return Impl.CheckCertRevocationStatus; }
257                 }
258
259                 public virtual X509Certificate LocalCertificate {
260                         get { return Impl.LocalCertificate; }
261                 }
262
263                 public virtual X509Certificate RemoteCertificate {
264                         get { return Impl.RemoteCertificate; }
265                 }
266
267                 public virtual CipherAlgorithmType CipherAlgorithm {
268                         get { return (CipherAlgorithmType)Impl.CipherAlgorithm; }
269                 }
270
271                 public virtual int CipherStrength {
272                         get { return Impl.CipherStrength; }
273                 }
274
275                 public virtual HashAlgorithmType HashAlgorithm {
276                         get { return (HashAlgorithmType)Impl.HashAlgorithm; }
277                 }
278
279                 public virtual int HashStrength {
280                         get { return Impl.HashStrength; }
281                 }
282
283                 public virtual ExchangeAlgorithmType KeyExchangeAlgorithm {
284                         get { return (ExchangeAlgorithmType)Impl.KeyExchangeAlgorithm; }
285                 }
286
287                 public virtual int KeyExchangeStrength {
288                         get { return Impl.KeyExchangeStrength; }
289                 }
290
291                 public override bool CanSeek {
292                         get { return false; }
293                 }
294
295                 public override bool CanRead {
296                         get { return Impl.CanRead; }
297                 }
298
299                 public override bool CanTimeout {
300                         get { return Impl.CanTimeout; }
301                 }
302
303                 public override bool CanWrite {
304                         get { return Impl.CanWrite; }
305                 }
306
307                 public override int ReadTimeout {
308                         get { return Impl.ReadTimeout; }
309                         set { Impl.ReadTimeout = value; }
310                 }
311
312                 public override int WriteTimeout {
313                         get { return Impl.WriteTimeout; }
314                         set { Impl.WriteTimeout = value; }
315                 }
316
317                 public override long Length {
318                         get { return Impl.Length; }
319                 }
320
321                 public override long Position {
322                         get { return Impl.Position; }
323                         set {
324                                 throw new NotSupportedException (SR.GetString (SR.net_noseek));
325                         }
326                 }
327
328                 public override void SetLength (long value)
329                 {
330                         Impl.SetLength (value);
331                 }
332
333                 public override long Seek (long offset, SeekOrigin origin)
334                 {
335                         throw new NotSupportedException (SR.GetString (SR.net_noseek));
336                 }
337
338                 public override void Flush ()
339                 {
340                         Impl.Flush ();
341                 }
342
343                 void CheckDisposed ()
344                 {
345                         if (impl == null)
346                                 throw new ObjectDisposedException ("SslStream");
347                 }
348
349                 protected override void Dispose (bool disposing)
350                 {
351                         try {
352                                 if (impl != null && disposing) {
353                                         impl.Dispose ();
354                                         impl = null;
355                                 }
356                         } finally {
357                                 base.Dispose (disposing);
358                         }
359                 }
360
361                 public override int Read (byte[] buffer, int offset, int count)
362                 {
363                         return Impl.Read (buffer, offset, count);
364                 }
365
366                 public void Write (byte[] buffer)
367                 {
368                         Impl.Write (buffer);
369                 }
370
371                 public override void Write (byte[] buffer, int offset, int count)
372                 {
373                         Impl.Write (buffer, offset, count);
374                 }
375
376                 // [HostProtection (ExternalThreading=true)]
377                 public override IAsyncResult BeginRead (byte[] buffer, int offset, int count, AsyncCallback asyncCallback, object asyncState)
378                 {
379                         return Impl.BeginRead (buffer, offset, count, asyncCallback, asyncState);
380                 }
381
382                 public override int EndRead (IAsyncResult asyncResult)
383                 {
384                         return Impl.EndRead (asyncResult);
385                 }
386
387                 // [HostProtection (ExternalThreading=true)]
388                 public override IAsyncResult BeginWrite (byte[] buffer, int offset, int count, AsyncCallback asyncCallback, object asyncState)
389                 {
390                         return Impl.BeginWrite (buffer, offset, count, asyncCallback, asyncState);
391                 }
392
393                 public override void EndWrite (IAsyncResult asyncResult)
394                 {
395                         Impl.EndWrite (asyncResult);
396                 }
397 #else // !SECURITY_DEP
398                 const string EXCEPTION_MESSAGE = "System.Net.Security.SslStream is not supported on the current platform.";
399
400                 public SslStream (Stream innerStream)
401                         : this (innerStream, false)
402                 {
403                 }
404
405                 public SslStream (Stream innerStream, bool leaveInnerStreamOpen)
406                         : base (innerStream, leaveInnerStreamOpen)
407                 {
408                         throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
409                 }
410
411                 public SslStream (Stream innerStream, bool leaveInnerStreamOpen, RemoteCertificateValidationCallback userCertificateValidationCallback)
412                         : this (innerStream, leaveInnerStreamOpen)
413                 {
414                 }
415
416                 public SslStream (Stream innerStream, bool leaveInnerStreamOpen, RemoteCertificateValidationCallback userCertificateValidationCallback, LocalCertificateSelectionCallback userCertificateSelectionCallback)
417                         : this (innerStream, leaveInnerStreamOpen)
418                 {
419                 }
420
421                 public SslStream (Stream innerStream, bool leaveInnerStreamOpen, RemoteCertificateValidationCallback userCertificateValidationCallback, LocalCertificateSelectionCallback userCertificateSelectionCallback, EncryptionPolicy encryptionPolicy)
422                         : this (innerStream, leaveInnerStreamOpen)
423                 {
424                 }
425
426                 public virtual void AuthenticateAsClient (string targetHost)
427                 {
428                         throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
429                 }
430
431                 public virtual void AuthenticateAsClient (string targetHost, X509CertificateCollection clientCertificates, SslProtocols enabledSslProtocols, bool checkCertificateRevocation)
432                 {
433                         throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
434                 }
435
436                 public virtual IAsyncResult BeginAuthenticateAsClient (string targetHost, AsyncCallback asyncCallback, object asyncState)
437                 {
438                         throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
439                 }
440
441                 public virtual IAsyncResult BeginAuthenticateAsClient (string targetHost, X509CertificateCollection clientCertificates, SslProtocols enabledSslProtocols, bool checkCertificateRevocation, AsyncCallback asyncCallback, object asyncState)
442                 {
443                         throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
444                 }
445
446                 public virtual void EndAuthenticateAsClient (IAsyncResult asyncResult)
447                 {
448                         throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
449                 }
450
451                 public virtual void AuthenticateAsServer (X509Certificate serverCertificate)
452                 {
453                         throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
454                 }
455
456                 public virtual void AuthenticateAsServer (X509Certificate serverCertificate, bool clientCertificateRequired, SslProtocols enabledSslProtocols, bool checkCertificateRevocation)
457                 {
458                         throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
459                 }
460
461                 public virtual IAsyncResult BeginAuthenticateAsServer (X509Certificate serverCertificate, AsyncCallback asyncCallback, object asyncState)
462                 {
463                         throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
464                 }
465
466                 public virtual IAsyncResult BeginAuthenticateAsServer (X509Certificate serverCertificate, bool clientCertificateRequired, SslProtocols enabledSslProtocols, bool checkCertificateRevocation, AsyncCallback asyncCallback, object asyncState)
467                 {
468                         throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
469                 }
470
471                 public virtual void EndAuthenticateAsServer (IAsyncResult asyncResult)
472                 {
473                         throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
474                 }
475
476                 public TransportContext TransportContext {
477                         get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
478                 }
479
480                 public virtual Task AuthenticateAsClientAsync (string targetHost)
481                 {
482                         throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
483                 }
484
485                 public virtual Task AuthenticateAsClientAsync (string targetHost, X509CertificateCollection clientCertificates, SslProtocols enabledSslProtocols, bool checkCertificateRevocation)
486                 {
487                         throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
488                 }
489
490                 public virtual Task AuthenticateAsServerAsync (X509Certificate serverCertificate)
491                 {
492                         throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
493                 }
494
495                 public virtual Task AuthenticateAsServerAsync (X509Certificate serverCertificate, bool clientCertificateRequired, SslProtocols enabledSslProtocols, bool checkCertificateRevocation)
496                 {
497                         throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
498                 }
499
500                 public override bool IsAuthenticated {
501                         get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
502                 }
503
504                 public override bool IsMutuallyAuthenticated {
505                         get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
506                 }
507
508                 public override bool IsEncrypted {
509                         get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
510                 }
511
512                 public override bool IsSigned {
513                         get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
514                 }
515
516                 public override bool IsServer {
517                         get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
518                 }
519
520                 public virtual SslProtocols SslProtocol {
521                         get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
522                 }
523
524                 public virtual bool CheckCertRevocationStatus {
525                         get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
526                 }
527
528                 public virtual X509Certificate LocalCertificate {
529                         get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
530                 }
531
532                 public virtual X509Certificate RemoteCertificate {
533                         get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
534                 }
535
536                 public virtual CipherAlgorithmType CipherAlgorithm {
537                         get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
538                 }
539
540                 public virtual int CipherStrength {
541                         get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
542                 }
543
544                 public virtual HashAlgorithmType HashAlgorithm {
545                         get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
546                 }
547
548                 public virtual int HashStrength {
549                         get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
550                 }
551
552                 public virtual ExchangeAlgorithmType KeyExchangeAlgorithm {
553                         get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
554                 }
555
556                 public virtual int KeyExchangeStrength {
557                         get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
558                 }
559
560                 public override bool CanSeek {
561                         get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
562                 }
563
564                 public override bool CanRead {
565                         get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
566                 }
567
568                 public override bool CanTimeout {
569                         get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
570                 }
571
572                 public override bool CanWrite {
573                         get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
574                 }
575
576                 public override int ReadTimeout {
577                         get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
578                         set { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
579                 }
580
581                 public override int WriteTimeout {
582                         get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
583                         set { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
584                 }
585
586                 public override long Length {
587                         get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
588                 }
589
590                 public override long Position {
591                         get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
592                         set { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
593                 }
594
595                 public override void SetLength (long value)
596                 {
597                         throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
598                 }
599
600                 public override long Seek (long offset, SeekOrigin origin)
601                 {
602                         throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
603                 }
604
605                 public override void Flush ()
606                 {
607                         throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
608                 }
609
610                 protected override void Dispose (bool disposing)
611                 {
612                 }
613
614                 public override int Read (byte[] buffer, int offset, int count)
615                 {
616                         throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
617                 }
618
619                 public void Write (byte[] buffer)
620                 {
621                         throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
622                 }
623
624                 public override void Write (byte[] buffer, int offset, int count)
625                 {
626                         throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
627                 }
628
629                 public override IAsyncResult BeginRead (byte[] buffer, int offset, int count, AsyncCallback asyncCallback, object asyncState)
630                 {
631                         throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
632                 }
633
634                 public override int EndRead (IAsyncResult asyncResult)
635                 {
636                         throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
637                 }
638
639                 public override IAsyncResult BeginWrite (byte[] buffer, int offset, int count, AsyncCallback asyncCallback, object asyncState)
640                 {
641                         throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
642                 }
643
644                 public override void EndWrite (IAsyncResult asyncResult)
645                 {
646                         throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
647                 }
648 #endif
649         }
650 }