Skip to content

Commit 95b1a54

Browse files
committed
fix: CVE
1 parent 0db19e6 commit 95b1a54

File tree

1 file changed

+18
-19
lines changed

1 file changed

+18
-19
lines changed

pyeudiw/jwk/parse.py

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,15 @@ def parse_certificate(cert: str | bytes) -> JWK:
5959
:rtype: JWK
6060
"""
6161

62-
parse_methods = [
63-
lambda x: parse_pem(x),
64-
lambda x: parse_pem(DER_cert_to_PEM_cert(x)),
65-
]
66-
67-
for method in parse_methods:
68-
try:
69-
return method(cert)
70-
except Exception:
71-
continue
62+
try:
63+
return parse_pem(cert)
64+
except Exception:
65+
pass
66+
67+
try:
68+
return parse_pem(DER_cert_to_PEM_cert(cert))
69+
except Exception:
70+
pass
7271

7372
raise InvalidJwk(f"unable to parse key from pem: {cert}")
7473

@@ -95,14 +94,14 @@ def parse_x5c_keys(x5c: list[str]) -> list[JWK]:
9594
:rtype: JWK
9695
"""
9796

98-
parse_methos = [
99-
lambda x5c: [parse_pem(pem) for pem in x5c],
100-
lambda x5c: [parse_pem(DER_cert_to_PEM_cert(cert)) for cert in x5c],
101-
]
97+
try:
98+
return [parse_certificate(cert) for cert in x5c]
99+
except Exception:
100+
pass
101+
102+
try:
103+
return [parse_certificate(DER_cert_to_PEM_cert(cert)) for cert in x5c]
104+
except Exception:
105+
pass
102106

103-
for method in parse_methos:
104-
try:
105-
return method(x5c)
106-
except Exception:
107-
continue
108107
raise InvalidJwk(f"unable to parse key from pem chain: {x5c}")

0 commit comments

Comments
 (0)