|
|
|
@ -70,19 +70,19 @@ class LocalKey(Resource): |
|
|
|
|
Resource.__init__(self) |
|
|
|
|
|
|
|
|
|
def update_response_body(self, time_now_msec: int) -> None: |
|
|
|
|
refresh_interval = self.config.key_refresh_interval |
|
|
|
|
refresh_interval = self.config.key.key_refresh_interval |
|
|
|
|
self.valid_until_ts = int(time_now_msec + refresh_interval) |
|
|
|
|
self.response_body = encode_canonical_json(self.response_json_object()) |
|
|
|
|
|
|
|
|
|
def response_json_object(self) -> JsonDict: |
|
|
|
|
verify_keys = {} |
|
|
|
|
for key in self.config.signing_key: |
|
|
|
|
for key in self.config.key.signing_key: |
|
|
|
|
verify_key_bytes = key.verify_key.encode() |
|
|
|
|
key_id = "%s:%s" % (key.alg, key.version) |
|
|
|
|
verify_keys[key_id] = {"key": encode_base64(verify_key_bytes)} |
|
|
|
|
|
|
|
|
|
old_verify_keys = {} |
|
|
|
|
for key_id, key in self.config.old_signing_keys.items(): |
|
|
|
|
for key_id, key in self.config.key.old_signing_keys.items(): |
|
|
|
|
verify_key_bytes = key.encode() |
|
|
|
|
old_verify_keys[key_id] = { |
|
|
|
|
"key": encode_base64(verify_key_bytes), |
|
|
|
@ -95,13 +95,13 @@ class LocalKey(Resource): |
|
|
|
|
"verify_keys": verify_keys, |
|
|
|
|
"old_verify_keys": old_verify_keys, |
|
|
|
|
} |
|
|
|
|
for key in self.config.signing_key: |
|
|
|
|
for key in self.config.key.signing_key: |
|
|
|
|
json_object = sign_json(json_object, self.config.server.server_name, key) |
|
|
|
|
return json_object |
|
|
|
|
|
|
|
|
|
def render_GET(self, request: Request) -> int: |
|
|
|
|
time_now = self.clock.time_msec() |
|
|
|
|
# Update the expiry time if less than half the interval remains. |
|
|
|
|
if time_now + self.config.key_refresh_interval / 2 > self.valid_until_ts: |
|
|
|
|
if time_now + self.config.key.key_refresh_interval / 2 > self.valid_until_ts: |
|
|
|
|
self.update_response_body(time_now) |
|
|
|
|
return respond_with_json_bytes(request, 200, self.response_body) |
|
|
|
|