Esempio n. 1
0
        public void CorrectNumberOfSctsReturnsSuccessTrusted()
        {
            foreach (var tp in _testParams)
            {
                var certMoq = new Moq.Mock <MoqX509Certificate2>();
                certMoq.Setup(c => c.MoqNotBefore).Returns(tp.Start);
                certMoq.Setup(c => c.MoqNotAfter).Returns(tp.End);

                var cert = certMoq.Object;
                var scts = new Dictionary <string, SctVerificationResult>();

                for (var i = 0; i < tp.SctsRequired; i++)
                {
                    scts[i.ToString()] = SctVerificationResult.Valid(DateTime.UtcNow, Guid.NewGuid().ToString());
                }

                for (var i = 0; i < 10; i++)
                {
                    scts[(i + 100).ToString()] = SctVerificationResult.FailedVerification(DateTime.UtcNow, Guid.NewGuid().ToString());
                }

                var result = new CtPolicyDefault().PolicyVerificationResult(cert, scts);

                Assert.True(result.Result == CtResult.Trusted, tp.Description);
            }
        }
Esempio n. 2
0
        public void FewerSctsThanRequiredReturnsFailure()
        {
            var rand = new Random();

            foreach (var tp in _testParams)
            {
                var certMoq = new Moq.Mock <MoqX509Certificate2>();
                certMoq.Setup(c => c.MoqNotBefore).Returns(tp.Start);
                certMoq.Setup(c => c.MoqNotAfter).Returns(tp.End);

                var cert = certMoq.Object;
                var scts = new Dictionary <string, SctVerificationResult>();

                var numScts = rand.Next(tp.SctsRequired);
                for (var i = 0; i < numScts; i++)
                {
                    scts[i.ToString()] = SctVerificationResult.Valid(DateTime.UtcNow, Guid.NewGuid().ToString());
                }

                for (var i = 0; i < 10; i++)
                {
                    scts[(i + 100).ToString()] = SctVerificationResult.FailedVerification(DateTime.UtcNow, Guid.NewGuid().ToString());
                }

                var result = new CtPolicyDefault().PolicyVerificationResult(cert, scts);

                Assert.True(tp.SctsRequired == result.MinSctCount, tp.Description);
                Assert.True(result.Result == CtResult.TooFewSctsTrusted, tp.Description);
            }
        }