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
27 #if SECURITY_DEP && MONO_X509_ALIAS
28 extern alias PrebuiltSystem;
29 using X509CertificateCollection = PrebuiltSystem::System.Security.Cryptography.X509Certificates.X509CertificateCollection;
35 using System.Net.Security;
36 using System.Threading.Tasks;
37 using System.Security.Authentication;
38 using System.Security.Cryptography.X509Certificates;
39 using System.Security.Principal;
40 using System.Security.Cryptography;
42 namespace Mono.Net.Security
44 interface IMonoSslStream : IDisposable
46 AuthenticatedStream AuthenticatedStream {
50 void AuthenticateAsClient (string targetHost);
52 void AuthenticateAsClient (string targetHost, X509CertificateCollection clientCertificates, SslProtocols enabledSslProtocols, bool checkCertificateRevocation);
54 IAsyncResult BeginAuthenticateAsClient (string targetHost, AsyncCallback asyncCallback, object asyncState);
56 IAsyncResult BeginAuthenticateAsClient (string targetHost, X509CertificateCollection clientCertificates,
57 SslProtocols enabledSslProtocols, bool checkCertificateRevocation,
58 AsyncCallback asyncCallback, object asyncState);
60 void EndAuthenticateAsClient (IAsyncResult asyncResult);
62 void AuthenticateAsServer (X509Certificate serverCertificate);
64 void AuthenticateAsServer (X509Certificate serverCertificate, bool clientCertificateRequired,
65 SslProtocols enabledSslProtocols, bool checkCertificateRevocation);
67 IAsyncResult BeginAuthenticateAsServer (X509Certificate serverCertificate, AsyncCallback asyncCallback, object asyncState);
69 IAsyncResult BeginAuthenticateAsServer (X509Certificate serverCertificate, bool clientCertificateRequired,
70 SslProtocols enabledSslProtocols, bool checkCertificateRevocation,
71 AsyncCallback asyncCallback,
74 void EndAuthenticateAsServer (IAsyncResult asyncResult);
76 TransportContext TransportContext {
80 Task AuthenticateAsClientAsync (string targetHost);
82 Task AuthenticateAsClientAsync (string targetHost, X509CertificateCollection clientCertificates, SslProtocols enabledSslProtocols, bool checkCertificateRevocation);
84 Task AuthenticateAsServerAsync (X509Certificate serverCertificate);
86 Task AuthenticateAsServerAsync (X509Certificate serverCertificate, bool clientCertificateRequired, SslProtocols enabledSslProtocols, bool checkCertificateRevocation);
90 // Base class properties
92 bool IsAuthenticated {
96 bool IsMutuallyAuthenticated {
114 //SSL specific properties
117 SslProtocols SslProtocol {
121 bool CheckCertRevocationStatus {
125 X509Certificate InternalLocalCertificate {
129 X509Certificate LocalCertificate {
133 X509Certificate RemoteCertificate {
138 // More informational properties
140 CipherAlgorithmType CipherAlgorithm {
148 HashAlgorithmType HashAlgorithm {
156 ExchangeAlgorithmType KeyExchangeAlgorithm {
160 int KeyExchangeStrength {
166 // Stream contract implementation
200 void SetLength (long value);
204 int Read (byte[] buffer, int offset, int count);
206 void Write (byte[] buffer);
208 void Write (byte[] buffer, int offset, int count);
210 IAsyncResult BeginRead (byte[] buffer, int offset, int count, AsyncCallback asyncCallback, object asyncState);
212 int EndRead (IAsyncResult asyncResult);
214 IAsyncResult BeginWrite (byte[] buffer, int offset, int count, AsyncCallback asyncCallback, object asyncState);
216 void EndWrite (IAsyncResult asyncResult);