generate jwt every registration call (#20740)

* generate jwt every registration call

* min not max
pull/20741/head
Greg Hogan 4 years ago committed by GitHub
parent 01cb8d401a
commit c9a29d6deb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      selfdrive/registration.py

@ -43,7 +43,6 @@ def register(show_spinner=False):
# Create registration token, in the future, this key will make JWTs directly # Create registration token, in the future, this key will make JWTs directly
private_key = open(PERSIST+"/comma/id_rsa").read() private_key = open(PERSIST+"/comma/id_rsa").read()
public_key = open(PERSIST+"/comma/id_rsa.pub").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 # Block until we get the imei
imei1, imei2 = None, None imei1, imei2 = None, None
@ -58,8 +57,10 @@ def register(show_spinner=False):
params.put("IMEI", imei1) params.put("IMEI", imei1)
params.put("HardwareSerial", serial) params.put("HardwareSerial", serial)
backoff = 0
while True: while True:
try: try:
register_token = jwt.encode({'register': True, 'exp': datetime.utcnow() + timedelta(hours=1)}, private_key, algorithm='RS256')
cloudlog.info("getting pilotauth") cloudlog.info("getting pilotauth")
resp = api_get("v2/pilotauth/", method='POST', timeout=15, resp = api_get("v2/pilotauth/", method='POST', timeout=15,
imei=imei1, imei2=imei2, serial=serial, public_key=public_key, register_token=register_token) imei=imei1, imei2=imei2, serial=serial, public_key=public_key, register_token=register_token)
@ -74,7 +75,8 @@ def register(show_spinner=False):
break break
except Exception: except Exception:
cloudlog.exception("failed to authenticate") cloudlog.exception("failed to authenticate")
time.sleep(1) backoff = min(backoff + 1, 15)
time.sleep(backoff)
if show_spinner: if show_spinner:
spinner.close() spinner.close()

Loading…
Cancel
Save