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 extern alias PrebuiltSystem;
31 #if MONO_SECURITY_ALIAS
32 extern alias MonoSecurity;
36 using X509CertificateCollection = PrebuiltSystem::System.Security.Cryptography.X509Certificates.X509CertificateCollection;
38 #if MONO_SECURITY_ALIAS
39 using MSI = MonoSecurity::Mono.Security.Interface;
41 using MSI = Mono.Security.Interface;
48 using System.Net.Security;
49 using System.Threading.Tasks;
50 using System.Security.Authentication;
51 using System.Security.Cryptography.X509Certificates;
52 using System.Security.Principal;
53 using System.Security.Cryptography;
55 namespace Mono.Net.Security
57 interface IMonoSslStream : IDisposable
59 AuthenticatedStream AuthenticatedStream {
63 void AuthenticateAsClient (string targetHost);
65 void AuthenticateAsClient (string targetHost, X509CertificateCollection clientCertificates, SslProtocols enabledSslProtocols, bool checkCertificateRevocation);
67 IAsyncResult BeginAuthenticateAsClient (string targetHost, AsyncCallback asyncCallback, object asyncState);
69 IAsyncResult BeginAuthenticateAsClient (string targetHost, X509CertificateCollection clientCertificates,
70 SslProtocols enabledSslProtocols, bool checkCertificateRevocation,
71 AsyncCallback asyncCallback, object asyncState);
73 void EndAuthenticateAsClient (IAsyncResult asyncResult);
75 void AuthenticateAsServer (X509Certificate serverCertificate);
77 void AuthenticateAsServer (X509Certificate serverCertificate, bool clientCertificateRequired,
78 SslProtocols enabledSslProtocols, bool checkCertificateRevocation);
80 IAsyncResult BeginAuthenticateAsServer (X509Certificate serverCertificate, AsyncCallback asyncCallback, object asyncState);
82 IAsyncResult BeginAuthenticateAsServer (X509Certificate serverCertificate, bool clientCertificateRequired,
83 SslProtocols enabledSslProtocols, bool checkCertificateRevocation,
84 AsyncCallback asyncCallback,
87 void EndAuthenticateAsServer (IAsyncResult asyncResult);
89 TransportContext TransportContext {
93 Task AuthenticateAsClientAsync (string targetHost);
95 Task AuthenticateAsClientAsync (string targetHost, X509CertificateCollection clientCertificates, SslProtocols enabledSslProtocols, bool checkCertificateRevocation);
97 Task AuthenticateAsServerAsync (X509Certificate serverCertificate);
99 Task AuthenticateAsServerAsync (X509Certificate serverCertificate, bool clientCertificateRequired, SslProtocols enabledSslProtocols, bool checkCertificateRevocation);
103 // Base class properties
105 bool IsAuthenticated {
109 bool IsMutuallyAuthenticated {
127 //SSL specific properties
130 SslProtocols SslProtocol {
134 bool CheckCertRevocationStatus {
138 X509Certificate InternalLocalCertificate {
142 X509Certificate LocalCertificate {
146 X509Certificate RemoteCertificate {
151 // More informational properties
153 CipherAlgorithmType CipherAlgorithm {
161 HashAlgorithmType HashAlgorithm {
169 ExchangeAlgorithmType KeyExchangeAlgorithm {
173 int KeyExchangeStrength {
179 // Stream contract implementation
213 void SetLength (long value);
217 int Read (byte[] buffer, int offset, int count);
219 void Write (byte[] buffer);
221 void Write (byte[] buffer, int offset, int count);
223 IAsyncResult BeginRead (byte[] buffer, int offset, int count, AsyncCallback asyncCallback, object asyncState);
225 int EndRead (IAsyncResult asyncResult);
227 IAsyncResult BeginWrite (byte[] buffer, int offset, int count, AsyncCallback asyncCallback, object asyncState);
229 void EndWrite (IAsyncResult asyncResult);
232 MSI.MonoTlsProvider Provider {
236 MSI.MonoTlsConnectionInfo GetConnectionInfo ();