fix: check for already existing cert

This commit is contained in:
2026-05-13 11:19:45 -03:00
parent 013d69e18a
commit f318327952
+11 -1
View File
@@ -103,7 +103,17 @@ bool CertificateManager::installCertificate()
bool success = false; bool success = false;
if (rootStore) if (rootStore)
{ {
success = CertAddCertificateContextToStore(rootStore, certCtx, CERT_STORE_ADD_REPLACE_EXISTING, NULL); 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); CertCloseStore(rootStore, 0);
} }
CertFreeCertificateContext(certCtx); CertFreeCertificateContext(certCtx);