Skip to content

Fix key update #117

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 14, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions src/cryptojwt/key_bundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,10 +362,9 @@ def jwk_dicts_as_keys(self, keys):
LOGGER.warning("While loading keys: %s", err)
_error = str(err)
else:
if _key not in self._keys:
if not _key.kid:
_key.add_kid()
_new_keys.append(_key)
if not _key.kid:
_key.add_kid()
_new_keys.append(_key)
_error = ""

if _error:
Expand Down Expand Up @@ -514,7 +513,7 @@ def _parse_remote_response(self, response):
# Check if the content type is the right one.
try:
if not check_content_type(response.headers["Content-Type"], "application/json"):
LOGGER.warning("Wrong Content_type (%s)", respeonse.headers["Content-Type"])
LOGGER.warning("Wrong Content_type (%s)", response.headers["Content-Type"])
except KeyError:
pass

Expand All @@ -541,19 +540,20 @@ def update(self):
:return: True if update was ok or False if we encountered an error during update.
"""
if self.source:
new_keys = []
updated = None

try:
if self.local:
if self.fileformat in ["jwks", "jwk"]:
updated, k = self._do_local_jwk(self.source)
updated, new_keys = self._do_local_jwk(self.source)
elif self.fileformat == "der":
updated, k = self._do_local_der(self.source, self.keytype, self.keyusage)
updated, new_keys = self._do_local_der(
self.source, self.keytype, self.keyusage
)
elif self.remote:
updated, k = self._do_remote(set_keys=False)
if k:
new_keys.extend(k)
updated, new_keys = self._do_remote(set_keys=False)
else:
new_keys = None
updated = False
except Exception as err:
LOGGER.error("Key bundle update failed: %s", err)
return False
Expand All @@ -564,7 +564,7 @@ def update(self):
if _key not in new_keys:
if not _key.inactive_since: # If already marked don't mess
_key.inactive_since = now
new_keys.append(_key)
new_keys.append(_key)
self._keys = new_keys

return True
Expand Down