2
2
import logging
3
3
import os
4
4
5
+ from requests import request
6
+
5
7
from .jws .utils import alg2keytype as jws_alg2keytype
6
8
from .jwe .jwe import alg2keytype as jwe_alg2keytype
7
9
8
10
from .exception import DeSerializationNotPossible
9
11
from .key_bundle import KeyBundle
10
12
from .key_bundle import ec_init
11
13
from .key_bundle import rsa_init
12
- from .utils import as_bytes
13
- from .utils import b64e
14
14
15
15
16
16
__author__ = 'Roland Hedberg'
@@ -38,7 +38,7 @@ class KeyJar(object):
38
38
""" A keyjar contains a number of KeyBundles sorted by owner/issuer """
39
39
40
40
def __init__ (self , ca_certs = None , verify_ssl = True , keybundle_cls = KeyBundle ,
41
- remove_after = 3600 ):
41
+ remove_after = 3600 , httpc = None ):
42
42
"""
43
43
KeyJar init function
44
44
@@ -52,6 +52,7 @@ def __init__(self, ca_certs=None, verify_ssl=True, keybundle_cls=KeyBundle,
52
52
self .verify_ssl = verify_ssl
53
53
self .keybundle_cls = keybundle_cls
54
54
self .remove_after = remove_after
55
+ self .httpc = httpc or request
55
56
56
57
def __repr__ (self ):
57
58
issuers = list (self .issuer_keys .keys ())
@@ -74,10 +75,11 @@ def add_url(self, issuer, url, **kwargs):
74
75
raise KeyError ("No url given" )
75
76
76
77
if "/localhost:" in url or "/localhost/" in url :
77
- kb = self .keybundle_cls (source = url , verify_ssl = False , ** kwargs )
78
+ kb = self .keybundle_cls (source = url , verify_ssl = False ,
79
+ httpc = self .httpc , ** kwargs )
78
80
else :
79
81
kb = self .keybundle_cls (source = url , verify_ssl = self .verify_ssl ,
80
- ** kwargs )
82
+ httpc = self . httpc , ** kwargs )
81
83
82
84
self .add_kb (issuer , kb )
83
85
@@ -679,10 +681,10 @@ def build_keyjar(key_conf, kid_template="", keyjar=None, owner=''):
679
681
680
682
kid = 0
681
683
684
+ tot_kb = KeyBundle ()
682
685
for spec in key_conf :
683
686
typ = spec ["type" ].upper ()
684
687
685
- kb = {}
686
688
if typ == "RSA" :
687
689
if "key" in spec :
688
690
error_to_catch = (OSError , IOError ,
@@ -699,6 +701,8 @@ def build_keyjar(key_conf, kid_template="", keyjar=None, owner=''):
699
701
kb = rsa_init (spec )
700
702
elif typ == "EC" :
701
703
kb = ec_init (spec )
704
+ else :
705
+ continue
702
706
703
707
for k in kb .keys ():
704
708
if kid_template :
@@ -707,7 +711,9 @@ def build_keyjar(key_conf, kid_template="", keyjar=None, owner=''):
707
711
else :
708
712
k .add_kid ()
709
713
710
- keyjar .add_kb (owner , kb )
714
+ tot_kb .extend (kb .keys ())
715
+
716
+ keyjar .add_kb (owner , tot_kb )
711
717
712
718
return keyjar
713
719
0 commit comments