From ca2c673ae55cb843931b1e6c71704a6a767d30a6 Mon Sep 17 00:00:00 2001 From: mekrapp <158028484+mekrapp@users.noreply.github.com> Date: Wed, 9 Jul 2025 21:35:39 +0200 Subject: [PATCH] Update pycarwings2.py w.r.t. URL and encryption NISSAN has changed the URL of its API as well as the method of encryption from Blowfish to AES --- modules/soc_leaf/pycarwings2.py | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/modules/soc_leaf/pycarwings2.py b/modules/soc_leaf/pycarwings2.py index 442f5e82f..fd50403f6 100755 --- a/modules/soc_leaf/pycarwings2.py +++ b/modules/soc_leaf/pycarwings2.py @@ -70,19 +70,25 @@ from datetime import date from responses import * import base64 -from Crypto.Cipher import Blowfish +from Crypto.Cipher import AES +from Crypto.Util.Padding import pad -BASE_URL = "https://gdcportalgw.its-mo.com/api_v230317_NE/gdc/" +BASE_URL = "https://gdcportalgw.its-mo.com/api_v250205_NE/gdc/" + +# New AES login constants +AES_KEY = "H9YsaE6mr3jBEsAaLC4EJRjn9VXEtTzV" +AES_IV = "xaX4ui2PLnwqcc74" log = logging.getLogger(__name__) -# from http://stackoverflow.com/questions/17134100/python-blowfish-encryption -def _PKCS5Padding(string): - byteNum = len(string) - packingLength = 8 - byteNum % 8 - appendage = chr(packingLength) * packingLength - return string + appendage +def encrypt_aes_password(password: str) -> str: + key = AES_KEY.encode("utf-8") + iv = AES_IV.encode("utf-8") + cipher = AES.new(key, AES.MODE_CBC, iv) + padded = pad(password.encode("utf-8"), AES.block_size) + encrypted = cipher.encrypt(padded) + return base64.standard_b64encode(encrypted).decode("utf-8") class CarwingsError(Exception): @@ -175,10 +181,7 @@ def connect(self): }) ret = CarwingsInitialAppResponse(response) - c1 = Blowfish.new(ret.baseprm.encode(), Blowfish.MODE_ECB) - packedPassword = _PKCS5Padding(self.password) - encryptedPassword = c1.encrypt(packedPassword.encode()) - encodedPassword = base64.standard_b64encode(encryptedPassword) + encodedPassword = encrypt_aes_password(self.password) response = self._request("UserLoginRequest.php", { "RegionCode": self.region_code,