internal static unsafe partial SafeCertContextHandle CertFindCertificateInStore(
     SafeCertStoreHandle hCertStore,
     CertEncodingType dwCertEncodingType,
     CertFindFlags dwFindFlags,
     CertFindType dwFindType,
     void *pvFindPara,
     CERT_CONTEXT *pPrevCertContext);
Beispiel #2
0
 internal static extern IntPtr CertFindCertificateInStore(
     IntPtr hCertStore,
     CertEncodingType dwCertEncodingType,
     CertFindFlags dwFindFlags,
     CertFindType dwFindType,
     IntPtr pszFindPara,
     IntPtr pPrevCertCntxt);
Beispiel #3
0
        private unsafe void FindCore(CertFindType dwFindType, void *pvFindPara, Func <SafeCertContextHandle, bool>?filter = null)
        {
            SafeCertStoreHandle findResults = Interop.crypt32.CertOpenStore(
                CertStoreProvider.CERT_STORE_PROV_MEMORY,
                CertEncodingType.All,
                IntPtr.Zero,
                CertStoreFlags.CERT_STORE_ENUM_ARCHIVED_FLAG | CertStoreFlags.CERT_STORE_CREATE_NEW_FLAG,
                null);

            if (findResults.IsInvalid)
            {
                throw Marshal.GetHRForLastWin32Error().ToCryptographicException();
            }

            SafeCertContextHandle?pCertContext = null;

            while (Interop.crypt32.CertFindCertificateInStore(_storePal.SafeCertStoreHandle, dwFindType, pvFindPara, ref pCertContext))
            {
                if (filter != null && !filter(pCertContext))
                {
                    continue;
                }

                if (_validOnly)
                {
                    if (!VerifyCertificateIgnoringErrors(pCertContext))
                    {
                        continue;
                    }
                }

                if (!Interop.crypt32.CertAddCertificateLinkToStore(findResults, pCertContext, CertStoreAddDisposition.CERT_STORE_ADD_ALWAYS, IntPtr.Zero))
                {
                    throw Marshal.GetLastWin32Error().ToCryptographicException();
                }
            }

            using (StorePal resultsStore = new StorePal(findResults))
            {
                resultsStore.CopyTo(_copyTo);
            }
        }
Beispiel #4
0
        /// <summary>
        /// A less error-prone wrapper for CertEnumCertificatesInStore().
        ///
        /// To begin the enumeration, set pCertContext to null. Each iteration replaces pCertContext with
        /// the next certificate in the iteration. The final call sets pCertContext to an invalid SafeCertStoreHandle
        /// and returns "false" to indicate the end of the store has been reached.
        /// </summary>
        public static unsafe bool CertFindCertificateInStore(SafeCertStoreHandle hCertStore, CertFindType dwFindType, void *pvFindPara, [NotNull] ref SafeCertContextHandle?pCertContext)
        {
            CERT_CONTEXT *pPrevCertContext = pCertContext == null ? null : pCertContext.Disconnect();

            pCertContext = CertFindCertificateInStore(hCertStore, CertEncodingType.All, CertFindFlags.None, dwFindType, pvFindPara, pPrevCertContext);
            return(!pCertContext.IsInvalid);
        }
Beispiel #5
0
 public static extern SafePCCTL_CONTEXT CertFindCTLInStore(HCERTSTORE hCertStore, CertEncodingType dwMsgAndCertEncodingType, CertInfoFlags dwFindFlags, CertFindType dwFindType, [In] IntPtr pvFindPara, [In] PCCTL_CONTEXT pPrevCtlContext);
Beispiel #6
0
 private static unsafe extern SafeCertContextHandle CertFindCertificateInStore(SafeCertStoreHandle hCertStore, CertEncodingType dwCertEncodingType, CertFindFlags dwFindFlags, CertFindType dwFindType, void* pvFindPara, CERT_CONTEXT* pPrevCertContext);
Beispiel #7
0
 /// <summary>
 /// A less error-prone wrapper for CertEnumCertificatesInStore().
 /// 
 /// To begin the enumeration, set pCertContext to null. Each iteration replaces pCertContext with
 /// the next certificate in the iteration. The final call sets pCertContext to an invalid SafeCertStoreHandle 
 /// and returns "false" to indicate the the end of the store has been reached.
 /// </summary>
 public static unsafe bool CertFindCertificateInStore(SafeCertStoreHandle hCertStore, CertFindType dwFindType, void* pvFindPara, ref SafeCertContextHandle pCertContext)
 {
     CERT_CONTEXT* pPrevCertContext = pCertContext == null ? null : pCertContext.Disconnect();
     pCertContext = CertFindCertificateInStore(hCertStore, CertEncodingType.All, CertFindFlags.None, dwFindType, pvFindPara, pPrevCertContext);
     return !pCertContext.IsInvalid;
 }
Beispiel #8
0
 internal static extern IntPtr CertFindCertificateInStore(IntPtr hCertStore, CertOpenStoreEncodingType dwEncodingType, int dwFindFlags, CertFindType dwFindType, [MarshalAs(UnmanagedType.LPWStr)] string pvFindPara, IntPtr notUsed1);
Beispiel #9
0
 internal static extern IntPtr CertFindCertificateInStore(IntPtr hCertStore, CertOpenStoreEncodingType dwEncodingType, int dwFindFlags, CertFindType dwFindType, [MarshalAs(UnmanagedType.LPWStr)] string pvFindPara, IntPtr notUsed1);
Beispiel #10
0
        private unsafe void FindCore(CertFindType dwFindType, void* pvFindPara, Func<SafeCertContextHandle, bool> filter = null)
        {
            SafeCertStoreHandle findResults = Interop.crypt32.CertOpenStore(
                CertStoreProvider.CERT_STORE_PROV_MEMORY,
                CertEncodingType.All,
                IntPtr.Zero,
                CertStoreFlags.CERT_STORE_ENUM_ARCHIVED_FLAG | CertStoreFlags.CERT_STORE_CREATE_NEW_FLAG,
                null);
            if (findResults.IsInvalid)
                throw Marshal.GetHRForLastWin32Error().ToCryptographicException();

            SafeCertContextHandle pCertContext = null;
            while (Interop.crypt32.CertFindCertificateInStore(_storePal.SafeCertStoreHandle, dwFindType, pvFindPara, ref pCertContext))
            {
                if (filter != null && !filter(pCertContext))
                    continue;

                if (_validOnly)
                {
                    if (!VerifyCertificateIgnoringErrors(pCertContext))
                        continue;
                }

                if (!Interop.crypt32.CertAddCertificateLinkToStore(findResults, pCertContext, CertStoreAddDisposition.CERT_STORE_ADD_ALWAYS, IntPtr.Zero))
                    throw Marshal.GetLastWin32Error().ToCryptographicException();
            }

            using (StorePal resultsStore = new StorePal(findResults))
            {
                resultsStore.CopyTo(_copyTo);
            }
        }