public void Dispose() { if (_caStackHandle != null) { _caStackHandle.Dispose(); _caStackHandle = null; } if (_x509Handle != null) { _x509Handle.Dispose(); _x509Handle = null; } if (_evpPkeyHandle != null) { _evpPkeyHandle.Dispose(); _evpPkeyHandle = null; } if (_pkcs12Handle != null) { _pkcs12Handle.Dispose(); } }
public void Dispose() { _storeCtx?.Dispose(); _untrustedLookup?.Dispose(); _store?.Dispose(); // We don't own this one. _leafHandle = null; }
internal static OpenSslX509ChainProcessor InitiateChain( SafeX509Handle leafHandle, X509Certificate2Collection customTrustStore, X509ChainTrustMode trustMode, DateTime verificationTime, TimeSpan remainingDownloadTime) { CachedSystemStoreProvider.GetNativeCollections( out SafeX509StackHandle systemTrust, out SafeX509StackHandle systemIntermediate); SafeX509StoreHandle store = null; SafeX509StackHandle untrusted = null; SafeX509StoreCtxHandle storeCtx = null; try { untrusted = Interop.Crypto.NewX509Stack(); Interop.Crypto.X509StackAddMultiple(untrusted, s_userIntermediateStore.GetNativeCollection()); Interop.Crypto.X509StackAddMultiple(untrusted, s_userPersonalStore.GetNativeCollection()); store = GetTrustStore(trustMode, customTrustStore, untrusted, systemTrust); 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; } }
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; } }