mirror of
https://github.com/infiniteCable2/openpilot.git
synced 2026-08-05 08:16:03 +08:00
generate jwt every registration call (#20740)
* generate jwt every registration call * min not max old-commit-hash: c9a29d6debc93e42a4f3b0e730cb68d0682d4ca7
This commit is contained in:
@@ -43,7 +43,6 @@ def register(show_spinner=False):
|
||||
# Create registration token, in the future, this key will make JWTs directly
|
||||
private_key = open(PERSIST+"/comma/id_rsa").read()
|
||||
public_key = open(PERSIST+"/comma/id_rsa.pub").read()
|
||||
register_token = jwt.encode({'register': True, 'exp': datetime.utcnow() + timedelta(hours=1)}, private_key, algorithm='RS256')
|
||||
|
||||
# Block until we get the imei
|
||||
imei1, imei2 = None, None
|
||||
@@ -58,8 +57,10 @@ def register(show_spinner=False):
|
||||
params.put("IMEI", imei1)
|
||||
params.put("HardwareSerial", serial)
|
||||
|
||||
backoff = 0
|
||||
while True:
|
||||
try:
|
||||
register_token = jwt.encode({'register': True, 'exp': datetime.utcnow() + timedelta(hours=1)}, private_key, algorithm='RS256')
|
||||
cloudlog.info("getting pilotauth")
|
||||
resp = api_get("v2/pilotauth/", method='POST', timeout=15,
|
||||
imei=imei1, imei2=imei2, serial=serial, public_key=public_key, register_token=register_token)
|
||||
@@ -74,7 +75,8 @@ def register(show_spinner=False):
|
||||
break
|
||||
except Exception:
|
||||
cloudlog.exception("failed to authenticate")
|
||||
time.sleep(1)
|
||||
backoff = min(backoff + 1, 15)
|
||||
time.sleep(backoff)
|
||||
|
||||
if show_spinner:
|
||||
spinner.close()
|
||||
|
||||
Reference in New Issue
Block a user