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 extern alias PrebuiltSystem;
32 #if MONO_SECURITY_ALIAS
33 extern alias MonoSecurity;
36 #if MONO_SECURITY_ALIAS
37 using MonoSecurity::Mono.Security.Interface;
39 using Mono.Security.Interface;
42 using XX509CertificateCollection = PrebuiltSystem::System.Security.Cryptography.X509Certificates.X509CertificateCollection;
44 using XTransportContext = PrebuiltSystem::System.Net.TransportContext;
45 using XAuthenticatedStream = PrebuiltSystem::System.Net.Security.AuthenticatedStream;
47 using XCipherAlgorithmType = PrebuiltSystem::System.Security.Authentication.CipherAlgorithmType;
48 using XHashAlgorithmType = PrebuiltSystem::System.Security.Authentication.HashAlgorithmType;
49 using XExchangeAlgorithmType = PrebuiltSystem::System.Security.Authentication.ExchangeAlgorithmType;
50 using XSslProtocols = PrebuiltSystem::System.Security.Authentication.SslProtocols;
52 using XX509CertificateCollection = System.Security.Cryptography.X509Certificates.X509CertificateCollection;
54 using XTransportContext = System.Net.TransportContext;
55 using XAuthenticatedStream = System.Net.Security.AuthenticatedStream;
57 using XCipherAlgorithmType = System.Security.Authentication.CipherAlgorithmType;
58 using XHashAlgorithmType = System.Security.Authentication.HashAlgorithmType;
59 using XExchangeAlgorithmType = System.Security.Authentication.ExchangeAlgorithmType;
60 using XSslProtocols = System.Security.Authentication.SslProtocols;
66 using System.Net.Security;
67 using System.Threading.Tasks;
68 using System.Security.Authentication;
69 using System.Security.Cryptography.X509Certificates;
70 using System.Security.Principal;
71 using System.Security.Cryptography;
73 namespace Mono.Net.Security
75 class MonoSslStreamImpl : MonoSslStream
79 internal IMonoSslStream Impl {
86 public MonoSslStreamImpl (IMonoSslStream impl)
91 public override void AuthenticateAsClient (string targetHost)
93 Impl.AuthenticateAsClient (targetHost);
96 public override void AuthenticateAsClient (string targetHost, XX509CertificateCollection clientCertificates, XSslProtocols enabledSslProtocols, bool checkCertificateRevocation)
98 Impl.AuthenticateAsClient (targetHost, clientCertificates, (SslProtocols)enabledSslProtocols, checkCertificateRevocation);
101 public override IAsyncResult BeginAuthenticateAsClient (string targetHost, AsyncCallback asyncCallback, object asyncState)
103 return Impl.BeginAuthenticateAsClient (targetHost, asyncCallback, asyncState);
106 public override IAsyncResult BeginAuthenticateAsClient (string targetHost, XX509CertificateCollection clientCertificates, XSslProtocols enabledSslProtocols, bool checkCertificateRevocation, AsyncCallback asyncCallback, object asyncState)
108 return Impl.BeginAuthenticateAsClient (targetHost, clientCertificates, (SslProtocols)enabledSslProtocols, checkCertificateRevocation, asyncCallback, asyncState);
111 public override void EndAuthenticateAsClient (IAsyncResult asyncResult)
113 Impl.EndAuthenticateAsClient (asyncResult);
116 public override void AuthenticateAsServer (X509Certificate serverCertificate)
118 Impl.AuthenticateAsServer (serverCertificate);
121 public override void AuthenticateAsServer (X509Certificate serverCertificate, bool clientCertificateRequired, XSslProtocols enabledSslProtocols, bool checkCertificateRevocation)
123 Impl.AuthenticateAsServer (serverCertificate, clientCertificateRequired, (SslProtocols)enabledSslProtocols, checkCertificateRevocation);
126 public override IAsyncResult BeginAuthenticateAsServer (X509Certificate serverCertificate, AsyncCallback asyncCallback, object asyncState)
128 return Impl.BeginAuthenticateAsServer (serverCertificate, asyncCallback, asyncState);
131 public override IAsyncResult BeginAuthenticateAsServer (X509Certificate serverCertificate, bool clientCertificateRequired, XSslProtocols enabledSslProtocols, bool checkCertificateRevocation, AsyncCallback asyncCallback, object asyncState)
133 return Impl.BeginAuthenticateAsServer (serverCertificate, clientCertificateRequired, (SslProtocols)enabledSslProtocols, checkCertificateRevocation, asyncCallback, asyncState);
136 public override void EndAuthenticateAsServer (IAsyncResult asyncResult)
138 Impl.EndAuthenticateAsServer (asyncResult);
141 public override Task AuthenticateAsClientAsync (string targetHost)
143 return Impl.AuthenticateAsClientAsync (targetHost);
146 public override Task AuthenticateAsClientAsync (string targetHost, XX509CertificateCollection clientCertificates, XSslProtocols enabledSslProtocols, bool checkCertificateRevocation)
148 return Impl.AuthenticateAsClientAsync (targetHost, clientCertificates, (SslProtocols)enabledSslProtocols, checkCertificateRevocation);
151 public override Task AuthenticateAsServerAsync (X509Certificate serverCertificate)
153 return Impl.AuthenticateAsServerAsync (serverCertificate);
156 public override Task AuthenticateAsServerAsync (X509Certificate serverCertificate, bool clientCertificateRequired, XSslProtocols enabledSslProtocols, bool checkCertificateRevocation)
158 return Impl.AuthenticateAsServerAsync (serverCertificate, clientCertificateRequired, (SslProtocols)enabledSslProtocols, checkCertificateRevocation);
161 public override void Flush ()
166 public override int Read (byte[] buffer, int offset, int count)
168 return Impl.Read (buffer, offset, count);
171 public override void Write (byte[] buffer)
176 public override void Write (byte[] buffer, int offset, int count)
178 Impl.Write (buffer, offset, count);
181 public override IAsyncResult BeginRead (byte[] buffer, int offset, int count, AsyncCallback asyncCallback, object asyncState)
183 return Impl.BeginRead (buffer, offset, count, asyncCallback, asyncState);
186 public override int EndRead (IAsyncResult asyncResult)
188 return Impl.EndRead (asyncResult);
191 public override IAsyncResult BeginWrite (byte[] buffer, int offset, int count, AsyncCallback asyncCallback, object asyncState)
193 return Impl.BeginWrite (buffer, offset, count, asyncCallback, asyncState);
196 public override void EndWrite (IAsyncResult asyncResult)
198 Impl.EndWrite (asyncResult);
201 public override XTransportContext TransportContext {
202 get { return (XTransportContext)(object)Impl.TransportContext; }
205 public override bool IsAuthenticated {
206 get { return Impl.IsAuthenticated; }
209 public override bool IsMutuallyAuthenticated {
210 get { return Impl.IsMutuallyAuthenticated; }
213 public override bool IsEncrypted {
214 get { return Impl.IsEncrypted; }
217 public override bool IsSigned {
218 get { return Impl.IsSigned; }
221 public override bool IsServer {
222 get { return Impl.IsServer; }
225 public override XCipherAlgorithmType CipherAlgorithm {
226 get { return (XCipherAlgorithmType)Impl.CipherAlgorithm; }
229 public override int CipherStrength {
230 get { return Impl.CipherStrength; }
233 public override XHashAlgorithmType HashAlgorithm {
234 get { return (XHashAlgorithmType)Impl.HashAlgorithm; }
237 public override int HashStrength {
238 get { return Impl.HashStrength; }
241 public override XExchangeAlgorithmType KeyExchangeAlgorithm {
242 get { return (XExchangeAlgorithmType)Impl.KeyExchangeAlgorithm; }
245 public override int KeyExchangeStrength {
246 get { return KeyExchangeStrength; }
249 public override bool CanRead {
250 get { return Impl.CanRead; }
253 public override bool CanTimeout {
254 get { return Impl.CanTimeout; }
257 public override bool CanWrite {
258 get { return Impl.CanWrite; }
261 public override long Length {
262 get { return Impl.Length; }
265 public override long Position {
266 get { return Impl.Position; }
269 public override void SetLength (long value)
271 Impl.SetLength (value);
274 public override XAuthenticatedStream AuthenticatedStream {
275 get { return (XAuthenticatedStream)(Stream)Impl.AuthenticatedStream; }
278 public override int ReadTimeout {
279 get { return Impl.ReadTimeout; }
280 set { Impl.ReadTimeout = value; }
283 public override int WriteTimeout {
284 get { return Impl.WriteTimeout; }
285 set { Impl.WriteTimeout = value; }
288 public override bool CheckCertRevocationStatus {
289 get { return Impl.CheckCertRevocationStatus; }
292 public override X509Certificate InternalLocalCertificate {
293 get { return Impl.InternalLocalCertificate; }
296 public override X509Certificate LocalCertificate {
297 get { return Impl.LocalCertificate; }
300 public override X509Certificate RemoteCertificate {
301 get { return Impl.RemoteCertificate; }
304 public override XSslProtocols SslProtocol {
305 get { return (XSslProtocols)Impl.SslProtocol; }
308 void CheckDisposed ()
311 throw new ObjectDisposedException ("MonoSslStream");
314 protected override void Dispose (bool disposing)
316 if (impl != null && disposing) {