Пример #1
0
        public void TestTimeoutSignAndVerify(string subPath, string nestDir)
        {
            using (var signer = new TimeoutSigner(Util.TestDataPath(TEST_DATA, subPath, nestDir)))
                using (var verifier = new TimeoutVerifier(Util.TestDataPath(TEST_DATA, subPath, nestDir)))
                {
                    // Create a signature that will be valid for a long time
                    var sig = signer.Sign(input, DateTime.Now.AddDays(365));
                    Expect(signer.Verify(input, sig), Is.True);
                    Expect(verifier.Verify(input, sig), Is.True);

                    // Create a signature that is already expired
                    sig = signer.Sign(input, DateTime.Now.AddDays(-1));
                    Expect(signer.Verify(input, sig), Is.False);
                    Expect(verifier.Verify(input, sig), Is.False);

                    // Create a valid signature, let it expire, and check that it is now invalid
                    var nearExpiration = DateTime.Now.AddSeconds(5);
                    sig = signer.Sign(input, nearExpiration);
                    Expect(verifier.Verify(input, sig), Is.True);
                    while (DateTime.Now < nearExpiration)
                    {
                        Thread.Sleep(1000);
                    }
                    Expect(verifier.Verify(input, sig), Is.False);
                }
        }
Пример #2
0
        public void VerifyTimeoutExpired()
        {
            Func <DateTime> lateCurrentTimeProvider =
                () => new DateTime(2012, 12, 21, 11, 11, 0, DateTimeKind.Utc).AddMinutes(5);
            var path = TestData(Location);

            using (var verifier = new TimeoutVerifier(path, lateCurrentTimeProvider))
            {
                var primarySignature = (WebBase64)File.ReadAllLines(Path.Combine(path, "2.timeout")).First();
                Expect(verifier.Verify(Input, primarySignature), Is.False);
            }
        }
Пример #3
0
        public void PublicVerifyTimeoutSucces()
        {
            var path = TestData(Location);

            Func <DateTime> earlyCurrentTimeProvider =
                () => new DateTime(2012, 12, 21, 11, 11, 0, DateTimeKind.Utc).AddMinutes(-5);

            using (var verifier = new TimeoutVerifier(path + ".public", earlyCurrentTimeProvider))
            {
                var primarySignature = (WebBase64)File.ReadAllLines(Path.Combine(path, "2.timeout")).First();
                Expect(verifier.Verify(Input, primarySignature), Is.True);
            }
        }
Пример #4
0
        public void TwoKeysWithSameHashTimeoutVerifyExpired(string dir)
        {
            Func <DateTime> lateCurrentTimeProvider =
                () => new DateTime(2012, 12, 21, 11, 11, 0, DateTimeKind.Utc).AddMinutes(5);

            var subPath = Util.TestDataPath(TEST_DATA, dir);

            using (var verifier = new TimeoutVerifier(subPath, lateCurrentTimeProvider))
            {
                var activeSignature  = (WebBase64)File.ReadAllLines(Path.Combine(subPath, "1.timeout")).First();
                var primarySignature = (WebBase64)File.ReadAllLines(Path.Combine(subPath, "2.timeout")).First();

                var activeVerify = verifier.Verify(input, activeSignature);
                Expect(activeVerify, Is.False);
                var primaryVerify = verifier.Verify(input, primarySignature);
                Expect(primaryVerify, Is.False);
            }
        }