Skip to content

signed and encrypted use case #19

@slisznia

Description

@slisznia

I'm trying to sign my claims, then encrypt, then serialize. What's the proper sequence of calls to get nested JWT like that? Below test fails with error:

File "../dist-packages/jose.py", line 140, in encrypt
claims[_TEMP_VER_KEY] = _TEMP_VER
TypeError: 'JWS' object does not support item assignment

Don't pay attention that I reuse the same key for signing and decryption, this is just a test...

import jose
from time import time
from Crypto.PublicKey import RSA

# key for demonstration purposes
key = RSA.generate(2048)

claims = {
    'iss': 'http://www.example.com',
    'exp': int(time()) + 3600,
    'sub': 42,
}

# asym. keys
pub_jwk = {'k': key.publickey().exportKey('PEM')}
priv_jwk = {'k': key.exportKey('PEM')}

# sign the message
jws_out = jose.sign(claims, priv_jwk, alg='RS256')

# encrypt the message
jwe_out = jose.encrypt(jws_out, pub_jwk)

# send to server...
jwt = jose.serialize_compact(jwe_out)
print jwt

# server unwraps it
jwe_in = jose.deserialize_compact(jwt)

# decrypt
jws = jose.decrypt(jwe_in, priv_jwk)

# check signature
jose.verify(jws, pub_jwk, 'RS256')

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions