[mono/monodevelop] ce69a461: [MacPlatform] code cleanup

"Jeffrey Stedfast ([email protected])" <[email protected]>
Newsgroups gmane.comp.gnome.mono.patches
Message-ID <0000014214b41efb-04de38d1-d652-47c5-b15d-c64ddd61a0c9-000000@email.amazonses.com>
   Branch: refs/heads/master
     Home: https://github.com/mono/monodevelop
  Compare: https://github.com/mono/monodevelop/compare/7a168760cb85...ce69a4617277

   Commit: ce69a461727725626db176aa9312195a97d1bf88
   Author: Jeffrey Stedfast <[email protected]> (jstedfast)
     Date: 2013-11-01 17:25:32 GMT
      URL: https://github.com/mono/monodevelop/commit/ce69a461727725626db176aa9312195a97d1bf88

[MacPlatform] code cleanup

Changed paths:
  M main/src/addins/MacPlatform/MacInterop/Keychain.cs

Modified: main/src/addins/MacPlatform/MacInterop/Keychain.cs
===================================================================
@@ -40,47 +40,9 @@ public static class Keychain
 	{
 		const string CoreFoundationLib = "/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation";
 		const string SecurityLib = "/System/Library/Frameworks/Security.framework/Security";
-//		const string SystemLib = "/usr/lib/libSystem.dylib";
 
 		internal static IntPtr CurrentKeychain = IntPtr.Zero;
 
-//		static IntPtr kCFTypeDictionaryValueCallbacks;
-//		static IntPtr kCFTypeDictionaryKeyCallbacks;
-//
-//		static IntPtr kSecReturnAttributes;
-//		static IntPtr kSecMatchLimitAll;
-//		static IntPtr kSecMatchLimit;
-//		static IntPtr kSecClass;
-//
-//		static IntPtr kCFBooleanFalse;
-//		static IntPtr kCFBooleanTrue;
-//
-//		static Keychain ()
-//		{
-//			var lib = dlopen (CoreFoundationLib, 0);
-//			try {
-//				kCFTypeDictionaryValueCallbacks = dlsym (lib, "kCFTypeDictionaryValueCallBacks");
-//				kCFTypeDictionaryKeyCallbacks = dlsym (lib, "kCFTypeDictionaryKeyCallBacks");
-//				kCFBooleanFalse = dlsym (lib, "kCFBooleanFalse");
-//				kCFBooleanTrue = dlsym (lib, "kCFBooleanTrue");
-//			} finally {
-//				dlclose (lib);
-//			}
-//		}
-//
-//		#region Dynamic Symbol Loading
-//
-//		[DllImport (SystemLib)]
-//		static extern IntPtr dlsym (IntPtr handle, string symbol);
-//
-//		[DllImport (SystemLib)]
-//		static extern IntPtr dlopen (string path, int mode);
-//
-//		[DllImport (SystemLib)]
-//		static extern int dlclose (IntPtr handle);
-//
-//		#endregion
-
 		[DllImport (CoreFoundationLib, EntryPoint="CFRelease")]
 		static extern void CFReleaseInternal (IntPtr cfRef);
 
@@ -90,42 +52,6 @@ static void CFRelease (IntPtr cfRef)
 				CFReleaseInternal (cfRef);
 		}
 
-		#region Managing Certificates
-
-		[DllImport (SecurityLib)]
-		static extern OSStatus SecCertificateAddToKeychain (IntPtr certificate, IntPtr keychain);
-
-		[DllImport (SecurityLib)]
-		static extern IntPtr SecCertificateCreateWithData (IntPtr allocator, IntPtr data);
-
-		[DllImport (SecurityLib)]
-		static extern IntPtr SecCertificateCopyData (IntPtr certificate);
-
-		[DllImport (SecurityLib)]
-		static extern OSStatus SecCertificateCopyCommonName (IntPtr certificate, out IntPtr commonName);
-
-		#endregion
-
-		#region Managing Identities
-
-		[DllImport (SecurityLib)]
-		static extern OSStatus SecIdentityCopyCertificate (IntPtr identityRef, out IntPtr certificateRef);
-
-		// WARNING: deprecated in Mac OS X 10.7
-		[DllImport (SecurityLib)]
-		static extern OSStatus SecIdentitySearchCreate (IntPtr keychainOrArray, CssmKeyUse keyUsage, out IntPtr searchRef);
-
-		// WARNING: deprecated in Mac OS X 10.7
-		[DllImport (SecurityLib)]
-		static extern OSStatus SecIdentitySearchCopyNext (IntPtr searchRef, out IntPtr identity);
-
-		// Note: SecIdentitySearch* has been replaced with SecItemCopyMatching
-
-		//[DllImport (SecurityLib)]
-		//OSStatus SecItemCopyMatching (CFDictionaryRef query, CFTypeRef *result);
-
-		#endregion
-
 		#region Getting Information About Security Result Codes
 
 		[DllImport (SecurityLib)]
@@ -388,198 +314,6 @@ static string GetError (OSStatus status)
 			}
 		}
 
-		[Obsolete ("What purpose does this really serve?")]
-		public static unsafe IList<string> GetAllCertificateNames ()
-		{
-			IntPtr searchRef, itemRef;
-			OSStatus status;
-
-			status = SecKeychainSearchCreateFromAttributes (CurrentKeychain, SecItemClass.Certificate, null, out searchRef);
-			if (status != OSStatus.Ok)
-				throw new Exception ("Could not enumerate certificates from the keychain. Error:\n" + GetError (status));
-
-			var names = new HashSet<string> ();
-
-			while ((status = SecKeychainSearchCopyNext (searchRef, out itemRef)) == OSStatus.Ok) {
-				IntPtr commonName;
-
-				if (SecCertificateCopyCommonName (itemRef, out commonName) == OSStatus.Ok) {
-					names.Add (CFStringGetString (commonName));
-					CFRelease (commonName);
-				}
-
-				CFRelease (itemRef);
-			}
-
-			if (status != OSStatus.ItemNotFound)
-				LoggingService.LogWarning ("Unexpected error retrieving certificates from keychain:\n" + GetError (status));
-
-			CFRelease (searchRef);
-
-			return names.ToList ();
-		}
-		
-		public static IList<string> GetAllSigningIdentities ()
-		{
-			IntPtr searchRef, itemRef, certRef, commonName;
-			OSStatus status;
-
-			status = SecIdentitySearchCreate (CurrentKeychain, CssmKeyUse.Sign, out searchRef);
-			if (status != OSStatus.Ok)
-				throw new Exception ("Could not enumerate signing identities from the keychain. Error:\n" + GetError (status));
-			
-			var identities = new HashSet<string> ();
-
-			while ((status = SecIdentitySearchCopyNext (searchRef, out itemRef)) == OSStatus.Ok) {
-				if (SecIdentityCopyCertificate (itemRef, out certRef) == OSStatus.Ok) {
-					if (SecCertificateCopyCommonName (certRef, out commonName) == OSStatus.Ok) {
-						string name = CFStringGetString (commonName);
-						if (name != null)
-							identities.Add (name);
-
-						CFRelease (commonName);
-					}
-
-					CFRelease (certRef);
-				}
-
-				CFRelease (itemRef);
-			}
-
-			if (status != OSStatus.ItemNotFound)
-				LoggingService.LogWarning ("Unexpected error retrieving identities from keychain:\n" + GetError (status));
-			
-			CFRelease (searchRef);
-
-			return identities.ToList ();
-		}
-		
-		public static IEnumerable<X509Certificate2> FindNamedSigningCertificates (Func<string,bool> nameCheck)
-		{
-			return GetAllSigningCertificates ().Where (x => {
-				var y = GetCertificateCommonName (x);
-				return !string.IsNullOrEmpty (y) && nameCheck (y);
-			});
-		}
-		
-		public static IList<X509Certificate2> GetAllSigningCertificates ()
-		{
-			IntPtr searchRef, itemRef, certRef;
-			OSStatus status;
-
-			status = SecIdentitySearchCreate (CurrentKeychain, CssmKeyUse.Sign, out searchRef);
-			if (status != OSStatus.Ok)
-				throw new Exception ("Could not enumerate signing certificates from the keychain. Error:\n" + GetError (status));
-			
-			var certs = new HashSet<X509Certificate2> ();
-
-			while ((status = SecIdentitySearchCopyNext (searchRef, out itemRef)) == OSStatus.Ok) {
-				if (SecIdentityCopyCertificate (itemRef, out certRef) == OSStatus.Ok) {
-					var data = SecCertificateCopyData (certRef);
-					var rawData = CFDataGetBytes (data);
-
-					if (rawData != null) {
-						try {
-							certs.Add (new X509Certificate2 (rawData));
-						} catch (Exception ex) {
-							LoggingService.LogWarning ("Error loading signing certificate from keychain", ex);
-						}
-					}
-
-					CFRelease (certRef);
-				}
-
-				CFRelease (itemRef);
-			}
-
-			if (status != OSStatus.ItemNotFound)
-				LoggingService.LogWarning ("Unexpected error code retrieving signing certificates from keychain:\n" + GetError (status));
-			
-			CFRelease (searchRef);
-
-			return certs.ToList ();
-		}
-
-		public static void AddCertificate (X509Certificate2 certificate)
-		{
-			if (ContainsCertificate (certificate))
-				return;
-
-			var rawData = certificate.RawData;
-			var certData = CFDataCreate (IntPtr.Zero, rawData, rawData.Length);
-			var cert = SecCertificateCreateWithData (IntPtr.Zero, certData);
-			var status = SecCertificateAddToKeychain (cert, CurrentKeychain);
-
-			CFRelease (certData);
-			CFRelease (cert);
-
-			if (status != OSStatus.Ok)
-				throw new Exception ("Cannot add certificate to keychain: " + GetError (status));
-		}
-
-		public static unsafe bool ContainsCertificate (X509Certificate2 certificate)
-		{
-			// Note: we don't have to use an alias attribute, it's just that it might be faster to use it (fewer certificates we have to compare raw data for)
-			byte[] alias = Encoding.UTF8.GetBytes (GetCertificateCommonName (certificate));
-			IntPtr searchRef, itemRef;
-			bool found = false;
-			byte[] certData;
-			OSStatus status;
-
-			fixed (byte* aliasPtr = alias) {
-				SecKeychainAttribute* attrs = stackalloc SecKeychainAttribute [1];
-				int n = 0;
-
-				if (alias != null)
-					attrs[n++] = new SecKeychainAttribute (SecItemAttr.Alias, (uint) alias.Length, (IntPtr) aliasPtr);
-
-				SecKeychainAttributeList attrList = new SecKeychainAttributeList (n, (IntPtr) attrs);
-
-				status = SecKeychainSearchCreateFromAttributes (CurrentKeychain, SecItemClass.Certificate, &attrList, out searchRef);
-				if (status != OSStatus.Ok)
-					throw new Exception ("Could not enumerate certificates from the keychain. Error:\n" + GetError (status));
-
-				// we cache certificate.RawData to avoid unneccessary duplication (X509Certificate2.RawData clones the byte[] each time)
-				certData = certificate.RawData;
-
-				while (!found && (status = SecKeychainSearchCopyNext (searchRef, out itemRef)) == OSStatus.Ok) {
-					SecItemClass itemClass = 0;
-					IntPtr data = IntPtr.Zero;
-					uint length = 0;
-
-					status = SecKeychainItemCopyContent (itemRef, ref itemClass, IntPtr.Zero, ref length, ref data);
-					if (status == OSStatus.Ok) {
-						if (certData.Length == (int) length) {
-							byte[] rawData = new byte[(int) length];
-
-							Marshal.Copy (data, rawData, 0, (int) length);
-
-							found = true;
-							for (int i = 0; i < rawData.Length; i++) {
-								if (rawData[i] != certData[i]) {
-									found = false;
-									break;
-								}
-							}
-						}
-
-						SecKeychainItemFreeContent (IntPtr.Zero, data);
-					}
-
-					CFRelease (itemRef);
-				}
-
-				CFRelease (searchRef);
-			}
-
-			return found;
-		}
-		
-		public static string GetCertificateCommonName (X509Certificate2 cert)
-		{
-			return cert.GetNameInfo (X509NameType.SimpleName, false);
-		}
-
 		static SecAuthenticationType GetSecAuthenticationType (string query)
 		{
 			if (string.IsNullOrEmpty (query))
@@ -865,175 +599,118 @@ public static string FindInternetPassword (Uri uri)
 
 			return Marshal.PtrToStringAuto (passwordData, (int) passwordLength);
 		}
+	}
 
-		enum SecItemClass : uint
-		{
-			InternetPassword     = 1768842612, // 'inet'
-			GenericPassword      = 1734700656, // 'genp'
-			AppleSharePassword   = 1634953328, // 'ashp'
-			Certificate          = 0x80000000 + 0x1000,
-			PublicKey            = 0x0000000A + 5,
-			PrivateKey           = 0x0000000A + 6,
-			SymmetricKey         = 0x0000000A + 7
-		}
-
-		enum SecItemAttr : int
-		{
-			CreationDate         = 1667522932,
-			ModDate              = 1835295092,
-			Description          = 1684370275,
-			Comment              = 1768123764,
-			Creator              = 1668445298,
-			Type                 = 1954115685,
-			ScriptCode           = 1935897200,
-			Label                = 1818321516,
-			Invisible            = 1768846953,
-			Negative             = 1852139361,
-			CustomIcon           = 1668641641,
-			Account              = 1633903476,
-			Service              = 1937138533,
-			Generic              = 1734700641,
-			SecurityDomain       = 1935961454,
-			Server               = 1936881266,
-			AuthType             = 1635023216,
-			Port                 = 1886351988,
-			Path                 = 1885434984,
-			Volume               = 1986817381,
-			Address              = 1633969266,
-			Signature            = 1936943463,
-			Protocol             = 1886675820,
-			CertificateType      = 1668577648,
-			CertificateEncoding  = 1667591779,
-			CrlType              = 1668445296,
-			CrlEncoding          = 1668443747,
-			Alias                = 1634494835,
-		}
-
-		enum OSStatus
-		{
-			Ok                   = 0,
-			ItemNotFound         = -25300,
-		}
-
-		enum SecKeyAttribute
-		{
-			KeyClass             = 0,
-			PrintName            = 1,
-			Alias                = 2,
-			Permanent            = 3,
-			Private              = 4,
-			Modifiable           = 5,
-			Label                = 6,
-			ApplicationTag       = 7,
-			KeyCreator           = 8,
-			KeyType              = 9,
-			KeySizeInBits        = 10,
-			EffectiveKeySize     = 11,
-			StartDate            = 12,
-			EndDate              = 13,
-			Sensitive            = 14,
-			AlwaysSensitive      = 15,
-			Extractable          = 16,
-			NeverExtractable     = 17,
-			Encrypt              = 18,
-			Decrypt              = 19,
-			Derive               = 20,
-			Sign                 = 21,
-			Verify               = 22,
-			SignRecover          = 23,
-			VerifyRecover        = 24,
-			Wrap                 = 25,
-			Unwrap               = 26,
-		}
+	enum SecItemClass : uint
+	{
+		InternetPassword     = 1768842612, // 'inet'
+		GenericPassword      = 1734700656, // 'genp'
+		AppleSharePassword   = 1634953328, // 'ashp'
+		Certificate          = 0x80000000 + 0x1000,
+		PublicKey            = 0x0000000A + 5,
+		PrivateKey           = 0x0000000A + 6,
+		SymmetricKey         = 0x0000000A + 7
+	}
 
-		enum SecAuthenticationType : int
-		{
-			NTLM                 = 1835824238,
-			MSN                  = 1634628461,
-			DPA                  = 1633775716,
-			RPA                  = 1633775730,
-			HTTPBasic            = 1886680168,
-			HTTPDigest           = 1685353576,
-			HTMLForm             = 1836216166,
-			Default              = 1953261156,
-			Any                  = 0
-		}
+	enum SecItemAttr : int
+	{
+		CreationDate         = 1667522932,
+		ModDate              = 1835295092,
+		Description          = 1684370275,
+		Comment              = 1768123764,
+		Creator              = 1668445298,
+		Type                 = 1954115685,
+		ScriptCode           = 1935897200,
+		Label                = 1818321516,
+		Invisible            = 1768846953,
+		Negative             = 1852139361,
+		CustomIcon           = 1668641641,
+		Account              = 1633903476,
+		Service              = 1937138533,
+		Generic              = 1734700641,
+		SecurityDomain       = 1935961454,
+		Server               = 1936881266,
+		AuthType             = 1635023216,
+		Port                 = 1886351988,
+		Path                 = 1885434984,
+		Volume               = 1986817381,
+		Address              = 1633969266,
+		Signature            = 1936943463,
+		Protocol             = 1886675820,
+		CertificateType      = 1668577648,
+		CertificateEncoding  = 1667591779,
+		CrlType              = 1668445296,
+		CrlEncoding          = 1668443747,
+		Alias                = 1634494835,
+	}
 
-		enum SecProtocolType : int
-		{
-			FTP                  = 1718906912,
-			FTPAccount           = 1718906977,
-			HTTP                 = 1752462448,
-			IRC                  = 1769104160,
-			NNTP                 = 1852732528,
-			POP3                 = 1886351411,
-			SMTP                 = 1936553072,
-			SOCKS                = 1936685088,
-			IMAP                 = 1768776048,
-			LDAP                 = 1818517872,
-			AppleTalk            = 1635019883,
-			AFP                  = 1634103328,
-			Telnet               = 1952803950,
-			SSH                  = 1936943136,
-			FTPS                 = 1718906995,
-			HTTPProxy            = 1752461432,
-			HTTPSProxy           = 1752462200,
-			FTPProxy             = 1718907000,
-			CIFS                 = 1667851891,
-			SMB                  = 1936548384,
-			RTSP                 = 1920234352,
-			RTSPProxy            = 1920234360,
-			DAAP                 = 1684103536,
-			EPPC                 = 1701867619,
-			IPP                  = 1768976416,
-			NNTPS                = 1853124723,
-			LDAPS                = 1818521715,
-			TelnetS              = 1952803955,
-			IMAPS                = 1768779891,
-			IRCS                 = 1769104243,
-			POP3S                = 1886351475,
-			CVSpserver           = 1668707184,
-			SVN                  = 1937141280,
-			Any                  = 0
-		}
+	enum OSStatus
+	{
+		Ok                   = 0,
+		ItemNotFound         = -25300,
+	}
 
-		[Flags]
-		enum CssmKeyUse : uint
-		{
-			Any                  = 0x80000000,
-			Encrypt              = 0x00000001,
-			Decrypt              = 0x00000002,
-			Sign                 = 0x00000004,
-			Verify               = 0x00000008,
-			SignRecover          = 0x00000010,
-			VerifyRecover        = 0x00000020,
-			Wrap                 = 0x00000040,
-			Unwrap               = 0x00000080,
-			Derive               = 0x00000100
-		}
+	enum SecAuthenticationType : int
+	{
+		NTLM                 = 1835824238,
+		MSN                  = 1634628461,
+		DPA                  = 1633775716,
+		RPA                  = 1633775730,
+		HTTPBasic            = 1886680168,
+		HTTPDigest           = 1685353576,
+		HTMLForm             = 1836216166,
+		Default              = 1953261156,
+		Any                  = 0
+	}
 
-		[Flags]
-		enum CssmTPAppleCertStatus : uint
-		{
-			Expired              = 0x00000001,
-			NotValidYet          = 0x00000002,
-			IsInInputCerts       = 0x00000004,
-			IsInAnchors          = 0x00000008,
-			IsRoot               = 0x00000010,
-			IsFromNet            = 0x00000020
-		}
+	enum SecProtocolType : int
+	{
+		FTP                  = 1718906912,
+		FTPAccount           = 1718906977,
+		HTTP                 = 1752462448,
+		IRC                  = 1769104160,
+		NNTP                 = 1852732528,
+		POP3                 = 1886351411,
+		SMTP                 = 1936553072,
+		SOCKS                = 1936685088,
+		IMAP                 = 1768776048,
+		LDAP                 = 1818517872,
+		AppleTalk            = 1635019883,
+		AFP                  = 1634103328,
+		Telnet               = 1952803950,
+		SSH                  = 1936943136,
+		FTPS                 = 1718906995,
+		HTTPProxy            = 1752461432,
+		HTTPSProxy           = 1752462200,
+		FTPProxy             = 1718907000,
+		CIFS                 = 1667851891,
+		SMB                  = 1936548384,
+		RTSP                 = 1920234352,
+		RTSPProxy            = 1920234360,
+		DAAP                 = 1684103536,
+		EPPC                 = 1701867619,
+		IPP                  = 1768976416,
+		NNTPS                = 1853124723,
+		LDAPS                = 1818521715,
+		TelnetS              = 1952803955,
+		IMAPS                = 1768779891,
+		IRCS                 = 1769104243,
+		POP3S                = 1886351475,
+		CVSpserver           = 1668707184,
+		SVN                  = 1937141280,
+		Any                  = 0
+	}
 
-		enum CssmDbAttributeFormat : int
-		{
-			String               = 0,
-			Int32                = 1,
-			UInt32               = 2,
-			BigNum               = 3,
-			Real                 = 4,
-			DateTime             = 5,
-			Blob                 = 6,
-			MultiUInt32          = 7,
-			Complex              = 8
-		}
+	enum CssmDbAttributeFormat : int
+	{
+		String               = 0,
+		Int32                = 1,
+		UInt32               = 2,
+		BigNum               = 3,
+		Real                 = 4,
+		DateTime             = 5,
+		Blob                 = 6,
+		MultiUInt32          = 7,
+		Complex              = 8
 	}
 }


_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.