2 // DotNetSslStreamImpl.cs
5 // Martin Baulig <martin.baulig@xamarin.com>
7 // Copyright (c) 2015 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
30 using System.Net.Security;
31 using System.Threading.Tasks;
32 using System.Security.Authentication;
33 using System.Security.Cryptography.X509Certificates;
34 using System.Security.Principal;
35 using System.Security.Cryptography;
36 using Mono.Security.Interface;
38 namespace Mono.Security.Providers.DotNet
40 class DotNetSslStreamImpl : MonoSslStream
44 internal SslStream Impl {
51 public DotNetSslStreamImpl (
52 Stream innerStream, bool leaveInnerStreamOpen,
53 RemoteCertificateValidationCallback userCertificateValidationCallback,
54 LocalCertificateSelectionCallback userCertificateSelectionCallback)
56 impl = new SslStream (
57 innerStream, leaveInnerStreamOpen,
58 userCertificateValidationCallback,
59 userCertificateSelectionCallback);
62 public override void AuthenticateAsClient (string targetHost)
64 Impl.AuthenticateAsClient (targetHost);
67 public override void AuthenticateAsClient (string targetHost, X509CertificateCollection clientCertificates, SslProtocols enabledSslProtocols, bool checkCertificateRevocation)
69 Impl.AuthenticateAsClient (targetHost, clientCertificates, enabledSslProtocols, checkCertificateRevocation);
72 public override IAsyncResult BeginAuthenticateAsClient (string targetHost, AsyncCallback asyncCallback, object asyncState)
74 return Impl.BeginAuthenticateAsClient (targetHost, asyncCallback, asyncState);
77 public override IAsyncResult BeginAuthenticateAsClient (string targetHost, X509CertificateCollection clientCertificates, SslProtocols enabledSslProtocols, bool checkCertificateRevocation, AsyncCallback asyncCallback, object asyncState)
79 return Impl.BeginAuthenticateAsClient (targetHost, clientCertificates, enabledSslProtocols, checkCertificateRevocation, asyncCallback, asyncState);
82 public override void EndAuthenticateAsClient (IAsyncResult asyncResult)
84 Impl.EndAuthenticateAsClient (asyncResult);
87 public override void AuthenticateAsServer (X509Certificate serverCertificate)
89 Impl.AuthenticateAsServer (serverCertificate);
92 public override void AuthenticateAsServer (X509Certificate serverCertificate, bool clientCertificateRequired, SslProtocols enabledSslProtocols, bool checkCertificateRevocation)
94 Impl.AuthenticateAsServer (serverCertificate, clientCertificateRequired, enabledSslProtocols, checkCertificateRevocation);
97 public override IAsyncResult BeginAuthenticateAsServer (X509Certificate serverCertificate, AsyncCallback asyncCallback, object asyncState)
99 return Impl.BeginAuthenticateAsServer (serverCertificate, asyncCallback, asyncState);
102 public override IAsyncResult BeginAuthenticateAsServer (X509Certificate serverCertificate, bool clientCertificateRequired, SslProtocols enabledSslProtocols, bool checkCertificateRevocation, AsyncCallback asyncCallback, object asyncState)
104 return Impl.BeginAuthenticateAsServer (serverCertificate, clientCertificateRequired, enabledSslProtocols, checkCertificateRevocation, asyncCallback, asyncState);
107 public override void EndAuthenticateAsServer (IAsyncResult asyncResult)
109 Impl.EndAuthenticateAsServer (asyncResult);
112 public override Task AuthenticateAsClientAsync (string targetHost)
114 return Impl.AuthenticateAsClientAsync (targetHost);
117 public override Task AuthenticateAsClientAsync (string targetHost, X509CertificateCollection clientCertificates, SslProtocols enabledSslProtocols, bool checkCertificateRevocation)
119 return Impl.AuthenticateAsClientAsync (targetHost, clientCertificates, enabledSslProtocols, checkCertificateRevocation);
122 public override Task AuthenticateAsServerAsync (X509Certificate serverCertificate)
124 return Impl.AuthenticateAsServerAsync (serverCertificate);
127 public override Task AuthenticateAsServerAsync (X509Certificate serverCertificate, bool clientCertificateRequired, SslProtocols enabledSslProtocols, bool checkCertificateRevocation)
129 return Impl.AuthenticateAsServerAsync (serverCertificate, clientCertificateRequired, enabledSslProtocols, checkCertificateRevocation);
132 public override void Flush ()
137 public override int Read (byte[] buffer, int offset, int count)
139 return Impl.Read (buffer, offset, count);
142 public override void Write (byte[] buffer)
147 public override void Write (byte[] buffer, int offset, int count)
149 Impl.Write (buffer, offset, count);
152 public override IAsyncResult BeginRead (byte[] buffer, int offset, int count, AsyncCallback asyncCallback, object asyncState)
154 return Impl.BeginRead (buffer, offset, count, asyncCallback, asyncState);
157 public override int EndRead (IAsyncResult asyncResult)
159 return Impl.EndRead (asyncResult);
162 public override IAsyncResult BeginWrite (byte[] buffer, int offset, int count, AsyncCallback asyncCallback, object asyncState)
164 return Impl.BeginWrite (buffer, offset, count, asyncCallback, asyncState);
167 public override void EndWrite (IAsyncResult asyncResult)
169 Impl.EndWrite (asyncResult);
172 public override TransportContext TransportContext {
173 get { throw new NotSupportedException (); }
176 public override bool IsAuthenticated {
177 get { return Impl.IsAuthenticated; }
180 public override bool IsMutuallyAuthenticated {
181 get { return Impl.IsMutuallyAuthenticated; }
184 public override bool IsEncrypted {
185 get { return Impl.IsEncrypted; }
188 public override bool IsSigned {
189 get { return Impl.IsSigned; }
192 public override bool IsServer {
193 get { return Impl.IsServer; }
196 public override CipherAlgorithmType CipherAlgorithm {
197 get { return Impl.CipherAlgorithm; }
200 public override int CipherStrength {
201 get { return Impl.CipherStrength; }
204 public override HashAlgorithmType HashAlgorithm {
205 get { return Impl.HashAlgorithm; }
208 public override int HashStrength {
209 get { return Impl.HashStrength; }
212 public override ExchangeAlgorithmType KeyExchangeAlgorithm {
213 get { return Impl.KeyExchangeAlgorithm; }
216 public override int KeyExchangeStrength {
217 get { return KeyExchangeStrength; }
220 public override bool CanRead {
221 get { return Impl.CanRead; }
224 public override bool CanTimeout {
225 get { return Impl.CanTimeout; }
228 public override bool CanWrite {
229 get { return Impl.CanWrite; }
232 public override long Length {
233 get { return Impl.Length; }
236 public override long Position {
237 get { return Impl.Position; }
240 public override void SetLength (long value)
242 Impl.SetLength (value);
245 public override AuthenticatedStream AuthenticatedStream {
249 public override int ReadTimeout {
250 get { return Impl.ReadTimeout; }
251 set { Impl.ReadTimeout = value; }
254 public override int WriteTimeout {
255 get { return Impl.WriteTimeout; }
256 set { Impl.WriteTimeout = value; }
259 public override bool CheckCertRevocationStatus {
260 get { return Impl.CheckCertRevocationStatus; }
263 public override X509Certificate InternalLocalCertificate {
266 return LocalCertificate;
273 public override X509Certificate LocalCertificate {
274 get { return Impl.LocalCertificate; }
277 public override X509Certificate RemoteCertificate {
278 get { return Impl.RemoteCertificate; }
281 public override SslProtocols SslProtocol {
282 get { return Impl.SslProtocol; }
285 void CheckDisposed ()
288 throw new ObjectDisposedException ("MonoSslStream");
291 protected override void Dispose (bool disposing)
293 if (impl != null && disposing) {