2 // MonoTlsProviderFactory.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
28 using Mono.Net.Security;
29 using System.Security.Cryptography.X509Certificates;
31 namespace Mono.Security.Interface
34 * Public API front-end to System.dll's version.
36 * Keep in sync with System/Mono.Net.Security/MonoTlsProviderFactory.cs.
38 public static class MonoTlsProviderFactory
41 * Returns the currently installed @MonoTlsProvider, falling back to the default one.
43 * This method throws @NotSupportedException if no TLS Provider can be found.
45 public static MonoTlsProvider GetProvider ()
47 return (MonoTlsProvider)NoReflectionHelper.GetProvider ();
51 * Returns the default @MonoTlsProvider.
53 * This method throws @NotSupportedException if no TLS Provider can be found.
55 public static MonoTlsProvider GetDefaultProvider ()
57 return (MonoTlsProvider)NoReflectionHelper.GetDefaultProvider ();
61 * GetProvider() attempts to load and install the default provider and throws on error.
63 * This property checks whether a provider has previously been installed by a call
64 * to either GetProvider() or InstallProvider().
67 public static bool HasProvider {
69 return NoReflectionHelper.HasProvider;
74 * Installs a custom TLS Provider.
76 * May only be called at application startup and will throw
77 * @InvalidOperationException if a provider has already been installed.
79 public static void InstallProvider (MonoTlsProvider provider)
81 NoReflectionHelper.InstallProvider (provider);
85 * Create @HttpWebRequest with the specified @provider (may be null to use the default one).
87 * NOTE: This needs to be written as "System.Uri" to avoid ambiguity with Mono.Security.Uri in the
91 public static HttpWebRequest CreateHttpsRequest (System.Uri requestUri, MonoTlsProvider provider, MonoTlsSettings settings = null)
93 return NoReflectionHelper.CreateHttpsRequest (requestUri, provider, settings);
96 public static HttpListener CreateHttpListener (X509Certificate certificate, MonoTlsProvider provider = null, MonoTlsSettings settings = null)
98 return (HttpListener)NoReflectionHelper.CreateHttpListener (certificate, provider, settings);