2 // MonoTlsProviderImpl.cs
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 extern alias PrebuiltSystem;
32 #if MONO_SECURITY_ALIAS
33 extern alias MonoSecurity;
36 #if MONO_SECURITY_ALIAS
37 using MSI = MonoSecurity::Mono.Security.Interface;
39 using MSI = Mono.Security.Interface;
42 using XHttpWebRequest = PrebuiltSystem::System.Net.HttpWebRequest;
43 using XX509CertificateCollection = PrebuiltSystem::System.Security.Cryptography.X509Certificates.X509CertificateCollection;
45 using XHttpWebRequest = System.Net.HttpWebRequest;
46 using XX509CertificateCollection = System.Security.Cryptography.X509Certificates.X509CertificateCollection;
52 using System.Net.Security;
53 using System.Security.Cryptography.X509Certificates;
55 namespace Mono.Net.Security.Private
58 * Strictly private - do not use outside the Mono.Net.Security directory.
60 abstract class MonoTlsProviderImpl : MSI.MonoTlsProvider, IMonoTlsProvider
62 MSI.MonoTlsProvider IMonoTlsProvider.Provider {
66 IMonoSslStream IMonoTlsProvider.CreateSslStream (
67 Stream innerStream, bool leaveInnerStreamOpen,
68 MSI.MonoTlsSettings settings)
70 return CreateSslStreamImpl (innerStream, leaveInnerStreamOpen, settings);
73 protected abstract IMonoSslStream CreateSslStreamImpl (
74 Stream innerStream, bool leaveInnerStreamOpen,
75 MSI.MonoTlsSettings settings);
77 public override MSI.IMonoSslStream CreateSslStream (
78 Stream innerStream, bool leaveInnerStreamOpen,
79 MSI.MonoTlsSettings settings = null)
81 var sslStream = CreateSslStreamImpl (innerStream, leaveInnerStreamOpen, settings);
82 return new MonoSslStreamImpl (sslStream);
85 MSI.IMonoTlsContext IMonoTlsProvider.CreateTlsContext (
86 string hostname, bool serverMode, MSI.TlsProtocols protocolFlags,
87 X509Certificate serverCertificate, XX509CertificateCollection clientCertificates,
88 bool remoteCertRequired, bool checkCertName, bool checkCertRevocationStatus,
89 MSI.MonoEncryptionPolicy encryptionPolicy, MSI.MonoTlsSettings settings)
91 return CreateTlsContextImpl (
92 hostname, serverMode, protocolFlags,
93 serverCertificate, (X509CertificateCollection)(object)clientCertificates,
94 remoteCertRequired, encryptionPolicy, settings);
97 protected abstract MSI.IMonoTlsContext CreateTlsContextImpl (
98 string hostname, bool serverMode, MSI.TlsProtocols protocolFlags,
99 X509Certificate serverCertificate, X509CertificateCollection clientCertificates,
100 bool remoteCertRequired, MSI.MonoEncryptionPolicy encryptionPolicy,
101 MSI.MonoTlsSettings settings);
103 public override MSI.IMonoTlsContext CreateTlsContext (
104 string hostname, bool serverMode, MSI.TlsProtocols protocolFlags,
105 X509Certificate serverCertificate, XX509CertificateCollection clientCertificates,
106 bool remoteCertRequired, MSI.MonoEncryptionPolicy encryptionPolicy,
107 MSI.MonoTlsSettings settings)
109 return CreateTlsContextImpl (
110 hostname, serverMode, (MSI.TlsProtocols)protocolFlags,
111 serverCertificate, (X509CertificateCollection)(object)clientCertificates,
112 remoteCertRequired, (MSI.MonoEncryptionPolicy)encryptionPolicy,