Module: wine
Branch: master
Commit: 216df7a714967a02e6eded40f0de8782e1e5da2b
URL: http://source.winehq.org/git/wine.git/?a=commit;h=216df7a714967a02e6eded40f…
Author: Juan Lang <juan.lang(a)gmail.com>
Date: Fri Nov 6 14:38:40 2009 -0800
crypt32: Reject certificates whose fields don't match their versions.
---
dlls/crypt32/chain.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 47 insertions(+), 0 deletions(-)
diff --git a/dlls/crypt32/chain.c b/dlls/crypt32/chain.c
index 76052b2..26627e2 100644
--- a/dlls/crypt32/chain.c
+++ b/dlls/crypt32/chain.c
@@ -1311,6 +1311,45 @@ static BOOL CRYPT_CriticalExtensionsSupported(PCCERT_CONTEXT cert)
return ret;
}
+static BOOL CRYPT_IsCertVersionValid(PCCERT_CONTEXT cert)
+{
+ BOOL ret = TRUE;
+
+ /* Checks whether the contents of the cert match the cert's version. */
+ switch (cert->pCertInfo->dwVersion)
+ {
+ case CERT_V1:
+ /* A V1 cert may not contain unique identifiers. See RFC 5280,
+ * section 4.1.2.8:
+ * "These fields MUST only appear if the version is 2 or 3 (Section
+ * 4.1.2.1). These fields MUST NOT appear if the version is 1."
+ */
+ if (cert->pCertInfo->IssuerUniqueId.cbData ||
+ cert->pCertInfo->SubjectUniqueId.cbData)
+ ret = FALSE;
+ /* A V1 cert may not contain extensions. See RFC 5280, section 4.1.2.9:
+ * "This field MUST only appear if the version is 3 (Section 4.1.2.1)."
+ */
+ if (cert->pCertInfo->cExtension)
+ ret = FALSE;
+ break;
+ case CERT_V2:
+ /* A V2 cert may not contain extensions. See RFC 5280, section 4.1.2.9:
+ * "This field MUST only appear if the version is 3 (Section 4.1.2.1)."
+ */
+ if (cert->pCertInfo->cExtension)
+ ret = FALSE;
+ break;
+ case CERT_V3:
+ /* Do nothing, all fields are allowed for V3 certs */
+ break;
+ default:
+ WARN_(chain)("invalid cert version %d\n", cert->pCertInfo->dwVersion);
+ ret = FALSE;
+ }
+ return ret;
+}
+
static void CRYPT_CheckSimpleChain(PCertificateChainEngine engine,
PCERT_SIMPLE_CHAIN chain, LPFILETIME time)
{
@@ -1332,6 +1371,14 @@ static void CRYPT_CheckSimpleChain(PCertificateChainEngine engine,
chain->rgpElement[i]->pCertContext);
else
isRoot = FALSE;
+ if (!CRYPT_IsCertVersionValid(chain->rgpElement[i]->pCertContext))
+ {
+ /* MS appears to accept certs whose versions don't match their
+ * contents, so there isn't an appropriate error code.
+ */
+ chain->rgpElement[i]->TrustStatus.dwErrorStatus |=
+ CERT_TRUST_INVALID_EXTENSION;
+ }
if (CertVerifyTimeValidity(time,
chain->rgpElement[i]->pCertContext->pCertInfo) != 0)
chain->rgpElement[i]->TrustStatus.dwErrorStatus |=
Module: wine
Branch: master
Commit: 9fe6be454f85d9770e79ee4b3111863cdd56487c
URL: http://source.winehq.org/git/wine.git/?a=commit;h=9fe6be454f85d9770e79ee4b3…
Author: Juan Lang <juan.lang(a)gmail.com>
Date: Fri Nov 6 13:56:09 2009 -0800
crypt32: Forbid minimum or maximum fields in name constraints.
---
dlls/crypt32/chain.c | 66 ++++++++++++++++++++++++++++++++++++++++----------
1 files changed, 53 insertions(+), 13 deletions(-)
diff --git a/dlls/crypt32/chain.c b/dlls/crypt32/chain.c
index 5323ac4..76052b2 100644
--- a/dlls/crypt32/chain.c
+++ b/dlls/crypt32/chain.c
@@ -728,6 +728,40 @@ static CERT_NAME_CONSTRAINTS_INFO *CRYPT_GetNameConstraints(CERT_INFO *cert)
return info;
}
+static BOOL CRYPT_IsValidNameConstraint(const CERT_NAME_CONSTRAINTS_INFO *info)
+{
+ DWORD i;
+ BOOL ret = TRUE;
+
+ /* Check that none of the constraints specifies a minimum or a maximum.
+ * See RFC 5280, section 4.2.1.10:
+ * "Within this profile, the minimum and maximum fields are not used with
+ * any name forms, thus, the minimum MUST be zero, and maximum MUST be
+ * absent. However, if an application encounters a critical name
+ * constraints extension that specifies other values for minimum or
+ * maximum for a name form that appears in a subsequent certificate, the
+ * application MUST either process these fields or reject the
+ * certificate."
+ * Since it gives no guidance as to how to process these fields, we
+ * reject any name constraint that contains them.
+ */
+ for (i = 0; ret && i < info->cPermittedSubtree; i++)
+ if (info->rgPermittedSubtree[i].dwMinimum ||
+ info->rgPermittedSubtree[i].fMaximum)
+ {
+ TRACE_(chain)("found a minimum or maximum in permitted subtrees\n");
+ ret = FALSE;
+ }
+ for (i = 0; ret && i < info->cExcludedSubtree; i++)
+ if (info->rgExcludedSubtree[i].dwMinimum ||
+ info->rgExcludedSubtree[i].fMaximum)
+ {
+ TRACE_(chain)("found a minimum or maximum in excluded subtrees\n");
+ ret = FALSE;
+ }
+ return ret;
+}
+
static void CRYPT_CheckChainNameConstraints(PCERT_SIMPLE_CHAIN chain)
{
int i, j;
@@ -751,21 +785,27 @@ static void CRYPT_CheckChainNameConstraints(PCERT_SIMPLE_CHAIN chain)
if ((nameConstraints = CRYPT_GetNameConstraints(
chain->rgpElement[i]->pCertContext->pCertInfo)))
{
- for (j = i - 1; j >= 0; j--)
+ if (!CRYPT_IsValidNameConstraint(nameConstraints))
+ chain->rgpElement[i]->TrustStatus.dwErrorStatus |=
+ CERT_TRUST_HAS_NOT_SUPPORTED_NAME_CONSTRAINT;
+ else
{
- DWORD errorStatus = 0;
-
- /* According to RFC 3280, self-signed certs don't have name
- * constraints checked unless they're the end cert.
- */
- if (j == 0 || !CRYPT_IsCertificateSelfSigned(
- chain->rgpElement[j]->pCertContext))
+ for (j = i - 1; j >= 0; j--)
{
- CRYPT_CheckNameConstraints(nameConstraints,
- chain->rgpElement[i]->pCertContext->pCertInfo,
- &errorStatus);
- chain->rgpElement[i]->TrustStatus.dwErrorStatus |=
- errorStatus;
+ DWORD errorStatus = 0;
+
+ /* According to RFC 3280, self-signed certs don't have name
+ * constraints checked unless they're the end cert.
+ */
+ if (j == 0 || !CRYPT_IsCertificateSelfSigned(
+ chain->rgpElement[j]->pCertContext))
+ {
+ CRYPT_CheckNameConstraints(nameConstraints,
+ chain->rgpElement[i]->pCertContext->pCertInfo,
+ &errorStatus);
+ chain->rgpElement[i]->TrustStatus.dwErrorStatus |=
+ errorStatus;
+ }
}
}
LocalFree(nameConstraints);