public async Task <string> CreateConnectionAsync(string counterPartyVaspId) { var counterPartyVaspCode = counterPartyVaspId.Substring(4, 8); var vaspTransportKey = await _vaspCodesService.GetTransportKeyAsync(counterPartyVaspCode); if (vaspTransportKey == null) { throw new InvalidOperationException($"Couldn't get TransportKey for vasp code {counterPartyVaspCode}"); } var sessionKey = ECDH_Key.GenerateKey(); var topic = TopicGenerator.GenerateConnectionTopic(); var privateKeyId = await _whisperRpc.RegisterKeyPairAsync(sessionKey.PrivateKey); var filter = await _whisperRpc.CreateMessageFilterAsync(topic, privateKeyId); _activeTopics.Add(topic); var connection = new Connection { Id = Guid.NewGuid().ToString("N"), Filter = filter, InboundTopic = topic, Status = ConnectionStatus.Active, CounterPartyVaspId = counterPartyVaspId, PrivateKey = sessionKey.PrivateKey, }; _connections[connection.Id] = connection; return(connection.Id); }
static async Task Main(string [] args) { var topicGenerator = new TopicGenerator(); var arguments = new AgentArgumentsParser().ParseArguments(args); var agent = new BuildAgent(topicGenerator, arguments.Version, arguments.VersionInfo); var runner = new AgentConsoleRunner <BuildAgent> (agent, arguments); await runner.RunAsync().ConfigureAwait(continueOnCapturedContext: false); }
public VaspSession( VaspContractInfo vaspContractInfo, VaspInformation vaspInfo, string counterPartyPubSigningKey, string sharedEncryptionKey, string privateSigningKey, IWhisperRpc whisperRpc, ITransportClient transportClient, ISignService signService) { this._vaspInfo = vaspInfo; this._vaspContractInfo = vaspContractInfo; this._sessionTopic = TopicGenerator.GenerateSessionTopic(); this._cancellationTokenSource = new CancellationTokenSource(); this._whisperRpc = whisperRpc; this._sharedKey = sharedEncryptionKey; this._privateSigningKey = privateSigningKey; this._counterPartyPubSigningKey = counterPartyPubSigningKey; this._messageHandlerResolverBuilder = new MessageHandlerResolverBuilder(); this._transportClient = transportClient; this._signService = signService; }
public void GetPropertyFromSubObjectWithDot() { Assert.AreEqual("FOOBAR", TopicGenerator.GetPropertyFromObject(new { Main = new { Sub = "FOOBAR" } }, "Main.Sub")); }
public void GetPropertyFromObject() { Assert.AreEqual("FOOBAR", TopicGenerator.GetPropertyFromObject(new { PropertyId = "FOOBAR" }, "PropertyId")); }
public void TextCanDoNested() { Assert.AreEqual("MenuChangeSuspected/2", TopicGenerator.GenerateTopicForObject("MenuChangeSuspected/{PropertyId.RevenueCenterId}", new { PropertyId = new { RevenueCenterId = 2 } }), "TopicGenerator should have swapped in a property"); }
public void SimpleProp() { Assert.AreEqual("test/test", TopicGenerator.GenerateTopicForObject("test/{prop}", new { prop = "test" }), "TopicGenerator should have swapped in a property"); }
public void TestDoesntAllowNullMessage() { Assert.ThrowsException <ArgumentNullException>(() => TopicGenerator.GenerateTopicForObject("test", null), "TopicGenerator shouldnt allow null messages"); }
public void TestDoesntAllowNullTopic() { Assert.ThrowsException <ArgumentNullException>(() => TopicGenerator.GenerateTopicForObject(null, new object()), "TopicGenerator shouldnt allow null topics"); }
public void TestNoWork() { Assert.AreEqual("test", TopicGenerator.GenerateTopicForObject("test", new object()), "TopicGenerator Should return topics without params in them"); }
private async Task HandleInviteMessageAsync(OpenVaspPayload payload) { var senderVaspCode = payload.SenderVaspId.Substring(4, 8); var vaspTransportKey = await _vaspCodesService.GetTransportKeyAsync(senderVaspCode); if (vaspTransportKey == null) { _logger?.LogError($"Transport key for vasp code {senderVaspCode} cannot be found during invitation processing"); return; } _connections.TryGetValue(payload.ConnectionId, out var connection); if (connection != null) { bool isSameData = connection.CounterPartyVaspId == payload.SenderVaspId && connection.OutboundTopic == payload.ReturnTopic; if (isSameData) { _logger?.LogWarning( $"Received invite for already existing connectionId {payload.ConnectionId} with the same data. Skipping."); await AcknowledgeMessageAsync( payload, null, payload.EcdhPk.DecompressPublicKey().ToHex(true)); } else { _logger?.LogWarning( $"Received invite for already existing connectionId {payload.ConnectionId} with the different data:{Environment.NewLine}" + $"SenderVaspId: {connection.CounterPartyVaspId} - {payload.SenderVaspId},{Environment.NewLine}" + $"Topic: {connection.OutboundTopic} - {payload.ReturnTopic},{Environment.NewLine}"); } return; } var topic = TopicGenerator.GenerateConnectionTopic(); var sessionKey = ECDH_Key.GenerateKey(); var sharedSecret = sessionKey.GenerateSharedSecretHex(payload.EcdhPk); var(filter, symKeyId) = await RegisterConnectionAsync(topic, sharedSecret); var newConnection = new Connection { Id = payload.ConnectionId, Filter = filter, InboundTopic = topic, OutboundTopic = payload.ReturnTopic, Status = ConnectionStatus.PartiallyActive, CounterPartyVaspId = payload.SenderVaspId, SymKeyId = symKeyId, SharedPrivateEncryptionKey = sharedSecret, PrivateKey = sessionKey.PrivateKey, CounterPartyPublicKey = payload.EcdhPk, }; _connections[newConnection.Id] = newConnection; await AcknowledgeMessageAsync( payload, null, payload.EcdhPk.DecompressPublicKey().ToHex(true)); var signingKey = await _vaspCodesService.GetSigningKeyAsync(senderVaspCode); await TriggerAsyncEvent(TransportMessageReceived, new TransportMessageEvent { ConnectionId = payload.ConnectionId, SenderVaspId = payload.SenderVaspId, Instruction = payload.Instruction, Payload = payload.OvMessage, Timestamp = DateTime.UtcNow, SigningKey = signingKey }); }