예제 #1
0
        /// <summary>
        /// Begins the message stream encryption handshaking process
        /// </summary>
        /// <param name="socket">The socket to perform handshaking with</param>
        public virtual async ReusableTask HandshakeAsync(IConnection2 socket)
        {
            this.socket = socket ?? throw new ArgumentNullException(nameof(socket));

            // Either "1 A->B: Diffie Hellman Ya, PadA" or "2 B->A: Diffie Hellman Yb, PadB"
            // These two steps will be done simultaneously to save time due to latency
            ReusableTask first  = SendY();
            ReusableTask second = ReceiveY();

            try {
                await first.ConfigureAwait(false);

                await second.ConfigureAwait(false);
            } catch (Exception ex) {
                socket.Dispose();
                throw new EncryptionException("Encrypted handshake failed", ex);
            }
        }