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 using System.Net.Security;
31 using System.Security.Authentication;
32 using System.Security.Cryptography.X509Certificates;
33 using Mono.Security.Protocol.Tls;
35 namespace Mono.Security.Interface
38 * Unfortunately, we can't use the public definitions from System.dll here, so we need to
41 * The @MonoRemoteCertificateValidationCallback also has an additional 'targetHost' argument.
46 public enum MonoSslPolicyErrors
49 RemoteCertificateNotAvailable = 1,
50 RemoteCertificateNameMismatch = 2,
51 RemoteCertificateChainErrors = 4,
54 public enum MonoEncryptionPolicy
56 // Prohibit null ciphers (current system defaults)
57 RequireEncryption = 0,
59 // Add null ciphers to current system defaults
62 // Request null ciphers only
66 public delegate bool MonoRemoteCertificateValidationCallback (
67 string targetHost, X509Certificate certificate, X509Chain chain, MonoSslPolicyErrors sslPolicyErrors);
69 public delegate X509Certificate MonoLocalCertificateSelectionCallback (
70 string targetHost, X509CertificateCollection localCertificates, X509Certificate remoteCertificate,
71 string[] acceptableIssuers);
73 public abstract class MonoTlsProvider
78 * This section abstracts the @SslStream class.
82 public abstract bool SupportsSslStream {
87 * Whether or not this TLS Provider supports Mono-specific extensions
88 * (via @MonoTlsSettings).
90 public abstract bool SupportsMonoExtensions {
94 public abstract SslProtocols SupportedProtocols {
99 * Obtain a @MonoSslStream instance.
102 public abstract MonoSslStream CreateSslStream (
103 Stream innerStream, bool leaveInnerStreamOpen,
104 MonoTlsSettings settings = null);
108 #region Certificate Validation
111 * Allows a TLS provider to provide a custom system certificiate validator.
113 public virtual bool HasCustomSystemCertificateValidator {
114 get { return false; }
118 * If @serverMode is true, then we're a server and want to validate a certificate
119 * that we received from a client.
121 * On OS X and Mobile, the @chain will be initialized with the @certificates, but not actually built.
123 * Returns `true` if certificate validation has been performed and `false` to invoke the
124 * default system validator.
126 public virtual bool InvokeSystemCertificateValidator (
127 ICertificateValidator validator, string targetHost, bool serverMode,
128 X509CertificateCollection certificates, X509Chain chain, out bool success,
129 ref MonoSslPolicyErrors errors, ref int status11)
140 * The managed SSPI implementation from the new TLS code.
143 public abstract bool SupportsTlsContext {
147 public abstract IMonoTlsContext CreateTlsContext (
148 string hostname, bool serverMode, TlsProtocols protocolFlags,
149 X509Certificate serverCertificate, X509CertificateCollection clientCertificates,
150 bool remoteCertRequired, MonoEncryptionPolicy encryptionPolicy,
151 MonoTlsSettings settings);