fix: check for already existing cert
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user