class FSJWKSBundle(JWKSBundle): """ A JWKSBundle that keeps the key information in a :py:class:`fedoidc.file_system.FileSystem` instance. """ def __init__(self, iss, sign_keys=None, fdir='./', key_conv=None): """ :param iss: Issuer ID for this entity :param sign_keys: Signing Keys used by this entity to sign JWTs :param fdir: A directory where JWKS can be stored :param key_conv: Specification of directory key to file name conversion. A set of keys are represented in the local cache as a KeyJar instance and as a JWKS on disc. """ JWKSBundle.__init__(self, iss, sign_keys=sign_keys) self.bundle = FileSystem(fdir, key_conv=key_conv, value_conv={ 'to': keyjar_to_jwks, 'from': jwks_to_keyjar }) def clear(self): self.bundle.clear()
def setup_ms(csms_def, ms_path, mds_dir, base_url, operators): """ :param csms_def: Definition of which signed metadata statements to build :param ms_path: Where to store the signed metadata statements and uris :param mds_dir: Directory where singed metadata statements published using ms_uri are kept :param base_url: Common base URL to all metadata_statement_uris :param operators: Dictionary with federation Operators :return: A tuple of (Signer dictionary and FSJWKSBundle instance) """ mds = MetaDataStore(mds_dir) mds.clear() for iss, sms_def in csms_def.items(): ms_dir = os.path.join(ms_path, quote_plus(iss)) for context, spec in sms_def.items(): _dir = os.path.join(ms_dir, context) metadata_statements = FileSystem(_dir, key_conv={ 'to': quote_plus, 'from': unquote_plus }) metadata_statements.clear() for fo, _desc in spec.items(): res = make_signed_metadata_statement(_desc, operators, mds, base_url) try: metadata_statements.update(res['ms']) except KeyError: pass try: metadata_statements.update(res['ms_uri']) except KeyError: pass signers = {} for iss, sms_def in csms_def.items(): ms_dir = os.path.join(ms_path, quote_plus(iss)) signers[iss] = Signer( InternalSigningService(iss, operators[iss].keyjar), ms_dir) return signers
} } KEY_DEFS = [{ "type": "RSA", "key": '', "use": ["sig"] }, { "type": "EC", "crv": "P-256", "use": ["sig"] }] MS_DIR = 'ms_dir_10' fs = FileSystem(MS_DIR) fs.clear() if os.path.isdir('mds'): shutil.rmtree('mds') liss = list(FO.values()) liss.extend(list(OA.values())) signer, keybundle = test_utils.setup(KEY_DEFS, TOOL_ISS, liss, ms_path=MS_DIR, csms_def=SMS_DEF, mds_dir='mds', base_url='https://localhost')