internal Task <int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) { ValidateParameters(buffer, offset, count); SslReadAsync read = new SslReadAsync(_sslState, cancellationToken); return(ReadAsyncInternal(read, new Memory <byte>(buffer, offset, count)).AsTask()); }
internal async Task ForceAuthenticationAsync(bool receiveFirst, byte[] buffer, CancellationToken cancellationToken) { _framing = Framing.Unknown; ProtocolToken message; SslReadAsync adapter = new SslReadAsync(this, cancellationToken); if (!receiveFirst) { message = _context.NextMessage(buffer, 0, (buffer == null ? 0 : buffer.Length)); if (message.Failed) { // tracing done in NextMessage() throw new AuthenticationException(SR.net_auth_SSPI, message.GetException()); } await InnerStream.WriteAsync(message.Payload, cancellationToken).ConfigureAwait(false); } do { message = await ReceiveBlobAsync(adapter, buffer, cancellationToken).ConfigureAwait(false); if (message.Size > 0) { // If there is message send it out even if call failed. It may contain TLS Alert. await InnerStream.WriteAsync(message.Payload, cancellationToken).ConfigureAwait(false); } if (message.Failed) { throw new AuthenticationException(SR.net_auth_SSPI, message.GetException()); } } while (message.Status.ErrorCode != SecurityStatusPalErrorCode.OK); ProtocolToken alertToken = null; if (!CompleteHandshake(ref alertToken)) { SendAuthResetSignal(alertToken, ExceptionDispatchInfo.Capture(new AuthenticationException(SR.net_ssl_io_cert_validation, null))); } if (NetEventSource.IsEnabled) { NetEventSource.Log.SspiSelectedCipherSuite(nameof(ForceAuthenticationAsync), SslProtocol, CipherAlgorithm, CipherStrength, HashAlgorithm, HashStrength, KeyExchangeAlgorithm, KeyExchangeStrength); } }
private async ValueTask <ProtocolToken> ReceiveBlobAsync(SslReadAsync adapter, byte[] buffer, CancellationToken cancellationToken) { ResetReadBuffer(); int readBytes = await FillBufferAsync(adapter, SecureChannel.ReadHeaderSize).ConfigureAwait(false); if (readBytes == 0) { throw new IOException(SR.net_io_eof); } if (_framing == Framing.Unified || _framing == Framing.Unknown) { _framing = DetectFraming(_internalBuffer, readBytes); } int payloadBytes = GetRemainingFrameSize(_internalBuffer, _internalOffset, readBytes); if (payloadBytes < 0) { throw new IOException(SR.net_frame_read_size); } int frameSize = SecureChannel.ReadHeaderSize + payloadBytes; if (readBytes < frameSize) { readBytes = await FillBufferAsync(adapter, frameSize).ConfigureAwait(false); Debug.Assert(readBytes >= 0); if (readBytes == 0) { throw new IOException(SR.net_io_eof); } } ProtocolToken token = _context.NextMessage(_internalBuffer, _internalOffset, frameSize); ConsumeBufferedBytes(frameSize); return(token); }
internal ValueTask <int> ReadAsync(Memory <byte> buffer, CancellationToken cancellationToken) { SslReadAsync read = new SslReadAsync(_sslState, cancellationToken); return(ReadAsyncInternal(read, buffer)); }