Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Certificate Delete function does not exist #2472

Open
B1ank-H opened this issue Feb 6, 2025 · 0 comments
Open

Certificate Delete function does not exist #2472

B1ank-H opened this issue Feb 6, 2025 · 0 comments

Comments

@B1ank-H
Copy link

B1ank-H commented Feb 6, 2025

In the case of importing win32crypt library, I try to use the CertDeleteCertificateFromStore function, which has been defined by Win, to delete the cert. But it prompts AttributeError: 'PyCERTSTORE' object has no attribute ' CertDeleteCertificateFromStore '

Here is part of my code

with open('mitmproxy-ca-cert.crt', 'r') as pfx_file:
    pfx_data = pfx_file.read()    
CERT_SYSTEM_STORE_CURRENT_USER_ACCOUNT = 1 << 16
cert_byte = win32crypt.CryptStringToBinary(pfx_data, CRYPT_STRING_BASE64HEADER)[0]

store = win32crypt.CertOpenStore(CERT_STORE_PROV_SYSTEM, 0, None,
                                     CERT_SYSTEM_STORE_CURRENT_USER_ACCOUNT | CERT_STORE_OPEN_EXISTING_FLAG, "ROOT")

pc_certs = store.CertEnumCertificatesInStore()
had_install = False
for pc_cert in pc_certs:
    if pc_cert.CertEncoded == cert_byte:
        if install:
            had_install = True
        else:
            store.CertDeleteCertificateFromStore(pc_cert) #???it can't work

my system is Win 10 and 11, python version is 3.9, pywin32 version is 308, pypiwin32 version is 223

So what should I do to delete the specified certificate using pywin32 library?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant