def main(x509_file, out="keys.jwk"): pb = PBase() ks = KeyStore(pb.http_request) key = x509_rsa_loads(open(x509_file).read()) ks.add_key(key, "rsa", "sig") f = open(out, "w") txt = ks.dumps("sig") f.write(txt) f.close()
def test_init_2(): #key, type, usage, owner jwt_keys = [["foobar","hmac", "sig", "."]] keystore = KeyStore(None, jwt_keys) skeys = keystore.get_sign_key() assert skeys == {'hmac': ['foobar']} skeys = keystore.get_sign_key("hmac") assert skeys == ['foobar']
def test_key_export(): keystore = KeyStore(None) part,res = keystore.key_export("http://www.example.com/as", "static", "keys", sig={"format":"jwk", "alg":"rsa"}) print part assert part.scheme == "http" assert part.netloc == "www.example.com" assert part.path == "/as" print res assert res.keys() == ["jwk_url"] url = res["jwk_url"] assert url == 'http://www.example.com/as/static/jwk.json' assert keystore.get_sign_key("rsa")
def test_3(): jwt_keys = [["foobar","hmac", "sig", "."]] keystore = KeyStore(None, jwt_keys) keystore.set_verify_key("xyz", owner="http://example.com/") skeys = keystore.get_sign_key("hmac") assert skeys == ['foobar'] skeys = keystore.get_verify_key("hmac", "http://example.com/") assert skeys == ['xyz'] skeys = keystore.get_sign_key(owner="http://example.com/") assert skeys == {}
def run_key_server(server_url_pattern, host): ks = KeyStore(None) part, res = ks.key_export(server_url_pattern % host, **KEY_EXPORT_ARGS) return start_key_server(part)