Пример #1
0
        private void AddManifest()
        {
            Log.Debug("Creating manifest");
            var manifest = CreateManifest();

            if (manifest.ManifestSpec == ManifestSpec.Cades && manifest.SignatureFileRef != null)
            {
                var signatureFile = SignatureCreator.Create(SignatureCertificate).CreateCadesSignatureFile(manifest);
                manifest.SignatureFileRef = signatureFile.SignatureFileRef;
                using (var signatureStream = new MemoryStream(signatureFile.Data.ToArray()))
                {
                    var entry = Archive.CreateEntry(signatureFile.SignatureFileRef.FileName);
                    using (var zipEntryStream = entry.Open())
                    {
                        signatureStream.CopyTo(zipEntryStream);
                    }
                }
            }

            using (var manifestStream = new MemoryStream(manifest.Data.ToArray()))
            {
                CreateEntry(manifestStream, new AsicePackageEntry(manifest.FileName, MimeType.ForString(AsiceConstants.ContentTypeXml), MessageDigestAlgorithm));
            }

            Log.Debug("Manifest added to archive");
        }
Пример #2
0
        public async Task CreatedSignature_FromRequestWithHeaders_CanBeValidated()
        {
            var sut = new SignatureCreator();

            IEnumerable <KeyValuePair <string, IEnumerable <string> > > headers = new List <KeyValuePair <string, IEnumerable <string> > >
            {
                new KeyValuePair <string, IEnumerable <string> >("X-Custom-Header", new List <string> {
                    "blah123blah"
                }),
                new KeyValuePair <string, IEnumerable <string> >("X-Custom-Header-Two", new List <string> {
                    "456qwerty"
                })
            };

            var signature = sut.Create(HttpMethod.Post, headers, _applicationUri, DateTime.UtcNow.ToTimeStamp(), new Nonce(), _requestPayload, _scope, _apiKey);

            var validator = new SignatureValidator();

            var request = new HttpRequestMessage(HttpMethod.Post, _applicationUri)
            {
                Content = new StringContent(_requestPayload)
            };

            foreach (var header in headers)
            {
                request.Headers.Add(header.Key, header.Value);
            }

            request.Headers.Add("Authorization", signature);

            (await validator.Validate(request, _scope, _apiKey)).ShouldBe(true);
        }