static async Task Main(string[] args)
        {
            UniversalClient _client = GetUniversalClient();

            string valueTitle = "VermeerVersion";

            UniversalPacket getValueCommand = new UniversalPacket(
                new Header()
            {
                status = UniversalPacket.HTTPSTATUS.GET
            },
                new Message()
            {
                Data = JsonConvert.SerializeObject(new string[] { "userdatabase", "getvalue", valueTitle }), IsEncrypted = true
            },
                _client.GetSignature);
            UniversalServerPacket serverReturn = _client.SendMessage(getValueCommand);

            switch (serverReturn.Message.ToUpper())
            {
            case "UNAUTHORIZED":
                break;

            case "UNKNOWNCOMMAND":
                break;

            case "USRDBS_GETVALUE_VALUEEXIST":
                break;

            default:
                break;
            }
        }
Esempio n. 2
0
        public async Task ConnectToRemoteServerAsync(string ServerIP, int ServerPort)
        {
            if (Client == null)
            {
                return;
            }

            await Client.ConnectAsync(ServerIP, ServerPort);

            if (Client.Connected)
            {
                UniversalPacket getServerPublicKeyRequest = new UniversalPacket(
                    new Header {
                    status = UniversalPacket.HTTPSTATUS.GET
                },
                    new Message {
                    Data = JsonConvert.SerializeObject(new string[] { "serverrequest.encryption.getserverpublickey" }), IsEncrypted = false
                },
                    clientSignature);
                Task <UniversalServerPacket> sendMessageTask = SendMessageAsync(getServerPublicKeyRequest);
                UniversalServerPacket        s = await sendMessageTask;
                this.Encryption.SetServerPublicKey(s.Message);

                UniversalPacket sendClientPublicKey = new UniversalPacket(
                    new Header {
                    status = UniversalPacket.HTTPSTATUS.POST
                },
                    new Message
                {
                    Data = JsonConvert.SerializeObject(new string[] { "serverrequest.encryption.setclientpublickey",
                                                                      Encryption.GetClientPublicKey() }, Formatting.None),
                    IsEncrypted = true
                },
                    clientSignature);
                Task <UniversalServerPacket> sendClientPublicKeyTask = SendMessageAsync(sendClientPublicKey);
                UniversalServerPacket        bs = await sendClientPublicKeyTask;

                UniversalPacket sendClientPrivateKey = new UniversalPacket(
                    new Header {
                    status = UniversalPacket.HTTPSTATUS.POST
                },
                    new Message
                {
                    Data = JsonConvert.SerializeObject(new string[] { "serverrequest.encryption.setclientprivatekey",
                                                                      Encryption.GetClientPrivateKey(), Encryption.GetServerPublicKey() }, Formatting.None),
                    IsEncrypted = true
                },
                    clientSignature);
                Task <UniversalServerPacket> sendClientPrivateKeyTask = SendMessageAsync(sendClientPrivateKey);
                UniversalServerPacket        bs2 = await sendClientPrivateKeyTask;
            }
        }
Esempio n. 3
0
        public async Task <UniversalServerPacket> WaitForResultAsync()
        {
            UniversalServerPacket serverPacket = null;
            await Task.Run(() =>
            {
                byte[] data            = new byte[Client.Client.ReceiveBufferSize];
                int receivedDataLength = Client.Client.Receive(data);
                serverPacket           = JsonConvert.DeserializeObject <UniversalServerPacket>
                                             (Encoding.ASCII.GetString(data, 0, receivedDataLength));

                if (serverPacket.Encrypted)
                {
                    serverPacket.Message = Encryption.Decrypt(serverPacket.Message, Encryption.GetClientPrivateKey());
                }
            });

            return(serverPacket);
        }
        public void Send(ClientWorkObject workObject, string data, bool useEncryption = true)
        {
            try
            {
                UniversalServerPacket serverPacket = new UniversalServerPacket
                {
                    Encrypted = useEncryption,
                    Message   = data
                };

                if (useEncryption)
                {
                    serverPacket.Message = workObject.Encryption.Encrypt(data, workObject.Encryption.GetClientPublicKey());
                }

                workObject.clientSocket.Send(Encoding.ASCII.GetBytes(JsonConvert.SerializeObject(serverPacket)));
            }
            catch (Exception e)
            {
                ILogger.LogExceptions(e);
                workObject.Dispose();
            }
        }