mirror of
https://github.com/wechat-article/wxdown-service.git
synced 2026-08-29 00:40:40 +08:00
update
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
import subprocess
|
||||
|
||||
|
||||
def is_certificate_installed(cert_name = 'mitmproxy'):
|
||||
try:
|
||||
result = subprocess.run(['security', 'find-certificate', '-c', cert_name], capture_output=True, text=True)
|
||||
return result.returncode == 0
|
||||
except FileNotFoundError:
|
||||
raise NotImplementedError("此系统中未找到 security 命令")
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
import wincertstore
|
||||
import os
|
||||
|
||||
|
||||
def is_certificate_installed(cert_name = "mitmproxy"):
|
||||
stores = ["MY", "ROOT", "CA"]
|
||||
for storename in stores:
|
||||
with wincertstore.CertSystemStore(storename) as store:
|
||||
for cert in store.itercerts():
|
||||
name = cert.get_name()
|
||||
if name == cert_name:
|
||||
return True
|
||||
return False
|
||||
@@ -1,13 +1,18 @@
|
||||
import re
|
||||
import subprocess
|
||||
import urllib.request
|
||||
|
||||
import requests
|
||||
|
||||
from cert import macos
|
||||
|
||||
|
||||
# 检查代理是否正确
|
||||
def is_proxy_correct(target_proxy_address):
|
||||
proxy = urllib.request.getproxies()
|
||||
response = requests.get('http://mitm.it', proxies=proxy).text
|
||||
|
||||
if re.search(r'If you can see this, traffic is not passing through mitmproxy', response) or proxy != target_proxy_address:
|
||||
if re.search(r'If you can see this, traffic is not passing through mitmproxy',
|
||||
response) or proxy != target_proxy_address:
|
||||
print("\n检测到系统的网络代理设置不正确")
|
||||
print(f"当前网络代理: {proxy}")
|
||||
print(f"目标网络代理: {target_proxy_address}")
|
||||
@@ -16,50 +21,15 @@ def is_proxy_correct(target_proxy_address):
|
||||
return True
|
||||
|
||||
|
||||
cert_name = 'mitmproxy'
|
||||
|
||||
def is_certificate_installed_macos():
|
||||
try:
|
||||
result = subprocess.run(['security', 'find-certificate', '-c', cert_name], capture_output=True, text=True)
|
||||
return result.returncode == 0
|
||||
except FileNotFoundError:
|
||||
raise NotImplementedError("此系统中未找到 security 命令")
|
||||
|
||||
def is_certificate_installed_windows():
|
||||
import wincertstore
|
||||
import os
|
||||
from cryptography import x509
|
||||
from cryptography.hazmat.backends import default_backend
|
||||
import hashlib
|
||||
|
||||
def is_certificate_installed(cert_name, thumbprint=None):
|
||||
if os.name != 'nt':
|
||||
raise NotImplementedError("此函数仅适用于 Windows")
|
||||
|
||||
stores = ["MY", "ROOT", "CA"]
|
||||
for storename in stores:
|
||||
with wincertstore.CertSystemStore(storename) as store:
|
||||
for cert in store.itercerts():
|
||||
name = cert.get_name()
|
||||
pem = cert.get_pem().decode("ascii")
|
||||
if name == cert_name:
|
||||
if thumbprint is None:
|
||||
return True
|
||||
else:
|
||||
cert_obj = x509.load_pem_x509_certificate(pem.encode('utf-8'), default_backend())
|
||||
der = cert_obj.public_bytes(x509.Encoding.DER)
|
||||
computed_thumbprint = hashlib.sha1(der).hexdigest().upper()
|
||||
if computed_thumbprint == thumbprint:
|
||||
return True
|
||||
return False
|
||||
|
||||
# 检测证书是否安装
|
||||
# 检查证书是否安装
|
||||
def wait_until_certificate_installed():
|
||||
while True:
|
||||
if is_certificate_installed_macos():
|
||||
if macos.is_certificate_installed('mitmproxy'):
|
||||
break
|
||||
else:
|
||||
input("系统中未检测到 mitmproxy 的证书,请进行手动安装。\n证书安装教程请参考: https://docs.mitmproxy.org/stable/concepts/certificates/#installing-the-mitmproxy-ca-certificate-manually\n\n证书安装后请按任意键继续")
|
||||
input(
|
||||
"系统中未检测到 mitmproxy 的证书,请进行手动安装。\n证书安装教程请参考: https://docs.mitmproxy.org/stable/concepts/certificates/#installing-the-mitmproxy-ca-certificate-manually\n\n证书安装后请按任意键继续")
|
||||
|
||||
|
||||
# 检查系统代理是否设置正确
|
||||
def wait_until_proxy_setting(proxy_address):
|
||||
@@ -69,7 +39,8 @@ def wait_until_proxy_setting(proxy_address):
|
||||
else:
|
||||
input("\n按任意键继续")
|
||||
|
||||
def wait_until_env_configured(proxy_address = None):
|
||||
|
||||
def wait_until_env_configured(proxy_address=None):
|
||||
# 检查证书是否安装
|
||||
wait_until_certificate_installed()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user