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

append _wixCert_ to cert name #546

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
9 changes: 8 additions & 1 deletion src/ext/ca/serverca/scasched/scacert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
Expand All @@ -691,7 +697,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, ccUniquePrefix, wzFriendlyName, ccUniquePrefix))
{
// If the certificate with matching friendly name is valid, let's use that.
long lVerify = ::CertVerifyTimeValidity(NULL, pCertContext->pCertInfo);
Expand All @@ -717,6 +723,7 @@ static HRESULT FindExistingCertificate(
pbCertificate = NULL;

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

if (pCertContext)
Expand Down