mirror of
https://github.com/wechat-article/wxdown-service.git
synced 2026-09-01 15:38:11 +08:00
25 lines
896 B
Python
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()}")
|