@@ -36,21 +36,29 @@ class KeyJar(object):
36
36
""" A keyjar contains a number of KeyBundles sorted by owner/issuer """
37
37
38
38
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 ):
40
40
"""
41
41
KeyJar init function
42
42
43
43
:param ca_certs: CA certificates, to be used for HTTPS
44
44
: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
45
49
:return: Keyjar instance
46
50
"""
47
51
self .spec2key = {}
48
52
self .issuer_keys = {}
49
53
self .ca_certs = ca_certs
50
- self .verify_ssl = verify_ssl
51
54
self .keybundle_cls = keybundle_cls
52
55
self .remove_after = remove_after
53
56
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
54
62
55
63
def __repr__ (self ):
56
64
issuers = list (self .issuer_keys .keys ())
@@ -73,11 +81,13 @@ def add_url(self, issuer, url, **kwargs):
73
81
raise KeyError ("No url given" )
74
82
75
83
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 )
78
88
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 )
81
91
82
92
kb .update ()
83
93
self .add_kb (issuer , kb )
@@ -104,9 +114,7 @@ def add_symmetric(self, issuer, key, usage=None):
104
114
else :
105
115
for use in usage :
106
116
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 }]))
110
118
111
119
def add_kb (self , issuer , kb ):
112
120
"""
@@ -412,10 +420,10 @@ def import_jwks(self, jwks, issuer):
412
420
else :
413
421
try :
414
422
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 ))
416
424
except KeyError :
417
425
self .issuer_keys [issuer ] = [self .keybundle_cls (
418
- _keys , verify_ssl = self .verify_ssl )]
426
+ _keys , httpc = self .httpc , httpc_params = self . httpc_params )]
419
427
420
428
def import_jwks_as_json (self , jwks , issuer ):
421
429
"""
@@ -458,7 +466,7 @@ def remove_outdated(self, when=0):
458
466
Outdated keys are keys that has been marked as inactive at a time that
459
467
is longer ago then some set number of seconds (when). If when=0 the
460
468
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
462
470
key jar.
463
471
464
472
:param when: To facilitate testing
@@ -485,8 +493,7 @@ def _add_key(self, keys, issuer, use, key_type='', kid='',
485
493
issuer , key_summary (self , issuer )))
486
494
487
495
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 ):
490
497
if _key and _key not in keys :
491
498
keys .append (_key )
492
499
return keys
@@ -637,7 +644,8 @@ def copy(self):
637
644
for issuer in self .owners ():
638
645
kj [issuer ] = [kb .copy () for kb in self [issuer ]]
639
646
640
- kj .verify_ssl = self .verify_ssl
647
+ kj .httpc_params = self .httpc_params
648
+ kj .httpc = self .httpc
641
649
return kj
642
650
643
651
0 commit comments