diff options
author | Martin Baulig <martin.baulig@xamarin.com> | 2016-04-08 15:18:46 +0300 |
---|---|---|
committer | Martin Baulig <martin.baulig@xamarin.com> | 2016-04-08 16:42:51 +0300 |
commit | 5eaf4db0918f4e59c47b22e6379236a55f6c813e (patch) | |
tree | 33eff9190f35109c1af6afd93324c88acc2372d3 | |
parent | 0977d531d2579c9051a6a2e6d0cb47e4f720bea4 (diff) |
[corlib]: Add internal callback to 'X509Helper' to use System's X509Helper2.
6 files changed, 77 insertions, 3 deletions
diff --git a/mcs/class/System/Mono.Net.Security/MonoTlsProviderFactory.cs b/mcs/class/System/Mono.Net.Security/MonoTlsProviderFactory.cs index 6731978c6f0..c4b17abcd0e 100644 --- a/mcs/class/System/Mono.Net.Security/MonoTlsProviderFactory.cs +++ b/mcs/class/System/Mono.Net.Security/MonoTlsProviderFactory.cs @@ -175,6 +175,7 @@ namespace Mono.Net.Security providerRegistration.Add ("newtls", "Mono.Security.Providers.NewTls.NewTlsProvider, Mono.Security.Providers.NewTls, Version=4.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756"); providerRegistration.Add ("oldtls", "Mono.Security.Providers.OldTls.OldTlsProvider, Mono.Security.Providers.OldTls, Version=4.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756"); providerRegistration.Add ("boringtls", "Xamarin.BoringTls.BoringTlsProvider, Xamarin.BoringTls, Version=4.0.0.0, Culture=neutral, PublicKeyToken=672c06b0b8f05406"); + X509Helper2.Initialize (); } } diff --git a/mcs/class/System/System.Security.Cryptography.X509Certificates/X509Helper2.cs b/mcs/class/System/System.Security.Cryptography.X509Certificates/X509Helper2.cs index 25d9fdf0d4a..ffd54a737b9 100644 --- a/mcs/class/System/System.Security.Cryptography.X509Certificates/X509Helper2.cs +++ b/mcs/class/System/System.Security.Cryptography.X509Certificates/X509Helper2.cs @@ -44,6 +44,11 @@ namespace System.Security.Cryptography.X509Certificates { internal static class X509Helper2 { + internal static void Initialize () + { + X509Helper.InstallNativeHelper (new MyNativeHelper ()); + } + internal static void ThrowIfContextInvalid (X509CertificateImpl impl) { X509Helper.ThrowIfContextInvalid (impl); @@ -95,6 +100,20 @@ namespace System.Security.Cryptography.X509Certificates { return new CryptographicException (Locale.GetText ("Chain instance is empty.")); } + + class MyNativeHelper : INativeCertificateHelper + { + public X509CertificateImpl Import ( + byte[] data, string password, X509KeyStorageFlags flags) + { + return X509Helper2.Import (data, password, flags); + } + + public X509CertificateImpl Import (X509Certificate cert) + { + return X509Helper2.Import (cert); + } + } } } #endif diff --git a/mcs/class/corlib/System.Security.Cryptography.X509Certificates/INativeCertificateHelper.cs b/mcs/class/corlib/System.Security.Cryptography.X509Certificates/INativeCertificateHelper.cs new file mode 100644 index 00000000000..2d56ac1564f --- /dev/null +++ b/mcs/class/corlib/System.Security.Cryptography.X509Certificates/INativeCertificateHelper.cs @@ -0,0 +1,35 @@ +// +// INativeCertificateHelper.cs +// +// Author: +// Martin Baulig <martin.baulig@xamarin.com> +// +// Copyright (c) 2016 Xamarin, Inc. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +namespace System.Security.Cryptography.X509Certificates +{ + internal interface INativeCertificateHelper + { + X509CertificateImpl Import (byte[] data, string password, X509KeyStorageFlags flags); + + X509CertificateImpl Import (X509Certificate cert); + } +} diff --git a/mcs/class/corlib/System.Security.Cryptography.X509Certificates/X509Certificate.cs b/mcs/class/corlib/System.Security.Cryptography.X509Certificates/X509Certificate.cs index 3ff0a2adead..135b270e508 100644 --- a/mcs/class/corlib/System.Security.Cryptography.X509Certificates/X509Certificate.cs +++ b/mcs/class/corlib/System.Security.Cryptography.X509Certificates/X509Certificate.cs @@ -122,9 +122,7 @@ namespace System.Security.Cryptography.X509Certificates { if (cert == null) throw new ArgumentNullException ("cert"); - X509Helper.ThrowIfContextInvalid (cert.impl); - - impl = X509Helper.InitFromCertificate (cert.impl); + impl = X509Helper.InitFromCertificate (cert); hideDates = false; } diff --git a/mcs/class/corlib/System.Security.Cryptography.X509Certificates/X509Helper.cs b/mcs/class/corlib/System.Security.Cryptography.X509Certificates/X509Helper.cs index dc73f5ad79d..1f3f1f83d1f 100644 --- a/mcs/class/corlib/System.Security.Cryptography.X509Certificates/X509Helper.cs +++ b/mcs/class/corlib/System.Security.Cryptography.X509Certificates/X509Helper.cs @@ -30,6 +30,7 @@ // using System; using System.Text; +using System.Threading; using System.Runtime.InteropServices; #if !NET_2_1 using System.Security.Permissions; @@ -40,6 +41,14 @@ namespace System.Security.Cryptography.X509Certificates { static partial class X509Helper { + static INativeCertificateHelper nativeHelper; + + internal static void InstallNativeHelper (INativeCertificateHelper helper) + { + if (nativeHelper == null) + Interlocked.CompareExchange (ref nativeHelper, helper, null); + } + #if !NET_2_1 // typedef struct _CERT_CONTEXT { // DWORD dwCertEncodingType; @@ -77,6 +86,14 @@ namespace System.Security.Cryptography.X509Certificates } #endif + public static X509CertificateImpl InitFromCertificate (X509Certificate cert) + { + if (nativeHelper != null) + return nativeHelper.Import (cert); + + return InitFromCertificate (cert.Impl); + } + public static X509CertificateImpl InitFromCertificate (X509CertificateImpl impl) { ThrowIfContextInvalid (impl); @@ -134,6 +151,9 @@ namespace System.Security.Cryptography.X509Certificates #if !MONOTOUCH && !XAMMAC public static X509CertificateImpl Import (byte[] rawData, string password, X509KeyStorageFlags keyStorageFlags) { + if (nativeHelper != null) + return nativeHelper.Import (rawData, password, keyStorageFlags); + MX.X509Certificate x509; if (password == null) { try { diff --git a/mcs/class/corlib/corlib.dll.sources b/mcs/class/corlib/corlib.dll.sources index 1e2b74926ef..cb79dfd78f2 100644 --- a/mcs/class/corlib/corlib.dll.sources +++ b/mcs/class/corlib/corlib.dll.sources @@ -732,6 +732,7 @@ System.Security.Cryptography/RSAPKCS1SignatureDeformatter.cs System.Security.Cryptography/RSAPKCS1SignatureFormatter.cs System.Security.Cryptography/SHA1CryptoServiceProvider.cs System.Security.Cryptography/TripleDESCryptoServiceProvider.cs +System.Security.Cryptography.X509Certificates/INativeCertificateHelper.cs System.Security.Cryptography.X509Certificates/X509Certificate.cs System.Security.Cryptography.X509Certificates/X509Certificate20.cs System.Security.Cryptography.X509Certificates/X509CertificateImpl.cs |