コード例 #1
0
ファイル: SecureSession.cs プロジェクト: zxshinxz/AaltoTLS
        private void SendDataCallback(IAsyncResult asyncResult)
        {
            AsyncSendDataResult asyncSendDataResult = (AsyncSendDataResult)asyncResult.AsyncState;

            try {
                _recordStream.EndSend(asyncResult);
                asyncSendDataResult.SetComplete();
            } catch (AlertException ae) {
                ProcessSendFatalAlert(new Alert(ae.AlertDescription, _handshakeSession.NegotiatedVersion));
                asyncSendDataResult.SetComplete(new Exception("Connection closed because of local alert", ae));
            } catch (IOException) {
                asyncSendDataResult.SetComplete(new EndOfStreamException("Connection closed unexpectedly"));
            } catch (Exception e) {
                ProcessSendFatalAlert(new Alert(AlertDescription.InternalError, _handshakeSession.NegotiatedVersion));
                asyncSendDataResult.SetComplete(new Exception("Connection closed because of local error", e));
            }
        }
コード例 #2
0
ファイル: SecureSession.cs プロジェクト: zxshinxz/AaltoTLS
        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);
        }
コード例 #3
0
ファイル: SecureSession.cs プロジェクト: juhovh/AaltoTLS
        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;
        }