Exemplo n.º 1
0
        public static IStorePal FromSystemStore(string storeName, StoreLocation storeLocation, OpenFlags openFlags)
        {
            StringComparer ordinalIgnoreCase = StringComparer.OrdinalIgnoreCase;

            if (ordinalIgnoreCase.Equals("Root", storeName))
            {
                throw new CryptographicException(
                          SR.Cryptography_X509_StoreNotFound,
                          new PlatformNotSupportedException(SR.Cryptography_X509_Store_RootUnsupported));
            }

            if (storeLocation == StoreLocation.CurrentUser)
            {
                if (ordinalIgnoreCase.Equals("My", storeName))
                {
                    return(AppleKeychainStore.OpenDefaultKeychain(openFlags));
                }
                if (ordinalIgnoreCase.Equals("Disallowed", storeName))
                {
                    return(new UnsupportedDisallowedStore(openFlags));
                }
            }

            if ((openFlags & OpenFlags.OpenExistingOnly) == OpenFlags.OpenExistingOnly)
            {
                throw new CryptographicException(SR.Cryptography_X509_StoreNotFound);
            }

            string message = SR.Format(
                SR.Cryptography_X509_StoreCannotCreate,
                storeName,
                storeLocation);

            throw new CryptographicException(message, new PlatformNotSupportedException(message));
        }
Exemplo n.º 2
0
        public static IStorePal FromSystemStore(string storeName, StoreLocation storeLocation, OpenFlags openFlags)
        {
            StringComparer ordinalIgnoreCase = StringComparer.OrdinalIgnoreCase;

            switch (storeLocation)
            {
            case StoreLocation.CurrentUser:
                if (ordinalIgnoreCase.Equals("My", storeName))
                {
                    return(AppleKeychainStore.OpenDefaultKeychain(openFlags));
                }
                if (ordinalIgnoreCase.Equals("Root", storeName))
                {
                    return(AppleTrustStore.OpenStore(StoreName.Root, storeLocation, openFlags));
                }
                if (ordinalIgnoreCase.Equals("Disallowed", storeName))
                {
                    return(AppleTrustStore.OpenStore(StoreName.Disallowed, storeLocation, openFlags));
                }

                break;

            case StoreLocation.LocalMachine:
                if (ordinalIgnoreCase.Equals("My", storeName))
                {
                    return(AppleKeychainStore.OpenSystemSharedKeychain(openFlags));
                }
                if (ordinalIgnoreCase.Equals("Root", storeName))
                {
                    return(AppleTrustStore.OpenStore(StoreName.Root, storeLocation, openFlags));
                }
                if (ordinalIgnoreCase.Equals("Disallowed", storeName))
                {
                    return(AppleTrustStore.OpenStore(StoreName.Disallowed, storeLocation, openFlags));
                }
                break;
            }

            if ((openFlags & OpenFlags.OpenExistingOnly) == OpenFlags.OpenExistingOnly)
            {
                throw new CryptographicException(SR.Cryptography_X509_StoreNotFound);
            }

            string message = SR.Format(
                SR.Cryptography_X509_StoreCannotCreate,
                storeName,
                storeLocation);

            throw new CryptographicException(message, new PlatformNotSupportedException(message));
        }