Skip to content

Commit

Permalink
Another requested changed
Browse files Browse the repository at this point in the history
As requested and as the alternative solution see:
#1256 (comment)

In order to not pass a card lock and the card->drv_data from piv_match_card
piv_match_card is split in 2 parts.

the piv_match_card_continued is called from  piv_init. piv_init may
now return with SC_ERROR_INVALID_CARD to single to sc_connect_card to look
for additional drivers.

 On branch piv-aid-discovery
 Changes to be committed:
	modified:   card-piv.c
  • Loading branch information
dengert committed Feb 22, 2018
1 parent 8c3cc91 commit 990f067
Showing 1 changed file with 36 additions and 6 deletions.
42 changes: 36 additions & 6 deletions src/libopensc/card-piv.c
Original file line number Diff line number Diff line change
Expand Up @@ -825,7 +825,7 @@ static int piv_find_aid(sc_card_t * card, sc_file_t *aid_file)
r = sc_check_sw(card, apdu.sw1, apdu.sw2);
if (r) {
if (card->type != 0 && card->type == piv_aids[i].enumtag)
LOG_FUNC_RETURN(card->ctx, i);
LOG_FUNC_RETURN(card->ctx, (r < 0)? r: i);
continue;
}

Expand Down Expand Up @@ -2949,13 +2949,33 @@ piv_finish(sc_card_t *card)
free(priv->obj_cache[i].internal_obj_data);
}
free(priv);
card->drv_data = NULL; /* priv */
card->drv_data = NULL; /* priv */
}
return 0;
}


static int piv_match_card(sc_card_t *card)
{
SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);

/* piv_match_card may be called with card->type, set by opensc.conf */
/* user provide card type must be one we know */
switch (card->type) {
case -1:
case SC_CARD_TYPE_PIV_II_GENERIC:
case SC_CARD_TYPE_PIV_II_HIST:
case SC_CARD_TYPE_PIV_II_NEO:
case SC_CARD_TYPE_PIV_II_YUBIKEY4:
break;
default:
return 0; /* can not handle the card */
}
/* its one we know, or we can test for it in piv_init */
return 1; /* Let piv_init finish matching */
}


static int piv_match_card_continued(sc_card_t *card)
{
int i, i7e, k;
size_t j;
Expand Down Expand Up @@ -3100,18 +3120,28 @@ static int piv_match_card(sc_card_t *card)
static int piv_init(sc_card_t *card)
{
int r = 0;
piv_private_data_t * priv = PIV_DATA(card);
piv_private_data_t * priv = NULL;
sc_apdu_t apdu;
unsigned long flags;
unsigned long ext_flags;
u8 neo_version_buf[3];

SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);

/* continue the matching get a lock and the priv */
r = piv_match_card_continued(card);
if (r != 1) {
sc_log(card->ctx,"piv_match_card_continued failed");
piv_finish(card);
/* tell sc_connect_card to try other drivers */
LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_CARD);
}

priv = PIV_DATA(card);

/* can not force the PIV driver to use non-PIV cards as tested in piv_card_match */
/* can not force the PIV driver to use non-PIV cards as tested in piv_card_match_continued */
if (!priv || card->type == -1)
LOG_FUNC_RETURN(card->ctx, SC_ERROR_NO_CARD_SUPPORT);
LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_CARD);

sc_log(card->ctx,
"Max send = %"SC_FORMAT_LEN_SIZE_T"u recv = %"SC_FORMAT_LEN_SIZE_T"u card->type = %d",
Expand Down

0 comments on commit 990f067

Please sign in to comment.