Esempio n. 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));
        }
Esempio n. 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);
        }