Merge pull request #2274 from esdrubal/udpclientreceive
[mono.git] / mcs / class / System / Mono.Net.Security / IMonoSslStream.cs
1 //
2 // IMonoSslStream.cs
3 //
4 // Author:
5 //       Martin Baulig <martin.baulig@xamarin.com>
6 //
7 // Copyright (c) 2015 Xamarin, Inc.
8 //
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:
15 //
16 // The above copyright notice and this permission notice shall be included in
17 // all copies or substantial portions of the Software.
18 //
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
25 // THE SOFTWARE.
26
27 #if SECURITY_DEP
28 #if MONO_X509_ALIAS
29 extern alias PrebuiltSystem;
30 #endif
31 #if MONO_SECURITY_ALIAS
32 extern alias MonoSecurity;
33 #endif
34
35 #if MONO_X509_ALIAS
36 using X509CertificateCollection = PrebuiltSystem::System.Security.Cryptography.X509Certificates.X509CertificateCollection;
37 #endif
38 #if MONO_SECURITY_ALIAS
39 using MSI = MonoSecurity::Mono.Security.Interface;
40 #else
41 using MSI = Mono.Security.Interface;
42 #endif
43 #endif
44
45 using System;
46 using System.IO;
47 using System.Net;
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;
54
55 namespace Mono.Net.Security
56 {
57         interface IMonoSslStream : IDisposable
58         {
59                 AuthenticatedStream AuthenticatedStream {
60                         get;
61                 }
62
63                 void AuthenticateAsClient (string targetHost);
64
65                 void AuthenticateAsClient (string targetHost, X509CertificateCollection clientCertificates, SslProtocols enabledSslProtocols, bool checkCertificateRevocation);
66
67                 IAsyncResult BeginAuthenticateAsClient (string targetHost, AsyncCallback asyncCallback, object asyncState);
68
69                 IAsyncResult BeginAuthenticateAsClient (string targetHost, X509CertificateCollection clientCertificates,
70                                                         SslProtocols enabledSslProtocols, bool checkCertificateRevocation,
71                                                         AsyncCallback asyncCallback, object asyncState);
72
73                 void EndAuthenticateAsClient (IAsyncResult asyncResult);
74
75                 void AuthenticateAsServer (X509Certificate serverCertificate);
76
77                 void AuthenticateAsServer (X509Certificate serverCertificate, bool clientCertificateRequired,
78                                           SslProtocols enabledSslProtocols, bool checkCertificateRevocation);
79
80                 IAsyncResult BeginAuthenticateAsServer (X509Certificate serverCertificate, AsyncCallback asyncCallback, object asyncState);
81
82                 IAsyncResult BeginAuthenticateAsServer (X509Certificate serverCertificate, bool clientCertificateRequired,
83                                                         SslProtocols enabledSslProtocols, bool checkCertificateRevocation,
84                                                         AsyncCallback asyncCallback,
85                                                         object asyncState);
86
87                 void EndAuthenticateAsServer (IAsyncResult asyncResult);
88
89                 TransportContext TransportContext {
90                         get;
91                 }
92
93                 Task AuthenticateAsClientAsync (string targetHost);
94
95                 Task AuthenticateAsClientAsync (string targetHost, X509CertificateCollection clientCertificates, SslProtocols enabledSslProtocols, bool checkCertificateRevocation);
96
97                 Task AuthenticateAsServerAsync (X509Certificate serverCertificate);
98
99                 Task AuthenticateAsServerAsync (X509Certificate serverCertificate, bool clientCertificateRequired, SslProtocols enabledSslProtocols, bool checkCertificateRevocation);
100
101                 //
102                 //
103                 // Base class properties
104                 //
105                 bool IsAuthenticated {
106                         get;
107                 }
108
109                 bool IsMutuallyAuthenticated {
110                         get;
111                 }
112
113                 bool IsEncrypted {
114                         get;
115                 }
116
117                 bool IsSigned {
118                         get;
119                 }
120
121                 bool IsServer {
122                         get;
123                 }
124
125                 //
126                 //
127                 //SSL specific properties
128                 //
129                 //
130                 SslProtocols SslProtocol {
131                         get;
132                 }
133
134                 bool CheckCertRevocationStatus {
135                         get;
136                 }
137
138                 X509Certificate InternalLocalCertificate {
139                         get;
140                 }
141
142                 X509Certificate LocalCertificate {
143                         get;
144                 }
145
146                 X509Certificate RemoteCertificate {
147                         get;
148                 }
149
150                 //
151                 // More informational properties
152                 //
153                 CipherAlgorithmType CipherAlgorithm {
154                         get;
155                 }
156
157                 int CipherStrength {
158                         get;
159                 }
160
161                 HashAlgorithmType HashAlgorithm {
162                         get;
163                 }
164
165                 int HashStrength {
166                         get;
167                 }
168
169                 ExchangeAlgorithmType KeyExchangeAlgorithm {
170                         get;
171                 }
172
173                 int KeyExchangeStrength {
174                         get;
175                 }
176
177                 //
178                 //
179                 // Stream contract implementation
180                 //
181                 //
182                 //
183                 bool CanRead {
184                         get;
185                 }
186
187                 bool CanTimeout {
188                         get;
189                 }
190
191                 bool CanWrite {
192                         get;
193                 }
194
195                 int ReadTimeout {
196                         get;
197                         set;
198                 }
199
200                 int WriteTimeout {
201                         get;
202                         set;
203                 }
204
205                 long Length {
206                         get;
207                 }
208
209                 long Position {
210                         get;
211                 }
212
213                 void SetLength (long value);
214
215                 void Flush ();
216
217                 int Read (byte[] buffer, int offset, int count);
218
219                 void Write (byte[] buffer);
220
221                 void Write (byte[] buffer, int offset, int count);
222
223                 IAsyncResult BeginRead (byte[] buffer, int offset, int count, AsyncCallback asyncCallback, object asyncState);
224
225                 int EndRead (IAsyncResult asyncResult);
226
227                 IAsyncResult BeginWrite (byte[] buffer, int offset, int count, AsyncCallback asyncCallback, object asyncState);
228
229                 void EndWrite (IAsyncResult asyncResult);
230
231 #if SECURITY_DEP
232                 MSI.MonoTlsProvider Provider {
233                         get;
234                 }
235
236                 MSI.MonoTlsConnectionInfo GetConnectionInfo ();
237 #endif
238         }
239 }