private static O_Flags Translate(OpenFlags flags) { return(Enum .GetValues(typeof(OpenFlags)) .Cast <OpenFlags>() .Where(f => flags.HasFlag(f)) .Aggregate(O_Flags.O_NONE, (acc, f) => acc | TranslateOne(f))); }
private static X509Store Open(Crypt32.CertStoreFlags storeFlags, OpenFlags openFlags, string storeName) { storeFlags |= openFlags.HasFlag(OpenFlags.MaxAllowed) ? Crypt32.CertStoreFlags.CERT_STORE_MAXIMUM_ALLOWED_FLAG : 0; storeFlags |= openFlags.HasFlag(OpenFlags.IncludeArchived) ? Crypt32.CertStoreFlags.CERT_STORE_ENUM_ARCHIVED_FLAG : 0; storeFlags |= openFlags.HasFlag(OpenFlags.OpenExistingOnly) ? Crypt32.CertStoreFlags.CERT_STORE_OPEN_EXISTING_FLAG : 0; storeFlags |= !openFlags.HasFlag(OpenFlags.ReadWrite) ? Crypt32.CertStoreFlags.CERT_STORE_READONLY_FLAG : 0; Crypt32.SafeHCERTSTORE pHandle = Crypt32.CertOpenStore(new Crypt32.SafeOID(10), Crypt32.CertEncodingType.X509_ASN_ENCODING, IntPtr.Zero, storeFlags, storeName); if (pHandle.IsInvalid) { throw new Win32Exception(Marshal.GetLastWin32Error()); } var store = new X509Store(pHandle.DangerousGetHandle()); pHandle.SetHandleAsInvalid(); // The X509Store object will take care of closing the handle return(store); }
public static IStorePal FromSystemStore(string storeName, StoreLocation storeLocation, OpenFlags openFlags) { if (storeLocation != StoreLocation.LocalMachine) { // TODO (#2206): Support CurrentUser persisted stores. throw new NotImplementedException(); } if (openFlags.HasFlag(OpenFlags.ReadWrite)) { // TODO (#2206): Support CurrentUser persisted stores // (they'd not be very useful without the ability to add/remove content) throw new NotImplementedException(); } // The static store approach here is making an optimization based on not // having write support. Once writing is permitted the stores would need // to fresh-read whenever being requested (or use FileWatcher/etc). if (s_machineRootStore == null) { lock (s_machineIntermediateStore) { if (s_machineRootStore == null) { LoadMachineStores(); } } } if (StringComparer.Ordinal.Equals("Root", storeName)) { return(CloneStore(s_machineRootStore)); } if (StringComparer.Ordinal.Equals("CA", storeName)) { return(CloneStore(s_machineIntermediateStore)); } // TODO (#2207): Support the rest of the stores, or throw PlatformNotSupportedException. throw new NotImplementedException(); }
public static IStorePal FromSystemStore(string storeName, StoreLocation storeLocation, OpenFlags openFlags) { if (storeLocation != StoreLocation.LocalMachine) { // TODO (#2206): Support CurrentUser persisted stores. throw new NotImplementedException(); } if (openFlags.HasFlag(OpenFlags.ReadWrite)) { // TODO (#2206): Support CurrentUser persisted stores // (they'd not be very useful without the ability to add/remove content) throw new NotImplementedException(); } // The static store approach here is making an optimization based on not // having write support. Once writing is permitted the stores would need // to fresh-read whenever being requested (or use FileWatcher/etc). if (s_machineRootStore == null) { lock (s_machineIntermediateStore) { if (s_machineRootStore == null) { LoadMachineStores(); } } } if (StringComparer.Ordinal.Equals("Root", storeName)) { return CloneStore(s_machineRootStore); } if (StringComparer.Ordinal.Equals("CA", storeName)) { return CloneStore(s_machineIntermediateStore); } // TODO (#2207): Support the rest of the stores, or throw PlatformNotSupportedException. throw new NotImplementedException(); }
public static IStorePal FromSystemStore(string storeName, StoreLocation storeLocation, OpenFlags openFlags) { if (storeLocation != StoreLocation.LocalMachine) { return(new DirectoryBasedStoreProvider(storeName, openFlags)); } if (openFlags.HasFlag(OpenFlags.ReadWrite)) { throw new PlatformNotSupportedException(SR.Cryptography_Unix_X509_MachineStoresReadOnly); } // The static store approach here is making an optimization based on not // having write support. Once writing is permitted the stores would need // to fresh-read whenever being requested (or use FileWatcher/etc). if (s_machineRootStore == null) { lock (s_machineIntermediateStore) { if (s_machineRootStore == null) { LoadMachineStores(); } } } if (StringComparer.Ordinal.Equals("Root", storeName)) { return(CloneStore(s_machineRootStore)); } if (StringComparer.Ordinal.Equals("CA", storeName)) { return(CloneStore(s_machineIntermediateStore)); } throw new PlatformNotSupportedException(SR.Cryptography_Unix_X509_MachineStoresRootOnly); }
public static IStorePal FromSystemStore(string storeName, StoreLocation storeLocation, OpenFlags openFlags) { if (storeLocation != StoreLocation.LocalMachine) { return new DirectoryBasedStoreProvider(storeName, openFlags); } if (openFlags.HasFlag(OpenFlags.ReadWrite)) { throw new PlatformNotSupportedException(SR.Cryptography_Unix_X509_MachineStoresReadOnly); } // The static store approach here is making an optimization based on not // having write support. Once writing is permitted the stores would need // to fresh-read whenever being requested (or use FileWatcher/etc). if (s_machineRootStore == null) { lock (s_machineIntermediateStore) { if (s_machineRootStore == null) { LoadMachineStores(); } } } if (StringComparer.Ordinal.Equals("Root", storeName)) { return CloneStore(s_machineRootStore); } if (StringComparer.Ordinal.Equals("CA", storeName)) { return CloneStore(s_machineIntermediateStore); } throw new PlatformNotSupportedException(SR.Cryptography_Unix_X509_MachineStoresRootOnly); }
public static AppleKeychainStore CreateOrOpenKeychain(string keychainPath, OpenFlags openFlags) { return(new AppleKeychainStore(Interop.AppleCrypto.CreateOrOpenKeychain(keychainPath, !openFlags.HasFlag(OpenFlags.OpenExistingOnly)), openFlags)); }