diff options
author | Martin Baulig <mabaul@microsoft.com> | 2017-04-14 21:50:36 +0300 |
---|---|---|
committer | Martin Baulig <mabaul@microsoft.com> | 2017-04-14 21:51:13 +0300 |
commit | c496d42bc004905fccee28002f43184f682cc4c4 (patch) | |
tree | 087e750fb573084f4df5cef52d4ab8d1075a2814 /mcs | |
parent | 9051fff9d88da29435b4b0faa1815f404564a941 (diff) |
[appletls]: Disable the new keychain code on XI. (#4695)
(cherry picked from commit b6255d35cd224bc2ed63e52689fc336c31e63a34)
Diffstat (limited to 'mcs')
-rw-r--r-- | mcs/class/System/Mono.AppleTls/Certificate.cs | 39 | ||||
-rw-r--r-- | mcs/class/System/Mono.AppleTls/Items.cs | 8 |
2 files changed, 37 insertions, 10 deletions
diff --git a/mcs/class/System/Mono.AppleTls/Certificate.cs b/mcs/class/System/Mono.AppleTls/Certificate.cs index c02c766c560..1bcf1b2937c 100644 --- a/mcs/class/System/Mono.AppleTls/Certificate.cs +++ b/mcs/class/System/Mono.AppleTls/Certificate.cs @@ -245,29 +245,46 @@ namespace Mono.AppleTls { } } - static CFDictionary CreateImportOptions (CFString password, SecKeyChain keychain, SecAccess access) + internal class ImportOptions { +#if !MONOTOUCH + public SecAccess Access { + get; set; + } + public SecKeyChain KeyChain { + get; set; + } +#endif + } + + static CFDictionary CreateImportOptions (CFString password, ImportOptions options = null) + { + if (options == null) + return CFDictionary.FromObjectAndKey (password.Handle, ImportExportPassphase.Handle); + var items = new List<Tuple<IntPtr, IntPtr>> (); items.Add (new Tuple<IntPtr, IntPtr> (ImportExportPassphase.Handle, password.Handle)); - if (keychain != null) - items.Add (new Tuple<IntPtr, IntPtr> (ImportExportKeychain.Handle, keychain.Handle)); - if (access != null) - items.Add (new Tuple<IntPtr, IntPtr> (ImportExportAccess.Handle, access.Handle)); +#if !MONOTOUCH + if (options.KeyChain != null) + items.Add (new Tuple<IntPtr, IntPtr> (ImportExportKeychain.Handle, options.KeyChain.Handle)); + if (options.Access != null) + items.Add (new Tuple<IntPtr, IntPtr> (ImportExportAccess.Handle, options.Access.Handle)); +#endif return CFDictionary.FromKeysAndObjects (items); } - public static SecIdentity Import (byte[] data, string password, SecKeyChain keychain = null, SecAccess access = null) + public static SecIdentity Import (byte[] data, string password, ImportOptions options = null) { if (data == null) throw new ArgumentNullException ("data"); if (string.IsNullOrEmpty (password)) // SecPKCS12Import() doesn't allow empty passwords. throw new ArgumentException ("password"); using (var pwstring = CFString.Create (password)) - using (var options = CreateImportOptions (pwstring, keychain, access)) { + using (var optionDict = CreateImportOptions (pwstring, options)) { CFDictionary [] array; - SecStatusCode result = SecImportExport.ImportPkcs12 (data, options, out array); + SecStatusCode result = SecImportExport.ImportPkcs12 (data, optionDict, out array); if (result != SecStatusCode.Success) throw new InvalidOperationException (result.ToString ()); @@ -275,7 +292,7 @@ namespace Mono.AppleTls { } } - public static SecIdentity Import (X509Certificate2 certificate, SecKeyChain keychain = null, SecAccess access = null) + public static SecIdentity Import (X509Certificate2 certificate, ImportOptions options = null) { if (certificate == null) throw new ArgumentNullException ("certificate"); @@ -288,7 +305,7 @@ namespace Mono.AppleTls { */ var password = Guid.NewGuid ().ToString (); var pkcs12 = certificate.Export (X509ContentType.Pfx, password); - return Import (pkcs12, password, keychain, access); + return Import (pkcs12, password, options); } ~SecIdentity () @@ -371,6 +388,7 @@ namespace Mono.AppleTls { } } +#if !MONOTOUCH class SecAccess : INativeObject, IDisposable { internal IntPtr handle; @@ -427,5 +445,6 @@ namespace Mono.AppleTls { } } } +#endif } #endif diff --git a/mcs/class/System/Mono.AppleTls/Items.cs b/mcs/class/System/Mono.AppleTls/Items.cs index 3eab7cc36f6..cb37e48e07e 100644 --- a/mcs/class/System/Mono.AppleTls/Items.cs +++ b/mcs/class/System/Mono.AppleTls/Items.cs @@ -44,11 +44,16 @@ namespace Mono.AppleTls { Certificate } +#if MONOTOUCH + static class SecKeyChain { +#else class SecKeyChain : INativeObject, IDisposable { +#endif internal static readonly IntPtr MatchLimitAll; internal static readonly IntPtr MatchLimitOne; internal static readonly IntPtr MatchLimit; +#if !MONOTOUCH IntPtr handle; internal SecKeyChain (IntPtr handle, bool owns = false) @@ -60,6 +65,7 @@ namespace Mono.AppleTls { if (!owns) CFObject.CFRetain (handle); } +#endif static SecKeyChain () { @@ -168,6 +174,7 @@ namespace Mono.AppleTls { return n; } +#if !MONOTOUCH [DllImport (AppleTlsContext.SecurityLibrary)] extern static /* OSStatus */ SecStatusCode SecKeychainCreate (/* const char * */ IntPtr pathName, uint passwordLength, /* const void * */ IntPtr password, bool promptUser, /* SecAccessRef */ IntPtr initialAccess, @@ -232,6 +239,7 @@ namespace Mono.AppleTls { handle = IntPtr.Zero; } } +#endif } class SecRecord : IDisposable { |