Skip to content

Fix missing apu/apv IdentityPython/JWTConnect-Python-CryptoJWT#159 #170

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/cryptojwt/jwe/jwe_ec.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def dec_setup(self, token, key=None, **kwargs):
raise Exception("Ephemeral Public Key Missing in ECDH-ES Computation")

epubkey = ECKey(**self.headers["epk"])
apu = apv = ""
apu = apv = b""
if "apu" in self.headers:
apu = b64d(self.headers["apu"].encode())
if "apv" in self.headers:
Expand Down
26 changes: 26 additions & 0 deletions tests/test_07_jwe.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,32 @@ def test_ecdh_encrypt_decrypt_direct_key():
assert msg == plain


def test_ecdh_encrypt_decrypt_direct_key_wo_apu_apv():
# Alice starts of
jwenc = JWE_EC(plain, alg="ECDH-ES", enc="A128GCM")

# Don't supply agreement party information.
cek, encrypted_key, iv, params, ret_epk = jwenc.enc_setup(plain, key=eck_bob, apu=b"", apv=b"")
# Assert they are not randomized
assert params["apv"] == b""
assert params["apu"] == b""

# Delete agreement party information
del params["apv"]
del params["apu"]

kwargs = {"params": params, "cek": cek, "iv": iv, "encrypted_key": encrypted_key}
jwt = jwenc.encrypt(**kwargs)

# Bob decrypts
ret_jwe = factory(jwt, alg="ECDH-ES", enc="A128GCM")
jwdec = JWE_EC()
jwdec.dec_setup(ret_jwe.jwt, key=bob)
msg = jwdec.decrypt(ret_jwe.jwt)

assert msg == plain


def test_ecdh_encrypt_decrypt_keywrapped_key():
jwenc = JWE_EC(plain, alg="ECDH-ES+A128KW", enc="A128GCM")
cek, encrypted_key, iv, params, ret_epk = jwenc.enc_setup(plain, key=eck_bob)
Expand Down