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 public override bool SupportsSslStream {
47 public override bool SupportsMonoExtensions {
51 public override bool SupportsTlsContext {
55 public override SslProtocols SupportedProtocols {
56 get { return (SslProtocols)ServicePointManager.SecurityProtocol; }
59 public override MonoSslStream CreateSslStream (
60 Stream innerStream, bool leaveInnerStreamOpen,
61 MonoTlsSettings settings = null)
64 throw new NotSupportedException ("Mono-specific API Extensions not available.");
66 RemoteCertificateValidationCallback validation_callback = null;
67 LocalCertificateSelectionCallback selection_callback = null;
69 if (settings != null) {
70 validation_callback = ConvertCallback (settings.RemoteCertificateValidationCallback);
71 selection_callback = ConvertCallback (settings.ClientCertificateSelectionCallback);
74 return new DotNetSslStreamImpl (innerStream, leaveInnerStreamOpen, validation_callback, selection_callback);
77 public override IMonoTlsContext CreateTlsContext (
78 string hostname, bool serverMode, TlsProtocols protocolFlags,
79 X509Certificate serverCertificate, X509CertificateCollection clientCertificates,
80 bool remoteCertRequired, MonoEncryptionPolicy encryptionPolicy,
81 MonoTlsSettings settings)
83 throw new NotSupportedException ();
86 internal static RemoteCertificateValidationCallback ConvertCallback (MonoRemoteCertificateValidationCallback callback)
91 return (s, c, ch, e) => callback (null, c, ch, (MonoSslPolicyErrors)e);
94 internal static LocalCertificateSelectionCallback ConvertCallback (MonoLocalCertificateSelectionCallback callback)
99 return (s, t, lc, rc, ai) => callback (t, lc, rc, ai);