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 override bool IsAuthenticated {
156 get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
159 public override bool IsMutuallyAuthenticated {
160 get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
163 public override bool IsEncrypted {
164 get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
167 public override bool IsSigned {
168 get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
171 public override bool IsServer {
172 get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
175 public virtual SslProtocols SslProtocol {
176 get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
179 public virtual bool CheckCertRevocationStatus {
180 get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
183 public virtual X509Certificate LocalCertificate {
184 get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
187 public virtual X509Certificate RemoteCertificate {
188 get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
191 public virtual CipherAlgorithmType CipherAlgorithm {
192 get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
195 public virtual int CipherStrength {
196 get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
199 public virtual HashAlgorithmType HashAlgorithm {
200 get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
203 public virtual int HashStrength {
204 get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
207 public virtual ExchangeAlgorithmType KeyExchangeAlgorithm {
208 get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
211 public virtual int KeyExchangeStrength {
212 get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
215 public override bool CanSeek {
216 get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
219 public override bool CanRead {
220 get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
223 public override bool CanTimeout {
224 get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
227 public override bool CanWrite {
228 get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
231 public override int ReadTimeout {
232 get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
233 set { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
236 public override int WriteTimeout {
237 get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
238 set { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
241 public override long Length {
242 get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
245 public override long Position {
246 get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
247 set { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
250 public override void SetLength (long value)
252 throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
255 public override long Seek (long offset, SeekOrigin origin)
257 throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
260 public override void Flush ()
262 throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
265 protected override void Dispose (bool disposing)
269 public override int Read (byte[] buffer, int offset, int count)
271 throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
274 public void Write (byte[] buffer)
276 throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
279 public override void Write (byte[] buffer, int offset, int count)
281 throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
284 public override IAsyncResult BeginRead (byte[] buffer, int offset, int count, AsyncCallback asyncCallback, object asyncState)
286 throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
289 public override int EndRead (IAsyncResult asyncResult)
291 throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
294 public override IAsyncResult BeginWrite (byte[] buffer, int offset, int count, AsyncCallback asyncCallback, object asyncState)
296 throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
299 public override void EndWrite (IAsyncResult asyncResult)
301 throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);