Exemple #1
0
 public void IsSelfIssued_WithPartialChain_ReturnsFalse()
 {
     using (var certificate = SignTestUtility.GetCertificate("leaf.crt"))
     {
         Assert.False(CertificateUtility.IsSelfIssued(certificate));
     }
 }
        public void GetCertificateChainForSigning_WithUntrustedRoot_Throws()
        {
            using (var chainHolder = new X509ChainHolder())
                using (var rootCertificate = SignTestUtility.GetCertificate("root.crt"))
                    using (var intermediateCertificate = SignTestUtility.GetCertificate("intermediate.crt"))
                        using (var leafCertificate = SignTestUtility.GetCertificate("leaf.crt"))
                        {
                            var chain      = chainHolder.Chain;
                            var extraStore = new X509Certificate2Collection()
                            {
                                rootCertificate, intermediateCertificate
                            };
                            var logger = new TestLogger();

                            var exception = Assert.Throws <SignatureException>(
                                () => CertificateChainUtility.GetCertificateChainForSigning(
                                    leafCertificate,
                                    extraStore,
                                    logger));

                            Assert.Equal(NuGetLogCode.NU3018, exception.Code);
                            Assert.Equal("Certificate chain validation failed.", exception.Message);

                            Assert.Equal(1, logger.Errors);
                            Assert.Equal(RuntimeEnvironmentHelper.IsWindows ? 2 : 1, logger.Warnings);

                            AssertUntrustedRoot(logger.LogMessages, LogLevel.Error);
                            AssertOfflineRevocation(logger.LogMessages, LogLevel.Warning);

                            if (RuntimeEnvironmentHelper.IsWindows)
                            {
                                AssertRevocationStatusUnknown(logger.LogMessages, LogLevel.Warning);
                            }
                        }
        }
Exemple #3
0
        public void CreateSignedAttributes_SignPackageRequest_WithValidInput_ReturnsAttributes()
        {
            using (var rootCertificate = SignTestUtility.GetCertificate("root.crt"))
                using (var intermediateCertificate = SignTestUtility.GetCertificate("intermediate.crt"))
                    using (var leafCertificate = SignTestUtility.GetCertificate("leaf.crt"))
                        using (var request = CreateRequest(leafCertificate))
                        {
                            var certList   = new[] { leafCertificate, intermediateCertificate, rootCertificate };
                            var attributes = SigningUtility.CreateSignedAttributes(request, certList);

                            Assert.Equal(3, attributes.Count);

                            VerifyAttributes(attributes, request);
                        }
        }
Exemple #4
0
        public void GetCertificateListFromChain_ReturnsCertificatesInOrder()
        {
            using (var chainHolder = new X509ChainHolder())
                using (var rootCertificate = SignTestUtility.GetCertificate("root.crt"))
                    using (var intermediateCertificate = SignTestUtility.GetCertificate("intermediate.crt"))
                        using (var leafCertificate = SignTestUtility.GetCertificate("leaf.crt"))
                        {
                            var chain = chainHolder.Chain;

                            chain.ChainPolicy.ExtraStore.Add(rootCertificate);
                            chain.ChainPolicy.ExtraStore.Add(intermediateCertificate);

                            chain.Build(leafCertificate);

                            var certificateChain = CertificateChainUtility.GetCertificateListFromChain(chain);

                            Assert.Equal(3, certificateChain.Count);
                            Assert.Equal(leafCertificate.Thumbprint, certificateChain[0].Thumbprint);
                            Assert.Equal(intermediateCertificate.Thumbprint, certificateChain[1].Thumbprint);
                            Assert.Equal(rootCertificate.Thumbprint, certificateChain[2].Thumbprint);
                        }
        }