Skip to content
Merged
Changes from 1 commit
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 @@ -48,12 +48,12 @@ internal static SslPolicyErrors VerifyCertificateProperties(
SafeFreeCertContext? remoteContext = null;
try
{
// SECPKG_ATTR_REMOTE_CERT_CHAIN can be used even before the TLS handshake completes, which is necessary
// in order to supply the certificate to the client cert selection callback. However, it is not available on
// windows 7, so use the SECPKG_ATTR_REMOTE_CERT_CONTEXT as a fallback option.
if (!SSPIWrapper.QueryContextAttributes_SECPKG_ATTR_REMOTE_CERT_CHAIN(GlobalSSPI.SSPISecureChannel, securityContext, out remoteContext))
if (!SSPIWrapper.QueryContextAttributes_SECPKG_ATTR_REMOTE_CERT_CONTEXT(GlobalSSPI.SSPISecureChannel, securityContext, out remoteContext))
{
SSPIWrapper.QueryContextAttributes_SECPKG_ATTR_REMOTE_CERT_CONTEXT(GlobalSSPI.SSPISecureChannel, securityContext, out remoteContext);
// The query can fail if TLS handshake has not completed yet. In that case we fallback to querying
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume we expect this to be rare?

Copy link
Member Author

@rzikm rzikm Mar 3, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK the only case when we need the remote cert before handshake completes is during the second call of the LocalClientCertificateSelectionCallback, which provides acceptable issuers and the server certificate as arguments. So the conditions for that happening should be:

  • Server requires client certificate
  • Client uses LocalClientCertificateSelectionCallback which during the first call returns null or a cert which does not match trusted issuers required by server.

I don't know how common that usage is, but since not many people complained that until #65134 the server cert was always null on Windows then I suppose it is indeed rare.

// SECPKG_ATTR_REMOTE_CERT_CHAIN that is more expensive but works even during handshake.
// Note: On Windows versions which don't support querying CERT_CHAIN, we fail and always return null
SSPIWrapper.QueryContextAttributes_SECPKG_ATTR_REMOTE_CERT_CHAIN(GlobalSSPI.SSPISecureChannel, securityContext, out remoteContext);
}

if (remoteContext != null && !remoteContext.IsInvalid)
Expand Down