Skip to content

Commit

Permalink
Merge pull request #5 from veselov/no-key
Browse files Browse the repository at this point in the history
Fixes cisco#88
  • Loading branch information
zandbelt authored Apr 5, 2022
2 parents 0d5e830 + 8b9416e commit 6a2611c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/jwe.c
Original file line number Diff line number Diff line change
Expand Up @@ -2015,6 +2015,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 @@ -1187,7 +1192,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

0 comments on commit 6a2611c

Please sign in to comment.