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

sc-hsm-tool: Add options for public key authentication #1711

Closed
wants to merge 23 commits into from
Closed
Changes from 1 commit
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
Prev Previous commit
check for possible out of bounds write
  • Loading branch information
Frank Braun committed Oct 29, 2019
commit 1eddb58cfbdadce46f47ca5615811da39edb64c8
8 changes: 6 additions & 2 deletions src/libopensc/card-sc-hsm.c
Original file line number Diff line number Diff line change
Expand Up @@ -1440,7 +1440,7 @@ static int sc_hsm_unwrap_key(sc_card_t *card, sc_cardctl_sc_hsm_wrapped_key_t *p



static int get_CAR(u8 *carstr, sc_context_t *ctx, const u8 *buf, size_t buflen)
static int get_CAR(u8 *carstr, size_t carstr_len, sc_context_t *ctx, const u8 *buf, size_t buflen)
{
const u8 *cb = NULL, *car = NULL;
size_t taglen;
Expand All @@ -1460,6 +1460,10 @@ static int get_CAR(u8 *carstr, sc_context_t *ctx, const u8 *buf, size_t buflen)
}

/* return CAR */
if (taglen > carstr_len) {
fprintf(stderr, "Output buffer too small.\n");
LOG_FUNC_RETURN(ctx, SC_ERROR_BUFFER_TOO_SMALL);
}
memcpy(carstr, car, taglen);
frankbraun marked this conversation as resolved.
Show resolved Hide resolved
LOG_FUNC_RETURN(ctx, SC_SUCCESS);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you also want to look at OpenPACE for more extended parsing/verification of CVCs. If you want to keep this self sustained within OpenSC, you should use sc_pkcs15emu_sc_hsm_decode_cvc()

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to parse this with sc_pkcs15emu_sc_hsm_decode_cvc(), but wasn't able to. I got the following error:

Required ASN.1 object not found

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea is not to parse ASN.1 by hand. Please check what object is missing and why.

Expand Down Expand Up @@ -1499,7 +1503,7 @@ static int verify_certificate(sc_card_t *card, const u8 *cert, size_t cert_len,
}

/* select public key for verification */
r = get_CAR(car, card->ctx, cert, cert_len);
r = get_CAR(car, sizeof car, card->ctx, cert, cert_len);
LOG_TEST_RET(card->ctx, r, "cannot parse CAR");
car_len = strnlen((const char*) car, sizeof car);

Expand Down