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
29 #if MONO_SECURITY_ALIAS
30 extern alias MonoSecurity;
33 #if MONO_SECURITY_ALIAS
34 using MSI = MonoSecurity::Mono.Security.Interface;
36 using MSI = Mono.Security.Interface;
42 using System.Net.Security;
43 using System.Threading.Tasks;
44 using System.Security.Authentication;
45 using System.Security.Cryptography.X509Certificates;
46 using System.Security.Principal;
47 using System.Security.Cryptography;
49 namespace Mono.Net.Security.Private
52 * Strictly private - do not use outside the Mono.Net.Security directory.
54 class MonoSslStreamImpl : MSI.IMonoSslStream
58 internal IMonoSslStream Impl {
65 public MonoSslStreamImpl (IMonoSslStream impl)
70 public void AuthenticateAsClient (string targetHost)
72 Impl.AuthenticateAsClient (targetHost);
75 public void AuthenticateAsClient (string targetHost, X509CertificateCollection clientCertificates, SslProtocols enabledSslProtocols, bool checkCertificateRevocation)
77 Impl.AuthenticateAsClient (targetHost, clientCertificates, enabledSslProtocols, checkCertificateRevocation);
80 public IAsyncResult BeginAuthenticateAsClient (string targetHost, AsyncCallback asyncCallback, object asyncState)
82 return Impl.BeginAuthenticateAsClient (targetHost, asyncCallback, asyncState);
85 public IAsyncResult BeginAuthenticateAsClient (string targetHost, X509CertificateCollection clientCertificates, SslProtocols enabledSslProtocols, bool checkCertificateRevocation, AsyncCallback asyncCallback, object asyncState)
87 return Impl.BeginAuthenticateAsClient (targetHost, clientCertificates, enabledSslProtocols, checkCertificateRevocation, asyncCallback, asyncState);
90 public void EndAuthenticateAsClient (IAsyncResult asyncResult)
92 Impl.EndAuthenticateAsClient (asyncResult);
95 public void AuthenticateAsServer (X509Certificate serverCertificate)
97 Impl.AuthenticateAsServer (serverCertificate);
100 public void AuthenticateAsServer (X509Certificate serverCertificate, bool clientCertificateRequired, SslProtocols enabledSslProtocols, bool checkCertificateRevocation)
102 Impl.AuthenticateAsServer (serverCertificate, clientCertificateRequired, enabledSslProtocols, checkCertificateRevocation);
105 public IAsyncResult BeginAuthenticateAsServer (X509Certificate serverCertificate, AsyncCallback asyncCallback, object asyncState)
107 return Impl.BeginAuthenticateAsServer (serverCertificate, asyncCallback, asyncState);
110 public IAsyncResult BeginAuthenticateAsServer (X509Certificate serverCertificate, bool clientCertificateRequired, SslProtocols enabledSslProtocols, bool checkCertificateRevocation, AsyncCallback asyncCallback, object asyncState)
112 return Impl.BeginAuthenticateAsServer (serverCertificate, clientCertificateRequired, enabledSslProtocols, checkCertificateRevocation, asyncCallback, asyncState);
115 public void EndAuthenticateAsServer (IAsyncResult asyncResult)
117 Impl.EndAuthenticateAsServer (asyncResult);
120 public Task AuthenticateAsClientAsync (string targetHost)
122 return Impl.AuthenticateAsClientAsync (targetHost);
125 public Task AuthenticateAsClientAsync (string targetHost, X509CertificateCollection clientCertificates, SslProtocols enabledSslProtocols, bool checkCertificateRevocation)
127 return Impl.AuthenticateAsClientAsync (targetHost, clientCertificates, enabledSslProtocols, checkCertificateRevocation);
130 public Task AuthenticateAsServerAsync (X509Certificate serverCertificate)
132 return Impl.AuthenticateAsServerAsync (serverCertificate);
135 public Task AuthenticateAsServerAsync (X509Certificate serverCertificate, bool clientCertificateRequired, SslProtocols enabledSslProtocols, bool checkCertificateRevocation)
137 return Impl.AuthenticateAsServerAsync (serverCertificate, clientCertificateRequired, enabledSslProtocols, checkCertificateRevocation);
145 public int Read (byte[] buffer, int offset, int count)
147 return Impl.Read (buffer, offset, count);
150 public void Write (byte[] buffer)
155 public void Write (byte[] buffer, int offset, int count)
157 Impl.Write (buffer, offset, count);
160 public IAsyncResult BeginRead (byte[] buffer, int offset, int count, AsyncCallback asyncCallback, object asyncState)
162 return Impl.BeginRead (buffer, offset, count, asyncCallback, asyncState);
165 public int EndRead (IAsyncResult asyncResult)
167 return Impl.EndRead (asyncResult);
170 public IAsyncResult BeginWrite (byte[] buffer, int offset, int count, AsyncCallback asyncCallback, object asyncState)
172 return Impl.BeginWrite (buffer, offset, count, asyncCallback, asyncState);
175 public void EndWrite (IAsyncResult asyncResult)
177 Impl.EndWrite (asyncResult);
180 public TransportContext TransportContext {
181 get { return Impl.TransportContext; }
184 public bool IsAuthenticated {
185 get { return Impl.IsAuthenticated; }
188 public bool IsMutuallyAuthenticated {
189 get { return Impl.IsMutuallyAuthenticated; }
192 public bool IsEncrypted {
193 get { return Impl.IsEncrypted; }
196 public bool IsSigned {
197 get { return Impl.IsSigned; }
200 public bool IsServer {
201 get { return Impl.IsServer; }
204 public CipherAlgorithmType CipherAlgorithm {
205 get { return Impl.CipherAlgorithm; }
208 public int CipherStrength {
209 get { return Impl.CipherStrength; }
212 public HashAlgorithmType HashAlgorithm {
213 get { return Impl.HashAlgorithm; }
216 public int HashStrength {
217 get { return Impl.HashStrength; }
220 public ExchangeAlgorithmType KeyExchangeAlgorithm {
221 get { return Impl.KeyExchangeAlgorithm; }
224 public int KeyExchangeStrength {
225 get { return Impl.KeyExchangeStrength; }
228 public bool CanRead {
229 get { return Impl.CanRead; }
232 public bool CanTimeout {
233 get { return Impl.CanTimeout; }
236 public bool CanWrite {
237 get { return Impl.CanWrite; }
241 get { return Impl.Length; }
244 public long Position {
245 get { return Impl.Position; }
248 public void SetLength (long value)
250 Impl.SetLength (value);
253 public AuthenticatedStream AuthenticatedStream {
254 get { return Impl.AuthenticatedStream; }
257 public int ReadTimeout {
258 get { return Impl.ReadTimeout; }
259 set { Impl.ReadTimeout = value; }
262 public int WriteTimeout {
263 get { return Impl.WriteTimeout; }
264 set { Impl.WriteTimeout = value; }
267 public bool CheckCertRevocationStatus {
268 get { return Impl.CheckCertRevocationStatus; }
271 public X509Certificate InternalLocalCertificate {
272 get { return Impl.InternalLocalCertificate; }
275 public X509Certificate LocalCertificate {
276 get { return Impl.LocalCertificate; }
279 public X509Certificate RemoteCertificate {
280 get { return Impl.RemoteCertificate; }
283 public SslProtocols SslProtocol {
284 get { return Impl.SslProtocol; }
287 public MSI.MonoTlsProvider Provider {
288 get { return Impl.Provider; }
291 public MSI.MonoTlsConnectionInfo GetConnectionInfo ()
293 return Impl.GetConnectionInfo ();
296 void CheckDisposed ()
299 throw new ObjectDisposedException ("MonoSslStream");
302 public void Dispose ()
305 GC.SuppressFinalize (this);
308 protected virtual void Dispose (bool disposing)
310 if (impl != null && disposing) {