Skip to content
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

Fixes #88 #89

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
6 changes: 6 additions & 0 deletions src/jwe.c
Original file line number Diff line number Diff line change
Expand Up @@ -1962,6 +1962,12 @@ uint8_t *cjose_jwe_decrypt_multi(cjose_jwe_t *jwe, cjose_key_locator key_locator
}
}

if (NULL == jwe->cek)
{
CJOSE_ERROR(err, CJOSE_ERR_CRYPTO);
goto _cjose_jwe_decrypt_multi_fail;
}

// decrypt JWE encrypted data
if (!jwe->fns.decrypt_dat(jwe, err))
{
Expand Down
13 changes: 12 additions & 1 deletion test/check_jwe.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ static const cjose_jwk_t *cjose_multi_key_locator(cjose_jwe_t *jwe, cjose_header
return NULL;
}

static const cjose_jwk_t *cjose_multi_key_locator_none(cjose_jwe_t *jwe, cjose_header_t *hdr, void *data)
{
return NULL;
}

START_TEST(test_cjose_jwe_node_jose_encrypt_self_decrypt)
{
cjose_err err;
Expand Down Expand Up @@ -1167,7 +1172,13 @@ START_TEST(test_cjose_jwe_multiple_recipients)
err.message, err.file, err.function, err.line);

size_t decoded_len;
uint8_t *decoded = cjose_jwe_decrypt_multi(jwe, cjose_multi_key_locator, rec, &decoded_len, &err);

CJOSE_ERROR(&err, CJOSE_ERR_NONE);
uint8_t *decoded = cjose_jwe_decrypt_multi(jwe, cjose_multi_key_locator_none, rec, &decoded_len, &err);
ck_assert_msg(NULL == decoded, "did not expect to decode with selected key");
ck_assert_msg(err.code == CJOSE_ERR_CRYPTO, "expected error to be set to CRYPTO");

decoded = cjose_jwe_decrypt_multi(jwe, cjose_multi_key_locator, rec, &decoded_len, &err);
ck_assert_msg(NULL != decoded,
"failed to decrypt for multiple recipients: "
"%s, file: %s, function: %s, line: %ld",
Expand Down