Module: wine Branch: master Commit: 3d38e85964386f6066758e088a10f58d35b7b354 URL: https://gitlab.winehq.org/wine/wine/-/commit/3d38e85964386f6066758e088a10f58...
Author: Paul Gofman pgofman@codeweavers.com Date: Thu Mar 23 12:59:42 2023 -0600
crypt32: Support user properties for certificates.
---
dlls/crypt32/cert.c | 13 +++++++++++++ dlls/crypt32/serialize.c | 6 ++++++ dlls/crypt32/tests/cert.c | 20 ++++++++++++++++++++ 3 files changed, 39 insertions(+)
diff --git a/dlls/crypt32/cert.c b/dlls/crypt32/cert.c index a0b5747f2d3..b9645770ce1 100644 --- a/dlls/crypt32/cert.c +++ b/dlls/crypt32/cert.c @@ -714,6 +714,19 @@ static BOOL CertContext_SetProperty(cert_t *cert, DWORD dwPropId,
if (!cert->base.properties) ret = FALSE; + else if (dwPropId >= CERT_FIRST_USER_PROP_ID && dwPropId <= CERT_LAST_USER_PROP_ID) + { + if (pvData) + { + const CRYPT_DATA_BLOB *blob = pvData; + ret = ContextPropertyList_SetProperty(cert->base.properties, dwPropId, blob->pbData, blob->cbData); + } + else + { + ContextPropertyList_RemoveProperty(cert->base.properties, dwPropId); + ret = TRUE; + } + } else { switch (dwPropId) diff --git a/dlls/crypt32/serialize.c b/dlls/crypt32/serialize.c index 47ab834bf48..11d39188880 100644 --- a/dlls/crypt32/serialize.c +++ b/dlls/crypt32/serialize.c @@ -405,6 +405,12 @@ static BOOL CRYPT_ReadContextProp( SetLastError(ERROR_FILE_NOT_FOUND); ret = FALSE; } + else if (hdr->propID >= CERT_FIRST_USER_PROP_ID && hdr->propID <= CERT_LAST_USER_PROP_ID) + { + CRYPT_DATA_BLOB blob = { hdr->cb, (LPBYTE)pbElement }; + + ret = contextInterface->setProp(context, hdr->propID, 0, &blob); + } else if (hdr->propID != CERT_CERT_PROP_ID && hdr->propID != CERT_CRL_PROP_ID && hdr->propID != CERT_CTL_PROP_ID) { diff --git a/dlls/crypt32/tests/cert.c b/dlls/crypt32/tests/cert.c index 0de6aa717bf..83594560efa 100644 --- a/dlls/crypt32/tests/cert.c +++ b/dlls/crypt32/tests/cert.c @@ -369,6 +369,7 @@ static void testCertProperties(void) BYTE hash[20] = { 0 }, hashProperty[20]; CRYPT_DATA_BLOB blob; CERT_KEY_CONTEXT keyContext; + unsigned int value;
ok(context != NULL, "CertCreateCertificateContext failed: %08lx\n", GetLastError());
@@ -566,6 +567,25 @@ static void testCertProperties(void) free(buf); } } + + ret = CertGetCertificateContextProperty(context, CERT_LAST_USER_PROP_ID, NULL, &size); + ok(!ret && GetLastError() == CRYPT_E_NOT_FOUND, "got ret %d, error %#lx.\n", ret, GetLastError()); + + blob.cbData = sizeof(value); + blob.pbData = (BYTE *)&value; + value = 1; + ret = CertSetCertificateContextProperty(context, CERT_LAST_USER_PROP_ID, 0, &blob); + ok(ret, "got error %#lx.\n", GetLastError()); + value = 0xdeadbeef; + size = 0xdeadbeef; + ret = CertGetCertificateContextProperty(context, CERT_LAST_USER_PROP_ID, NULL, &size); + ok(ret, "got error %#lx.\n", GetLastError()); + ok(size == sizeof(value), "got size %lu.\n", size); + ret = CertGetCertificateContextProperty(context, CERT_LAST_USER_PROP_ID, &value, &size); + ok(ret, "got error %#lx.\n", GetLastError()); + ok(size == sizeof(value), "got size %lu.\n", size); + ok(value == 1, "got value %u.\n", value); + CertFreeCertificateContext(context);
context = CertCreateCertificateContext(X509_ASN_ENCODING,