@@ -162,6 +162,7 @@ def __init__(
162162 keytype = "RSA" ,
163163 keyusage = None ,
164164 kid = "" ,
165+ ignore_invalid_keys = True ,
165166 httpc = None ,
166167 httpc_params = None ,
167168 ):
@@ -181,6 +182,7 @@ def __init__(
181182 presently 'rsa' and 'ec' are supported.
182183 :param keyusage: What the key loaded from file should be used for.
183184 Only applicable for DER files
185+ :param ignore_invalid_keys: Ignore invalid keys
184186 :param httpc: A HTTP client function
185187 :param httpc_params: Additional parameters to pass to the HTTP client
186188 function
@@ -202,6 +204,7 @@ def __init__(
202204 self .last_updated = 0
203205 self .last_remote = None # HTTP Date of last remote update
204206 self .last_local = None # UNIX timestamp of last local update
207+ self .ignore_invalid_keys = ignore_invalid_keys
205208
206209 if httpc :
207210 self .httpc = httpc
@@ -274,6 +277,8 @@ def do_keys(self, keys):
274277 elif inst ["kty" ].upper () in K2C :
275278 inst ["kty" ] = inst ["kty" ].upper ()
276279 else :
280+ if not self .ignore_invalid_keys :
281+ raise UnknownKeyType (inst )
277282 LOGGER .warning ("While loading keys, unknown key type: %s" , inst ["kty" ])
278283 continue
279284
@@ -290,12 +295,18 @@ def do_keys(self, keys):
290295 try :
291296 _key = K2C [_typ ](use = _use , ** inst )
292297 except KeyError :
298+ if not self .ignore_invalid_keys :
299+ raise UnknownKeyType (inst )
293300 _error = "UnknownKeyType: {}" .format (_typ )
294301 continue
295302 except (UnsupportedECurve , UnsupportedAlgorithm ) as err :
303+ if not self .ignore_invalid_keys :
304+ raise err
296305 _error = str (err )
297306 break
298307 except JWKException as err :
308+ if not self .ignore_invalid_keys :
309+ raise err
299310 LOGGER .warning ("While loading keys: %s" , err )
300311 _error = str (err )
301312 else :
0 commit comments