2 // MonoDefaultTlsProvider.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
29 using System.Net.Security;
30 using System.Security.Authentication;
31 using System.Security.Cryptography.X509Certificates;
32 using Mono.Security.Interface;
34 namespace Mono.Security.Providers.DotNet
37 * This provider only uses the public .NET APIs from System.dll.
39 * It is primarily intended for testing.
41 public class DotNetTlsProvider : MonoTlsProvider
43 static readonly Guid id = new Guid ("3a7b3a26-0dbd-4572-a5b8-fdce766bf0dd");
45 public override Guid ID {
49 public override string Name {
50 get { return "dotnet"; }
53 public override bool SupportsSslStream {
57 public override bool SupportsConnectionInfo {
61 public override bool SupportsMonoExtensions {
65 internal override bool SupportsTlsContext {
69 public override SslProtocols SupportedProtocols {
70 get { return (SslProtocols)ServicePointManager.SecurityProtocol; }
73 public override IMonoSslStream CreateSslStream (
74 Stream innerStream, bool leaveInnerStreamOpen,
75 MonoTlsSettings settings = null)
78 throw new NotSupportedException ("Mono-specific API Extensions not available.");
80 RemoteCertificateValidationCallback validation_callback = null;
81 LocalCertificateSelectionCallback selection_callback = null;
83 if (settings != null) {
84 validation_callback = ConvertCallback (settings.RemoteCertificateValidationCallback);
85 selection_callback = ConvertCallback (settings.ClientCertificateSelectionCallback);
88 return new DotNetSslStreamImpl (innerStream, leaveInnerStreamOpen, this, validation_callback, selection_callback);
91 internal override IMonoTlsContext CreateTlsContext (
92 string hostname, bool serverMode, TlsProtocols protocolFlags,
93 X509Certificate serverCertificate, X509CertificateCollection clientCertificates,
94 bool remoteCertRequired, MonoEncryptionPolicy encryptionPolicy,
95 MonoTlsSettings settings)
97 throw new NotSupportedException ();
100 internal static RemoteCertificateValidationCallback ConvertCallback (MonoRemoteCertificateValidationCallback callback)
102 if (callback == null)
105 return (s, c, ch, e) => callback (null, c, ch, (MonoSslPolicyErrors)e);
108 internal static LocalCertificateSelectionCallback ConvertCallback (MonoLocalCertificateSelectionCallback callback)
110 if (callback == null)
113 return (s, t, lc, rc, ai) => callback (t, lc, rc, ai);