public byte[] Export(X509ContentType contentType, SafePasswordHandle password) { using (IExportPal storePal = StorePal.FromCertificate(this)) { return(storePal.Export(contentType, password)); } }
public void FindAndCopyTo(X509FindType findType, object findValue, bool validOnly, X509Certificate2Collection collection) { Debug.Assert(collection != null); StorePal findResults = CreatedLinkedStoreWithFindResults(findType, findValue, validOnly); findResults.CopyTo(collection); }
private static SafeCertStoreHandle ConvertExtraStoreToSafeHandle(X509Certificate2Collection extraStore) { if (extraStore == null || extraStore.Count == 0) { return(SafeCertStoreHandle.InvalidHandle); } return(((StorePal)StorePal.LinkFromCertificateCollection(extraStore)).SafeCertStoreHandle); }
public byte[] Export(X509ContentType contentType, SafePasswordHandle password) { using (IExportPal storePal = StorePal.FromCertificate(this)) { byte[]? exported = storePal.Export(contentType, password); Debug.Assert(exported != null); return(exported); } }
public static IStorePal FromHandle(IntPtr storeHandle) { if (storeHandle == IntPtr.Zero) throw new ArgumentNullException(nameof(storeHandle)); SafeCertStoreHandle certStoreHandle = Interop.crypt32.CertDuplicateStore(storeHandle); if (certStoreHandle == null || certStoreHandle.IsInvalid) throw new CryptographicException(SR.Cryptography_InvalidStoreHandle, nameof(storeHandle)); var pal = new StorePal(certStoreHandle); return pal; }
internal static OpenSslX509ChainProcessor InitiateChain( SafeX509Handle leafHandle, DateTime verificationTime, TimeSpan remainingDownloadTime) { SafeX509StackHandle systemTrust = StorePal.GetMachineRoot().GetNativeCollection(); SafeX509StackHandle systemIntermediate = StorePal.GetMachineIntermediate().GetNativeCollection(); SafeX509StoreHandle store = null; SafeX509StackHandle untrusted = null; SafeX509StoreCtxHandle storeCtx = null; try { store = Interop.Crypto.X509ChainNew(systemTrust, s_userRootPath); untrusted = Interop.Crypto.NewX509Stack(); Interop.Crypto.X509StackAddDirectoryStore(untrusted, s_userIntermediatePath); Interop.Crypto.X509StackAddDirectoryStore(untrusted, s_userPersonalPath); Interop.Crypto.X509StackAddMultiple(untrusted, systemIntermediate); Interop.Crypto.X509StoreSetVerifyTime(store, verificationTime); storeCtx = Interop.Crypto.X509StoreCtxCreate(); if (!Interop.Crypto.X509StoreCtxInit(storeCtx, store, leafHandle, untrusted)) { throw Interop.Crypto.CreateOpenSslCryptographicException(); } return(new OpenSslX509ChainProcessor( leafHandle, store, untrusted, storeCtx, verificationTime, remainingDownloadTime)); } catch { store?.Dispose(); untrusted?.Dispose(); storeCtx?.Dispose(); throw; } }
public static IStorePal FromHandle(IntPtr storeHandle) { if (storeHandle == IntPtr.Zero) { throw new ArgumentNullException(nameof(storeHandle)); } SafeCertStoreHandle certStoreHandle = Interop.crypt32.CertDuplicateStore(storeHandle); if (certStoreHandle == null || certStoreHandle.IsInvalid) { throw new CryptographicException(SR.Cryptography_InvalidStoreHandle, nameof(storeHandle)); } var pal = new StorePal(certStoreHandle); return(pal); }
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); } }
internal FindPal(X509Certificate2Collection findFrom, X509Certificate2Collection copyTo, bool validOnly) { _storePal = (StorePal)StorePal.LinkFromCertificateCollection(findFrom); _copyTo = copyTo; _validOnly = validOnly; }
public IEnumerable <X509Certificate2> Find(X509FindType findType, Object findValue, bool validOnly) { StorePal findResults = CreatedLinkedStoreWithFindResults(findType, findValue, validOnly); return(findResults.Certificates); }
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); } }
internal FindPal(X509Certificate2Collection findFrom, X509Certificate2Collection copyTo, bool validOnly) { _storePal = (StorePal)StorePal.LinkFromCertificateCollection(findFrom); _copyTo = copyTo; _validOnly = validOnly; }