Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1056,8 +1056,9 @@ internal bool VerifyRemoteCertificate(RemoteCertificateValidationCallback? remot
return true;
}

_remoteCertificate = certificate;
if (_remoteCertificate == null)
// don't assign to _remoteCertificate yet, this prevents weird exceptions if SslStream is disposed in parallel with X509Chain building

if (certificate == null)
{
if (NetEventSource.Log.IsEnabled() && RemoteCertRequired) NetEventSource.Error(this, $"Remote certificate required, but no remote certificate received");
sslPolicyErrors |= SslPolicyErrors.RemoteCertificateNotAvailable;
Expand Down Expand Up @@ -1099,15 +1100,17 @@ internal bool VerifyRemoteCertificate(RemoteCertificateValidationCallback? remot
sslPolicyErrors |= CertificateValidationPal.VerifyCertificateProperties(
_securityContext!,
chain,
_remoteCertificate,
certificate,
_sslAuthenticationOptions.CheckCertName,
_sslAuthenticationOptions.IsServer,
TargetHostNameHelper.NormalizeHostName(_sslAuthenticationOptions.TargetHost));
}

_remoteCertificate = certificate;

if (remoteCertValidationCallback != null)
{
success = remoteCertValidationCallback(this, _remoteCertificate, chain, sslPolicyErrors);
success = remoteCertValidationCallback(this, certificate, chain, sslPolicyErrors);
}
else
{
Expand Down
Loading