[英]Silently deleting a certificate from Windows Root Store
我正在嘗試使用WinCrypt API函數從根存儲中刪除證書:
HANDLE hStoreHandle = INVALID_HANDLE_VALUE;
PCCERT_CONTEXT pCertContext = NULL;
char * pszStoreName = "ROOT";
char pszNameString[256];
//hStoreHandle = CertOpenSystemStoreA(NULL, pszStoreName);
hStoreHandle = CertOpenStore(CERT_STORE_PROV_SYSTEM,
X509_ASN_ENCODING | PKCS_7_ASN_ENCODING,
0,
CERT_SYSTEM_STORE_CURRENT_USER,
(LPVOID) L"Root");
if(hStoreHandle == INVALID_HANDLE_VALUE)
//Fail
while(pCertContext = CertEnumCertificatesInStore(hStoreHandle, pCertContext))
{
if(CertGetNameStringA(
pCertContext,
CERT_NAME_SIMPLE_DISPLAY_TYPE,
0,
NULL,
pszNameString,
256))
{
if(strcmp(pszNameString, "DummyCertificate") == 0)
{
if(!CertDeleteCertificateFromStore(
CertDuplicateCertificateContext(pCertContext))
)
{
//Fail
}
}
}
else
{
//Fail
}
}
這是在使用MyService.exe /Service
注冊我的應用程序Windows Service時調用的函數中發生的。 因此,從理論上講,它應該具有刪除證書所需的所有必要訪問權限。 但是,當調用CertDeleteCertificateFromStore
函數時, CertDeleteCertificateFromStore
出現一個彈出窗口,詢問用戶是否真的要刪除證書。
我試圖阻止此窗口出現,並在找到后靜默刪除證書。 有什么建議么?
我研究了命令行實用程序certutil
和certmgr
。 據我從Internet上了解到, certutil
在客戶端計算機上受到一定程度的限制,而certmgr
不允許刪除Root證書。 我想要一個程序化的解決方案,但如果可以完成工作,則可以使用工具。
您可以通過在程序中自動回答對話框來進行破解。 嘗試在另一個主題和發布消息中找到與對話框關聯的按鈕窗口,以在“是”按鈕上生成BN_CLICKED事件。
CERT_SYSTEM_STORE_CURRENT_USER->CERT_SYSTEM_STORE_LOCAL_MACHINE
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.