Example #1
0
        private static X509Certificate2 KeychainCertificateFromThumbprint(string thumbprint, bool validOnly)
        {
            X509Certificate2 resultCert = null;

            using (SafeKeychainHandle handle = SafeKeychainHandle.Open(CertificateManager.OSXCustomKeychainFilePath, CertificateManager.OSXCustomKeychainPassword))
            {
                using (X509Store store = new X509Store(handle.DangerousGetHandle()))
                {
                    resultCert = CertificateFromThumbprint(store, thumbprint, validOnly);
                }
            }

            return(resultCert);
        }
Example #2
0
        // Install the certificate into a custom keychain on OSX. The TrustedPeople store isn't supported
        // on OSX but a similar mechanism can be achieved by creating a custom keychain and using it in
        // the same way as the TrustedPeople store.
        // It will not install the certificate if it is already present in the store.
        // It returns the thumbprint of the certificate, regardless whether it was added or found.
        public static X509Certificate2 InstallCertificateToOSXKeychainStore(X509Certificate2 certificate)
        {
            SafeKeychainHandle keychain;

            if (!File.Exists(OSXCustomKeychainFilePath))
            {
                keychain = SafeKeychainHandle.Create(OSXCustomKeychainFilePath, OSXCustomKeychainPassword);
            }
            else
            {
                keychain = SafeKeychainHandle.Open(OSXCustomKeychainFilePath, OSXCustomKeychainPassword);
            }

            certificate = AddToOSXKeyChainIfNeeded(keychain, certificate);

            return(certificate);
        }