From e6548ee212bf98ee9fe3f457398f2da1ca7ff47c Mon Sep 17 00:00:00 2001 From: Ilya Samokhin Date: Fri, 30 Sep 2022 13:54:43 +0300 Subject: [PATCH] append _wixCert_ to cert name --- src/ext/ca/serverca/scasched/scacert.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/ext/ca/serverca/scasched/scacert.cpp b/src/ext/ca/serverca/scasched/scacert.cpp index 2252ac492..2311e16fb 100644 --- a/src/ext/ca/serverca/scasched/scacert.cpp +++ b/src/ext/ca/serverca/scasched/scacert.cpp @@ -679,6 +679,12 @@ static HRESULT FindExistingCertificate( PCCERT_CONTEXT pCertContext = NULL; BYTE* pbCertificate = NULL; DWORD cbCertificate = 0; + LPWSTR pwzUniquePrefix = NULL; + int ccUniquePrefix = 0; + + hr = StrAllocFormatted(&pwzUniquePrefix, L"%s_wixCert_", wzName); + ExitOnFailure(hr, "Failed to format unique name"); + ccUniquePrefix = ::lstrlenW(pwzUniquePrefix); hCertStore = ::CertOpenStore(CERT_STORE_PROV_SYSTEM, 0, NULL, dwStoreLocation | CERT_STORE_READONLY_FLAG, wzStore); MessageExitOnNullWithLastError(hCertStore, hr, msierrCERTFailedOpen, "Failed to open certificate store."); @@ -691,7 +697,7 @@ static HRESULT FindExistingCertificate( DWORD cbFriendlyName = sizeof(wzFriendlyName); if (::CertGetCertificateContextProperty(pCertContext, CERT_FRIENDLY_NAME_PROP_ID, reinterpret_cast(wzFriendlyName), &cbFriendlyName) && - CSTR_EQUAL == ::CompareStringW(LOCALE_SYSTEM_DEFAULT, 0, wzName, -1, wzFriendlyName, -1)) + CSTR_EQUAL == ::CompareStringW(LOCALE_SYSTEM_DEFAULT, 0, pwzUniquePrefix, ccUniquePrefix, wzFriendlyName, ccUniquePrefix)) { // If the certificate with matching friendly name is valid, let's use that. long lVerify = ::CertVerifyTimeValidity(NULL, pCertContext->pCertInfo); @@ -717,6 +723,7 @@ static HRESULT FindExistingCertificate( pbCertificate = NULL; LExit: + ReleaseStr(pwzUniquePrefix); ReleaseMem(pbCertificate); if (pCertContext)