-
-
Notifications
You must be signed in to change notification settings - Fork 275
Support Turing Smart Display 8.8" V1.x #892
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
| cipher = DES.new(key, DES.MODE_CBC, key) | ||
| padded_len = (len(data) + 7) // 8 * 8 | ||
| padded_data = data.ljust(padded_len, b'\x00') | ||
| return cipher.encrypt(padded_data) |
Check failure
Code scanning / CodeQL
Use of a broken or weak cryptographic algorithm High
The cryptographic algorithm DES
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 3 days ago
To fix the issue, replace the use of DES with AES. Update both imports and code so that encrypt_with_des is converted to encrypt_with_aes, using parameters suitable for AES. This involves importing AES from Crypto.Cipher, replacing the key and IV to match AES requirements (key lengths of 16, 24, or 32 bytes; IV length of exactly 16 bytes for AES-CBC), and padding plaintext to a multiple of AES block size (16 bytes). Update usages of both the encryption method and key/IV selection. You should edit the regions touching lines 33 (import), the definition of encrypt_with_des (~lines 56–61), and the related usages in encrypt_command_packet.
We need to:
- Replace
from Crypto.Cipher import DESwithfrom Crypto.Cipher import AES. - Replace
encrypt_with_desand its logic with an AES version (encrypt_with_aes), updating padding and key sizing. - Update any references to DES keys/constants and method calls to match AES requirements (key/IV).
- Update usages in
encrypt_command_packetaccordingly.
-
Copy modified line R33 -
Copy modified lines R56-R59 -
Copy modified lines R64-R67
| @@ -30,7 +30,7 @@ | ||
|
|
||
| import usb.core | ||
| import usb.util | ||
| from Crypto.Cipher import DES | ||
| from Crypto.Cipher import AES | ||
| from PIL import Image | ||
|
|
||
| from library.log import logger | ||
| @@ -53,16 +53,18 @@ | ||
| return packet | ||
|
|
||
|
|
||
| def encrypt_with_des(key: bytes, data: bytes) -> bytes: | ||
| cipher = DES.new(key, DES.MODE_CBC, key) | ||
| padded_len = (len(data) + 7) // 8 * 8 | ||
| def encrypt_with_aes(key: bytes, iv: bytes, data: bytes) -> bytes: | ||
| cipher = AES.new(key, AES.MODE_CBC, iv) | ||
| block_size = AES.block_size # 16 bytes | ||
| padded_len = (len(data) + block_size - 1) // block_size * block_size | ||
| padded_data = data.ljust(padded_len, b'\x00') | ||
| return cipher.encrypt(padded_data) | ||
|
|
||
|
|
||
| def encrypt_command_packet(data: bytearray) -> bytearray: | ||
| des_key = b'slv3tuzx' | ||
| encrypted = encrypt_with_des(des_key, data) | ||
| # AES requires key of length 16, 24, or 32 bytes, and IV of length 16 bytes (block size) | ||
| aes_key = b'slv3tuzx12345678' # NOTE: must be 16 bytes for AES-128; adjust as needed. | ||
| aes_iv = b'\x00' * 16 # Fixed IV for example; ideally, use a random IV and transmit it with the packet. | ||
| encrypted = encrypt_with_aes(aes_key, aes_iv, data) | ||
| final_packet = bytearray(512) | ||
| final_packet[:len(encrypted)] = encrypted | ||
| final_packet[510] = 161 |
Might also add support for the following models: