def test_make_signed_metadata_statements(): mds = MetaDataStore('mds') liss = list(FO.values()) liss.extend(list(OA.values())) key_bundle = make_fs_jwks_bundle(TEST_ISS, liss, SIGN_KEYJAR, KEYDEFS, './') operator = {} for entity, _keyjar in key_bundle.items(): operator[entity] = Operator(iss=entity, keyjar=_keyjar) _spec = SMS_DEF[OA['sunet']]["discovery"][FO['swamid']] ms = make_signed_metadata_statement(_spec, operator, mds=mds, base_uri='https:/example.org/ms') assert ms _spec = SMS_DEF[OA['sunet']]["discovery"][FO['edugain']] res = make_signed_metadata_statement(_spec, operator, mds=mds, base_uri='https:/example.org/ms') assert list(res['ms_uri'].keys()) == [FO['edugain']] _spec = SMS_DEF[OA['sunet']]["discovery"][FO['example']] res = make_signed_metadata_statement(_spec, operator, mds=mds, base_uri='https:/example.org/ms') assert list(res['ms'].keys()) == [FO['example']] _jws = factory(res['ms'][FO['example']]) assert _jws
def setup(keydefs, tool_iss, liss, csms_def, oa, ms_path): sig_keys = build_keyjar(keydefs)[1] key_bundle = make_fs_jwks_bundle(tool_iss, liss, sig_keys, keydefs, './') sig_keys = build_keyjar(keydefs)[1] jb = FSJWKSBundle(tool_iss, sig_keys, 'fo_jwks', key_conv={ 'to': quote_plus, 'from': unquote_plus }) # Need to save the private parts jb.bundle.value_conv['to'] = keyjar_to_jwks_private jb.bundle.sync() operator = {} for entity, _keyjar in jb.items(): operator[entity] = Operator(iss=entity, keyjar=_keyjar) signers = {} for sig, sms_def in csms_def.items(): ms_dir = os.path.join(ms_path, sig) metadata_statements = FileSystem(ms_dir) for name, spec in sms_def.items(): res = make_signed_metadata_statement(spec, operator) metadata_statements[name] = res['ms'] _iss = oa[sig] signers[_iss] = Signer( InternalSigningService(_iss, operator[_iss].keyjar), ms_dir) return signers, key_bundle
def test_make_signed_metadata_statement_mixed(): liss = list(FO.values()) liss.extend(list(OA.values())) key_bundle = make_fs_jwks_bundle(TEST_ISS, liss, SIGN_KEYJAR, KEYDEFS, './') operator = {} for entity, _keyjar in key_bundle.items(): operator[entity] = Operator(iss=entity, keyjar=_keyjar) _spec = SMS_DEF[OA['sunet']]["discovery"][FO['swamid']] mds = MetaDataStore('mds') mds.clear() sms = make_signed_metadata_statement(_spec, operator, mds=mds, base_uri='https:/example.org/ms') assert sms _spec = SMS_DEF[OA['sunet']]["discovery"][FO['edugain']] sms = make_signed_metadata_statement(_spec, operator, mds=mds, base_uri='https:/example.org/ms') assert list(sms['ms_uri'].keys()) == [FO['edugain']] # Now parse the result _md0 = unpack_using_metadata_store(sms['ms_uri'][FO['edugain']], mds) op = Operator() _res = op.evaluate_metadata_statement(_md0) assert _res[0].le =={'federation_usage':'discovery'}
def test_metadatastore(): mds = MetaDataStore('mds') desc = SMS_DEF[OA['sunet']]["discovery"][FO['swamid']][0] operator = {} liss = list(FO.values()) liss.extend(list(OA.values())) key_bundle = make_fs_jwks_bundle(TEST_ISS, liss, SIGN_KEYJAR, KEYDEFS, './') for entity, _keyjar in key_bundle.items(): operator[entity] = Operator(iss=entity, keyjar=_keyjar) _x = make_ms(desc, False, operator) _jws = list(_x.values())[0] mds[mds.hash(_jws)] = _jws assert mds.hash(_jws) in list(mds.keys())
def test_make_fs_jwks_bundle(): """ testing on disc JWKS bundle """ liss = ['https://foo.example.com', 'https://bar.example.com'] if os.path.isdir('./fo_jwks'): shutil.rmtree('./fo_jwks') jb = make_fs_jwks_bundle(TEST_ISS, liss, SIGN_KEYJAR, KEYDEFS) assert set(jb.keys()) == set(liss) for iss in liss: _kj = jb[iss] assert isinstance(_kj, KeyJar) assert len(_kj.keys()) == 1 # Issuers assert list(_kj.keys())[0] == iss _keys = _kj.get_issuer_keys(iss) assert len(_keys) == 2 assert _kj.keys_by_alg_and_usage(iss, 'RS256', 'sig') assert _kj.keys_by_alg_and_usage(iss, 'ES256', 'sig')