Skip to content

WRAP operation with MyEID driver fails when using T0 protocol. #2694

@popovec

Description

@popovec

Problem Description

WRAP operation with MyEID driver fails when using T0 protocol.

Proposed Resolution

diff --git a/src/libopensc/card-myeid.c b/src/libopensc/card-myeid.c
index de9ec7eb..2ee89593 100644
--- a/src/libopensc/card-myeid.c
+++ b/src/libopensc/card-myeid.c
@@ -1446,7 +1446,7 @@ static int myeid_wrap_key(struct sc_card *card, u8 *out, size_t outlen)
        sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0x2A, 0x84, 0x00);
        apdu.resp = rbuf;
        apdu.resplen = sizeof(rbuf);
-       apdu.le = 0;
+       apdu.le = sizeof(rbuf) <= 256 ? sizeof(rbuf) : 256;
        apdu.lc = 0;
 
        r = sc_transmit_apdu(card, &apdu);

I will prepare PR.

Logs

T1 protocol (without problem, operation PSO and DEAUTH):
-------------------------------------------------------
Outgoing APDU (5 bytes):
00 2A 84 00 00 .*...
Incoming APDU (34 bytes):
3F 05 C2 55 77 31 05 F9 76 BE F1 20 AA 65 47 60 ?..Uw1..v.. .eG`
B0 5D DF 10 18 B6 AA 0D AE D8 FE A8 92 22 68 FC .]..........."h.
90 00                                           ..
Outgoing APDU (4 bytes):
00 2E 00 00 ....
Incoming APDU (2 bytes):
90 00 ..
T0 protocol (wrong)
-------------------
Outgoing APDU (5 bytes):
00 2A 84 00 00 .*...
Incoming APDU (2 bytes):
61 20 a
Outgoing APDU (4 bytes):
00 2E 00 00 ....
Incoming APDU (2 bytes):
90 00 ..
T0 protocol (with the use of the mentioned patch)
-------------------------------------------------
Outgoing APDU (5 bytes):
00 2A 84 00 00 .*...
Incoming APDU (2 bytes):
61 20 a
Outgoing APDU (5 bytes):
00 C0 00 00 20 ....
Incoming APDU (34 bytes):
3F 05 C2 55 77 31 05 F9 76 BE F1 20 AA 65 47 60 ?..Uw1..v.. .eG`
B0 5D DF 10 18 B6 AA 0D AE D8 FE A8 92 22 68 FC .]..........."h.
90 00                                           ..
Outgoing APDU (4 bytes):
00 2E 00 00 ....
Incoming APDU (2 bytes):
90 00 ..

Comment

We should really rename apdu.le to apdu.ne to avoid such problems.
Please read: #1734 (comment)

I would also consider adding a test in sc_check_apdu(). We do not check the
Le field in SC_APDU_CASE_2_SHORT and SC_APDU_CASE_4_SHORT cases.

I would also suggest renaming Lc to Nc and removing the datalen field, the
sc_check_apdu() only accepts APDUs if lc == datalen.

Discussion on Le/Ne, Lc/Nc, datalen is welcome.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions