def get_jwks(path, private_path): if os.path.isfile(private_path): _jwks = open(path, 'r').read() _kj = KeyJar() _kj.import_jwks(json.loads(_jwks), '') else: _kj = build_keyjar(config.ENT_KEYS)[1] jwks = _kj.export_jwks(private=True) fp = open(private_path, 'w') fp.write(json.dumps(jwks)) fp.close() jwks = _kj.export_jwks() # public part fp = open(path, 'w') fp.write(json.dumps(jwks)) fp.close() return _kj
def own_sign_keys(sigkey_name, issuer, sig_def_keys): try: jwks = json.loads(open(sigkey_name, 'r').read()) sign_kj = KeyJar() sign_kj.import_jwks(jwks, issuer) except FileNotFoundError: jwks, sign_kj, _ = build_keyjar(sig_def_keys) sign_kj.issuer_keys[issuer] = sign_kj.issuer_keys[''] fp = open(sigkey_name, 'w') fp.write(json.dumps(sign_kj.export_jwks(private=True, issuer=issuer))) fp.close() return sign_kj
def get_signing_keys(iss, keydef, key_file): if os.path.isfile(key_file): kj = KeyJar() kj.import_jwks(json.loads(open(key_file, 'r').read()), iss) else: kj = build_keyjar(keydef)[1] # make it know under both names fp = open(key_file, 'w') fp.write(json.dumps(kj.export_jwks())) fp.close() kj.issuer_keys[iss] = kj.issuer_keys[''] return kj
def get_signing_keys(eid, keydef, key_file): """ If the *key_file* file exists then read the keys from there, otherwise create the keys and store them a file with the name *key_file*. :param eid: The ID of the entity that the keys belongs to :param keydef: What keys to create :param key_file: A file name :return: A KeyJar instance """ if os.path.isfile(key_file): kj = KeyJar() kj.import_jwks(json.loads(open(key_file, 'r').read()), eid) else: kj = build_keyjar(keydef)[1] # make it know under both names fp = open(key_file, 'w') fp.write(json.dumps(kj.export_jwks())) fp.close() kj.issuer_keys[eid] = kj.issuer_keys[''] return kj
import argparse import json import os from urllib.parse import quote_plus from oic.utils.keyio import KeyJar parser = argparse.ArgumentParser() parser.add_argument(dest="nickname") args = parser.parse_args() if not os.path.isdir(args.nickname): print('No such entity') exit(-1) kj = KeyJar() iss = open(os.path.join(args.nickname, 'iss')).read() imp_jwks = open(os.path.join(args.nickname, 'jwks')).read() kj.import_jwks(jwks=json.loads(imp_jwks), issuer=iss) exp_jwks = kj.export_jwks(issuer=iss) fname = quote_plus(iss) fp = open(fname, 'w') fp.write(json.dumps(exp_jwks)) fp.close()
return TestConfiguration._instance CLIENT_ID = "client_1" _, idp_key_file = FileGenerator.get_instance().generate_cert("idp") KC_RSA = keybundle_from_local_file( idp_key_file.name, "RSA", ["ver", "sig"], "op_sign" ) KEYJAR = KeyJar() KEYJAR[CLIENT_ID] = [KC_RSA] KEYJAR[""] = KC_RSA JWKS = KEYJAR.export_jwks() CDB = { CLIENT_ID: { "client_secret": "client_secret", "redirect_uris": [("%sauthz" % TestConfiguration.get_instance().rp_base, None)], "client_salt": "salted", "response_types": ["code", "token"] } } op_url = TestConfiguration.get_instance().rp_config.OP_URL SERVER_INFO = { "version": "3.0", "issuer": op_url,
Returns an instance of the singleton class. """ if not TestConfiguration._instance: TestConfiguration._instance = TestConfiguration() return TestConfiguration._instance CLIENT_ID = "client_1" _, idp_key_file = FileGenerator.get_instance().generate_cert("idp") KC_RSA = keybundle_from_local_file(idp_key_file.name, "RSA", ["ver", "sig"], "op_sign") KEYJAR = KeyJar() KEYJAR[CLIENT_ID] = [KC_RSA] KEYJAR[""] = KC_RSA JWKS = KEYJAR.export_jwks() CDB = { CLIENT_ID: { "client_secret": "client_secret", "redirect_uris": [("%sauthz" % TestConfiguration.get_instance().rp_base, None)], "client_salt": "salted", "response_types": ["code", "token"] } } op_url = TestConfiguration.get_instance().rp_config.OP_URL