diff --git a/Dockerfile b/Dockerfile index 9990cac..a54d448 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,7 +8,9 @@ WORKDIR /srv COPY ./utils ./utils -COPY ./pyproject.toml ./miuitask.py ./docker_start.sh ./ +RUN echo "VERSION='$(git describe --tags --abbrev=0)'" > ./utils/__version__.py + +COPY ./pyproject.toml ./pdm.lock ./miuitask.py ./docker_start.sh ./ RUN pdm install --prod && \ echo '0 4 * * * /bin/sh -c "sleep $((RANDOM % 1800 + 1)); cd /srv && pdm run /srv/miuitask.py"' > /var/spool/cron/crontabs/root && \ diff --git a/pyproject.toml b/pyproject.toml index d925376..c8905de 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,12 +1,12 @@ [project] -name = "" -version = "" +name = "miui-auto-tasks" +version = "1.0.0" description = "" authors = [] dependencies = [ "loguru>=0.7.2", "httpx>=0.25.1", - "cryptography==44.0.0", + "pycryptodome>=3.21.0", "pyyaml>=6.0.1", "tenacity>=8.2.3", "tzdata>=2023.3", diff --git a/requirements.txt b/requirements.txt index 2109429..3f9b53a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,7 @@ -cryptography==44.0.0 jsonpath_ng==1.7.0 loguru==0.7.3 onepush==1.4.0 +pycryptodome==3.21.0 PyYAML==6.0.2 qrcode==8.0 Requests==2.32.3 diff --git a/utils/__version__.py b/utils/__version__.py new file mode 100644 index 0000000..8ea9577 --- /dev/null +++ b/utils/__version__.py @@ -0,0 +1,4 @@ +""" +版本记录文件 +""" +VERSION = "DEBUG" diff --git a/utils/captcha.py b/utils/captcha.py index 99a163b..f871010 100644 --- a/utils/captcha.py +++ b/utils/captcha.py @@ -1,13 +1,15 @@ """ Date: 2023-11-13 19:55:22 LastEditors: Night-stars-1 nujj1042633805@gmail.com -LastEditTime: 2025-01-24 22:02:00 +LastEditTime: 2025-01-25 21:27:29 """ import json import time +from traceback import print_exc from jsonpath_ng import parse +from jsonpath_ng.exceptions import JsonPathParserError from .config import ConfigManager from .data_model import GeetestResult @@ -99,18 +101,21 @@ def get_validate( ) log.debug(response.text) result = response.json() - geetest_validate_expr = parse(_conf.preference.geetest_validate_path) - geetest_validate_match = geetest_validate_expr.find(result) - if len(geetest_validate_match) > 0: - validate = geetest_validate_match[0].value - geetest_challenge_expr = parse(_conf.preference.geetest_challenge_path) - geetest_challenge_match = geetest_challenge_expr.find(result) - if len(geetest_challenge_match) > 0: - challenge = geetest_challenge_match[0].value - geetest_result_expr = parse(_conf.preference.geetest_result_path) - geetest_result_match = geetest_result_expr.find(result) - if len(geetest_result_match) > 0: - result = geetest_result_match[0].value + try: + geetest_validate_expr = parse(_conf.preference.geetest_validate_path) + geetest_validate_match = geetest_validate_expr.find(result) + if len(geetest_validate_match) > 0: + validate = geetest_validate_match[0].value + geetest_challenge_expr = parse(_conf.preference.geetest_challenge_path) + geetest_challenge_match = geetest_challenge_expr.find(result) + if len(geetest_challenge_match) > 0: + challenge = geetest_challenge_match[0].value + geetest_result_expr = parse(_conf.preference.geetest_result_path) + geetest_result_match = geetest_result_expr.find(result) + if len(geetest_result_match) > 0: + result = geetest_result_match[0].value + except JsonPathParserError: + print_exc() if validate and challenge: return GeetestResult(challenge=challenge, validate=validate) else: diff --git a/utils/config.py b/utils/config.py index 5c0fe8e..7117bf6 100644 --- a/utils/config.py +++ b/utils/config.py @@ -148,13 +148,13 @@ class Preference: geetest_data: Optional[dict] = None, geetest_validate_path="$.data.validate", geetest_challenge_path="$.data.challenge", - geetest_result_path="", + geetest_result_path="$", get_geetest_url="", get_geetest_method: Literal["post", "get"] = "post", get_geetest_params: Optional[dict] = None, get_geetest_data: Optional[dict] = None, - get_geetest_validate_path="", - get_geetest_challenge_path="", + get_geetest_validate_path="$", + get_geetest_challenge_path="$", ): self.geetest_url = geetest_url """极验验证URL""" diff --git a/utils/system_info.py b/utils/system_info.py index 5eb66b1..99f6bd1 100644 --- a/utils/system_info.py +++ b/utils/system_info.py @@ -8,12 +8,13 @@ LastEditTime: 2025-01-19 16:48:47 import platform from urllib.request import getproxies +from utils.__version__ import VERSION from utils.logger import log def print_info(): """打印系统信息""" - log.info("MIUI-AUTO-TASK v1.7.5") + log.info(f"MIUI-AUTO-TASK {VERSION}") log.info("---------- 系统信息 -------------") system_info() log.info("---------- 项目信息 -------------") diff --git a/utils/utils.py b/utils/utils.py index 2b55c29..dd6292d 100644 --- a/utils/utils.py +++ b/utils/utils.py @@ -8,10 +8,9 @@ from io import BytesIO from typing import Type from urllib.parse import parse_qsl, urlparse -from cryptography.hazmat.backends import default_backend -from cryptography.hazmat.primitives import padding, serialization -from cryptography.hazmat.primitives.asymmetric.padding import PKCS1v15 -from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes +from Crypto.Cipher import AES, PKCS1_v1_5 +from Crypto.PublicKey import RSA +from Crypto.Util.Padding import pad from qrcode import QRCode, constants from tenacity import RetryError, Retrying, stop_after_attempt @@ -56,27 +55,20 @@ def get_random_chars_as_string( return "".join(random.choice(characters) for _ in range(length)) -def aes_encrypt(key: str, data: str) -> base64: - """AES加密""" - iv = b"0102030405060708" # pylint: disable=invalid-name - cipher = Cipher( - algorithms.AES(key.encode("utf-8")), modes.CBC(iv), backend=default_backend() - ) - encryptor = cipher.encryptor() - padder = padding.PKCS7(algorithms.AES.block_size).padder() - padded_data = padder.update(data.encode("utf-8")) + padder.finalize() - ciphertext = encryptor.update(padded_data) + encryptor.finalize() +def aes_encrypt(key: str, data: str): + """AES 加密""" + iv = "0102030405060708".encode("utf-8") + cipher = AES.new(key.encode("utf-8"), AES.MODE_CBC, iv) + padded_data = pad(data.encode("utf-8"), AES.block_size, style="pkcs7") + ciphertext = cipher.encrypt(padded_data) return base64.b64encode(ciphertext).decode("utf-8") -def rsa_encrypt(public_key_pem: str, data: str) -> base64: - """RSA加密""" - public_key = serialization.load_pem_public_key( - public_key_pem.encode("utf-8"), backend=default_backend() - ) - encoded_data = base64.b64encode(data.encode("utf-8")) - ciphertext = public_key.encrypt(encoded_data, PKCS1v15()) - +def rsa_encrypt(key: str, data: str): + """RSA 加密""" + public_key = RSA.import_key(key) + cipher = PKCS1_v1_5.new(public_key) + ciphertext = cipher.encrypt(base64.b64encode(data.encode("utf-8"))) return base64.b64encode(ciphertext).decode("utf-8")