Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 3a1daf3857 | |||
| 52dd9f050e |
19
main.py
19
main.py
@@ -66,12 +66,15 @@ def _aes_cbc_b64(pt, key, iv):
|
|||||||
|
|
||||||
|
|
||||||
def _sign(model, cfg, t_ms):
|
def _sign(model, cfg, t_ms):
|
||||||
a = _sha_hex("computility:model-verify:browser-submit" + "|v1|" + str(t_ms) + "|" + model)
|
try:
|
||||||
ii = _sha_hex(cfg)
|
a = _sha_hex("computility:model-verify:browser-submit" + "|v1|" + str(t_ms) + "|" + model)
|
||||||
kf = _sha_bytes("key|" + a + "|" + ii)[:16]
|
ii = _sha_hex(cfg)
|
||||||
ivf = _sha_bytes("iv|" + model + "|" + str(t_ms) + "|" + str(len(cfg)))[:16]
|
kf = _sha_bytes("key|" + a + "|" + ii)[:16]
|
||||||
o = str(t_ms) + "\n" + model + "\n" + cfg
|
ivf = _sha_bytes("iv|" + model + "|" + str(t_ms) + "|" + str(len(cfg)))[:16]
|
||||||
return _sha_hex("v1." + a + "." + _aes_cbc_b64(o, kf, ivf) + "." + ii)
|
o = str(t_ms) + "\n" + model + "\n" + cfg
|
||||||
|
return _sha_hex("v1." + a + "." + _aes_cbc_b64(o, kf, ivf) + "." + ii)
|
||||||
|
except Exception:
|
||||||
|
return None # cryptography 不可用(零依赖构建)→ 提交走 token-only
|
||||||
|
|
||||||
|
|
||||||
def build_config(gpu):
|
def build_config(gpu):
|
||||||
@@ -109,7 +112,9 @@ def _post(model, gpu, cfg, signed):
|
|||||||
t_ms = int(time.time() * 1000)
|
t_ms = int(time.time() * 1000)
|
||||||
h = {"Authorization": TOKEN, "Content-Type": "application/json"}
|
h = {"Authorization": TOKEN, "Content-Type": "application/json"}
|
||||||
if signed:
|
if signed:
|
||||||
h.update({"X-Request-Time": str(t_ms), "X-Model-Address": model, "X-Request-Sign": _sign(model, cfg, t_ms)})
|
sig = _sign(model, cfg, t_ms)
|
||||||
|
if sig:
|
||||||
|
h.update({"X-Request-Time": str(t_ms), "X-Model-Address": model, "X-Request-Sign": sig})
|
||||||
body = json.dumps({"modelAddress": model, "taskType": TASK_TYPE, "targetGpu": gpu,
|
body = json.dumps({"modelAddress": model, "taskType": TASK_TYPE, "targetGpu": gpu,
|
||||||
"framework": FRAMEWORK, "configParams": cfg})
|
"framework": FRAMEWORK, "configParams": cfg})
|
||||||
st, txt = _http("POST", MAIN + "/api/adapt/task/add", h, body)
|
st, txt = _http("POST", MAIN + "/api/adapt/task/add", h, body)
|
||||||
|
|||||||
@@ -1 +1,2 @@
|
|||||||
cryptography>=42.0.0
|
# 零依赖:纯 stdlib。签名需 AES,构建环境 pip 装 cryptography 会卡(疑 PyPI 不通),
|
||||||
|
# 故设为可选——签名不可用时提交走 token-only。确认需签名后再解决 crypto。
|
||||||
|
|||||||
Reference in New Issue
Block a user