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

Log .kid element when we are unable to find the Validating Key #14

Merged
merged 2 commits into from
Jan 3, 2018
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/validator.c
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,10 @@ xjwt_verify(xjwt_verify_options_t *opts, const char *data, size_t len,
ref_pubkey = xjwt_keyset__get_by_keyid(opts->keyset, ref_hdr_kid);
if (ref_pubkey == NULL) {
reason = XJWT_VERIFY_NO_VALIDATORS;
err = xjwt_error_create(
XJWT_EINVAL, "xjwt_verify: invalid JWT Header: unknown key id (.kid)");
err = xjwt_error_createf(
XJWT_EINVAL,
"xjwt_verify: invalid JWT Header: unknown key id (.kid): \"%s\"",
ref_hdr_kid);
goto failed;
}

Expand Down
40 changes: 40 additions & 0 deletions tests/fixtures/jwk_none.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"keys": [
{
"use": "sig",
"kty": "EC",
"kid": "1829299e1398f522",
"crv": "P-256",
"alg": "ES256",
"x": "RD9C-gHc1m0MAnOnOtHHwWW79vD8Si_mWMKSksMYHtY",
"y": "6baTs0UOBMuZ8fBIEbAWXoM4Kxir2prjVPXjkgemIjY"
},
{
"use": "sig",
"kty": "EC",
"kid": "5dc5b11e299373b5",
"crv": "P-256",
"alg": "ES256",
"x": "nWzPJ001WxYHD-9WzaN700Dngg2SzTPlfirGE_7rHTo",
"y": "Kt82ey0Wgfk5SS76UI5Phftn4K0U1gkYHVZyivDjKMA"
},
{
"use": "sig",
"kty": "EC",
"kid": "52e60a7740b31710",
"crv": "P-256",
"alg": "ES256",
"x": "wJVcMx_RQSU6ENr8plktSBjt1fxqGbC17sst_ll9z3Q",
"y": "8PPFbXN2ii92y1m5y0DXmipJROqe61sm5ham5R1-5mQ"
},
{
"use": "sig",
"kty": "EC",
"kid": "3ed3cf591a2dedba",
"crv": "P-256",
"alg": "ES256",
"x": "Cjs_E1o0mcAVYlrkMEsh_tg7CkUWgXNfjn9rXpIFs-c",
"y": "06kM06zfSrKFjmdw7MxWp4RkHb5MKQFkpRaBT_irZPw"
}
]
}
32 changes: 32 additions & 0 deletions tests/test_verify.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,37 @@ typedef struct tcb_baton_t {

static uint64_t tcb(void *baton) { return ((tcb_baton_t *)baton)->now; }

static void verify_no_validators(void **state) {
char *buf = NULL;
size_t len = 0;
xjwt_verify_options_t opts = {0};
xjwt_verify_failure_t *failed = NULL;
xjwt_verify_success_t *success = NULL;
tcb_baton_t baton = {0};

xjwt_load_fixture("jwk_none.json", &buf, &len);
XJWT_NO_ERROR(xjwt_keyset_create_from_memory(buf, len, &opts.keyset));
free(buf);
xjwt_load_fixture("e1_af.jwt", &buf, &len);

opts.expected_issuer = "https://issuer.example.com";
opts.expected_subject = "ab0edaf1-4ed1-40c0-afcb-18dcf75712e7";
opts.expected_audience = "https://audience.example.com";
opts.now = tcb;
baton.now = 1510621410;
opts.baton = &baton;

xjwt_verify(&opts, buf, len, &success, &failed);
XJWT_ASSERT(success == NULL);
XJWT_ASSERT(failed != NULL);
XJWT_ASSERT(failed->err != NULL);
XJWT_ASSERT(failed->err->err == XJWT_EINVAL);
XJWT_ASSERT(strstr(failed->err->msg, "unknown key id") != NULL);
XJWT_ASSERT(
strstr(failed->err->msg, "65289b19-e0c6-4918-8933-7961781adb0d") != NULL);
xjwt_verify_failure_destroy(failed);
}

static void verify_e1(void **state) {
char *buf = NULL;
size_t len = 0;
Expand Down Expand Up @@ -74,4 +105,5 @@ static void verify_e1(void **state) {

XJWT_TESTS_START(verify)
XJWT_TESTS_ENTRY(verify_e1)
XJWT_TESTS_ENTRY(verify_no_validators)
XJWT_TESTS_END()