Skip to content

Commit

Permalink
Merge pull request #170 from vernans/fix-missing-apu-apv
Browse files Browse the repository at this point in the history
Fix missing apu/apv #159
  • Loading branch information
jschlyter authored Nov 16, 2024
2 parents 776aef5 + 65d16fb commit 978df14
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
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

0 comments on commit 978df14

Please sign in to comment.