public async Task HandleAsync() { ConversationsUsersNodeResponse response; List <ChatUserVm> chatsUsers = new List <ChatUserVm>(); List <ChannelUserVm> channelsUsers = new List <ChannelUserVm>(); foreach (long id in nodeRequest.ConversationsIds) { switch (nodeRequest.ConversationType) { case ObjectsLibrary.Enums.ConversationType.Chat: { chatsUsers.AddRange(await loadChatsService.GetChatUsersAsync(id, null, int.MaxValue).ConfigureAwait(false)); } break; case ObjectsLibrary.Enums.ConversationType.Channel: { channelsUsers.AddRange(await loadChannelsService.GetChannelUsersAsync(id, null, null).ConfigureAwait(false)); } break; } } response = new ConversationsUsersNodeResponse(nodeRequest.RequestId, chatsUsers, channelsUsers); await NodeWebSocketCommunicationManager.SendResponseAsync(response, nodeConnection).ConfigureAwait(false); }
public async Task HandleAsync() { NodeResponse response; if (request.KeyId == null) { response = new PublicKeyNodeResponse( request.RequestId, NodeData.Instance.NodeKeys.PublicKey, NodeData.Instance.NodeKeys.SignPublicKey, NodeData.Instance.NodeKeys.KeyId, NodeData.Instance.NodeKeys.ExpirationTime); } else { var key = await keysService.GetNodeKeysAsync(NodeSettings.Configs.Node.Id, request.KeyId.Value); if (key == null) { response = new ResultNodeResponse(request.RequestId, ObjectsLibrary.Enums.ErrorCode.ObjectDoesNotExists, "The key was not found."); } else { response = new PublicKeyNodeResponse(request.RequestId, key.PublicKey, key.SignPublicKey, key.KeyId, key.ExpirationTime); } } await NodeWebSocketCommunicationManager.SendResponseAsync(response, current).ConfigureAwait(false); }
public async Task HandleAsync() { try { var nodeKey = request.Keys; ConnectData connectData = request.GetConnectData(nodeKey.SignPublicKey, NodeData.Instance.NodeKeys.Password, NodeData.Instance.NodeKeys.PrivateKey); nodeConnection.Node = connectData.Node; nodeConnection.Node.StartDay = nodeConnection.Node.StartDay.ToUniversalTime(); var nodeJson = ObjectSerializer.ObjectToJson(nodeConnection.Node); bool isValid = Encryptor.CheckSign( connectData.LicensorSign, LicensorClient.Instance.GetSignPublicKey(), Encoding.UTF8.GetBytes(nodeJson), NodeData.Instance.NodeKeys.Password); if (!isValid) { NodeWebSocketCommunicationManager.SendResponse( new ResultNodeResponse(request.RequestId, ErrorCode.AuthorizationProblem, "Wrong sign for node data."), nodeConnection); } LicenseVm license = connectData.License; long currentTime = DateTime.UtcNow.ToUnixTime(); if (!license.IsLicenseValid(currentTime, LicensorClient.Instance.GetSignPublicKey(), NodeData.Instance.NodeKeys.Password, out _)) { var licenseFromLicensor = await LicensorClient.Instance.GetLicenseAsync(nodeConnection.Node.Id).ConfigureAwait(false); if (!licenseFromLicensor.IsLicenseValid(currentTime, LicensorClient.Instance.GetSignPublicKey(), NodeData.Instance.NodeKeys.Password, out var errorMessage)) { var isBlockchainLicenseValid = await BlockchainReadService.IsNodeLicenseValidAsync(nodeConnection.Node.Id, currentTime).ConfigureAwait(false); if (!isBlockchainLicenseValid) { NodeWebSocketCommunicationManager.SendResponse( new ResultNodeResponse(request.RequestId, ErrorCode.AuthorizationProblem, errorMessage), nodeConnection); } } } nodeConnection.Uri = new Uri($"wss://{nodeConnection.Node.Domains.FirstOrDefault()}:{nodeConnection.Node.NodesPort}"); ConnectData responseConnectData = new ConnectData { Node = NodeSettings.Configs.Node, LicensorSign = NodeSettings.Configs.LicensorSign.Sign, License = NodeSettings.Configs.License }; byte[] encryptedData = Encryptor.SymmetricDataEncrypt( ObjectSerializer.ObjectToByteArray(responseConnectData), NodeData.Instance.NodeKeys.SignPrivateKey, connectData.SymmetricKey, MessageDataType.Binary, NodeData.Instance.NodeKeys.Password); await NodeWebSocketCommunicationManager.SendResponseAsync(new NodesInformationResponse(request.RequestId, encryptedData), nodeConnection).ConfigureAwait(false); nodeConnection.PublicKey = nodeKey.PublicKey; nodeConnection.SymmetricKey = connectData.SymmetricKey; nodeConnection.Node.NodeKey.EncPublicKey = nodeKey.PublicKey; nodeConnection.PublicKeyExpirationTime = nodeKey.ExpirationTime; nodeConnection.PublicKeyId = nodeKey.KeyId; nodeConnection.SignPublicKey = nodeKey.SignPublicKey; nodesService.CreateOrUpdateNodeInformationAsync(nodeConnection.Node); connectionsService.AddOrUpdateNodeConnection(nodeConnection.Node.Id, nodeConnection); await Task.Delay(TimeSpan.FromSeconds(1)).ConfigureAwait(false); await nodeNoticeService.SendPendingMessagesAsync(nodeConnection.Node.Id).ConfigureAwait(false); } catch (Exception ex) { Logger.WriteLog(ex); NodeWebSocketCommunicationManager.SendResponse(new ResultNodeResponse(request.RequestId, ErrorCode.UnknownError, ex.Message), nodeConnection); } }