Esempio n. 1
0
        /// <inheritdoc/>
        public override async ValueTask DisposeAsync(CancellationToken cancellationToken)
        {
            await _connection.DisposeAsync(cancellationToken).ConfigureAwait(false);

            _readBuffer.Dispose();
            _writeBuffer.Dispose();
        }
Esempio n. 2
0
 public void ReturnBuffer()
 {
     _buffer.Dispose();
     _decryptedLength  = 0;
     _decryptedPadding = 0;
     _isValid          = false;
 }
Esempio n. 3
0
 public void TestCreateEmpty(ArrayBuffer arrayBuffer)
 {
     try {
         // Test ArrayBufferBase interface
         base.TestCreateEmpty(arrayBuffer);
     } finally {
         arrayBuffer.Dispose();
     }
 }
Esempio n. 4
0
 public override ValueTask DisposeAsync()
 {
     _readBuffer.Dispose();
     return(_connection.DisposeAsync());
 }
Esempio n. 5
0
        // reAuthenticationData is only used on Windows in case of renegotiation.
        private async Task ForceAuthenticationAsync <TIOAdapter>(TIOAdapter adapter, bool receiveFirst, byte[] reAuthenticationData, bool isApm = false)
            where TIOAdapter : ISslIOAdapter
        {
            _framing = Framing.Unknown;
            ProtocolToken message;

            if (reAuthenticationData == null)
            {
                // prevent nesting only when authentication functions are called explicitly. e.g. handle renegotiation transparently.
                if (Interlocked.Exchange(ref _nestedAuth, 1) == 1)
                {
                    throw new InvalidOperationException(SR.Format(SR.net_io_invalidnestedcall, isApm ? "BeginAuthenticate" : "Authenticate", "authenticate"));
                }
            }

            try
            {
                if (!receiveFirst)
                {
                    message = _context.NextMessage(reAuthenticationData);
                    if (message.Size > 0)
                    {
                        await adapter.WriteAsync(message.Payload, 0, message.Size).ConfigureAwait(false);
                    }

                    if (message.Failed)
                    {
                        // tracing done in NextMessage()
                        throw new AuthenticationException(SR.net_auth_SSPI, message.GetException());
                    }
                }

                _handshakeBuffer = new ArrayBuffer(InitialHandshakeBufferSize);
                do
                {
                    message = await ReceiveBlobAsync(adapter).ConfigureAwait(false);

                    if (message.Size > 0)
                    {
                        // If there is message send it out even if call failed. It may contain TLS Alert.
                        await adapter.WriteAsync(message.Payload, 0, message.Size).ConfigureAwait(false);
                    }

                    if (message.Failed)
                    {
                        throw new AuthenticationException(SR.net_auth_SSPI, message.GetException());
                    }
                } while (message.Status.ErrorCode != SecurityStatusPalErrorCode.OK);

                if (_handshakeBuffer.ActiveLength > 0)
                {
                    // If we read more than we needed for handshake, move it to input buffer for further processing.
                    ResetReadBuffer();
                    _handshakeBuffer.ActiveSpan.CopyTo(_internalBuffer);
                    _internalBufferCount = _handshakeBuffer.ActiveLength;
                }

                ProtocolToken alertToken = null;
                if (!CompleteHandshake(ref alertToken))
                {
                    SendAuthResetSignal(alertToken, ExceptionDispatchInfo.Capture(new AuthenticationException(SR.net_ssl_io_cert_validation, null)));
                }
            }
            finally
            {
                _handshakeBuffer.Dispose();
                if (reAuthenticationData == null)
                {
                    _nestedAuth = 0;
                }
            }

            if (NetEventSource.IsEnabled)
            {
                NetEventSource.Log.SspiSelectedCipherSuite(nameof(ForceAuthenticationAsync),
                                                           SslProtocol,
                                                           CipherAlgorithm,
                                                           CipherStrength,
                                                           HashAlgorithm,
                                                           HashStrength,
                                                           KeyExchangeAlgorithm,
                                                           KeyExchangeStrength);
            }
        }