Closed aio-witc closed 5 months ago
Ideas: add option to:
joserfc.jwe.decrypt_json(...)
example:
plaintext=joserfc.jwe.decrypt_json(msg, joserfc.jwk.KeySet([key1]), single_recipient = True)
Quickfix:
def _perform_decrypt(obj: EncryptionData, registry: JWERegistry) -> None:
enc = registry.get_enc(obj.protected["enc"])
iv = obj.bytes_segments["iv"]
enc.check_iv(iv)
tag = obj.bytes_segments["tag"]
ciphertext = obj.bytes_segments["ciphertext"]
cek_set = set()
for recipient in obj.recipients:
headers = recipient.headers()
registry.check_header(headers, True)
# Step 6, Determine the Key Management Mode employed by the algorithm
# specified by the "alg" (algorithm) Header Parameter.
alg = registry.get_alg(headers["alg"])
**_try:_**
cek = decrypt_recipient(alg, enc, recipient, tag)
cek_set.add(cek)
**_except:
continue_**
def _attach_recipient_keys(
recipients: t.List[Recipient[Key]],
private_key: KeyFlexible,
sender_key: t.Optional[t.Union[ECKey, OKPKey, KeySet]] = None) -> None:
for recipient in recipients:
**_try:_**
key = guess_key(private_key, recipient)
key.check_use("enc")
_**except:
continue**_
Setup: Message contains two recipients I try to decrypt the message with ONE correct key.
RFC: https://datatracker.ietf.org/doc/html/rfc7516#page-17
When there are multiple recipients, it is an application decision which of the recipients' encrypted content must successfully validate for the JWE to be accepted. In some cases, encrypted content for all recipients must successfully validate or the JWE will be considered invalid. In other cases, only the encrypted content for a single recipient needs to be successfully validated. However, in all cases, the encrypted content for at least one recipient MUST successfully validate or the JWE MUST be considered invalid.
Sample Message:
Code:
private.pem and private.pem.bak contain one of the two keys each.