Exemplo n.º 1
0
            internal static async Task <GetTrustResultAsyncTest> CreateAsync(SignedPackageVerifierSettings settings, X509Certificate2 certificate)
            {
                using (var certificateClone = new X509Certificate2(certificate))
                {
                    var directory           = TestDirectory.Create();
                    var packageContext      = new SimpleTestPackageContext();
                    var unsignedPackageFile = packageContext.CreateAsFile(directory, "package.nupkg");
                    var signedPackageFile   = await SignedArchiveTestUtility.SignPackageFileWithBasicSignedCmsAsync(
                        directory,
                        unsignedPackageFile,
                        certificateClone);

                    var package          = new SignedPackageArchive(signedPackageFile.OpenRead(), new MemoryStream());
                    var primarySignature = await package.GetPrimarySignatureAsync(CancellationToken.None);

                    return(new GetTrustResultAsyncTest(directory, package, primarySignature, settings));
                }
            }
Exemplo n.º 2
0
        public async Task StripsRepositoryCounterSignatures()
        {
            // Arrange
            var packageBytes = await _fixture.GenerateSignedPackageBytesAsync(
                await GetSignedPackageStream1Async(),
                new RepositorySignPackageRequest(
                    await _fixture.GetSigningCertificateAsync(),
                    NuGetHashAlgorithmName.SHA256,
                    NuGetHashAlgorithmName.SHA256,
                    new Uri("https://example-source/v3/index.json"),
                    new[] { "nuget", "microsoft" }),
                await _fixture.GetTimestampServiceUrlAsync(),
                _output);

            var packageStream = new MemoryStream(packageBytes);

            // Act
            var result = await _target.ValidateAsync(
                _packageKey,
                packageStream,
                _message,
                _token);

            // Assert
            VerifyPackageSigningStatus(result, ValidationStatus.Succeeded, PackageSigningStatus.Valid);
            Assert.Empty(result.Issues);
            Assert.Equal(_nupkgUri, result.NupkgUri);
            Assert.NotNull(_savedPackageBytes);
            using (var savedPackageStream = new MemoryStream(_savedPackageBytes))
                using (var packageReader = new SignedPackageArchive(savedPackageStream, Stream.Null))
                {
                    Assert.Equal("TestSigned.leaf-1", packageReader.NuspecReader.GetId());
                    Assert.Equal("1.0.0", packageReader.NuspecReader.GetVersion().ToNormalizedString());
                    Assert.True(await packageReader.IsSignedAsync(CancellationToken.None), "The package should still be signed.");
                    var signature = await packageReader.GetPrimarySignatureAsync(CancellationToken.None);

                    Assert.Equal(SignatureType.Author, signature.Type);
                    Assert.Empty(signature.SignedCms.SignerInfos[0].CounterSignerInfos);
                }
        }