Skip to content

Release 1.5.1 #82

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 11 commits into from
Apr 12, 2021
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ exclude_lines = [

[tool.poetry]
name = "cryptojwt"
version = "1.5.0"
version = "1.5.1"
description = "Python implementation of JWT, JWE, JWS and JWK"
authors = ["Roland Hedberg <roland@catalogix.se>"]
license = "Apache-2.0"
Expand Down
56 changes: 30 additions & 26 deletions src/cryptojwt/key_bundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import json
import logging
import os
import threading
import time
from datetime import datetime
from functools import cmp_to_key
Expand Down Expand Up @@ -46,6 +47,8 @@

MAP = {"dec": "enc", "enc": "enc", "ver": "sig", "sig": "sig"}

update_lock = threading.Lock()


def harmonize_usage(use):
"""
Expand Down Expand Up @@ -507,34 +510,35 @@ def update(self):
:return: True if update was ok or False if we encountered an error during update.
"""
if self.source:
_old_keys = self._keys # just in case
with update_lock:
_old_keys = self._keys # just in case

# reread everything
self._keys = []
updated = None
# reread everything
self._keys = []
updated = None

try:
if self.local:
if self.fileformat in ["jwks", "jwk"]:
updated = self.do_local_jwk(self.source)
elif self.fileformat == "der":
updated = self.do_local_der(self.source, self.keytype, self.keyusage)
elif self.remote:
updated = self.do_remote()
except Exception as err:
LOGGER.error("Key bundle update failed: %s", err)
self._keys = _old_keys # restore
return False

if updated:
now = time.time()
for _key in _old_keys:
if _key not in self._keys:
if not _key.inactive_since: # If already marked don't mess
_key.inactive_since = now
self._keys.append(_key)
else:
self._keys = _old_keys
try:
if self.local:
if self.fileformat in ["jwks", "jwk"]:
updated = self.do_local_jwk(self.source)
elif self.fileformat == "der":
updated = self.do_local_der(self.source, self.keytype, self.keyusage)
elif self.remote:
updated = self.do_remote()
except Exception as err:
LOGGER.error("Key bundle update failed: %s", err)
self._keys = _old_keys # restore
return False

if updated:
now = time.time()
for _key in _old_keys:
if _key not in self._keys:
if not _key.inactive_since: # If already marked don't mess
_key.inactive_since = now
self._keys.append(_key)
else:
self._keys = _old_keys

return True

Expand Down