Beispiel #1
0
def jwks():
    from authlib.jose import JsonWebKey
    from authlib.jose import JWK_ALGORITHMS
    jwk = JsonWebKey(algorithms=JWK_ALGORITHMS)
    key = jwk.dumps(config['PUBLIC_KEY'], kty='RSA')
    key['kid'] = '1'
    return {"keys": [key]}
Beispiel #2
0
def jwks_schema() -> dict:
    from authlib.jose import JsonWebKey
    from authlib.jose import JWK_ALGORITHMS

    jwk = JsonWebKey(algorithms=JWK_ALGORITHMS)
    key = jwk.dumps(current_app.config['PUBLIC_KEY'], kty='RSA')
    key['kid'] = '1'

    return {'keys': [key]}
Beispiel #3
0
def get_jwk():
    LOGGER.debug('Loading jwk from public key...')
    key_data = None
    with open(app_context().config['jwk_public_key_path'], 'rb') as _key_file:
        key_data = _key_file.read()
    _jwk = JsonWebKey(JWK_ALGORITHMS)
    _key_dict = _jwk.dumps(key_data,
                           kty='RSA',
                           use='sig',
                           alg='RS256',
                           kid="demo_key")
    return {'keys': [_key_dict]}
Beispiel #4
0
    def test_03_keyid(self):
        print("\n-----", sys._getframe().f_code.co_name, "-----")
        pem1 = "-----BEGIN EC PRIVATE KEY-----\nMHcCAQEEIDSt1IOhS5ZmY6nkX/Wh7pT+Y45TmYxrwoc1pG72v387oAoGCCqGSM49\nAwEHoUQDQgAEdEsjD2i2LytHOjNxxc9PbFeqQ89aMLOfmdBbEoSOhZBukJ52EqQM\nhOdgHqyqD4hEyYxgDu3uIbKat+lEZEhb3Q==\n-----END EC PRIVATE KEY-----"
        keypair1 = bbclib.KeyPair()
        keypair1.mk_keyobj_from_private_key_pem(pem1)
        keyid1 = keypair1.get_key_id()

        pubkey = keypair1.get_public_key_in_pem()
        jwk = JsonWebKey(algorithms=JWK_ALGORITHMS)
        obj = jwk.dumps(pubkey, kty='EC')
        json_obj = json.dumps(obj, separators=(',', ':'), sort_keys=True)
        keyid2 = hashlib.sha256(json_obj.encode()).digest()
        assert keyid1 == keyid2