Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct client certificate validation policy on Windows and macOS. #1966

Merged
merged 15 commits into from
Sep 21, 2021
Merged
Show file tree
Hide file tree
Changes from 4 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
2 changes: 1 addition & 1 deletion src/inc/quic_cert.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ CxPlatCertValidateChain(
_In_ const QUIC_CERTIFICATE* Certificate,
_In_opt_z_ const char* Host,
_In_ uint32_t CertFlags,
_In_ uint32_t IgnoreFlags,
_In_ uint32_t CredFlags,
_Out_opt_ uint32_t* ValidationError
);

Expand Down
29 changes: 18 additions & 11 deletions src/platform/cert_capi.c
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,7 @@ DWORD
CxPlatCertVerifyCertChainPolicy(
_In_ PCCERT_CHAIN_CONTEXT ChainContext,
_In_opt_ PWSTR ServerName,
_In_ ULONG IgnoreFlags
_In_ uint32_t CredFlags
)
{
DWORD Status = NO_ERROR;
Expand All @@ -801,9 +801,10 @@ CxPlatCertVerifyCertChainPolicy(

memset(&HttpsPolicy, 0, sizeof(HTTPSPolicyCallbackData));
HttpsPolicy.cbStruct = sizeof(HTTPSPolicyCallbackData);
HttpsPolicy.dwAuthType = AUTHTYPE_SERVER;
HttpsPolicy.dwAuthType =
(CredFlags & QUIC_CREDENTIAL_FLAG_CLIENT) ? AUTHTYPE_SERVER : AUTHTYPE_CLIENT;
HttpsPolicy.fdwChecks = 0;
HttpsPolicy.pwszServerName = ServerName;
HttpsPolicy.pwszServerName = (CredFlags & QUIC_CREDENTIAL_FLAG_CLIENT) ? ServerName : NULL;

memset(&PolicyPara, 0, sizeof(PolicyPara));
PolicyPara.cbSize = sizeof(PolicyPara);
Expand All @@ -826,10 +827,10 @@ CxPlatCertVerifyCertChainPolicy(
goto Exit;

} else if (PolicyStatus.dwError == CRYPT_E_NO_REVOCATION_CHECK &&
(IgnoreFlags & QUIC_CREDENTIAL_FLAG_IGNORE_NO_REVOCATION_CHECK)) {
(CredFlags & QUIC_CREDENTIAL_FLAG_IGNORE_NO_REVOCATION_CHECK)) {
Status = NO_ERROR;
} else if (PolicyStatus.dwError == CRYPT_E_REVOCATION_OFFLINE &&
(IgnoreFlags & QUIC_CREDENTIAL_FLAG_IGNORE_REVOCATION_OFFLINE)) {
(CredFlags & QUIC_CREDENTIAL_FLAG_IGNORE_REVOCATION_OFFLINE)) {
Status = NO_ERROR;
} else if (PolicyStatus.dwError != NO_ERROR) {

Expand All @@ -848,7 +849,7 @@ CxPlatCertVerifyCertChainPolicy(
CertCapiVerifiedChain,
"CertVerifyChain: %S 0x%x, result=0x%x",
ServerName,
IgnoreFlags,
CredFlags,
Status);

return Status;
Expand All @@ -860,7 +861,7 @@ CxPlatCertValidateChain(
_In_ const QUIC_CERTIFICATE* Certificate,
_In_opt_z_ PCSTR Host,
_In_ uint32_t CertFlags,
_In_ uint32_t IgnoreFlags,
_In_ uint32_t CredFlags,
_Out_opt_ uint32_t* ValidationError
)
{
Expand All @@ -873,21 +874,27 @@ CxPlatCertValidateChain(

CERT_CHAIN_PARA ChainPara;

static const LPSTR UsageOids[] = {
static const LPSTR ServerUsageOids[] = {
szOID_PKIX_KP_SERVER_AUTH,
szOID_SERVER_GATED_CRYPTO,
szOID_SGC_NETSCAPE
};

static const LPSTR ClientUsageOids[] = {
szOID_PKIX_KP_CLIENT_AUTH
};

if (ValidationError != NULL) {
*ValidationError = NO_ERROR;
}

memset(&ChainPara, 0, sizeof(ChainPara));
ChainPara.cbSize = sizeof(ChainPara);
ChainPara.RequestedUsage.dwType = USAGE_MATCH_TYPE_OR;
ChainPara.RequestedUsage.Usage.cUsageIdentifier = ARRAYSIZE(UsageOids);
ChainPara.RequestedUsage.Usage.rgpszUsageIdentifier = (LPSTR*)UsageOids;
ChainPara.RequestedUsage.Usage.cUsageIdentifier =
(CredFlags & QUIC_CREDENTIAL_FLAG_CLIENT) ? ARRAYSIZE(ServerUsageOids) : ARRAYSIZE(ClientUsageOids);
ChainPara.RequestedUsage.Usage.rgpszUsageIdentifier =
(CredFlags & QUIC_CREDENTIAL_FLAG_CLIENT) ? (LPSTR*)ServerUsageOids : (LPSTR*)ClientUsageOids;

if (!CertGetCertificateChain(
NULL,
Expand Down Expand Up @@ -927,7 +934,7 @@ CxPlatCertValidateChain(
CxPlatCertVerifyCertChainPolicy(
ChainContext,
ServerName,
IgnoreFlags);
CredFlags);

Result = NO_ERROR == Error;

Expand Down
5 changes: 1 addition & 4 deletions src/platform/cert_capi_openssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,12 @@ CxPlatTlsVerifyCertificate(
CertFlags |= CERT_CHAIN_REVOCATION_CHECK_CHAIN_EXCLUDE_ROOT;
}

uint32_t IgnoreFlags =
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I feel like I did this on purpose when I wrote it, but I don't remember now, so I'm removing it.

CredFlags & (QUIC_CREDENTIAL_FLAG_IGNORE_REVOCATION_OFFLINE | QUIC_CREDENTIAL_FLAG_IGNORE_NO_REVOCATION_CHECK);

Result =
CxPlatCertValidateChain(
CertContext,
SNI,
CertFlags,
IgnoreFlags,
CredFlags,
PlatformVerificationError);

Exit:
Expand Down
5 changes: 4 additions & 1 deletion src/platform/darwin_openssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,10 @@ CxPlatTlsVerifyCertificate(
goto Exit;
}

SSLPolicy = SecPolicyCreateSSL(true, SNIString);
SSLPolicy =
SecPolicyCreateSSL(
(CredFlags & QUIC_CREDENTIAL_FLAG_CLIENT) ? FALSE : TRUE,
anrossi marked this conversation as resolved.
Show resolved Hide resolved
SNIString);
if (SSLPolicy == NULL) {
QuicTraceEvent(
LibraryError,
Expand Down