Пример #1
0
            public void CertificateSignedIndirectly_Should_FindIntermediateCertificateViaLocator()
            {
                // Arrange
                var intermediateKey               = RsaKey.Generate();
                var intermediateCertificate       = intermediateKey.DeriveCertificate();
                var signedIntermediateCertificate = ScenarioRsa.DefaultSignerKey.Sign((RsaCertificate)intermediateCertificate);
                var key               = RsaKey.Generate();
                var certificate       = key.DeriveCertificate();
                var signedCertificate = intermediateKey.Sign((RsaCertificate)certificate);

                var scenario = new Scenario3();
                var lookedUpIntermediateCertificate = false;

                Mock.Get(scenario.CertificateLocator)
                .Setup(m => m.Get(It.IsAny <IHash>()))
                .Returns <IHash>((_hash) =>
                {
                    if (_hash.Hash.SequenceEqual(intermediateCertificate.Hash.Hash))
                    {
                        lookedUpIntermediateCertificate = true;
                        return(signedIntermediateCertificate);
                    }
                    else
                    {
                        return(null);
                    }
                });

                // Act
                // Assert
                scenario.ChainWithLocator.Verify(signedCertificate);
                lookedUpIntermediateCertificate.Should().BeTrue();
            }
Пример #2
0
            public void CertificateSignedWithUnlocatableCertificate_ShouldThrow_TrustException()
            {
                // Arrange
                var intermediateKey               = RsaKey.Generate();
                var intermediateCertificate       = intermediateKey.DeriveCertificate();
                var signedIntermediateCertificate = ScenarioRsa.DefaultSignerKey.Sign((RsaCertificate)intermediateCertificate);
                var key               = RsaKey.Generate();
                var certificate       = key.DeriveCertificate();
                var signedCertificate = intermediateKey.Sign((RsaCertificate)certificate);

                var scenario = new Scenario3();
                var lookedUpIntermediateCertificate = false;

                Mock.Get(scenario.CertificateLocator)
                .Setup(m => m.Get(It.IsAny <IHash>()))
                .Returns <IHash>((_hash) =>
                {
                    lookedUpIntermediateCertificate = true;
                    return(null);
                });

                // Act
                // Assert
                Assert.Throws <TrustException>(() => scenario.ChainWithLocator.Verify(signedCertificate));
                lookedUpIntermediateCertificate.Should().BeTrue();
            }