@@ -162,6 +162,7 @@ def __init__(
162
162
keytype = "RSA" ,
163
163
keyusage = None ,
164
164
kid = "" ,
165
+ ignore_invalid_keys = True ,
165
166
httpc = None ,
166
167
httpc_params = None ,
167
168
):
@@ -181,6 +182,7 @@ def __init__(
181
182
presently 'rsa' and 'ec' are supported.
182
183
:param keyusage: What the key loaded from file should be used for.
183
184
Only applicable for DER files
185
+ :param ignore_invalid_keys: Ignore invalid keys
184
186
:param httpc: A HTTP client function
185
187
:param httpc_params: Additional parameters to pass to the HTTP client
186
188
function
@@ -202,6 +204,7 @@ def __init__(
202
204
self .last_updated = 0
203
205
self .last_remote = None # HTTP Date of last remote update
204
206
self .last_local = None # UNIX timestamp of last local update
207
+ self .ignore_invalid_keys = ignore_invalid_keys
205
208
206
209
if httpc :
207
210
self .httpc = httpc
@@ -274,6 +277,8 @@ def do_keys(self, keys):
274
277
elif inst ["kty" ].upper () in K2C :
275
278
inst ["kty" ] = inst ["kty" ].upper ()
276
279
else :
280
+ if not self .ignore_invalid_keys :
281
+ raise UnknownKeyType (inst )
277
282
LOGGER .warning ("While loading keys, unknown key type: %s" , inst ["kty" ])
278
283
continue
279
284
@@ -290,12 +295,18 @@ def do_keys(self, keys):
290
295
try :
291
296
_key = K2C [_typ ](use = _use , ** inst )
292
297
except KeyError :
298
+ if not self .ignore_invalid_keys :
299
+ raise UnknownKeyType (inst )
293
300
_error = "UnknownKeyType: {}" .format (_typ )
294
301
continue
295
302
except (UnsupportedECurve , UnsupportedAlgorithm ) as err :
303
+ if not self .ignore_invalid_keys :
304
+ raise err
296
305
_error = str (err )
297
306
break
298
307
except JWKException as err :
308
+ if not self .ignore_invalid_keys :
309
+ raise err
299
310
LOGGER .warning ("While loading keys: %s" , err )
300
311
_error = str (err )
301
312
else :
0 commit comments