public void Reset()
        {
            X509ChainPolicy cp = GetPolicy();

            cp.ApplicationPolicy.Add(new Oid(signingTimeOid));
            cp.CertificatePolicy.Add(new Oid(signingTimeOid));
            cp.ExtraStore.Add(new X509Certificate2());
            cp.RevocationFlag      = X509RevocationFlag.EndCertificateOnly;
            cp.RevocationMode      = X509RevocationMode.NoCheck;
            cp.UrlRetrievalTimeout = new TimeSpan(100);
            cp.VerificationFlags   = X509VerificationFlags.AllFlags;
            DateTime vt = cp.VerificationTime;

            Assert.IsTrue(((vt <= DateTime.Now) && (vt > DateTime.Now.AddMinutes(-1))), "VerificationTime");
            // wait a bit before calling Reset, otherwise we could end up with the same time value
            Thread.Sleep(100);
            cp.Reset();
            Assert.IsTrue((vt != cp.VerificationTime), "VerificationTime-Reset");
            // default properties
            Assert.AreEqual(0, cp.ApplicationPolicy.Count, "ApplicationPolicy");
            Assert.AreEqual(0, cp.CertificatePolicy.Count, "CertificatePolicy");
            Assert.AreEqual(0, cp.ExtraStore.Count, "ExtraStore");
            Assert.AreEqual(X509RevocationFlag.ExcludeRoot, cp.RevocationFlag, "RevocationFlag");
            Assert.AreEqual(X509RevocationMode.Online, cp.RevocationMode, "RevocationMode");
            Assert.AreEqual(0, cp.UrlRetrievalTimeout.Ticks, "UrlRetrievalTimeout");
            Assert.AreEqual(X509VerificationFlags.NoFlag, cp.VerificationFlags, "VerificationFlags");
            vt = cp.VerificationTime;
            Assert.IsTrue(((vt <= DateTime.Now) && (vt > DateTime.Now.AddMinutes(-1))), "VerificationTime");
        }
        public void ApplicationPolicy_Reset()
        {
            X509ChainPolicy cp = GetPolicy();

            cp.ApplicationPolicy.Add(new Oid(signingTimeOid));
            OidCollection oc = cp.ApplicationPolicy;

            Assert.AreEqual(1, oc.Count, "ApplicationPolicy-1");
            cp.Reset();
            Assert.AreEqual(1, oc.Count, "ApplicationPolicy-2");
            Assert.AreEqual(0, cp.ApplicationPolicy.Count, "ApplicationPolicy-3");
        }
        public void ExtraStore_Reset()
        {
            X509ChainPolicy cp = GetPolicy();

            cp.ExtraStore.Add(new X509Certificate2());
            X509Certificate2Collection cc = cp.ExtraStore;

            Assert.AreEqual(1, cc.Count, "ExtraStore-1");
            cp.Reset();
            Assert.AreEqual(1, cc.Count, "ExtraStore-2");
            Assert.AreEqual(0, cp.ExtraStore.Count, "ExtraStore-3");
        }
Beispiel #4
0
        public static void ResetAfterChanges()
        {
            using (X509Certificate2 cert = new X509Certificate2(TestData.SelfSigned1PemBytes))
            {
                X509ChainPolicy policy = new X509ChainPolicy();
                policy.CertificatePolicy.Add(s_emailProtectionEku);
                policy.ApplicationPolicy.Add(s_timestampEku);
                policy.ExtraStore.Add(cert);
                policy.CustomTrustStore.Add(cert);
                policy.DisableCertificateDownloads = true;
                policy.VerificationTime            = DateTime.MinValue;
                policy.VerificationTimeIgnored     = false;
                policy.UrlRetrievalTimeout         = TimeSpan.MaxValue;
                policy.VerificationFlags           = X509VerificationFlags.IgnoreCtlNotTimeValid;
                policy.RevocationMode = X509RevocationMode.Offline;
                policy.RevocationFlag = X509RevocationFlag.EntireChain;

                policy.Reset();
                AssertDefaultState(policy);
            }
        }