2 // MonoTlsProviderWrapper.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 * This is used by MonoTlsProviderFactory.InstallProvider() to wrap and masquerade
61 * a user-supplied @MonoTlsProvider as @IMonoTlsProvider.
63 class MonoTlsProviderWrapper : IMonoTlsProvider
65 MSI.MonoTlsProvider provider;
67 public MonoTlsProviderWrapper (MSI.MonoTlsProvider provider)
69 this.provider = provider;
72 public MSI.MonoTlsProvider Provider {
73 get { return provider; }
76 public IMonoSslStream CreateSslStream (
77 Stream innerStream, bool leaveInnerStreamOpen,
78 MSI.MonoTlsSettings settings)
80 var sslStream = provider.CreateSslStream (innerStream, leaveInnerStreamOpen, settings);
81 var monoSslStreamImpl = sslStream as MonoSslStreamImpl;
82 if (monoSslStreamImpl != null)
83 return monoSslStreamImpl.Impl;
84 return new MonoSslStreamWrapper (sslStream);
87 public MSI.IMonoTlsContext CreateTlsContext (
88 string hostname, bool serverMode, MSI.TlsProtocols protocolFlags,
89 X509Certificate serverCertificate, XX509CertificateCollection clientCertificates,
90 bool remoteCertRequired, bool checkCertName, bool checkCertRevocationStatus,
91 MSI.MonoEncryptionPolicy encryptionPolicy, MSI.MonoTlsSettings settings)
93 return provider.CreateTlsContext (
94 hostname, serverMode, protocolFlags,
95 serverCertificate, (XX509CertificateCollection)(object)clientCertificates,
96 remoteCertRequired, (MSI.MonoEncryptionPolicy)encryptionPolicy,