コード例 #1
0
        public CertificatesFixture()
        {
            Key = RSA.Create(keySizeInBits: 2048);
            _defaultCertificate   = SigningTestUtility.GenerateCertificate("test", Key);
            _rsaSsaPssCertificate = SigningTestUtility.GenerateCertificate("test",
                                                                           generator => { },
                                                                           hashAlgorithm: Common.HashAlgorithmName.SHA256,
                                                                           paddingMode: RSASignaturePaddingMode.Pss);
            _lifetimeSigningCertificate = SigningTestUtility.GenerateCertificate(
                "test",
                generator =>
            {
                generator.Extensions.Add(
                    new X509EnhancedKeyUsageExtension(
                        new OidCollection {
                    new Oid(Oids.LifetimeSigningEku)
                },
                        critical: true));
            });
            _expiredCertificate = SigningTestUtility.GenerateCertificate(
                "test",
                SigningTestUtility.CertificateModificationGeneratorExpiredCert);
            _notYetValidCertificate = SigningTestUtility.GenerateCertificate(
                "test",
                SigningTestUtility.CertificateModificationGeneratorNotYetValidCert);
            _nonSelfSignedCertificate = SigningTestUtility.GenerateCertificate(
                "test non-self-signed certificate", // Must be different than the issuing certificate's subject name.
                generator => { },
                chainCertificateRequest: new ChainCertificateRequest()
            {
                Issuer = _defaultCertificate
            });
            _selfIssuedCertificate = SigningTestUtility.GenerateSelfIssuedCertificate(isCa: false);
            _rootCertificate       = SigningTestUtility.GenerateSelfIssuedCertificate(isCa: true);

            const string name1 = "NuGet Cyclic Test Certificate 1";
            const string name2 = "NuGet Cyclic Test Certificate 2";

            using (var rsa1 = RSA.Create(keySizeInBits: 2048))
                using (var rsa2 = RSA.Create(keySizeInBits: 2048))
                {
                    _cyclicChain = new DisposableList <X509Certificate2>()
                    {
                        SigningTestUtility.GenerateCertificate(name1, name2, rsa1, rsa2),
                        SigningTestUtility.GenerateCertificate(name2, name1, rsa2, rsa1)
                    };
                }
        }
コード例 #2
0
        public CertificatesFixture()
        {
            DefaultKeyPair              = SigningTestUtility.GenerateKeyPair(publicKeyLength: 2048);
            _defaultCertificate         = SigningTestUtility.GenerateCertificate("test", DefaultKeyPair);
            _rsaSsaPssCertificate       = SigningTestUtility.GenerateCertificate("test", generator => { }, "SHA256WITHRSAANDMGF1");
            _lifetimeSigningCertificate = SigningTestUtility.GenerateCertificate(
                "test",
                generator =>
            {
                generator.AddExtension(
                    X509Extensions.ExtendedKeyUsage.Id,
                    critical: true,
                    extensionValue: new DerSequence(new DerObjectIdentifier(Oids.LifetimeSigningEku)));
            });
            _expiredCertificate = SigningTestUtility.GenerateCertificate(
                "test",
                SigningTestUtility.CertificateModificationGeneratorExpiredCert);
            _notYetValidCertificate = SigningTestUtility.GenerateCertificate(
                "test",
                SigningTestUtility.CertificateModificationGeneratorNotYetValidCert);
            _nonSelfSignedCertificate = SigningTestUtility.GenerateCertificate(
                "test non-self-signed certificate", // Must be different than the issuing certificate's subject name.
                generator => { },
                chainCertificateRequest: new ChainCertificateRequest()
            {
                Issuer = _defaultCertificate
            });
            _selfIssuedCertificate = SigningTestUtility.GenerateSelfIssuedCertificate(isCa: false);
            _rootCertificate       = SigningTestUtility.GenerateSelfIssuedCertificate(isCa: true);

            const string name1 = "NuGet Cyclic Test Certificate 1";
            const string name2 = "NuGet Cyclic Test Certificate 2";

            var keyPair1 = SigningTestUtility.GenerateKeyPair(publicKeyLength: 2048);
            var keyPair2 = SigningTestUtility.GenerateKeyPair(publicKeyLength: 2048);

            _cyclicChain = new DisposableList <X509Certificate2>()
            {
                SigningTestUtility.GenerateCertificate(name1, name2, keyPair1.Private, keyPair2),
                SigningTestUtility.GenerateCertificate(name2, name1, keyPair2.Private, keyPair1)
            };
        }