/// <inheritdoc/>
        public async Task <(DidExchangeResponseMessage, ConnectionRecord)> CreateResponseAsync(IAgentContext agentContext, ConnectionRecord connectionRecord)
        {
            await connectionRecord.TriggerAsync(ConnectionTrigger.Response);

            var myDid = await Did.CreateAndStoreMyDidAsync(agentContext.Wallet, "{}");

            connectionRecord.MyDid = DidUtils.ConvertVerkeyToDidKey(myDid.VerKey);
            connectionRecord.MyVk  = myDid.VerKey;

            var provisioningRecord = await _provisioningService.GetProvisioningAsync(agentContext.Wallet);

            var didDoc = new AttachmentContent
            {
                Base64 = connectionRecord.MyDidDoc(provisioningRecord).ToJson().ToBase64Url()
            };
            await didDoc.SignWithJsonWebSignature(agentContext.Wallet, myDid.VerKey);

            var attachment = new Attachment
            {
                Id       = Guid.NewGuid().ToString(),
                MimeType = "application/json",
                Data     = didDoc
            };

            var response = new DidExchangeResponseMessage
            {
                Id     = Guid.NewGuid().ToString(),
                Did    = connectionRecord.MyDid,
                DidDoc = attachment
            };
            await _recordService.UpdateAsync(agentContext.Wallet, connectionRecord);

            return(response, connectionRecord);
        }
Beispiel #2
0
        public async Task SignAttachmentThrowsIfContentIsNull()
        {
            var content = new AttachmentContent();
            var key     = await Crypto.CreateKeyAsync(_agent.Wallet, "{}");

            await Assert.ThrowsAsync <NullReferenceException>(async() => await content.SignWithJsonWebSignature(_agent.Wallet, key));
        }
Beispiel #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="content"></param>
        /// <returns></returns>
        public AttachmentContent SaveOrUpdate(AttachmentContent content)
        {
            if (content == null)
            {
                return(null);
            }

            AttachmentContent attachmentContent = null;

            if (content.Id > 0)
            {
                bool isUpdate = FILE_REPOSITORY.UpdateExecute(content);

                if (isUpdate)
                {
                    attachmentContent = content;
                }
            }
            else
            {
                int id = FILE_REPOSITORY.AddExecute(content);

                if (id > 0)
                {
                    attachmentContent = FILE_REPOSITORY.GetContentByItemId(content.AttachmentItemId);
                }
            }

            return(attachmentContent);
        }
Beispiel #4
0
        public async Task VerifyReturnsFalseIfSignatureIsNull()
        {
            var base64Content = "Hello World!".ToBase64Url();
            var content       = new AttachmentContent {
                Base64 = base64Content
            };

            var result = await content.VerifyJsonWebSignature();

            Assert.False(result);
        }
        /// <summary>
        /// Deserialize fields from a FastTransferStream.
        /// </summary>
        /// <param name="stream">A FastTransferStream.</param>
        public override void Deserialize(FastTransferStream stream)
        {
            if (stream.ReadMarker(StartMarker))
            {
                this.attachmentContent = new AttachmentContent(stream);
                if (stream.ReadMarker(EndMarker))
                {
                    return;
                }
            }

            AdapterHelper.Site.Assert.Fail("The stream cannot be deserialized successfully.");
        }
        /// <summary>
        /// Deserialize fields from a FastTransferStream.
        /// </summary>
        /// <param name="stream">A FastTransferStream.</param>
        public override void Deserialize(FastTransferStream stream)
        {
            if (stream.ReadMarker(StartMarker))
            {
                this.attachmentContent = new AttachmentContent(stream);
                if (stream.ReadMarker(EndMarker))
                {
                    return;
                }
            }

            AdapterHelper.Site.Assert.Fail("The stream cannot be deserialized successfully.");
        }
        public void RemoveExpireResult()
        {
            AttachmentContent attachment = new AttachmentContent()
            {
                Content  = byteArray,
                ExpireIn = DateTime.Now.AddDays(-1)
            };

            AttachmentHelper.AttachmentResults[flag] = attachment;

            AttachmentHelper.RemoveExpireResult();

            Assert.IsTrue(AttachmentHelper.AttachmentResults.Count == 0);
        }
Beispiel #8
0
        public async Task CanVerifySignedAttachmentContent()
        {
            var base64Content = "Hello World!".ToBase64Url();
            var content       = new AttachmentContent {
                Base64 = base64Content
            };
            var key = await Crypto.CreateKeyAsync(_agent.Wallet, "{}");

            await content.SignWithJsonWebSignature(_agent.Wallet, key);

            var result = await content.VerifyJsonWebSignature();

            Assert.True(result);
        }
        public bool Add(Attachment entity)
        {
            var content = new AttachmentContent {
                Content = entity.Content
            };

            entity.InternalContent = content;

            Database.AttachmentContents.Add(content);
            Database.Attachments.Add(entity);

            Database.SaveChanges();

            return(true);
        }
Beispiel #10
0
        public async Task CanSignAttachmentContent()
        {
            var base64Content = "Hello World!".ToBase64Url();
            var content       = new AttachmentContent {
                Base64 = base64Content
            };
            var key = await Crypto.CreateKeyAsync(_agent.Wallet, "{}");

            await content.SignWithJsonWebSignature(_agent.Wallet, key);

            Assert.NotNull(content.JsonWebSignature);
            Assert.NotNull(content.JsonWebSignature.Header);
            Assert.NotNull(content.JsonWebSignature.Protected);
            Assert.NotNull(content.JsonWebSignature.Signature);
        }
Beispiel #11
0
        public async Task VerifyReturnsFalseWithWrongSignature()
        {
            var base64Content = "Hello World!".ToBase64Url();
            var content       = new AttachmentContent {
                Base64 = base64Content
            };
            var key = await Crypto.CreateKeyAsync(_agent.Wallet, "{}");

            await content.SignWithJsonWebSignature(_agent.Wallet, key);

            content.Base64 = "Changed content".ToBase64Url();

            var result = await content.VerifyJsonWebSignature();

            Assert.False(result);
        }
        /// <inheritdoc/>
        public async Task <(DidExchangeRequestMessage, ConnectionRecord)> CreateRequestAsync(IAgentContext agentContext, string did)
        {
            var key = await Did.KeyForDidAsync(await agentContext.Pool, agentContext.Wallet, did);

            var endpointResult = await _ledgerService.LookupServiceEndpointAsync(agentContext, did);

            var myDid = await Did.CreateAndStoreMyDidAsync(agentContext.Wallet, "{}");

            var connection = new ConnectionRecord
            {
                Endpoint = new AgentEndpoint {
                    Uri = endpointResult.Result.Endpoint
                },
                MyDid    = DidUtils.ConvertVerkeyToDidKey(myDid.VerKey),
                MyVk     = myDid.VerKey,
                TheirDid = did,
                TheirVk  = key,
                State    = ConnectionState.Negotiating,
            };
            await _recordService.AddAsync(agentContext.Wallet, connection);

            var provisioningRecord = await _provisioningService.GetProvisioningAsync(agentContext.Wallet);

            var didDoc = new AttachmentContent
            {
                Base64 = connection.MyDidDoc(provisioningRecord).ToJson().ToBase64Url()
            };
            await didDoc.SignWithJsonWebSignature(agentContext.Wallet, myDid.VerKey);

            var attachment = new Attachment
            {
                Id       = Guid.NewGuid().ToString(),
                MimeType = "application/json",
                Data     = didDoc
            };

            var request = new DidExchangeRequestMessage
            {
                Did    = connection.MyDid,
                Label  = provisioningRecord.Owner.Name,
                DidDoc = attachment
            };

            return(request, connection);
        }
        public void TryGetAttachmentResult()
        {
            AttachmentHelper.SetAttachmentResult(flag, byteArray);
            AttachmentHelper.TryGetAttachmentResult(flag, out var result);

            Assert.IsNotNull(result);


            AttachmentContent attachment = new AttachmentContent()
            {
                Content  = byteArray,
                ExpireIn = DateTime.Now.AddDays(-1)
            };

            AttachmentHelper.AttachmentResults[flag] = attachment;
            AttachmentHelper.TryGetAttachmentResult(flag, out var result2);

            Assert.IsNull(result2);
        }
        private static bool CheckEquality(AttachmentContent d, string name)
        {
            var dynamicName = Convert.ToString(d.FileName);

            return(name.Equals(dynamicName));
        }
Beispiel #15
0
 public void Delete(AttachmentContent attachmentContent)
 {
     _contentRepository.Delete(attachmentContent);
     _unitOfWork.SaveChangesAsync();
 }
Beispiel #16
0
 public async Task<AttachmentContent> UpdateAsync(AttachmentContent attachmentContent)
 {
     _contentRepository.Update(attachmentContent);
     await _unitOfWork.SaveChangesAsync();
     return attachmentContent;
 }