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
34 public class SslStream : AuthenticatedStream
36 const string EXCEPTION_MESSAGE = "System.Net.Security.SslStream is not supported on the current platform.";
38 public SslStream (Stream innerStream)
39 : this (innerStream, false, null, null)
43 public SslStream (Stream innerStream, bool leaveInnerStreamOpen)
44 : this (innerStream, leaveInnerStreamOpen, null, null)
48 public SslStream (Stream innerStream, bool leaveInnerStreamOpen, RemoteCertificateValidationCallback userCertificateValidationCallback)
49 : this (innerStream, leaveInnerStreamOpen, userCertificateValidationCallback, null)
53 public SslStream (Stream innerStream, bool leaveInnerStreamOpen, RemoteCertificateValidationCallback userCertificateValidationCallback, LocalCertificateSelectionCallback userCertificateSelectionCallback)
54 : base (innerStream, leaveInnerStreamOpen)
56 throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
59 public SslStream (Stream innerStream, bool leaveInnerStreamOpen, RemoteCertificateValidationCallback userCertificateValidationCallback, LocalCertificateSelectionCallback userCertificateSelectionCallback, EncryptionPolicy encryptionPolicy)
60 : this (innerStream, leaveInnerStreamOpen, userCertificateValidationCallback, userCertificateSelectionCallback)
64 public virtual void AuthenticateAsClient (string targetHost)
66 throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
69 public virtual void AuthenticateAsClient (string targetHost, X509CertificateCollection clientCertificates, SslProtocols enabledSslProtocols, bool checkCertificateRevocation)
71 throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
74 public virtual IAsyncResult BeginAuthenticateAsClient (string targetHost, AsyncCallback asyncCallback, object asyncState)
76 throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
79 public virtual IAsyncResult BeginAuthenticateAsClient (string targetHost, X509CertificateCollection clientCertificates, SslProtocols enabledSslProtocols, bool checkCertificateRevocation, AsyncCallback asyncCallback, object asyncState)
81 throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
84 public virtual void EndAuthenticateAsClient (IAsyncResult asyncResult)
86 throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
89 public virtual void AuthenticateAsServer (X509Certificate serverCertificate)
91 throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
94 public virtual void AuthenticateAsServer (X509Certificate serverCertificate, bool clientCertificateRequired, SslProtocols enabledSslProtocols, bool checkCertificateRevocation)
96 throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
99 public virtual IAsyncResult BeginAuthenticateAsServer (X509Certificate serverCertificate, AsyncCallback asyncCallback, object asyncState)
101 throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
104 public virtual IAsyncResult BeginAuthenticateAsServer (X509Certificate serverCertificate, bool clientCertificateRequired, SslProtocols enabledSslProtocols, bool checkCertificateRevocation, AsyncCallback asyncCallback, object asyncState)
106 throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
109 public virtual void EndAuthenticateAsServer (IAsyncResult asyncResult)
111 throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
114 public TransportContext TransportContext {
115 get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
118 public virtual Task AuthenticateAsClientAsync (string targetHost)
120 throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
123 public virtual Task AuthenticateAsClientAsync (string targetHost, X509CertificateCollection clientCertificates, SslProtocols enabledSslProtocols, bool checkCertificateRevocation)
125 throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
128 public virtual Task AuthenticateAsServerAsync (X509Certificate serverCertificate)
130 throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
133 public virtual Task AuthenticateAsServerAsync (X509Certificate serverCertificate, bool clientCertificateRequired, SslProtocols enabledSslProtocols, bool checkCertificateRevocation)
135 throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
138 public override bool IsAuthenticated {
139 get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
142 public override bool IsMutuallyAuthenticated {
143 get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
146 public override bool IsEncrypted {
147 get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
150 public override bool IsSigned {
151 get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
154 public override bool IsServer {
155 get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
158 public virtual SslProtocols SslProtocol {
159 get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
162 public virtual bool CheckCertRevocationStatus {
163 get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
166 public virtual X509Certificate LocalCertificate {
167 get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
170 public virtual X509Certificate RemoteCertificate {
171 get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
174 public virtual CipherAlgorithmType CipherAlgorithm {
175 get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
178 public virtual int CipherStrength {
179 get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
182 public virtual HashAlgorithmType HashAlgorithm {
183 get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
186 public virtual int HashStrength {
187 get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
190 public virtual ExchangeAlgorithmType KeyExchangeAlgorithm {
191 get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
194 public virtual int KeyExchangeStrength {
195 get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
198 public override bool CanSeek {
199 get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
202 public override bool CanRead {
203 get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
206 public override bool CanTimeout {
207 get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
210 public override bool CanWrite {
211 get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
214 public override int ReadTimeout {
215 get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
216 set { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
219 public override int WriteTimeout {
220 get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
221 set { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
224 public override long Length {
225 get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
228 public override long Position {
229 get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
230 set { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
233 public override void SetLength (long value)
235 throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
238 public override long Seek (long offset, SeekOrigin origin)
240 throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
243 public override void Flush ()
245 throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
248 protected override void Dispose (bool disposing)
252 public override int Read (byte[] buffer, int offset, int count)
254 throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
257 public void Write (byte[] buffer)
259 throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
262 public override void Write (byte[] buffer, int offset, int count)
264 throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
267 public override IAsyncResult BeginRead (byte[] buffer, int offset, int count, AsyncCallback asyncCallback, object asyncState)
269 throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
272 public override int EndRead (IAsyncResult asyncResult)
274 throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
277 public override IAsyncResult BeginWrite (byte[] buffer, int offset, int count, AsyncCallback asyncCallback, object asyncState)
279 throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
282 public override void EndWrite (IAsyncResult asyncResult)
284 throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);