Ejemplo n.º 1
0
        private static void VerifyAttributes(
            System.Security.Cryptography.CryptographicAttributeObjectCollection attributes,
            SignPackageRequest request)
        {
            var pkcs9SigningTimeAttributeFound         = false;
            var commitmentTypeIndicationAttributeFound = false;
            var signingCertificateV2AttributeFound     = false;

            foreach (var attribute in attributes)
            {
                Assert.Equal(1, attribute.Values.Count);

                switch (attribute.Oid.Value)
                {
                case "1.2.840.113549.1.9.5":     // PKCS #9 signing time
                    Assert.IsType <Pkcs9SigningTime>(attribute.Values[0]);

                    pkcs9SigningTimeAttributeFound = true;
                    break;

                case Oids.CommitmentTypeIndication:
                    var qualifier = CommitmentTypeQualifier.Read(attribute.Values[0].RawData);
                    var expectedCommitmentType = AttributeUtility.GetSignatureTypeOid(request.SignatureType);

                    Assert.Equal(expectedCommitmentType, qualifier.CommitmentTypeIdentifier.Value);

                    commitmentTypeIndicationAttributeFound = true;
                    break;

                case Oids.SigningCertificateV2:
                    var signingCertificateV2 = SigningCertificateV2.Read(attribute.Values[0].RawData);

                    Assert.Equal(1, signingCertificateV2.Certificates.Count);

                    var essCertIdV2 = signingCertificateV2.Certificates[0];

                    Assert.Equal(SigningTestUtility.GetHash(request.Certificate, request.SignatureHashAlgorithm), essCertIdV2.CertificateHash);
                    Assert.Equal(request.SignatureHashAlgorithm.ConvertToOidString(), essCertIdV2.HashAlgorithm.Algorithm.Value);
                    Assert.Equal(request.Certificate.IssuerName.Name, essCertIdV2.IssuerSerial.GeneralNames[0].DirectoryName.Name);
                    SigningTestUtility.VerifySerialNumber(request.Certificate, essCertIdV2.IssuerSerial);
                    Assert.Null(signingCertificateV2.Policies);

                    signingCertificateV2AttributeFound = true;
                    break;
                }
            }

            Assert.True(pkcs9SigningTimeAttributeFound);
            Assert.True(commitmentTypeIndicationAttributeFound);
            Assert.True(signingCertificateV2AttributeFound);
        }
Ejemplo n.º 2
0
        private static void VerifyAttributesRepository(
            System.Security.Cryptography.CryptographicAttributeObjectCollection attributes,
            RepositorySignPackageRequest request)
        {
            VerifyAttributes(attributes, request);

            var nugetV3ServiceIndexUrlAttributeFound = false;
            var nugetPackageOwnersAttributeFound     = false;

            foreach (var attribute in attributes)
            {
                Assert.Equal(1, attribute.Values.Count);

                switch (attribute.Oid.Value)
                {
                case Oids.NuGetV3ServiceIndexUrl:
                    var nugetV3ServiceIndexUrl = NuGetV3ServiceIndexUrl.Read(attribute.Values[0].RawData);

                    Assert.True(nugetV3ServiceIndexUrl.V3ServiceIndexUrl.IsAbsoluteUri);
                    Assert.Equal(request.V3ServiceIndexUrl.OriginalString, nugetV3ServiceIndexUrl.V3ServiceIndexUrl.OriginalString);

                    nugetV3ServiceIndexUrlAttributeFound = true;
                    break;

                case Oids.NuGetPackageOwners:
                    var nugetPackageOwners = NuGetPackageOwners.Read(attribute.Values[0].RawData);

                    Assert.Equal(request.PackageOwners, nugetPackageOwners.PackageOwners);

                    nugetPackageOwnersAttributeFound = true;
                    break;
                }
            }

            Assert.True(nugetV3ServiceIndexUrlAttributeFound);
            Assert.Equal(request.PackageOwners != null && request.PackageOwners.Count > 0, nugetPackageOwnersAttributeFound);
        }