/// <summary>
        /// Adds a repository countersignature for a given primary signature for tests.
        /// </summary>
        /// <param name="signature">Primary signature to add the repository countersignature.</param>
        /// <param name="request">RepositorySignPackageRequest containing the metadata for the signature request.</param>
        /// <returns>Primary signature with a repository countersignature.</returns>
        public static async Task <PrimarySignature> RepositoryCountersignPrimarySignatureAsync(PrimarySignature signature, RepositorySignPackageRequest request)
        {
            var testLogger        = new TestLogger();
            var signatureProvider = new X509SignatureProvider(timestampProvider: null);

            return(await signatureProvider.CreateRepositoryCountersignatureAsync(request, signature, testLogger, CancellationToken.None));
        }
Exemple #2
0
        private static async Task AddRepositoryCountersignatureToSignedPackageAsync(SimpleTestPackageContext packageContext, ISignedPackage package, RepositorySignPackageRequest request, ILogger logger)
        {
            var primarySignature = await package.GetPrimarySignatureAsync(CancellationToken.None);

            if (primarySignature != null)
            {
                var testSignatureProvider = new X509SignatureProvider(packageContext.CounterTimestampProvider);

                var signature = await testSignatureProvider.CreateRepositoryCountersignatureAsync(request, primarySignature, logger, CancellationToken.None);

                using (var stream = new MemoryStream(signature.GetBytes()))
                {
                    await package.AddSignatureAsync(stream, CancellationToken.None);
                }
            }
        }
Exemple #3
0
        /// <summary>
        /// Adds a Repository countersignature to a given primary signature
        /// </summary>
        /// <param name="testCert">Certificate to be used while generating the countersignature.</param>
        /// <param name="primarySignature">Primary signature to add countersignature.</param>
        /// <param name="timestampProvider">An optional timestamp provider.</param>
        /// <returns></returns>
        public static async Task <PrimarySignature> RepositoryCountersignPrimarySignatureAsync(
            X509Certificate2 testCert,
            PrimarySignature primarySignature,
            ITimestampProvider timestampProvider = null)
        {
            var testLogger        = new TestLogger();
            var hashAlgorithm     = HashAlgorithmName.SHA256;
            var v3ServiceIndexUrl = new Uri("https://v3serviceIndex.test/api/index.json");

            using (var request = new RepositorySignPackageRequest(testCert, hashAlgorithm, hashAlgorithm, v3ServiceIndexUrl, null))
            {
                var testSignatureProvider = new X509SignatureProvider(timestampProvider);

                return(await testSignatureProvider.CreateRepositoryCountersignatureAsync(request, primarySignature, testLogger, CancellationToken.None));
            }
        }