Skip to content

Commit dfeeac6

Browse files
dengertJakuje
authored andcommitted
card-piv.c SM move check for no response data to after MAC is checked
On branch PIV-4-extensions Changes to be committed: modified: card-piv.c
1 parent d0791b7 commit dfeeac6

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

src/libopensc/card-piv.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1239,11 +1239,6 @@ static int piv_decode_apdu(sc_card_t *card, sc_apdu_t *plain, sc_apdu_t *sm_apdu
12391239
goto err;
12401240
}
12411241

1242-
/* no SM data results in no plain text data */
1243-
if (!(asn1_sm_response[0].flags & SC_ASN1_PRESENT)) {
1244-
plain->resplen = 0;
1245-
}
1246-
12471242
if ((asn1_sm_response[1].flags & SC_ASN1_PRESENT) == 0
12481243
|| (asn1_sm_response[2].flags & SC_ASN1_PRESENT) == 0) {
12491244
sc_log(card->ctx,"SM missing status or R-MAC");
@@ -1325,10 +1320,12 @@ static int piv_decode_apdu(sc_card_t *card, sc_apdu_t *plain, sc_apdu_t *sm_apdu
13251320
}
13261321

13271322
/* some commands do not have response data */
1328-
if (ee.value != NULL) {
1323+
if (ee.value == NULL) {
1324+
plain->resplen = 0;
1325+
} else {
13291326
p = ee.value;
13301327
inlen = ee.len;
1331-
if (inlen < 17 || *p != 0x01) { /*padding indicator is required */
1328+
if (inlen < 17 || *p != 0x01) { /*padding and padding indicator are required */
13321329
sc_log(card->ctx, "SM padding indicator not 0x01");
13331330
r = SC_ERROR_SM_AUTHENTICATION_FAILED;
13341331
goto err;

0 commit comments

Comments
 (0)