fix: check for already existing cert

This commit is contained in:
2026-05-13 11:19:45 -03:00
parent 013d69e18a
commit f318327952
+10
View File
@@ -102,8 +102,18 @@ bool CertificateManager::installCertificate()
HCERTSTORE rootStore = CertOpenStore(CERT_STORE_PROV_SYSTEM, 0, NULL, CERT_SYSTEM_STORE_CURRENT_USER, L"Root");
bool success = false;
if (rootStore)
{
PCCERT_CONTEXT existingCert = CertFindCertificateInStore(rootStore, X509_ASN_ENCODING | PKCS_7_ASN_ENCODING, 0,
CERT_FIND_EXISTING, certCtx, NULL);
if (existingCert)
{
CertFreeCertificateContext(existingCert);
success = true;
}
else
{
success = CertAddCertificateContextToStore(rootStore, certCtx, CERT_STORE_ADD_REPLACE_EXISTING, NULL);
}
CertCloseStore(rootStore, 0);
}
CertFreeCertificateContext(certCtx);