5 // Rolf Bjarne Kvinge <rolf@xamarin.com>
7 // Copyright (c) 2016 Xamarin, Inc.
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:
16 // The above copyright notice and this permission notice shall be included in
17 // all copies or substantial portions of the Software.
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
28 using System.Security.Authentication;
29 using System.Security.Cryptography.X509Certificates;
30 using System.Threading.Tasks;
32 namespace System.Net.Security
35 * These two are defined by the referencesource; add them here to make
36 * it easy to switch between the two implementations.
39 internal delegate bool RemoteCertValidationCallback (
41 X509Certificate certificate,
43 SslPolicyErrors sslPolicyErrors);
45 internal delegate X509Certificate LocalCertSelectionCallback (
47 X509CertificateCollection localCertificates,
48 X509Certificate remoteCertificate,
49 string[] acceptableIssuers);
51 public class SslStream : AuthenticatedStream
53 const string EXCEPTION_MESSAGE = "System.Net.Security.SslStream is not supported on the current platform.";
55 public SslStream (Stream innerStream)
56 : this (innerStream, false)
60 public SslStream (Stream innerStream, bool leaveInnerStreamOpen)
61 : base (innerStream, leaveInnerStreamOpen)
63 throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
66 public SslStream (Stream innerStream, bool leaveInnerStreamOpen, RemoteCertificateValidationCallback userCertificateValidationCallback)
67 : this (innerStream, leaveInnerStreamOpen)
71 public SslStream (Stream innerStream, bool leaveInnerStreamOpen, RemoteCertificateValidationCallback userCertificateValidationCallback, LocalCertificateSelectionCallback userCertificateSelectionCallback)
72 : this (innerStream, leaveInnerStreamOpen)
76 public SslStream (Stream innerStream, bool leaveInnerStreamOpen, RemoteCertificateValidationCallback userCertificateValidationCallback, LocalCertificateSelectionCallback userCertificateSelectionCallback, EncryptionPolicy encryptionPolicy)
77 : this (innerStream, leaveInnerStreamOpen)
81 public virtual void AuthenticateAsClient (string targetHost)
83 throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
86 public virtual void AuthenticateAsClient (string targetHost, X509CertificateCollection clientCertificates, SslProtocols enabledSslProtocols, bool checkCertificateRevocation)
88 throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
91 public virtual IAsyncResult BeginAuthenticateAsClient (string targetHost, AsyncCallback asyncCallback, object asyncState)
93 throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
96 public virtual IAsyncResult BeginAuthenticateAsClient (string targetHost, X509CertificateCollection clientCertificates, SslProtocols enabledSslProtocols, bool checkCertificateRevocation, AsyncCallback asyncCallback, object asyncState)
98 throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
101 public virtual void EndAuthenticateAsClient (IAsyncResult asyncResult)
103 throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
106 public virtual void AuthenticateAsServer (X509Certificate serverCertificate)
108 throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
111 public virtual void AuthenticateAsServer (X509Certificate serverCertificate, bool clientCertificateRequired, SslProtocols enabledSslProtocols, bool checkCertificateRevocation)
113 throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
116 public virtual IAsyncResult BeginAuthenticateAsServer (X509Certificate serverCertificate, AsyncCallback asyncCallback, object asyncState)
118 throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
121 public virtual IAsyncResult BeginAuthenticateAsServer (X509Certificate serverCertificate, bool clientCertificateRequired, SslProtocols enabledSslProtocols, bool checkCertificateRevocation, AsyncCallback asyncCallback, object asyncState)
123 throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
126 public virtual void EndAuthenticateAsServer (IAsyncResult asyncResult)
128 throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
131 public TransportContext TransportContext {
132 get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
135 public virtual Task AuthenticateAsClientAsync (string targetHost)
137 throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
140 public virtual Task AuthenticateAsClientAsync (string targetHost, X509CertificateCollection clientCertificates, SslProtocols enabledSslProtocols, bool checkCertificateRevocation)
142 throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
145 public virtual Task AuthenticateAsServerAsync (X509Certificate serverCertificate)
147 throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
150 public virtual Task AuthenticateAsServerAsync (X509Certificate serverCertificate, bool clientCertificateRequired, SslProtocols enabledSslProtocols, bool checkCertificateRevocation)
152 throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
155 public virtual Task ShutdownAsync ()
157 throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
160 public override bool IsAuthenticated {
161 get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
164 public override bool IsMutuallyAuthenticated {
165 get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
168 public override bool IsEncrypted {
169 get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
172 public override bool IsSigned {
173 get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
176 public override bool IsServer {
177 get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
180 public virtual SslProtocols SslProtocol {
181 get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
184 public virtual bool CheckCertRevocationStatus {
185 get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
188 public virtual X509Certificate LocalCertificate {
189 get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
192 public virtual X509Certificate RemoteCertificate {
193 get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
196 public virtual CipherAlgorithmType CipherAlgorithm {
197 get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
200 public virtual int CipherStrength {
201 get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
204 public virtual HashAlgorithmType HashAlgorithm {
205 get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
208 public virtual int HashStrength {
209 get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
212 public virtual ExchangeAlgorithmType KeyExchangeAlgorithm {
213 get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
216 public virtual int KeyExchangeStrength {
217 get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
220 public override bool CanSeek {
221 get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
224 public override bool CanRead {
225 get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
228 public override bool CanTimeout {
229 get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
232 public override bool CanWrite {
233 get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
236 public override int ReadTimeout {
237 get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
238 set { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
241 public override int WriteTimeout {
242 get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
243 set { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
246 public override long Length {
247 get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
250 public override long Position {
251 get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
252 set { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
255 public override void SetLength (long value)
257 throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
260 public override long Seek (long offset, SeekOrigin origin)
262 throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
265 public override void Flush ()
267 throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
270 protected override void Dispose (bool disposing)
274 public override int Read (byte[] buffer, int offset, int count)
276 throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
279 public void Write (byte[] buffer)
281 throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
284 public override void Write (byte[] buffer, int offset, int count)
286 throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
289 public override IAsyncResult BeginRead (byte[] buffer, int offset, int count, AsyncCallback asyncCallback, object asyncState)
291 throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
294 public override int EndRead (IAsyncResult asyncResult)
296 throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
299 public override IAsyncResult BeginWrite (byte[] buffer, int offset, int count, AsyncCallback asyncCallback, object asyncState)
301 throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
304 public override void EndWrite (IAsyncResult asyncResult)
306 throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);