/// <inheritdoc /> public virtual async Task <string> AcceptInvitationAsync(Wallet wallet, ConnectionInvitationMessage invitation) { Logger.LogInformation(LoggingEvents.AcceptInvitation, "Key {0}, Endpoint {1}", invitation.ConnectionKey, invitation.Endpoint.Uri); var my = await Did.CreateAndStoreMyDidAsync(wallet, "{}"); var connection = new ConnectionRecord { Endpoint = invitation.Endpoint, MyDid = my.Did, MyVk = my.VerKey, ConnectionId = Guid.NewGuid().ToString().ToLowerInvariant() }; connection.Tags.Add(TagConstants.MyDid, my.Did); if (!string.IsNullOrEmpty(invitation.Name) || !string.IsNullOrEmpty(invitation.ImageUrl)) { connection.Alias = new ConnectionAlias { Name = invitation.Name, ImageUrl = invitation.ImageUrl }; if (string.IsNullOrEmpty(invitation.Name)) { connection.Tags.Add(TagConstants.Alias, invitation.Name); } } await connection.TriggerAsync(ConnectionTrigger.InvitationAccept); await RecordService.AddAsync(wallet, connection); var provisioning = await ProvisioningService.GetProvisioningAsync(wallet); var connectionDetails = new ConnectionDetails { Did = my.Did, Verkey = my.VerKey, Endpoint = provisioning.Endpoint }; var request = await MessageSerializer.PackSealedAsync <ConnectionRequestMessage>(connectionDetails, wallet, my.VerKey, invitation.ConnectionKey); request.Key = invitation.ConnectionKey; request.Type = MessageUtils.FormatKeyMessageType(invitation.ConnectionKey, MessageTypes.ConnectionRequest); var forwardMessage = new ForwardToKeyEnvelopeMessage { Type = MessageUtils.FormatKeyMessageType(invitation.ConnectionKey, MessageTypes.ForwardToKey), Content = request.ToJson() }; await RouterService.ForwardAsync(forwardMessage, invitation.Endpoint); return(connection.GetId()); }
public async Task AnonPrepareMessageRoutingAsync() { var message = new ConnectionInvitationMessage { RecipientKeys = new[] { "123" } }; var recipient = await Did.CreateAndStoreMyDidAsync(_wallet, "{}"); var routingRecipient = await Did.CreateAndStoreMyDidAsync(_wallet, "{}"); var encrypted = await _messagingService.PrepareAsync(_wallet, message, recipient.VerKey, new [] { routingRecipient.VerKey }); var unpackRes = await CryptoUtils.UnpackAsync(_wallet, encrypted); var unpackMsg = JsonConvert.DeserializeObject <ForwardMessage>(unpackRes.Message); Assert.NotNull(unpackMsg); Assert.True(string.IsNullOrEmpty(unpackRes.SenderVerkey)); Assert.True(unpackRes.RecipientVerkey == routingRecipient.VerKey); Assert.Equal(recipient.VerKey, unpackMsg.To); var unpackRes1 = await CryptoUtils.UnpackAsync(_wallet, unpackMsg.Message.GetUTF8Bytes()); var unpackMsg1 = JsonConvert.DeserializeObject <ConnectionInvitationMessage>(unpackRes1.Message); Assert.NotNull(unpackMsg1); Assert.True(string.IsNullOrEmpty(unpackRes1.SenderVerkey)); Assert.True(unpackRes1.RecipientVerkey == recipient.VerKey); Assert.Equal("123", unpackMsg1.RecipientKeys[0]); }
private async Task CreateConnection(IAgentContext context, ConnectionInvitationMessage invite) { var logger = App.Container.Resolve <ILogger <AcceptInviteViewModel> >(); var fmt = new JsonSerializerSettings { Formatting = Formatting.Indented }; logger.LogTrace($"context = {context.ToJson(fmt)}"); logger.LogTrace($"_invite = {_invite.ToJson(fmt)}"); var provisioningRecord = await _provisioningService.GetProvisioningAsync(context.Wallet); logger.LogTrace($"provisioningRecord = {provisioningRecord.ToJson(new JsonSerializerSettings{Formatting = Formatting.Indented})}"); var isEndpointUriAbsent = provisioningRecord.Endpoint.Uri == null; var(msg, rec) = await _connectionService.CreateRequestAsync(context, _invite); msg.Label = DeviceInfo.Name + " osma agent"; logger.LogTrace($"Connection Message (msg) being Sent = {msg.ToJson(fmt)}"); logger.LogTrace($"ConnectionRecord (rec) being saved = {rec.ToJson(fmt)}"); var rsp = await _messageService.SendAsync(context.Wallet, msg, rec, _invite.RecipientKeys.First(), isEndpointUriAbsent); logger.LogTrace($"rsp = {rsp.ToJson(fmt)}"); if (isEndpointUriAbsent) { var response = rsp.GetMessage <ConnectionResponseMessage>(); logger.LogTrace($"response = {response.ToJson(fmt)}"); await _connectionService.ProcessResponseAsync(context, response, rec); } }
public async Task AuthPrepareMessageNoRoutingAsync() { var message = new ConnectionInvitationMessage { RecipientKeys = new[] { "123" } }; var recipient = await Did.CreateAndStoreMyDidAsync(_wallet, "{}"); var sender = await Did.CreateAndStoreMyDidAsync(_wallet, "{}"); var agentContext = new AgentContext() { Wallet = _wallet }; var encrypted = await CryptoUtils.PrepareAsync(agentContext, message, recipient.VerKey, new string[0], sender.VerKey); var unpackRes = await CryptoUtils.UnpackAsync(_wallet, encrypted); var unpackMsg = JsonConvert.DeserializeObject <ConnectionInvitationMessage>(unpackRes.Message); Assert.NotNull(unpackMsg); Assert.True(unpackRes.SenderVerkey == sender.VerKey); Assert.True(unpackRes.RecipientVerkey == recipient.VerKey); Assert.Equal("123", unpackMsg.RecipientKeys[0]); }
public async Task ScanInvite() { ConnectionInvitationMessage invitation = null; bool isEmulated = false; //ONLY FOR TESTING if (!isEmulated) { var expectedFormat = ZXing.BarcodeFormat.QR_CODE; var opts = new ZXing.Mobile.MobileBarcodeScanningOptions { PossibleFormats = new List <ZXing.BarcodeFormat> { expectedFormat } }; var scanner = new ZXing.Mobile.MobileBarcodeScanner(); var result = await scanner.Scan(opts); if (result == null) { return; } try { invitation = await MessageDecoder.ParseMessageAsync(result.Text) as ConnectionInvitationMessage ?? throw new Exception("Unknown message type"); } catch (Exception) { DialogService.Alert("Invalid invitation!"); return; } } else { invitation = new ConnectionInvitationMessage() { Id = "453b0d8e-50d0-4a18-bf44-7d7369a0c31f", Label = "Verifier", Type = "did:sov:BzCbsNYhMrjHiqZDTUASHg;spec/connections/1.0/invitation", ImageUrl = "", RecipientKeys = new List <string>() { "DPqj1fdVajDYdVgeT36NUSoVghjkapaHpVUdwbL1z6ye" }, RoutingKeys = new List <string>() { "9RUPb4jPtR2S1P9yVy85ugwiywqqzDfxRrDZnKCTQCtH" }, ServiceEndpoint = "http://mylocalhost:5002" }; } Device.BeginInvokeOnMainThread(async() => { await NavigationService.NavigateToAsync <AcceptInviteViewModel>(invitation, NavigationType.Modal); }); }
public async Task PrepareMessageForMultipleRoutingHops() { var message = new ConnectionInvitationMessage { RecipientKeys = new[] { "123" } }; var json = message.ToJson(); var messageBack = json.ToObject <ConnectionInvitationMessage>(); var keys = new { Sender = await Did.CreateAndStoreMyDidAsync(_wallet, "{}"), Recipient = await Did.CreateAndStoreMyDidAsync(_wallet, "{}"), RoutingOne = await Did.CreateAndStoreMyDidAsync(_wallet, "{}"), RoutingTwo = await Did.CreateAndStoreMyDidAsync(_wallet, "{}") }; // Prepare the message for transport by packing the agent message with multiple forward messages var transportMessage = await CryptoUtils.PrepareAsync( wallet : _wallet, message : message, recipientKey : keys.Recipient.VerKey, routingKeys : new[] { keys.RoutingOne.VerKey, keys.RoutingTwo.VerKey }, senderKey : keys.Sender.VerKey); // Unpack and assert outter forward message var outterResult = await CryptoUtils.UnpackAsync(_wallet, transportMessage); var outterMessage = outterResult.Message.ToObject <ForwardMessage>(); Assert.Equal(keys.RoutingTwo.VerKey, outterResult.RecipientVerkey); Assert.Null(outterResult.SenderVerkey); Assert.NotNull(outterMessage); Assert.Equal(outterMessage.To, keys.RoutingOne.VerKey); // Unpack and test inner forward message var innerResult = await CryptoUtils.UnpackAsync(_wallet, outterMessage.Message.ToJson().GetUTF8Bytes()); var innerMessage = innerResult.Message.ToObject <ForwardMessage>(); Assert.Equal(keys.RoutingOne.VerKey, innerResult.RecipientVerkey); Assert.Null(innerResult.SenderVerkey); Assert.NotNull(innerMessage); Assert.Equal(innerMessage.To, keys.Recipient.VerKey); // Unpack and test inner content message var contentResult = await CryptoUtils.UnpackAsync(_wallet, innerMessage.Message.ToJson().GetUTF8Bytes()); var contentMessage = contentResult.Message.ToObject <ConnectionInvitationMessage>(); Assert.Equal(keys.Recipient.VerKey, contentResult.RecipientVerkey); Assert.Equal(keys.Sender.VerKey, contentResult.SenderVerkey); Assert.NotNull(contentMessage); Assert.NotEmpty(contentMessage.RecipientKeys); Assert.Single(contentMessage.RecipientKeys); Assert.Equal("123", contentMessage.RecipientKeys.First()); }
public void CanEncodeMessageToUrl() { var message = new ConnectionInvitationMessage(); var exampleUrl = "http://example.com"; var encodedMessage = MessageUtils.EncodeMessageToUrlFormat(exampleUrl, message); Uri.IsWellFormedUriString(encodedMessage, UriKind.Absolute); }
public override Task InitializeAsync(object navigationData) { if (navigationData is ConnectionInvitationMessage invite) { InviteTitle = $"{invite.Label}"; InviterUrl = invite.ImageUrl; InviteContents = AppResources.ConnectionInviteMessage; _invite = invite; } return(base.InitializeAsync(navigationData)); }
public override Task InitializeAsync(object navigationData) { if (navigationData is ConnectionInvitationMessage invite) { InviteTitle = $"Trust {invite.Label}?"; InviterUrl = invite.ImageUrl; InviteContents = $"{invite.Label} would like to establish a pairwise DID connection with you. This will allow secure communication between you and {invite.Label}."; _invite = invite; } return(base.InitializeAsync(navigationData)); }
public CreateInvitationResponse ( Guid aRequestId, ConnectionInvitationMessage aConnectionInvitationMessage, ConnectionRecord aConnectionRecord, string aInvitationUrl ) : base(aRequestId) { ConnectionInvitationMessage = aConnectionInvitationMessage; ConnectionRecord = aConnectionRecord; InvitationUrl = aInvitationUrl; }
public void CanConvertUnsecuredMessage() { var expected = new ConnectionInvitationMessage { ConnectionKey = "123" }; var json = JsonConvert.SerializeObject(expected); var actual = JsonConvert.DeserializeObject <IUnsecuredMessage>(json); Assert.IsType <ConnectionInvitationMessage>(actual); Assert.Equal("123", ((ConnectionInvitationMessage)actual).ConnectionKey); }
public override Task InitializeAsync(object navigationData) { if (navigationData is ConnectionInvitationMessage invitation) { InvitationTitle = $"Connect to {invitation.Label}?"; InvitationImageUrl = invitation.ImageUrl; InvitationContents = $"{invitation.Label} has invited you to connect?"; InvitationLabel = invitation.Label; _invitation = invitation; } return(base.InitializeAsync(navigationData)); }
internal static void ValidateReceiveInvitationResponse ( ReceiveInvitationRequest aReceiveInvitationRequest, ReceiveInvitationResponse aReceiveInvitationRespone ) { aReceiveInvitationRespone.CorrelationId.Should().Be(aReceiveInvitationRequest.CorrelationId); ConnectionInvitationMessage connectionInvitationMessage = aReceiveInvitationRespone.ConnectionInvitationMessage; connectionInvitationMessage.Should().NotBeNull(); // check Other properties here }
public async Task PackAuth() { var message = new ConnectionInvitationMessage { RecipientKeys = new[] { "123" } }.ToByteArray(); var my = await Did.CreateAndStoreMyDidAsync(_wallet, "{}"); var anotherMy = await Did.CreateAndStoreMyDidAsync(_wallet, "{}"); var packed = await CryptoUtils.PackAsync(_wallet, anotherMy.VerKey, message, my.VerKey); Assert.NotNull(packed); }
/// <inheritdoc /> public (string sessionId, ConnectionInvitationMessage connectionInvitationMessage, bool awaitableConnection) ReadTransactionUrl(string invitationUrl) { string sessionId = null; ConnectionInvitationMessage invitationMessage = null; bool awaitableConnection = false; Uri uri = null; try { uri = new Uri(invitationUrl); } catch (Exception) { return(null, null, false); } try { if (uri.Query.StartsWith("?t_o=")) { var arguments = uri.Query .Substring(1) // Remove '?' .Split('&') .Select(q => q.Split('=')) .ToDictionary(q => q.FirstOrDefault(), q => q.Skip(1).FirstOrDefault()); sessionId = arguments["t_o"]; invitationMessage = arguments["c_i"].FromBase64().ToObject <ConnectionInvitationMessage>(); try { awaitableConnection = bool.Parse(arguments["wait"]); } catch (Exception) { awaitableConnection = false; } return(sessionId, invitationMessage, awaitableConnection); } } catch (Exception e) { Debug.WriteLine(e); } return(sessionId, invitationMessage, awaitableConnection); }
public async Task <ReceiveInvitationResponse> Handle ( ReceiveInvitationRequest aReceiveInvitationRequest, CancellationToken aCancellationToken ) { ConnectionInvitationMessage connectionInvitationMessage = MessageUtils .DecodeMessageFromUrlFormat <ConnectionInvitationMessage>(aReceiveInvitationRequest.InvitationDetails); var response = new ReceiveInvitationResponse(aReceiveInvitationRequest.CorrelationId, connectionInvitationMessage); return(await Task.Run(() => response)); }
private async Task CreateConnection(IAgentContext context, ConnectionInvitationMessage invite) { var provisioningRecord = await _provisioningService.GetProvisioningAsync(context.Wallet); var isEndpointUriAbsent = provisioningRecord.Endpoint.Uri == null; var(msg, rec) = await _connectionService.CreateRequestAsync(context, _invitation); var rsp = await _messageService.SendReceiveAsync <ConnectionResponseMessage>(context.Wallet, msg, rec); if (isEndpointUriAbsent) { await _connectionService.ProcessResponseAsync(context, rsp, rec); } }
public async Task PackAnon() { var message = new ConnectionInvitationMessage() { ConnectionKey = "123" }.ToByteArray(); var my = await Did.CreateAndStoreMyDidAsync(_wallet, "{}"); var anotherMy = await Did.CreateAndStoreMyDidAsync(_wallet, "{}"); var packed = await CryptoUtils.PackAsync(_wallet, anotherMy.VerKey, null, message); Assert.NotNull(packed); }
public void ThreadFromThrowsExceptionOnAlreadyThreadedMessage() { var message = new ConnectionRequestMessage(); var threadId = Guid.NewGuid().ToString(); message.AddDecorator(new ThreadDecorator() { ThreadId = threadId }, "thread"); var inboundMessage = new ConnectionInvitationMessage(); var ex = Assert.Throws <AriesFrameworkException>(() => message.ThreadFrom(inboundMessage)); Assert.True(ex.ErrorCode == ErrorCode.InvalidMessage); }
public async Task UnpackToCustomType() { var message = new ConnectionInvitationMessage { RecipientKeys = new [] { "123" } }; var my = await Did.CreateAndStoreMyDidAsync(_wallet, "{}"); var anotherMy = await Did.CreateAndStoreMyDidAsync(_wallet, "{}"); var packed = await CryptoUtils.PackAsync(_wallet, anotherMy.VerKey, message, null); var unpack = await CryptoUtils.UnpackAsync <ConnectionInvitationMessage>(_wallet, packed); Assert.NotNull(unpack); Assert.Equal("123", unpack.RecipientKeys[0]); }
/// <inheritdoc /> public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { IUnsecuredMessage message; var item = JObject.Load(reader); switch (item["@type"].ToObject <string>()) { case MessageTypes.ConnectionInvitation: message = new ConnectionInvitationMessage(); break; default: throw new TypeLoadException("Unsupported serialization type."); } serializer.Populate(item.CreateReader(), message); return(message); }
public async Task PackAndUnpackAnon() { var message = new ConnectionInvitationMessage { RecipientKeys = new[] { "123" } }; var my = await Did.CreateAndStoreMyDidAsync(_wallet, "{}"); var anotherMy = await Did.CreateAndStoreMyDidAsync(_wallet, "{}"); var packed = await CryptoUtils.PackAsync(_wallet, anotherMy.VerKey, message, null); var unpack = await CryptoUtils.UnpackAsync(_wallet, packed); Assert.NotNull(unpack); Assert.Null(unpack.SenderVerkey); Assert.NotNull(unpack.RecipientVerkey); Assert.Equal(unpack.RecipientVerkey, anotherMy.VerKey); }
public async Task <AcceptInvitationResponse> Handle ( AcceptInvitationRequest aAcceptInvitationRequest, CancellationToken aCancellationToken ) { IAgentContext agentContext = await AgentProvider.GetContextAsync(); ConnectionInvitationMessage connectionInvitationMessage = MessageUtils .DecodeMessageFromUrlFormat <ConnectionInvitationMessage>(aAcceptInvitationRequest.InvitationDetails); (ConnectionRequestMessage connectionRequestMessage, ConnectionRecord connectionRecord) = await ConnectionService.CreateRequestAsync(agentContext, connectionInvitationMessage); await MessageService.SendAsync(agentContext, connectionRequestMessage, connectionRecord); var response = new AcceptInvitationResponse(aAcceptInvitationRequest.CorrelationId); return(response); }
public async Task PackAndUnpackAuth() { var message = new ConnectionInvitationMessage { RecipientKeys = new[] { "123" } }.ToByteArray(); var my = await Did.CreateAndStoreMyDidAsync(_wallet, "{}"); var anotherMy = await Did.CreateAndStoreMyDidAsync(_wallet, "{}"); var packed = await CryptoUtils.PackAsync(_wallet, anotherMy.VerKey, message, my.VerKey); var unpack = await CryptoUtils.UnpackAsync(_wallet, packed); var jObject = JObject.Parse(unpack.Message); Assert.NotNull(unpack); Assert.NotNull(unpack.SenderVerkey); Assert.NotNull(unpack.RecipientVerkey); Assert.Equal(unpack.RecipientVerkey, anotherMy.VerKey); Assert.Equal(unpack.SenderVerkey, my.VerKey); Assert.Equal(MessageTypes.ConnectionInvitation, jObject["@type"].ToObject <string>()); }
private async Task <bool> CreateConnection(IAgentContext context, ConnectionInvitationMessage invite) { var provisioningRecord = await _provisioningService.GetProvisioningAsync(context.Wallet); if (provisioningRecord.Endpoint.Uri != null) { try { var(msg, rec) = await _connectionService.CreateRequestAsync(context, _invite); await _messageService.SendAsync(context.Wallet, msg, rec, _invite.RecipientKeys.First()); return(true); } catch (Exception) //TODO more granular error protection { return(false); } } else { try { var(msg, rec) = await _connectionService.CreateRequestAsync(context, _invite); var rsp = await _messageService.SendAsync(context.Wallet, msg, rec, _invite.RecipientKeys.First(), true); await _connectionService.ProcessResponseAsync(context, rsp.GetMessage <ConnectionResponseMessage>(), rec); return(true); } catch (Exception) //TODO more granular error protection { return(false); } } }
private async Task CreateConnection(IAgentContext context, ConnectionInvitationMessage invite) { var provisioningRecord = await _provisioningService.GetProvisioningAsync(context.Wallet); var isEndpointUriAbsent = provisioningRecord.Endpoint.Uri == null; var(msg, connection) = await _connectionService.CreateRequestAsync(context, invite); msg.Label = msg.Label == null ? "OsmaAgent" : msg.Label; var recipientKey = invite.RecipientKeys.First() ?? connection.TheirVk ?? throw new AriesFrameworkException( ErrorCode.A2AMessageTransmissionError, "Cannot find encryption key"); var routingKeys = connection.Endpoint?.Verkey != null ? new[] { connection.Endpoint.Verkey } : new string[0]; if (connection.Endpoint?.Uri == null) { throw new AriesFrameworkException(ErrorCode.A2AMessageTransmissionError, "Cannot send to connection that does not have endpoint information specified"); } if (isEndpointUriAbsent) { var rsp = await _messageService.SendReceiveAsync(context.Wallet, msg, recipientKey, connection.Endpoint.Uri, routingKeys, connection.MyVk); var unpackedRsp = (UnpackedMessageContext)rsp; await _connectionService.ProcessResponseAsync(context, unpackedRsp.GetMessage <ConnectionResponseMessage>(), connection); } else { await _messageService.SendAsync(context.Wallet, msg, recipientKey, connection.Endpoint.Uri, routingKeys, connection.MyVk); } }
/// <summary> /// Encodes the invitation to a base64 string which can be presented to the user as QR code or a deep link Url /// </summary> /// <returns>The invitation.</returns> /// <param name="invitation">Invitation.</param> public string EncodeInvitation(ConnectionInvitationMessage invitation) { return(Convert.ToBase64String(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(invitation)))); }
public Task <(ConnectionRequestMessage, ConnectionRecord)> CreateRequestAsync(IAgentContext agentContext, ConnectionInvitationMessage offer) { throw new System.NotImplementedException(); }
public async Task <ConnectionRecord> ProcessInvitationAsync(IAgentContext agentContext, ConnectionInvitationMessage offer) { throw new System.NotImplementedException(); }
public ReceiveInvitationResponse(Guid aCorrelationId, ConnectionInvitationMessage aConnectionInvitationMessage) : base(aCorrelationId) { ConnectionInvitationMessage = aConnectionInvitationMessage; }