Skip to content

Commit

Permalink
CardOS: Try forcing max_send_size for PSO:DEC
Browse files Browse the repository at this point in the history
Fixes #1208
Fixes #1118
Fixes #1005
Fixes #802
  • Loading branch information
frankmorgner committed Dec 4, 2017
1 parent 3e7f7e6 commit bb4bdc8
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/libopensc/card-cardos.c
Original file line number Diff line number Diff line change
Expand Up @@ -977,6 +977,32 @@ cardos_compute_signature(sc_card_t *card, const u8 *data, size_t datalen,
LOG_FUNC_RETURN(ctx, SC_ERROR_INTERNAL);
}

static int
cardos_decipher(struct sc_card *card,
const u8 * crgram, size_t crgram_len,
u8 * out, size_t outlen)
{
int r;
size_t card_max_send_size = card->max_send_size;
size_t reader_max_send_size = card->reader->max_send_size;

if (sc_get_max_send_size(card) < crgram_len + 1) {
/* CardOS doesn't support chaining for PSO:DEC, so we just _hope_
* that both, the reader and the card are able to send enough data.
* (data is prefixed with 1 byte padding content indicator) */
card->max_send_size = crgram_len + 1;
card->reader->max_send_size = crgram_len + 1;
}

r = iso_ops->decipher(card, crgram, crgram_len, out, outlen);

/* reset whatever we've modified above */
card->max_send_size = card_max_send_size;
card->reader->max_send_size = reader_max_send_size;

return r;
}

static int
cardos_lifecycle_get(sc_card_t *card, int *mode)
{
Expand Down Expand Up @@ -1280,6 +1306,7 @@ static struct sc_card_driver * sc_get_driver(void)
cardos_ops.set_security_env = cardos_set_security_env;
cardos_ops.restore_security_env = cardos_restore_security_env;
cardos_ops.compute_signature = cardos_compute_signature;
cardos_ops.decipher = cardos_decipher;

cardos_ops.list_files = cardos_list_files;
cardos_ops.check_sw = cardos_check_sw;
Expand Down

0 comments on commit bb4bdc8

Please sign in to comment.