@@ -36,21 +36,29 @@ class KeyJar(object):
3636 """ A keyjar contains a number of KeyBundles sorted by owner/issuer """
3737
3838 def __init__ (self , ca_certs = None , verify_ssl = True , keybundle_cls = KeyBundle ,
39- remove_after = 3600 , httpc = None ):
39+ remove_after = 3600 , httpc = None , httpc_params = None ):
4040 """
4141 KeyJar init function
4242
4343 :param ca_certs: CA certificates, to be used for HTTPS
4444 :param verify_ssl: Attempting SSL certificate verification
45+ :param keybundle_cls: The KeyBundle class
46+ :param remove_after: How long keys marked as inactive will remain in the key Jar.
47+ :param httpc: A HTTP client to use. Default is Requests request.
48+ :param httpc_params: HTTP request parameters
4549 :return: Keyjar instance
4650 """
4751 self .spec2key = {}
4852 self .issuer_keys = {}
4953 self .ca_certs = ca_certs
50- self .verify_ssl = verify_ssl
5154 self .keybundle_cls = keybundle_cls
5255 self .remove_after = remove_after
5356 self .httpc = httpc or request
57+ self .httpc_params = httpc_params or {}
58+ # Now part of httpc_params
59+ # self.verify_ssl = verify_ssl
60+ if not self .httpc_params : # backward compatibility
61+ self .httpc_params ["verify" ] = verify_ssl
5462
5563 def __repr__ (self ):
5664 issuers = list (self .issuer_keys .keys ())
@@ -73,11 +81,13 @@ def add_url(self, issuer, url, **kwargs):
7381 raise KeyError ("No url given" )
7482
7583 if "/localhost:" in url or "/localhost/" in url :
76- kb = self .keybundle_cls (source = url , verify_ssl = False ,
77- httpc = self .httpc , ** kwargs )
84+ _params = self .httpc_params .copy ()
85+ _params ['verify' ] = False
86+ kb = self .keybundle_cls (source = url , httpc = self .httpc ,
87+ httpc_params = _params , ** kwargs )
7888 else :
79- kb = self .keybundle_cls (source = url , verify_ssl = self .verify_ssl ,
80- httpc = self .httpc , ** kwargs )
89+ kb = self .keybundle_cls (source = url , httpc = self .httpc ,
90+ httpc_params = self .httpc_params , ** kwargs )
8191
8292 kb .update ()
8393 self .add_kb (issuer , kb )
@@ -104,9 +114,7 @@ def add_symmetric(self, issuer, key, usage=None):
104114 else :
105115 for use in usage :
106116 self .issuer_keys [issuer ].append (
107- self .keybundle_cls ([{"kty" : "oct" ,
108- "key" : key ,
109- "use" : use }]))
117+ self .keybundle_cls ([{"kty" : "oct" , "key" : key , "use" : use }]))
110118
111119 def add_kb (self , issuer , kb ):
112120 """
@@ -412,10 +420,10 @@ def import_jwks(self, jwks, issuer):
412420 else :
413421 try :
414422 self .issuer_keys [issuer ].append (
415- self .keybundle_cls (_keys , verify_ssl = self .verify_ssl ))
423+ self .keybundle_cls (_keys , httpc = self .httpc , httpc_params = self . httpc_params ))
416424 except KeyError :
417425 self .issuer_keys [issuer ] = [self .keybundle_cls (
418- _keys , verify_ssl = self .verify_ssl )]
426+ _keys , httpc = self .httpc , httpc_params = self . httpc_params )]
419427
420428 def import_jwks_as_json (self , jwks , issuer ):
421429 """
@@ -458,7 +466,7 @@ def remove_outdated(self, when=0):
458466 Outdated keys are keys that has been marked as inactive at a time that
459467 is longer ago then some set number of seconds (when). If when=0 the
460468 the base time is set to now.
461- The number of seconds a carried in the remove_after parameter in the
469+ The number of seconds are carried in the remove_after parameter in the
462470 key jar.
463471
464472 :param when: To facilitate testing
@@ -485,8 +493,7 @@ def _add_key(self, keys, issuer, use, key_type='', kid='',
485493 issuer , key_summary (self , issuer )))
486494
487495 if kid :
488- for _key in self .get (key_use = use , owner = issuer , kid = kid ,
489- key_type = key_type ):
496+ for _key in self .get (key_use = use , owner = issuer , kid = kid , key_type = key_type ):
490497 if _key and _key not in keys :
491498 keys .append (_key )
492499 return keys
@@ -637,7 +644,8 @@ def copy(self):
637644 for issuer in self .owners ():
638645 kj [issuer ] = [kb .copy () for kb in self [issuer ]]
639646
640- kj .verify_ssl = self .verify_ssl
647+ kj .httpc_params = self .httpc_params
648+ kj .httpc = self .httpc
641649 return kj
642650
643651
0 commit comments