How to use the jwcrypto.jwk.JWK function in jwcrypto

To help you get started, we’ve selected a few jwcrypto examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github latchset / custodia / tests / test_custodia.py View on Github external
def generate_all_keys(custodia_conf):
    parser = configparser.ConfigParser(
        interpolation=configparser.ExtendedInterpolation()
    )
    with open(custodia_conf) as f:
        parser.read_file(f)

    filename = parser.get('store:encgen', 'master_key')
    key = jwk.JWK(generate='oct', size=256)
    with open(filename, 'w+') as keyfile:
        keyfile.write(key.export())

    store = SqliteStore(parser, 'store:simple')

    srv_kid = "srvkid"
    cli_kid = "clikid"
    ss_key = jwk.JWK(generate='RSA', kid=srv_kid, use="sig")
    se_key = jwk.JWK(generate='RSA', kid=srv_kid, use="enc")
    store.set('kemkeys/sig/%s' % srv_kid, ss_key.export())
    store.set('kemkeys/enc/%s' % srv_kid, se_key.export())

    cs_key = jwk.JWK(generate='RSA', kid=cli_kid, use="sig")
    ce_key = jwk.JWK(generate='RSA', kid=cli_kid, use="enc")
    store.set('kemkeys/sig/%s' % cli_kid, cs_key.export_public())
    store.set('kemkeys/enc/%s' % cli_kid, ce_key.export_public())
github freeipa / freeipa / ipaserver / secrets / kem.py View on Github external
def newServerKeys(path, keyid):
    skey = JWK(generate='RSA', use='sig', kid=keyid)
    ekey = JWK(generate='RSA', use='enc', kid=keyid)
    with open(path, 'w') as f:
        os.fchmod(f.fileno(), 0o600)
        os.fchown(f.fileno(), 0, 0)
        f.write('[%s,%s]' % (skey.export(), ekey.export()))
    return [skey.get_op_key('verify'), ekey.get_op_key('encrypt')]
github freeipa / freeipa / ipaserver / secrets / kem.py View on Github external
def newServerKeys(path, keyid):
    skey = JWK(generate='RSA', use='sig', kid=keyid)
    ekey = JWK(generate='RSA', use='enc', kid=keyid)
    with open(path, 'w') as f:
        os.fchmod(f.fileno(), 0o600)
        os.fchown(f.fileno(), 0, 0)
        f.write('[%s,%s]' % (skey.export(), ekey.export()))
    return [skey.get_op_key('verify'), ekey.get_op_key('encrypt')]
github Axtell / Axtell / app / notifications / webpush.py View on Github external
def create_webpush_jwt(endpoint_url):
    with open(WEBPUSH_PRIVATE_KEY_PATH, 'rb') as key:
        jwk = JWK.from_pem(key.read())

    jwt = JWT(
        header={
            'typ': 'JWT',
            'alg': 'ES256'
        },
        claims={
            'sub': f'mailto:{notifications["support_email"]}',
            'exp': str(int(time() + WEBPUSH_EXPIRATION)),
            'aud': f'{endpoint_url.scheme}://{endpoint_url.netloc}'
        },
        algs=['ES256']
    )

    jwt.make_signed_token(jwk)
    return jwt.serialize()