4

I have a DESfire Ev1 version 1.3 card and I'm trying to select a file using ISO7816 apdu style.

I have one file, with aid A0 A1 A2 and I can select it using both native or wrapped mode:

Native:

-> 5A A0 A1 A2
<- 00

Wrapped:

-> 90 5A 00 00 03 A0 A1 A2 00
<- 91 00

However, if I try to select it using ISO7816 style, I always get a file not found error:

ISO7816:

-> 00 A4 04 00 03 A0 A1 A2 00
-> 6A 82

When using ISO apdu, is the AID in a different format? How can I select this AID using it?

Marcos Ramos
  • 135
  • 1
  • 2
  • 4
  • 1
    Welcome to Stack Overflow! Nice first question; you described your problem succinctly, added the expected result, provided the actual result, and narrowed it down to only the information that reproduces the issue. – Lynn Crumbling Dec 17 '14 at 21:57
  • 1
    Ah, thanks :) I think it's the effect of the years of lurking around :) – Marcos Ramos Dec 17 '14 at 22:24

1 Answers1

0

From the docs:

This APDU selects an ISO Application by it’s ISO Application Identifier (AID). The ISO AID of DESFire is ”0xD2 76 00 00 85 01 00”. The full ISO AID has to be transmitted, partial selection is NOT supported. Other ISO AIDs are not supported by DESFire

This appears to contradict the fact that you have an AID 0xA0 0xA1 0xA2.

Seems like you need to be sending:

[CLA] [INS] [P1] [P2] [Len(AID)] [AID] 

Thus:

0x00 0xA4 0x04 0x00 0x07 0xD2 0x76 0x00 0x00 0x85 0x01 0x00

** EDIT **

Try ISO SELECT DIRECTORY instead:

This APDU selects a DESFire Application by it’s three byte DESFire Application Identifier (DESFire AID). ...

The functionality of the ISO SELECT DIRECTORY Command is compatible with the native DESFire “Select Application” command.

So:

0x00 0xA4 0x04 0x00 0x03 0xA0 0xA1 0xA2

(this was on the following page, and probably what you wanted in the first place.)

I think this is identical to what you had, minus the NUL at the end.

Lynn Crumbling
  • 12,985
  • 8
  • 57
  • 95
  • Ok, now I'm confused. I've used `0xA0 A1 A2` because inside DESfire the files must have three byte long IDs. So `CA A0 A1 A2 0F 01` created this application and I can select using `5A A0 A1 A2`. This AID refers to the card itself, then? (And it would automagically select the master file?) – Marcos Ramos Dec 17 '14 at 22:17
  • It's contradictory to me as well; the manual effectively says that you must hardcode that ID (page 72 of the product spec.), and that the ID is 7 bytes. It's almost as if you cannot select individual files in the ISO 7816 mode. – Lynn Crumbling Dec 17 '14 at 22:19
  • If I can't select individual files than it still possible to write data in the master file? I don't have my reader with me at the moment, but I'll see what I can do when I have it (tomorrow). – Marcos Ramos Dec 17 '14 at 22:23
  • Take a look at my edit; I think you just need to get rid of the `NUL` at the end of your attempt. – Lynn Crumbling Dec 17 '14 at 22:26
  • I'll try and post the results tomorrow! Thanks! – Marcos Ramos Dec 17 '14 at 22:28
  • Good luck; if I'm wrong, and this isn't helpful, let me know and I'll delete it. – Lynn Crumbling Dec 17 '14 at 22:28
  • 1
    So, if I use `00 a4 04 00 07 d2 76 00 00 85 01 00` it works (response `90 00`) but if I use `00 a4 04 00 03 a0 a1 a2` it doesn't. Now I have to figure out how to use it properly. – Marcos Ramos Dec 18 '14 at 08:59