Skip to content
Draft
Changes from all 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
7 changes: 6 additions & 1 deletion src/ext/Iis/ca/scacert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,10 @@ static HRESULT FindExistingCertificate(
PCCERT_CONTEXT pCertContext = NULL;
BYTE* pbCertificate = NULL;
DWORD cbCertificate = 0;
LPWSTR pwzUniquePrefix = NULL;

hr = StrAllocFormatted(&pwzUniquePrefix, L"%s_wixCert_", wzName);
ExitOnFailure(hr, "Failed to format unique name");

hCertStore = ::CertOpenStore(CERT_STORE_PROV_SYSTEM, 0, NULL, dwStoreLocation | CERT_STORE_READONLY_FLAG, wzStore);
MessageExitOnNullWithLastError(hCertStore, hr, msierrCERTFailedOpen, "Failed to open certificate store.");
Expand All @@ -713,7 +717,7 @@ static HRESULT FindExistingCertificate(
DWORD cbFriendlyName = sizeof(wzFriendlyName);

if (::CertGetCertificateContextProperty(pCertContext, CERT_FRIENDLY_NAME_PROP_ID, reinterpret_cast<BYTE*>(wzFriendlyName), &cbFriendlyName) &&
CSTR_EQUAL == ::CompareStringW(LOCALE_SYSTEM_DEFAULT, 0, wzName, -1, wzFriendlyName, -1))
CSTR_EQUAL == ::CompareStringW(LOCALE_SYSTEM_DEFAULT, 0, pwzUniquePrefix, -1, wzFriendlyName, -1))
{
// If the certificate with matching friendly name is valid, let's use that.
long lVerify = ::CertVerifyTimeValidity(NULL, pCertContext->pCertInfo);
Expand All @@ -739,6 +743,7 @@ static HRESULT FindExistingCertificate(
pbCertificate = NULL;

LExit:
ReleaseStr(pwzUniquePrefix);
ReleaseMem(pbCertificate);

if (pCertContext)
Expand Down