def test_dump_jwk(): keylist0 = KEYS() keylist0.wrap_add(pem_cert2rsa(CERT)) jwk = keylist0.dump_jwks() print(jwk) _wk = json.loads(jwk) assert list(_wk.keys()) == ["keys"] assert len(_wk["keys"]) == 1 assert _eq(list(_wk["keys"][0].keys()), ["kty", "e", "n"])
def test_load_jwk(): keylist0 = KEYS() keylist0.wrap_add(pem_cert2rsa(CERT)) jwk = keylist0.dump_jwks() keylist1 = KEYS() keylist1.load_jwks(jwk) print(keylist1) assert len(keylist1) == 1 key = keylist1["rsa"][0] assert key.kty == 'RSA' assert isinstance(key.key, RsaKey)
def test_load_jwk(): keylist0 = KEYS() keylist0.wrap_add(pem_cert2rsa(CERT)) jwk = keylist0.dump_jwks() keylist1 = KEYS() keylist1.load_jwks(jwk) print(keylist1) assert len(keylist1) == 1 key = keylist1["rsa"][0] assert key.kty == 'RSA' assert isinstance(key.key, _RSAobj)
# # A key jar can also be created with the method build_keyjar specifying a key_conf containing a list of keys to be # created, with their type, name and usage (encryption of signature) key = create_and_store_rsa_key_pair("foo", size=4096) key2 = create_and_store_rsa_key_pair("foo2", size=4096) rsa = RSAKey().load_key(key) print "--- JWK ---" print json.dumps(rsa.serialize(), sort_keys=True, indent=4, separators=(',', ': ')) print ######################################################## keys = KEYS() keys.wrap_add(key, use="sig", kid="rsa1") keys.wrap_add(key2, use="enc", kid="rsa1") print "--- JWKS---" print keys.dump_jwks() print ######################################################## key_conf = [ {"type": "RSA", "name": "rsa_key", "use": ["enc", "sig"]}, {"type": "EC", "name": "elliptic_curve_1", "crv": "P-256", "use": ["sig"]}, {"type": "EC", "name": "elliptic_curve_2", "crv": "P-256", "use": ["enc"]} ] jwks, keyjar, kdd = build_keyjar(key_conf, "m%d", None, None)