示例#1
0
        public static IStorePal FromSystemStore(string storeName, StoreLocation storeLocation, OpenFlags openFlags)
        {
            CertStoreFlags certStoreFlags = MapX509StoreFlags(storeLocation, openFlags);

            SafeCertStoreHandle certStore = Interop.crypt32.CertOpenStore(CertStoreProvider.CERT_STORE_PROV_SYSTEM_A, CertEncodingType.All, IntPtr.Zero, certStoreFlags, storeName);

            if (certStore.IsInvalid)
            {
                throw Marshal.GetLastWin32Error().ToCryptographicException();
            }

            //
            // We want the store to auto-resync when requesting a snapshot so that
            // updates to the store will be taken into account.
            //
            // For compat with desktop, ignoring any failures from this call. (It is pretty unlikely to fail, in any case.)
            //
            bool ignore = Interop.crypt32.CertControlStore(certStore, CertControlStoreFlags.None, CertControlStoreType.CERT_STORE_CTRL_AUTO_RESYNC, IntPtr.Zero);

            return(new StorePal(certStore));
        }
示例#2
0
        // this method maps X509Store OpenFlags to a combination of crypto API flags
        private static CertStoreFlags MapX509StoreFlags(StoreLocation storeLocation, OpenFlags flags)
        {
            CertStoreFlags dwFlags  = 0;
            uint           openMode = ((uint)flags) & 0x3;

            switch (openMode)
            {
            case (uint)OpenFlags.ReadOnly:
                dwFlags |= CertStoreFlags.CERT_STORE_READONLY_FLAG;
                break;

            case (uint)OpenFlags.MaxAllowed:
                dwFlags |= CertStoreFlags.CERT_STORE_MAXIMUM_ALLOWED_FLAG;
                break;
            }

            if ((flags & OpenFlags.OpenExistingOnly) == OpenFlags.OpenExistingOnly)
            {
                dwFlags |= CertStoreFlags.CERT_STORE_OPEN_EXISTING_FLAG;
            }
            if ((flags & OpenFlags.IncludeArchived) == OpenFlags.IncludeArchived)
            {
                dwFlags |= CertStoreFlags.CERT_STORE_ENUM_ARCHIVED_FLAG;
            }

            if (storeLocation == StoreLocation.LocalMachine)
            {
                dwFlags |= CertStoreFlags.CERT_SYSTEM_STORE_LOCAL_MACHINE;
            }
            else if (storeLocation == StoreLocation.CurrentUser)
            {
                dwFlags |= CertStoreFlags.CERT_SYSTEM_STORE_CURRENT_USER;
            }

            return(dwFlags);
        }
示例#3
0
 private static partial SafeCertStoreHandle CertOpenStore(IntPtr lpszStoreProvider, CertEncodingType dwMsgAndCertEncodingType, IntPtr hCryptProv, CertStoreFlags dwFlags, [MarshalAs(UnmanagedType.LPWStr)] string?pvPara);
示例#4
0
 public static SafeCertStoreHandle CertOpenStore(CertStoreProvider lpszStoreProvider, CertEncodingType dwMsgAndCertEncodingType, IntPtr hCryptProv, CertStoreFlags dwFlags, string?pvPara)
 {
     return(CertOpenStore((IntPtr)lpszStoreProvider, dwMsgAndCertEncodingType, hCryptProv, dwFlags, pvPara));
 }
示例#5
0
 private static extern SafeCertStoreHandle CertOpenStore(IntPtr lpszStoreProvider, CertEncodingType dwMsgAndCertEncodingType, IntPtr hCryptProv, CertStoreFlags dwFlags, string pvPara);
示例#6
0
 private static extern SafeCertStoreHandle CertOpenStore(IntPtr lpszStoreProvider, CertEncodingType dwMsgAndCertEncodingType, IntPtr hCryptProv, CertStoreFlags dwFlags, [MarshalAs(UnmanagedType.LPWStr)] String pvPara);
示例#7
0
 public static SafeCertStoreHandle CertOpenStore(CertStoreProvider lpszStoreProvider, CertEncodingType dwMsgAndCertEncodingType, IntPtr hCryptProv, CertStoreFlags dwFlags, String pvPara)
 {
     return CertOpenStore((IntPtr)lpszStoreProvider, dwMsgAndCertEncodingType, hCryptProv, dwFlags, pvPara);
 }
示例#8
0
 internal static extern bool CertEnumSystemStore(CertStoreFlags Flags, IntPtr notUsed1, IntPtr notUsed2, CertEnumSystemStoreCallBackProto fn);
示例#9
0
 internal static extern bool CertEnumSystemStore(CertStoreFlags Flags, IntPtr notUsed1, IntPtr notUsed2, CertEnumSystemStoreCallBackProto fn);
示例#10
0
 bool CertEnumSystemStore(CertStoreFlags Flags,
                          IntPtr notUsed1,
                          IntPtr notUsed2,
                          CertEnumSystemStoreCallBackProto fn);