Esempio n. 1
0
        public async Task PerformClientHandshake(CancellationToken token)
        {
            if (_isHandshaking)
            {
                throw new InvalidOperationException("Handshake already in progress");
            }

            if (_isAuthenticated)
            {
                throw new InvalidOperationException("Renegotiation not supported");
            }

            // Create record protocol handler
            _recordHandler = new RecordHandler(_securityParameters.MinimumVersion, isClient: true);

            // Create handshake protocol sub handler
            _handshakeSession = new ClientHandshakeSession(_securityParameters);
            _isHandshaking    = true;

            await SendClientHello(token);
            await ReceiveServerHello(token);
            await SendClientKeyExchange(token);

            await Task.Delay(100);

            //await this.ReceiveAlert(token);

            await SendClientChangeCipherSpec(token);
            await SendClientFinished(token);
            await ReceiveChangeCipherSpecAndFinished(token);

            _isHandshaking   = false;
            _isAuthenticated = true;
        }
Esempio n. 2
0
        public IAsyncResult BeginServerHandshake(X509Certificate serverCertificate,
                                                 AsyncCallback asyncCallback,
                                                 Object asyncState)
        {
            lock (_handshakeLock) {
                if (_isHandshaking)
                {
                    throw new InvalidOperationException("Handshake already in progress");
                }

                if (_isAuthenticated)
                {
                    throw new InvalidOperationException("Renegotiation not supported");
                }

                _recordHandler    = new RecordHandler(_securityParameters.MinimumVersion, false);
                _handshakeSession = new ServerHandshakeSession(_securityParameters);
                _isHandshaking    = true;
            }

            AsyncHandshakeResult asyncHandshakeResult = new AsyncHandshakeResult(asyncCallback, asyncState);

            _recordStream.BeginReceive(new AsyncCallback(ReceiveHandshakeCallback), asyncHandshakeResult);
            return(asyncHandshakeResult);
        }
Esempio n. 3
0
        public async Task PerformServerHandshake(X509Certificate serverCertificate, CancellationToken token)
        {
            if (_isHandshaking)
            {
                throw new InvalidOperationException("Handshake already in progress");
            }

            if (_isAuthenticated)
            {
                throw new InvalidOperationException("Renegotiation not supported");
            }

            _recordHandler    = new RecordHandler(_securityParameters.MinimumVersion, isClient: false);
            _handshakeSession = new ServerHandshakeSession(_securityParameters);
            _isHandshaking    = true;

            var timoutCts = new CancellationTokenSource(TimeSpan.FromSeconds(30));
            var cts       = CancellationTokenSource.CreateLinkedTokenSource(token, timoutCts.Token);

            await ReceiveClientHello(cts.Token);
            await SendServerHello(cts.Token);
            await ReceiveClientKeyExchangeChangeCipherSpecAndFinished(cts.Token);
            await SendServerChangeCipherSpec(cts.Token);
            await SendServerFinished(cts.Token);

            _isHandshaking   = false;
            _isAuthenticated = true;
        }
Esempio n. 4
0
        public IAsyncResult BeginClientHandshake(string targetHost,
                                                 AsyncCallback asyncCallback,
                                                 Object asyncState)
        {
            lock (_handshakeLock) {
                if (_isHandshaking)
                {
                    throw new InvalidOperationException("Handshake already in progress");
                }

                if (_isAuthenticated)
                {
                    throw new InvalidOperationException("Renegotiation not supported");
                }

                _recordHandler    = new RecordHandler(_securityParameters.MinimumVersion, true);
                _handshakeSession = new ClientHandshakeSession(_securityParameters);
                _isHandshaking    = true;
            }

            AsyncHandshakeResult asyncHandshakeResult = new AsyncHandshakeResult(asyncCallback, asyncState);

            ProcessSendHandshakePacket(asyncHandshakeResult);
            return(asyncHandshakeResult);
        }