Files
wxdown-service/cert/__init__.py
T
2025-06-09 15:45:09 +08:00

25 lines
896 B
Python

import platform
import subprocess
def is_certificate_installed(cert_name = 'mitmproxy'):
if platform.system() == 'Windows':
import wincertstore
stores = ["MY", "ROOT", "CA"]
for store in stores:
with wincertstore.CertSystemStore(store) as store:
for cert in store.itercerts():
name = cert.get_name()
if name == cert_name:
return True
return False
elif platform.system() == 'Darwin':
try:
result = subprocess.run(['security', 'find-certificate', '-c', cert_name], capture_output=True, text=True)
return result.returncode == 0
except FileNotFoundError:
raise NotImplementedError("此系统中未找到 security 命令")
else:
raise NotImplementedError(f"暂不支持该系统: {platform.system()}")