From f318327952d8ef1688b3e1e9c78d28a56e2364cc Mon Sep 17 00:00:00 2001 From: neru Date: Wed, 13 May 2026 11:19:45 -0300 Subject: [PATCH] fix: check for already existing cert --- src/proxy/tinymitm/ssl.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/proxy/tinymitm/ssl.cpp b/src/proxy/tinymitm/ssl.cpp index fd9d633..8cf3406 100644 --- a/src/proxy/tinymitm/ssl.cpp +++ b/src/proxy/tinymitm/ssl.cpp @@ -103,7 +103,17 @@ bool CertificateManager::installCertificate() bool success = false; 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); } CertFreeCertificateContext(certCtx);