Example #1
0
        /// <summary>
        /// Performs the handshake to the server and gets the version number of the protocol.
        /// </summary>
        /// <returns>The version of the protocol as string in format x.x.x</returns>
        /// <param name="client">Connected network client holding the socket</param>
        /// <param name="token">Cancellation Token.</param>
        protected async Task <string> DoHandshake(IConnectedNetworkClient client, CancellationToken token)
        {
            Debug.WriteLine("[BaseCommand] - starting handshake");

            await client.SendAsync(Protocol.HELLO, token);

            string answer = await client.ReceiveAsync(token);

            return(ValidateAnswer(answer));
        }
Example #2
0
        protected async Task <byte[]> SendKey(IConnectedNetworkClient client, CancellationToken token)
        {
            Debug.WriteLine("[BaseCommand] - starting send key");

            byte[] aesKey  = _cryptoService.GetSha256Hash(_cryptoService.GetRandomString(512, token));
            string crKey   = _cryptoService.EncodeRSA(_settings.GetServerPublicKey(), aesKey);
            string command = String.Format("{0}{1}{2}", Protocol.XCHANGEKEY, Protocol.SPLITTER, crKey);
            await client.SendAsync(command, token);

            string answer = await client.ReceiveAsync(token);

            ValidateAnswer(answer);
            return(aesKey);
        }
Example #3
0
        protected override async Task <int> Run(string value = default(string), CancellationToken token = default(CancellationToken))
        {
            Debug.WriteLine("[Call] -  running");
            IConnectedNetworkClient client = null;

            try {
                var flashCommand = BuildFlashCommand();
                client = await Connect(token);

                var version = await DoHandshake(client, token);

                Debug.WriteLine("Protocol version: {0}\ncommand: {1} ", version, flashCommand);
                // todo call sendkey, check answer lrc
                await client.SendAsync(flashCommand);
            } finally {
                if (client != null)
                {
                    client.Close();
                }
            }
            return(0);
        }