11
11
from .key_issuer import KeyIssuer
12
12
from .key_issuer import build_keyissuer
13
13
from .key_issuer import init_key_issuer
14
+ from .utils import deprecated_alias
14
15
from .utils import importer
15
16
from .utils import qualified_name
16
17
@@ -79,6 +80,7 @@ def _issuer_ids(self) -> List[str]:
79
80
"""
80
81
return list (self ._issuers .keys ())
81
82
83
+ @deprecated_alias (issuer = 'issuer_id' , owner = 'issuer_id' )
82
84
def _get_issuer (self , issuer_id : str ) -> Optional [KeyIssuer ]:
83
85
"""
84
86
Return the KeyIssuer instance that has name == issuer_id
@@ -89,6 +91,7 @@ def _get_issuer(self, issuer_id: str) -> Optional[KeyIssuer]:
89
91
90
92
return self ._issuers .get (issuer_id )
91
93
94
+ @deprecated_alias (issuer = 'issuer_id' , owner = 'issuer_id' )
92
95
def _add_issuer (self , issuer_id ) -> KeyIssuer :
93
96
_iss = KeyIssuer (ca_certs = self .ca_certs , name = issuer_id ,
94
97
keybundle_cls = self .keybundle_cls ,
@@ -109,6 +112,7 @@ def __repr__(self):
109
112
issuers = self ._issuer_ids ()
110
113
return '<KeyJar(issuers={})>' .format (issuers )
111
114
115
+ @deprecated_alias (issuer = 'issuer_id' , owner = 'issuer_id' )
112
116
def return_issuer (self , issuer_id ):
113
117
"""
114
118
Return a KeyIssuer instance with name == issuer_id.
@@ -122,6 +126,7 @@ def return_issuer(self, issuer_id):
122
126
return self ._add_issuer (issuer_id )
123
127
return _iss
124
128
129
+ @deprecated_alias (issuer = 'issuer_id' , owner = 'issuer_id' )
125
130
def add_url (self , issuer_id : str , url : str , ** kwargs ) -> KeyBundle :
126
131
"""
127
132
Add a set of keys by url. This method will create a
@@ -139,20 +144,22 @@ def add_url(self, issuer_id: str, url: str, **kwargs) -> KeyBundle:
139
144
kb = issuer .add_url (url , ** kwargs )
140
145
return kb
141
146
147
+ @deprecated_alias (issuer = 'issuer_id' , owner = 'issuer_id' )
142
148
def add_symmetric (self , issuer_id , key , usage = None ):
143
149
"""
144
150
Add a symmetric key. This is done by wrapping it in a key bundle
145
151
cloak since KeyJar does not handle keys directly but only through
146
152
key bundles.
147
153
148
- :param issuer : Owner of the key
154
+ :param issuer_id : Owner of the key
149
155
:param key: The key
150
156
:param usage: What the key can be used for signing/signature
151
157
verification (sig) and/or encryption/decryption (enc)
152
158
"""
153
159
issuer = self .return_issuer (issuer_id )
154
160
issuer .add_symmetric (key , usage = usage )
155
161
162
+ @deprecated_alias (issuer = 'issuer_id' , owner = 'issuer_id' )
156
163
def add_kb (self , issuer_id , kb ):
157
164
"""
158
165
Add a key bundle and bind it to an identifier
@@ -164,6 +171,7 @@ def add_kb(self, issuer_id, kb):
164
171
issuer .add_kb (kb )
165
172
self [issuer_id ] = issuer
166
173
174
+ @deprecated_alias (issuer = 'issuer_id' , owner = 'issuer_id' )
167
175
def get (self , key_use , key_type = "" , issuer_id = "" , kid = None , ** kwargs ):
168
176
"""
169
177
Get all keys that matches a set of search criteria
@@ -242,6 +250,7 @@ def get(self, key_use, key_type="", issuer_id="", kid=None, **kwargs):
242
250
#
243
251
# return lst
244
252
253
+ @deprecated_alias (issuer = 'issuer_id' , owner = 'issuer_id' )
245
254
def get_signing_key (self , key_type = "" , issuer_id = "" , kid = None , ** kwargs ):
246
255
"""
247
256
Shortcut to use for signing keys only.
@@ -254,15 +263,19 @@ def get_signing_key(self, key_type="", issuer_id="", kid=None, **kwargs):
254
263
"""
255
264
return self .get ("sig" , key_type , issuer_id , kid , ** kwargs )
256
265
266
+ @deprecated_alias (issuer = 'issuer_id' , owner = 'issuer_id' )
257
267
def get_verify_key (self , key_type = "" , issuer_id = "" , kid = None , ** kwargs ):
258
268
return self .get ("ver" , key_type , issuer_id , kid , ** kwargs )
259
269
270
+ @deprecated_alias (issuer = 'issuer_id' , owner = 'issuer_id' )
260
271
def get_encrypt_key (self , key_type = "" , issuer_id = "" , kid = None , ** kwargs ):
261
272
return self .get ("enc" , key_type , issuer_id , kid , ** kwargs )
262
273
274
+ @deprecated_alias (issuer = 'issuer_id' , owner = 'issuer_id' )
263
275
def get_decrypt_key (self , key_type = "" , issuer_id = "" , kid = None , ** kwargs ):
264
276
return self .get ("dec" , key_type , issuer_id , kid , ** kwargs )
265
277
278
+ @deprecated_alias (issuer = 'issuer_id' , owner = 'issuer_id' )
266
279
def keys_by_alg_and_usage (self , issuer_id , alg , usage ):
267
280
"""
268
281
Find all keys that can be used for a specific crypto algorithm and
@@ -280,11 +293,12 @@ def keys_by_alg_and_usage(self, issuer_id, alg, usage):
280
293
281
294
return self .get (usage , ktype , issuer_id )
282
295
296
+ @deprecated_alias (issuer = 'issuer_id' , owner = 'issuer_id' )
283
297
def get_issuer_keys (self , issuer_id ):
284
298
"""
285
299
Get all the keys that belong to an entity.
286
300
287
- :param issuer : The entity ID
301
+ :param issuer_id : The entity ID
288
302
:return: A possibly empty list of keys
289
303
"""
290
304
_issuer = self ._get_issuer (issuer_id )
@@ -293,12 +307,14 @@ def get_issuer_keys(self, issuer_id):
293
307
else :
294
308
return []
295
309
310
+ @deprecated_alias (issuer = 'issuer_id' , owner = 'issuer_id' )
296
311
def __contains__ (self , issuer_id ):
297
312
if self ._get_issuer (issuer_id ):
298
313
return True
299
314
else :
300
315
return False
301
316
317
+ @deprecated_alias (issuer = 'issuer_id' , owner = 'issuer_id' )
302
318
def __getitem__ (self , issuer_id = '' ):
303
319
"""
304
320
Get all the KeyIssuer with the name == issuer_id
@@ -308,14 +324,15 @@ def __getitem__(self, issuer_id=''):
308
324
"""
309
325
return self ._get_issuer (issuer_id )
310
326
311
- def __setitem__ (self , issuer_id , issuer ):
327
+ @deprecated_alias (issuer = 'issuer_id' , owner = 'issuer_id' )
328
+ def __setitem__ (self , issuer_id , key_issuer ):
312
329
"""
313
330
Set a KeyIssuer with the name == issuer_id
314
331
315
332
:param issuer_id: The entity ID
316
- :param issuer : KeyIssuer instance
333
+ :param key_issuer : KeyIssuer instance
317
334
"""
318
- self ._issuers [issuer_id ] = issuer
335
+ self ._issuers [issuer_id ] = key_issuer
319
336
320
337
def set (self , issuer_id , issuer ):
321
338
self [issuer_id ] = issuer
@@ -349,13 +366,14 @@ def __str__(self):
349
366
_res [_id ] = _issuer .key_summary ()
350
367
return json .dumps (_res )
351
368
369
+ @deprecated_alias (issuer = 'issuer_id' , owner = 'issuer_id' )
352
370
def load_keys (self , issuer_id , jwks_uri = '' , jwks = None , replace = False ):
353
371
"""
354
372
Fetch keys from another server
355
373
356
374
:param jwks_uri: A URL pointing to a site that will return a JWKS
357
375
:param jwks: A dictionary representation of a JWKS
358
- :param issuer : The provider URL
376
+ :param issuer_id : The provider URL
359
377
:param replace: If all previously gathered keys from this provider
360
378
should be replace.
361
379
:return: Dictionary with usage as key and keys as values
@@ -376,12 +394,13 @@ def load_keys(self, issuer_id, jwks_uri='', jwks=None, replace=False):
376
394
377
395
self [issuer_id ] = _issuer
378
396
397
+ @deprecated_alias (issuer = 'issuer_id' , owner = 'issuer_id' )
379
398
def find (self , source , issuer_id = None ):
380
399
"""
381
400
Find a key bundle based on the source of the keys
382
401
383
402
:param source: A source url
384
- :param issuer : The issuer of keys
403
+ :param issuer_id : The issuer of keys
385
404
:return: List of :py:class:`oidcmsg.key_bundle.KeyBundle` instances or None
386
405
"""
387
406
if issuer_id is None :
@@ -399,13 +418,14 @@ def find(self, source, issuer_id=None):
399
418
400
419
return res
401
420
421
+ @deprecated_alias (issuer = 'issuer_id' , owner = 'issuer_id' )
402
422
def export_jwks (self , private = False , issuer_id = "" , usage = None ):
403
423
"""
404
424
Produces a dictionary that later can be easily mapped into a
405
425
JSON string representing a JWKS.
406
426
407
427
:param private: Whether it should be the private keys or the public
408
- :param issuer : The entity ID.
428
+ :param issuer_id : The entity ID.
409
429
:return: A dictionary with one key: 'keys'
410
430
"""
411
431
_issuer = self ._get_issuer (issuer_id = issuer_id )
@@ -419,6 +439,7 @@ def export_jwks(self, private=False, issuer_id="", usage=None):
419
439
usage is None or (hasattr (k , 'use' ) and k .use == usage ))])
420
440
return {"keys" : keys }
421
441
442
+ @deprecated_alias (issuer = 'issuer_id' , owner = 'issuer_id' )
422
443
def export_jwks_as_json (self , private = False , issuer_id = "" ):
423
444
"""
424
445
Export a JWKS as a JSON document.
@@ -429,6 +450,7 @@ def export_jwks_as_json(self, private=False, issuer_id=""):
429
450
"""
430
451
return json .dumps (self .export_jwks (private , issuer_id ))
431
452
453
+ @deprecated_alias (issuer = 'issuer_id' , owner = 'issuer_id' )
432
454
def import_jwks (self , jwks , issuer_id ):
433
455
"""
434
456
Imports all the keys that are represented in a JWKS
@@ -447,16 +469,18 @@ def import_jwks(self, jwks, issuer_id):
447
469
httpc_params = self .httpc_params ))
448
470
self [issuer_id ] = _issuer
449
471
472
+ @deprecated_alias (issuer = 'issuer_id' , owner = 'issuer_id' )
450
473
def import_jwks_as_json (self , jwks , issuer_id ):
451
474
"""
452
475
Imports all the keys that are represented in a JWKS expressed as a
453
476
JSON object
454
477
455
478
:param jwks: JSON representation of a JWKS
456
- :param issuer : Who 'owns' the JWKS
479
+ :param issuer_id : Who 'owns' the JWKS
457
480
"""
458
481
return self .import_jwks (json .loads (jwks ), issuer_id )
459
482
483
+ @deprecated_alias (issuer = 'issuer_id' , owner = 'issuer_id' )
460
484
def import_jwks_from_file (self , filename , issuer_id ):
461
485
with open (filename ) as jwks_file :
462
486
self .import_jwks_as_json (jwks_file .read (), issuer_id )
@@ -495,6 +519,7 @@ def remove_outdated(self, when=0):
495
519
_before = len (_issuer )
496
520
_issuer .remove_outdated (when )
497
521
522
+ @deprecated_alias (issuer = 'issuer_id' , owner = 'issuer_id' )
498
523
def _add_key (self , keys , issuer_id , use , key_type = '' , kid = '' ,
499
524
no_kid_issuer = None , allow_missing_kid = False ):
500
525
@@ -695,6 +720,7 @@ def load(self, info):
695
720
self ._issuers [_issuer_id ] = KeyIssuer ().load (_issuer_desc )
696
721
return self
697
722
723
+ @deprecated_alias (issuer = 'issuer_id' , owner = 'issuer_id' )
698
724
def key_summary (self , issuer_id ):
699
725
_issuer = self ._get_issuer (issuer_id )
700
726
if _issuer :
@@ -706,15 +732,20 @@ def update(self):
706
732
"""
707
733
Go through the whole key jar, key issuer by key issuer and update them one
708
734
by one.
709
-
710
- :param keyjar: The key jar to update
711
735
"""
712
736
ids = self ._issuers .keys ()
713
737
for _id in ids :
714
738
_issuer = self [_id ]
715
739
_issuer .update ()
716
740
self [_id ] = _issuer
717
741
742
+ @deprecated_alias (issuer = 'issuer_id' , owner = 'issuer_id' )
743
+ def rotate_keys (self , key_conf , kid_template = "" , issuer_id = '' ):
744
+ _issuer = self [issuer_id ]
745
+ _issuer .rotate_keys (key_conf = key_conf , kid_template = kid_template )
746
+ self [issuer_id ] = _issuer
747
+ return self
748
+
718
749
719
750
# =============================================================================
720
751
@@ -807,21 +838,16 @@ def init_key_jar(public_path='', private_path='', key_defs='', issuer_id='', rea
807
838
808
839
The keys stored in the KeyJar will be stored under the '' identifier.
809
840
810
- :param public_path: A file path to a file that contains a JWKS with public
811
- keys
812
- :param private_path: A file path to a file that contains a JWKS with
813
- private keys.
814
- :param key_defs: A definition of what keys should be created if they are
815
- not already available
841
+ :param public_path: A file path to a file that contains a JWKS with public keys
842
+ :param private_path: A file path to a file that contains a JWKS with private keys.
843
+ :param key_defs: A definition of what keys should be created if they are not already available
816
844
:param issuer_id: The owner of the keys
817
- :param read_only: This function should not attempt to write anything
818
- to a file system.
845
+ :param read_only: This function should not attempt to write anything to a file system.
819
846
:return: An instantiated :py:class;`oidcmsg.key_jar.KeyJar` instance
820
847
"""
821
848
822
849
_issuer = init_key_issuer (public_path = public_path , private_path = private_path ,
823
- key_defs = key_defs , read_only = read_only ,
824
- storage_conf = storage_conf , abstract_storage_cls = abstract_storage_cls )
850
+ key_defs = key_defs , read_only = read_only )
825
851
826
852
if _issuer is None :
827
853
raise ValueError ('Could not find any keys' )
0 commit comments