python-siseli 0.2.0__py3-none-any.whl → 0.2.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {python_siseli-0.2.0.dist-info → python_siseli-0.2.1.dist-info}/METADATA +1 -1
- {python_siseli-0.2.0.dist-info → python_siseli-0.2.1.dist-info}/RECORD +5 -5
- {python_siseli-0.2.0.dist-info → python_siseli-0.2.1.dist-info}/WHEEL +1 -1
- siseli/open_auth.py +21 -30
- {python_siseli-0.2.0.dist-info → python_siseli-0.2.1.dist-info}/top_level.txt +0 -0
|
@@ -10,7 +10,7 @@ siseli/device.py,sha256=crix14pYakrDaFmomPC3Uwgdq-1boZ-ZaEg2HgzXibs,2762
|
|
|
10
10
|
siseli/dictionary.py,sha256=VSO83uXPaGLPzKGRmpROuWQKivXN7DNOmXN8QQJ-Y-w,1120
|
|
11
11
|
siseli/exceptions.py,sha256=y9ws9c2vr5Q3bZxLwkXybUqQooq57YEEXAN0wO3_fxk,1420
|
|
12
12
|
siseli/history.py,sha256=CgBvDfZBIrrewu7PeRv08-Zr4boEVOY8Xevruu-ge-I,3869
|
|
13
|
-
siseli/open_auth.py,sha256=
|
|
13
|
+
siseli/open_auth.py,sha256=w3Jq7ZA2m3d-A_ZR_O8G1bODHvcUJ4Rc1eOS4uq69l0,5570
|
|
14
14
|
siseli/state.py,sha256=d7Exlf7FzF8O_CcF-NbAt6kq8qaR4fFhjGW8028kbrM,5800
|
|
15
15
|
siseli/station.py,sha256=e1OK4OIry9WUjT8KggQI5b4Acypm9D31mWAMTjDGFew,5531
|
|
16
16
|
siseli/models/__init__.py,sha256=WSIXRM_JRKNhB_hDwxrpeQgdqKUHdbT3KiFvdrLrrzY,1242
|
|
@@ -24,7 +24,7 @@ siseli/models/dictionary.py,sha256=d6KCu77UMlPcIDON8G3sjuytkSfbI5go1y3I_jAGTX8,4
|
|
|
24
24
|
siseli/models/history.py,sha256=dx26VWLJosucMvwL36vojvAguvkMiv5GEKTllUtZV0Y,791
|
|
25
25
|
siseli/models/state.py,sha256=VK5CNqMLRkY1w9HrcUhvaO_6J-rjqP7VwvbppCFpucI,2393
|
|
26
26
|
siseli/models/station.py,sha256=02OLINAVblnKkF73ZwKxYvPtUFROsu4-g544oDg8ApA,1783
|
|
27
|
-
python_siseli-0.2.
|
|
28
|
-
python_siseli-0.2.
|
|
29
|
-
python_siseli-0.2.
|
|
30
|
-
python_siseli-0.2.
|
|
27
|
+
python_siseli-0.2.1.dist-info/METADATA,sha256=wzl4nryFI-fsKCerJ7V60RUJggiQTAqX1DAwAnAfba8,1439
|
|
28
|
+
python_siseli-0.2.1.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
|
|
29
|
+
python_siseli-0.2.1.dist-info/top_level.txt,sha256=Dofr9c7hGvRRV6ij6aoPuAZqxEjkgtsBeN4KtFHbGgo,7
|
|
30
|
+
python_siseli-0.2.1.dist-info/RECORD,,
|
siseli/open_auth.py
CHANGED
|
@@ -7,18 +7,20 @@ client (CryptoJS-based) exactly:
|
|
|
7
7
|
1. Decrypt the base64-encoded app secret with AES-128-CBC.
|
|
8
8
|
Key and IV are derived from MD5(app_id) as ASCII hex chars.
|
|
9
9
|
2. Compute a body hash: empty string for GET; SHA-256 hex for everything else.
|
|
10
|
-
3.
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
3. Sign input: ``IOT-Open-AppID``, ``IOT-Open-Body-Hash`` and
|
|
11
|
+
``IOT-Open-Nonce`` only, sorted by key, joined as ``k=v&k=v`` without
|
|
12
|
+
URL-encoding, then base64-encoded (UTF-8).
|
|
13
|
+
4. Sign: HMAC-SHA256(base64_string, secret) raw digest → MD5 → lowercase hex.
|
|
14
|
+
5. The body hash is part of the signature but is NOT sent as an HTTP header.
|
|
13
15
|
"""
|
|
14
16
|
|
|
15
17
|
from __future__ import annotations
|
|
16
18
|
|
|
19
|
+
import base64
|
|
17
20
|
import hashlib
|
|
18
21
|
import hmac
|
|
19
22
|
import uuid
|
|
20
23
|
from typing import TYPE_CHECKING, Any
|
|
21
|
-
from urllib.parse import parse_qs
|
|
22
24
|
|
|
23
25
|
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
|
|
24
26
|
|
|
@@ -37,8 +39,6 @@ def decrypt_open_secret(app_id: str, encrypted_secret_b64: str) -> str:
|
|
|
37
39
|
|
|
38
40
|
ZeroPadding is assumed: trailing null bytes are stripped from the output.
|
|
39
41
|
"""
|
|
40
|
-
import base64
|
|
41
|
-
|
|
42
42
|
md5_hex = hashlib.md5(app_id.encode()).hexdigest() # noqa: S324
|
|
43
43
|
key = md5_hex[:16].encode("ascii")
|
|
44
44
|
iv = md5_hex[16:].encode("ascii")
|
|
@@ -72,7 +72,8 @@ def build_open_headers(
|
|
|
72
72
|
method:
|
|
73
73
|
HTTP method ("GET", "POST", …).
|
|
74
74
|
query:
|
|
75
|
-
The raw query string portion of the URL
|
|
75
|
+
The raw query string portion of the URL. Accepted for API
|
|
76
|
+
compatibility; it does not take part in the signature.
|
|
76
77
|
body:
|
|
77
78
|
Raw request body bytes, or *None* / empty for GET requests.
|
|
78
79
|
app_id:
|
|
@@ -90,39 +91,28 @@ def build_open_headers(
|
|
|
90
91
|
else:
|
|
91
92
|
body_hash = _sha256_hex(body if body else b"")
|
|
92
93
|
|
|
93
|
-
# --- params
|
|
94
|
-
params
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
for field in ("IOT-Open-AppID", "IOT-Open-Nonce", "IOT-Open-Sign", "IOT-Open-Body-Hash"):
|
|
101
|
-
params.pop(field, None)
|
|
102
|
-
|
|
103
|
-
params["IOT-Open-AppID"] = app_id
|
|
104
|
-
params["IOT-Open-Nonce"] = nonce
|
|
105
|
-
params["IOT-Open-Body-Hash"] = body_hash
|
|
106
|
-
|
|
107
|
-
# Sort alphabetically (case-sensitive, matching JS default sort order).
|
|
108
|
-
query_str = "&".join(f"{k}={v}" for k, v in sorted(params.items()))
|
|
94
|
+
# --- sign input: exactly three params, sorted, no URL-encoding -----------
|
|
95
|
+
params = {
|
|
96
|
+
"IOT-Open-AppID": app_id,
|
|
97
|
+
"IOT-Open-Body-Hash": body_hash,
|
|
98
|
+
"IOT-Open-Nonce": nonce,
|
|
99
|
+
}
|
|
100
|
+
signing_string = "&".join(f"{k}={v}" for k, v in sorted(params.items()))
|
|
109
101
|
|
|
110
|
-
# --- sign
|
|
111
|
-
|
|
112
|
-
# Then: HmacSHA256(hex_string, secret) → MD5 → hex
|
|
113
|
-
hex_str = query_str.encode("utf-8").hex()
|
|
102
|
+
# --- sign: base64 -> HMAC-SHA256 (raw digest) -> MD5 hex -----------------
|
|
103
|
+
base64_input = base64.b64encode(signing_string.encode("utf-8")).decode("ascii")
|
|
114
104
|
hmac_digest = hmac.new(
|
|
115
105
|
app_secret.encode("utf-8"),
|
|
116
|
-
|
|
106
|
+
base64_input.encode("ascii"),
|
|
117
107
|
hashlib.sha256,
|
|
118
108
|
).digest()
|
|
119
109
|
sign = hashlib.md5(hmac_digest).hexdigest() # noqa: S324
|
|
120
110
|
|
|
111
|
+
# The body hash takes part in the signature but is not sent as a header.
|
|
121
112
|
return {
|
|
122
113
|
"IOT-Time-Zone": timezone,
|
|
123
114
|
"IOT-Open-AppID": app_id,
|
|
124
115
|
"IOT-Open-Nonce": nonce,
|
|
125
|
-
"IOT-Open-Body-Hash": body_hash,
|
|
126
116
|
"IOT-Open-Sign": sign,
|
|
127
117
|
}
|
|
128
118
|
|
|
@@ -141,9 +131,10 @@ def attach_open_auth(
|
|
|
141
131
|
- ``IOT-Time-Zone``
|
|
142
132
|
- ``IOT-Open-AppID``
|
|
143
133
|
- ``IOT-Open-Nonce``
|
|
144
|
-
- ``IOT-Open-Body-Hash``
|
|
145
134
|
- ``IOT-Open-Sign``
|
|
146
135
|
|
|
136
|
+
``IOT-Open-Body-Hash`` is part of the signature but is not sent.
|
|
137
|
+
|
|
147
138
|
Parameters
|
|
148
139
|
----------
|
|
149
140
|
client:
|
|
File without changes
|