internal static void X509StoreCtxResetForSignatureError(
            SafeX509StoreCtxHandle ctx,
            out SafeX509StoreHandle newStore)
        {
            if (CryptoNative_X509StoreCtxResetForSignatureError(ctx, out newStore) != 1)
            {
                newStore.Dispose();
                newStore = null;
                throw CreateOpenSslCryptographicException();
            }

            if (newStore.IsInvalid)
            {
                newStore.Dispose();
                newStore = null;
            }
        }
Exemplo n.º 2
0
        public void Dispose()
        {
            _storeCtx?.Dispose();
            _untrustedLookup?.Dispose();
            _store?.Dispose();

            // We don't own this one.
            _leafHandle = null;
        }
            public static AndroidKeyStore OpenDefault(OpenFlags openFlags)
            {
                SafeX509StoreHandle store = Interop.AndroidCrypto.X509StoreOpenDefault();

                if (store.IsInvalid)
                {
                    store.Dispose();
                    throw new CryptographicException();
                }

                return(new AndroidKeyStore(store, openFlags));
            }
Exemplo n.º 4
0
        internal static SafeX509StoreHandle X509ChainNew(SafeX509StackHandle systemTrust, SafeX509StackHandle userTrust)
        {
            SafeX509StoreHandle store = CryptoNative_X509ChainNew(systemTrust, userTrust);

            if (store.IsInvalid)
            {
                Exception e = CreateOpenSslCryptographicException();
                store.Dispose();
                throw e;
            }

            return(store);
        }
Exemplo n.º 5
0
        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;
            }
        }
Exemplo n.º 6
0
        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 void Dispose()
 {
     _keyStoreHandle.Dispose();
 }