Skip to content

Instantly share code, notes, and snippets.

@dajiaji
Created July 12, 2021 23:13
Show Gist options
  • Save dajiaji/c4d64d463f9e1f1e3d6e15e8e060cd59 to your computer and use it in GitHub Desktop.
Save dajiaji/c4d64d463f9e1f1e3d6e15e8e060cd59 to your computer and use it in GitHub Desktop.
A simple EUDCC verifier implementation with Python CWT: refresh_trustlist
def refresh_trustlist(self):
self._dscs = []
self._trustlist = []
# Get a trust-list signer certificate.
r = requests.get(self._base_url + "/cert")
if r.status_code != 200:
raise Exception(f"Received {r.status_code} from /cert")
key = r.text
cose_key = COSEKey.from_pem(key)
# Get DSCs
r = requests.get(self._base_url + "/trust-list")
if r.status_code != 200:
raise Exception(f"Received {r.status_code} from /trust-list")
decoded = jwt.decode(
r.text,
cose_key.key,
algorithms=["ES256"],
options={"verify_aud": False},
)
for v in decoded["dsc_trust_list"].values():
for k in v["keys"]:
if "use" in k and k["use"] == "enc":
# Workaround for a wrong DSC.
del k["use"]
if k["kty"] == "RSA":
k["alg"] = "PS256"
self._dscs.append(COSEKey.from_jwk(k))
self._trustlist.append(k)
# Update trustlist store.
with open(self._trustlist_store_path, "w") as f:
json.dump(self._trustlist, f, indent=4)
return
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment