示例#1
0
        private async Task SendClientFinished(CancellationToken token)
        {
            // >>> IVU: create finished message by hand
            var finishedMsg = _handshakeSession.GetOutputMessages();

            if (finishedMsg.Length != 1 || finishedMsg.First().Type != HandshakeMessageType.Finished)
            {
                throw new InvalidOperationException("Oops, I thought the handshake session should create a finished message?!?");
            }

            foreach (var msg in finishedMsg)
            {
                logger?.Debug("Sending HandshakeMessage {0} back to server...", msg.Type);
            }

            // finished message resides in only one record
            var records =
                _handshakePacketizer.ProcessHandshakeMessages(
                    _handshakeSession.NegotiatedVersion,
                    finishedMsg,
                    _recordStream.MaximumFragmentLength);

            foreach (var record in records)
            {
                _recordHandler.ProcessOutputRecord(record);
            }

            await _recordStream.SendAsync(records, token);

            // <<< IVU
        }
示例#2
0
        public void SendClientHello(Stream stream)
        {
            HandshakeClientHello hello = new HandshakeClientHello(VERSION);

            _clientRandom = hello.Random.GetBytes();
            hello.CipherSuites.Add(CIPHER_SUITE);
            hello.CompressionMethods.Add(0);

            Record record = new Record(22, VERSION);

            record.Fragment = hello.Encode();

            _recordHandler.ProcessOutputRecord(record);
            SendRecord(stream, record);
        }
示例#3
0
        public IAsyncResult BeginSend(byte[] buffer, int offset, int count,
                                      AsyncCallback asyncCallback,
                                      Object asyncState)
        {
            AsyncSendDataResult asyncSendResult = new AsyncSendDataResult(asyncCallback, asyncState);

            lock (_handshakeLock) {
                if (!_isAuthenticated)
                {
                    Exception e = new InvalidOperationException("Trying to send on an unauthenticated session");
                    asyncSendResult.SetComplete(e);
                    return(asyncSendResult);
                }
                if (_isHandshaking)
                {
                    // Queue requests to send data during renegotiation
                    // TODO: implement this when renegotiation is implemented
                    Exception e = new InvalidOperationException("Sending data during renegotiation not implemented");
                    asyncSendResult.SetComplete(e);
                    return(asyncSendResult);
                }
            }

            // Copy the bytes to send into own buffer
            byte[] outputBuffer = new byte[count];
            Buffer.BlockCopy(buffer, offset, outputBuffer, 0, count);

            // Create and encrypt the data output record
            Record[] records = _handshakePacketizer.ProcessOutputData(_handshakeSession.NegotiatedVersion,
                                                                      RecordType.Data, outputBuffer,
                                                                      _recordStream.MaximumFragmentLength);
            for (int i = 0; i < records.Length; i++)
            {
                _recordHandler.ProcessOutputRecord(records[i]);
            }

            // Send the data output record
            _recordStream.BeginSend(records, new AsyncCallback(SendDataCallback), asyncSendResult);
            return(asyncSendResult);
        }