-
Notifications
You must be signed in to change notification settings - Fork 504
初步接入米家小爱音箱 #250
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: master
Are you sure you want to change the base?
初步接入米家小爱音箱 #250
Conversation
'_sign': resp['_sign'], | ||
'callback': resp['callback'], | ||
'user': self.username, | ||
'hash': hashlib.md5(self.password.encode()).hexdigest().upper() |
Check failure
Code scanning / CodeQL
Use of a broken or weak cryptographic hashing algorithm on sensitive data
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 3 months ago
To fix the problem, we need to replace the use of the MD5 hashing algorithm with a more secure and computationally expensive hashing algorithm suitable for passwords. One of the best options is to use the argon2
algorithm, which is designed for secure password hashing. This will involve importing the argon2
library and updating the code to use argon2
for hashing the password.
- Install the
argon2-cffi
package if it is not already installed. - Import the
PasswordHasher
class from theargon2
library. - Replace the MD5 hashing code with
argon2
hashing.
-
Copy modified line R10 -
Copy modified line R52 -
Copy modified line R67
@@ -1,3 +1,2 @@ | ||
import base64 | ||
import hashlib | ||
import json | ||
@@ -10,2 +9,3 @@ | ||
from aiofiles import open as async_open | ||
from argon2 import PasswordHasher | ||
|
||
@@ -51,2 +51,3 @@ | ||
self.token = None | ||
self.ph = PasswordHasher() | ||
|
||
@@ -65,3 +66,3 @@ | ||
'user': self.username, | ||
'hash': hashlib.md5(self.password.encode()).hexdigest().upper() | ||
'hash': self.ph.hash(self.password) | ||
} |
-
Copy modified lines R20-R21
@@ -19,2 +19,3 @@ | ||
aiodocker | ||
silk-python | ||
silk-python | ||
argon2-cffi==23.1.0 |
Package | Version | Security advisories |
argon2-cffi (pypi) | 23.1.0 | None |
def miot_decode(ssecurity, nonce, data, gzip=False): | ||
from Crypto.Cipher import ARC4 | ||
r = ARC4.new(base64.b64decode(MiIOService.sign_nonce(ssecurity, nonce))) | ||
r.encrypt(bytes(1024)) |
Check failure
Code scanning / CodeQL
Use of a broken or weak cryptographic algorithm
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 3 months ago
To fix the problem, we need to replace the use of the ARC4 algorithm with a more secure algorithm, such as AES. This involves:
- Importing the AES module from
Crypto.Cipher
. - Modifying the
miot_decode
method to use AES for decryption. - Ensuring that the key and data are appropriately handled for AES encryption/decryption.
-
Copy modified lines R166-R169
@@ -165,6 +165,6 @@ | ||
def miot_decode(ssecurity, nonce, data, gzip=False): | ||
from Crypto.Cipher import ARC4 | ||
r = ARC4.new(base64.b64decode(MiIOService.sign_nonce(ssecurity, nonce))) | ||
r.encrypt(bytes(1024)) | ||
decrypted = r.encrypt(base64.b64decode(data)) | ||
from Crypto.Cipher import AES | ||
key = base64.b64decode(MiIOService.sign_nonce(ssecurity, nonce)) | ||
cipher = AES.new(key, AES.MODE_EAX, nonce=base64.b64decode(nonce)) | ||
decrypted = cipher.decrypt(base64.b64decode(data)) | ||
if gzip: |
from Crypto.Cipher import ARC4 | ||
r = ARC4.new(base64.b64decode(MiIOService.sign_nonce(ssecurity, nonce))) | ||
r.encrypt(bytes(1024)) | ||
decrypted = r.encrypt(base64.b64decode(data)) |
Check failure
Code scanning / CodeQL
Use of a broken or weak cryptographic algorithm
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 3 months ago
To fix the problem, we should replace the use of the ARC4 algorithm with a stronger, modern cryptographic algorithm such as AES. The pycryptodome
library provides an implementation of AES that we can use. Specifically, we will use AES in CTR (Counter) mode, which is suitable for stream encryption and is a direct replacement for ARC4 in this context.
We need to:
- Import the AES module from
Crypto.Cipher
. - Replace the ARC4 cipher initialization with AES.
- Adjust the encryption process to use AES.
-
Copy modified lines R166-R171
@@ -165,6 +165,8 @@ | ||
def miot_decode(ssecurity, nonce, data, gzip=False): | ||
from Crypto.Cipher import ARC4 | ||
r = ARC4.new(base64.b64decode(MiIOService.sign_nonce(ssecurity, nonce))) | ||
r.encrypt(bytes(1024)) | ||
decrypted = r.encrypt(base64.b64decode(data)) | ||
from Crypto.Cipher import AES | ||
from Crypto.Util import Counter | ||
key = base64.b64decode(MiIOService.sign_nonce(ssecurity, nonce)) | ||
ctr = Counter.new(128, initial_value=int.from_bytes(base64.b64decode(nonce), byteorder='big')) | ||
cipher = AES.new(key, AES.MODE_CTR, counter=ctr) | ||
decrypted = cipher.decrypt(base64.b64decode(data)) | ||
if gzip: |
99edcc5
to
6c18971
Compare
No description provided.