3
votes

I create a .cap file of this sample code [a Simple Hello World] and upload it on my javacard successfully via JCManager.

  • Package AID:01 02 01 02 01 02 01

  • Applet AID:01 02 01 02 01 02 01 02

This is output of JCManager :

    Open terminal ...
    EstablishContext(): ...
    Wait for card in a certain reader ...
    Pick reader ...
    **********************
    Selecting Card Manager
    ***********************
    -> 00 A4 04 00 08 A0 00 00 00 03 00 00 00
    <- 6F 10 84 08 A0 00 00 00 03 00 00 00 A5 04 9F 65 01 FF 90 00
    ************
    Init Update
    *************
    -> 80 50 00 00 08 3C 8A 0C 90 E4 5D 3B D9
    <- 00 00 11 60 01 00 8A 79 0A F9 FF 02 00 A3 7F BB 51 31 B4 DE 16 9F 77 9E F7 49 1F EF 90 00
    HostChallenge: 3C 8A 0C 90 E4 5D 3B D9
    CardChallenge: 7F BB 51 31 B4 DE
    Card Calculated Card Cryptogram: 16 9F 77 9E F7 49 1F EF
    Derivation Data is 01 82 00 A3 00 00 00 00 00 00 00 00 00 00 00 00
    Host Cryptogram Data (to encrypt) 00 A3 7F BB 51 31 B4 DE 3C 8A 0C 90 E4 5D 3B D9 80 00 00 00 00 00 00 00
    Card Cryptogram Data (to encrypt for verification) 3C 8A 0C 90 E4 5D 3B D9 00 A3 7F BB 51 31 B4 DE 80 00 00 00 00 00 00 00
    S_ENC: 69 1E A3 CB 6A 58 DD 17 BA 88 A8 4F 20 A7 35 30 69 1E A3 CB 6A 58 DD 17
    The Current session MAC key is FB 23 0F 31 D7 6C AA 49 25 4C 7E E4 69 7E 1B 5B
    The Current session DEK key is 8C C2 98 68 76 9C C1 90 21 CF 6B 42 A0 33 D1 D3
    Encrypted CardCryptoGram is 93 24 10 54 22 E4 A0 B9 44 D1 D9 16 27 66 63 91 16 9F 77 9E F7 49 1F EF
    Encrypted HostCryptoGram is E1 7D F6 51 0E 45 0F 6D 23 40 F3 E1 92 5F 8D 23 DB A2 05 4E FD 75 DD F0
    -> 84 82 03 00 10 DB A2 05 4E FD 75 DD F0 D0 92 13 C0 0B 8C 31 74
    <- 90 00
    Authenticated
    ************
    UplaodCAP
    *************
    Get AID from header.cap file
    FOR LOAD DATA: EF 04 C6 02 01 B3
    AID:01 02 01 02 01 02 01
    Applet AID:01 02 01 02 01 02 01 02
    Try to delete if existing...
    -> 84 E4 00 00 18 A7 A8 54 56 4B 28 4F 80 5E 89 9F 26 61 3D E8 1D 88 D5 63 10 5F 51 ED AA
    <- 6A 88
    -> 84 E4 00 00 18 8E DD 49 5F EB 3D E7 E5 8B 39 83 9B 8E EA 74 77 69 CF 75 A8 55 C5 D4 BA
    <- 6A 88
    Loading cap file. Please wait...
    Install for Load
    -> 84 E6 02 00 20 10 44 CD 0E 2A 30 2C F8 B9 8A B3 6E 3D 01 5A A2 3A 8B 3D 8C 19 0F 09 AB DD 13 2A E5 27 BE 03 88
    <- 00 90 00
    Load CAP
    -> 84 E8 00 00 D8 20 0F 77 44 1A 60 F7 61 57 82 15 9D 7F 19 6E 6C 73 13 6C F7 12 B0 CA FC 8E BF 61 68 F5 CF 74 4A D5 6D 25 B5 DE 70 5E 74 77 0B 16 E3 D9 C5 A4 25 DC 3C C4 07 80 D1 01 F2 12 87 A2 3C A1 FF 41 68 0C A6 70 2E 08 53 86 DF 9F 59 A2 DF 96 1A C9 4F CF F8 B3 15 05 A7 02 30 4C 8C 31 AE E2 B9 1A 98 10 63 0B 32 D7 96 70 2D 85 BD 40 69 9D 76 1A 06 91 39 E8 7D 68 C0 3F D7 45 AD 52 91 AB 16 EF 3D 34 E6 97 DF 54 4B EC A9 F2 2D 41 48 00 BC C7 7E F4 A2 6F 3A 10 38 52 12 16 22 DA D4 50 0F B4 3E 40 B8 CB 48 B1 B4 FE CE B7 A6 83 69 07 40 F3 66 18 08 45 08 CC 21 13 29 35 74 FA 8F 61 8F F0 6C 92 9E 94 5A CE 6A D0 68 95 25 A5 8A 0F 53 69 1E CF FF 86 57 67 DD 02 15
    <- 00 90 00
    -> 84 E8 00 01 D8 7B 56 34 47 73 D9 9F 19 35 20 5E 52 B6 FD 36 94 C9 E1 FB 69 BA D6 7D 15 65 C1 DB 41 33 04 57 E6 41 76 8B 77 4E DE BD 42 52 94 8F AA 6D 64 43 2B A5 C7 19 D8 F9 19 62 6A 27 40 C9 CF 38 63 D1 F0 CB B7 73 5A 63 F1 49 A1 62 F5 D7 7D 46 06 9D F0 0E 6E FA 44 46 37 EC 2D 17 3D D3 EC 87 C8 8F 8F 00 C7 DD 29 47 80 F7 55 FE A5 C0 02 C8 58 6B 62 E5 0C 15 1F 24 56 2F 64 2F E7 00 D7 0C 05 40 DD 6B 6D AD 14 F7 FA E0 E9 7E BA 11 87 15 0E D7 BD 99 9F 37 AF 38 C7 E2 91 2A 92 C2 12 0B C4 02 A7 BE CE C9 D1 48 E0 9C 1D 51 B0 F9 B1 3C 0F 73 9B DA 84 2B 90 09 1B 94 80 9B D8 76 6A 95 7E 04 90 34 4A C9 C8 F1 5B 16 8D 13 3C 14 DC FC A6 7F 49 B6 6B 81 B2 51 94 23 39
    <- 00 90 00
    -> 84 E8 80 02 28 2F 42 03 0A FC 19 2E 45 A8 86 73 F7 DA FE CA D0 F5 9A 5D F4 72 3E DF E3 89 31 52 56 C6 F9 29 D3 1C 42 ED 3C 7B 45 5A 51
    <- 00 90 00
    -> 84 E6 0C 00 30 10 44 CD 0E 2A 30 2C F8 7E D9 A5 69 72 B5 85 54 57 A7 0B 84 42 7F 21 45 69 25 9F 81 CC 96 C0 E8 10 37 64 61 8F 80 8E 29 67 B1 D7 81 D5 F8 EE 31
    <- 00 90 00
    Applet loaded & registered

And this is output of GPJ when I list the applets :

C:\Users\thegooduser\Desktop\gpj-20120310>GPJ -list

C:\Users\thegooduser\Desktop\gpj-20120310>java -jar gpj.jar -list
Found terminals: [PC/SC terminal ACS CCID USB Reader 0]
Found card in terminal: ACS CCID USB Reader 0
ATR: 3B 68 00 00 00 73 C8 40 12 00 90 00

DEBUG: Command  APDU: 00 A4 04 00 08 A0 00 00 00 03 00 00 00
DEBUG: Response APDU: 6F 10 84 08 A0 00 00 00 03 00 00 00 A5 04 9F 65 01 FF 90 0
0
Successfully selected Security Domain OP201a A0 00 00 00 03 00 00 00
DEBUG: Command  APDU: 80 50 00 00 08 93 6A 63 09 6D 3D 06 B2
DEBUG: Response APDU: 00 00 11 60 01 00 8A 79 0A F9 FF 02 00 A4 66 04 93 67 B8 9
3 F0 87 EB 95 AD DB 88 68 90 00
DEBUG: Command  APDU: 84 82 00 00 10 C2 5A 5C D3 CB F3 DE 73 6E 2E 29 B2 73 DC A
2 06
DEBUG: Response APDU: 90 00
DEBUG: Command  APDU: 84 82 00 00 08 C2 5A 5C D3 CB F3 DE 73
DEBUG: Response APDU: 90 00
DEBUG: Command  APDU: 80 F2 80 00 02 4F 00
DEBUG: Response APDU: 08 A0 00 00 00 03 00 00 00 01 9E 90 00
DEBUG: Command  APDU: 80 F2 80 00 02 4F 00
DEBUG: Response APDU: 08 A0 00 00 00 03 00 00 00 01 9E 90 00
DEBUG: Command  APDU: 80 F2 40 00 02 4F 00
DEBUG: Response APDU: 0B 01 02 03 04 05 06 07 08 09 01 01 07 00 07 D2 76 00 00 6
0 41 01 07 00 08 01 02 01 02 01 02 01 02 07 00 90 00
DEBUG: Command  APDU: 80 F2 40 00 02 4F 00
DEBUG: Response APDU: 0B 01 02 03 04 05 06 07 08 09 01 01 07 00 07 D2 76 00 00 6
0 41 01 07 00 08 01 02 01 02 01 02 01 02 07 00 90 00
DEBUG: Command  APDU: 80 F2 10 00 02 4F 00
DEBUG: Response APDU: 6A 81
DEBUG: Command  APDU: 80 F2 10 00 02 4F 00
DEBUG: Response APDU: 6A 81
DEBUG: Command  APDU: 80 F2 20 00 02 4F 00
DEBUG: Response APDU: 0A 01 02 03 04 05 06 07 08 09 01 01 00 07 D2 76 00 00 60 5
0 01 01 00 07 01 02 01 02 01 02 01 01 00 90 00
DEBUG: Command  APDU: 80 F2 20 00 02 4F 00
DEBUG: Response APDU: 0A 01 02 03 04 05 06 07 08 09 01 01 00 07 D2 76 00 00 60 5
0 01 01 00 07 01 02 01 02 01 02 01 01 00 90 00
AID: A0 00 00 00 03 00 00 00                       |........|        ISD LC: 1 P
R: 0x9E

AID: 01 02 03 04 05 06 07 08 09 01 01              |...........|     App LC: 7 P
R: 0x00

AID: D2 76 00 00 60 41 01                          |.v..`A.|         App LC: 7 P
R: 0x00

AID: 01 02 01 02 01 02 01 02                       |........|        App LC: 7 P
R: 0x00

AID: 01 02 03 04 05 06 07 08 09 01                 |..........|      Exe LC: 1 P
R: 0x00

AID: D2 76 00 00 60 50 01                          |.v..`P.|         Exe LC: 1 P
R: 0x00

AID: 01 02 01 02 01 02 01                          |.......|         Exe LC: 1 P
R: 0x00

As you see above my applet uploaded successfully. But when I try to select it with Opensc-tool I receive 6E00. Why?

Update:This is opensc-tool output when I send select command with 80 or 00 in class byte

Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\Users\ghasemi\Desktop\OpenSC Project\OpenSC\tools>opensc-tool -s 00a404000801
02010201020102
Using reader with a card: ACS CCID USB Reader 0
Sending: 00 A4 04 00 08 01 02 01 02 01 02 01 02
Received (SW1=0x6E, SW2=0x00)

C:\Users\ghasemi\Desktop\OpenSC Project\OpenSC\tools>opensc-tool -s 00a404000701
020102010201
Using reader with a card: ACS CCID USB Reader 0
Sending: 00 A4 04 00 07 01 02 01 02 01 02 01
Received (SW1=0x6E, SW2=0x00)

C:\Users\ghasemi\Desktop\OpenSC Project\OpenSC\tools>opensc-tool -s 80a404000801
02010201020102
Using reader with a card: ACS CCID USB Reader 0
Sending: 80 A4 04 00 08 01 02 01 02 01 02 01 02
Received (SW1=0x6E, SW2=0x00)

C:\Users\ghasemi\Desktop\OpenSC Project\OpenSC\tools>opensc-tool -s 80a404000701
020102010201
Using reader with a card: ACS CCID USB Reader 0
Sending: 80 A4 04 00 07 01 02 01 02 01 02 01
Received (SW1=0x6E, SW2=0x00)

C:\Users\ghasemi\Desktop\OpenSC Project\OpenSC\tools>

Update2:As you see below , I can select other applets successfully :

C:\Users\ghasemi\Desktop\OpenSC Project\OpenSC\tools>opensc-tool -s 00a404000b01
02030405060708090101
Using reader with a card: ACS CCID USB Reader 0
Sending: 00 A4 04 00 0B 01 02 03 04 05 06 07 08 09 01 01
Received (SW1=0x90, SW2=0x00)

C:\Users\ghasemi\Desktop\OpenSC Project\OpenSC\tools>opensc-tool -s 00a404000a01
020304050607080901
Using reader with a card: ACS CCID USB Reader 0
Sending: 00 A4 04 00 0A 01 02 03 04 05 06 07 08 09 01
Received (SW1=0x90, SW2=0x00)

C:\Users\ghasemi\Desktop\OpenSC Project\OpenSC\tools>

And this is output of my smartcard factory tool :

Answer-to-Reset
3B  68  00  00  00  73  C8  40  12  00  90  00  
< 00 A4 04 00 00 00
> 6112

< 00 C0 00 00 00 12
> 6F 10 84 08 A0 00 00 00 03 00 00 00 A5 04 9F 65 01 FF
> 9000

< 00 A4 04 00 08 00
< 01 02 01 02 01 02 01 02
> 6E00

< 00 A4 04 00 07 00
< 01 02 01 02 01 02 01
> 6E00

Update3: Send Select Applet APDU command right after ATR :

C:\Users\ghasemi\Desktop\OpenSC Project\OpenSC\tools>opensc-tool -a -s 80a404000
80102010201020102
Using reader with a card: ACS CCID USB Reader 0
3b:68:00:00:00:73:c8:40:12:00:90:00
Sending: 80 A4 04 00 08 01 02 01 02 01 02 01 02
Received (SW1=0x6E, SW2=0x00)

C:\Users\ghasemi\Desktop\OpenSC Project\OpenSC\tools>opensc-tool -a -s 80a404000
701020102010201
Using reader with a card: ACS CCID USB Reader 0
3b:68:00:00:00:73:c8:40:12:00:90:00
Sending: 80 A4 04 00 07 01 02 01 02 01 02 01
Received (SW1=0x6E, SW2=0x00)

C:\Users\ghasemi\Desktop\OpenSC Project\OpenSC\tools>opensc-tool -a -s 00a404000
80102010201020102
Using reader with a card: ACS CCID USB Reader 0
3b:68:00:00:00:73:c8:40:12:00:90:00
Sending: 00 A4 04 00 08 01 02 01 02 01 02 01 02
Received (SW1=0x6E, SW2=0x00)

C:\Users\ghasemi\Desktop\OpenSC Project\OpenSC\tools>opensc-tool -a -s 00a404000
701020102010201
Using reader with a card: ACS CCID USB Reader 0
3b:68:00:00:00:73:c8:40:12:00:90:00
Sending: 00 A4 04 00 07 01 02 01 02 01 02 01
Received (SW1=0x6E, SW2=0x00)

C:\Users\ghasemi\Desktop\OpenSC Project\OpenSC\tools>
2
This is baffling! What you can try first is to change the status code 0x6E00 returned by your applet to something else, such as 0x6789. Do you still get 0x6E00 back, or 0x6789?TonyK
I retract my comment -- I think Michael Roland's answer explains the problem.TonyK

2 Answers

5
votes

The reason why you receive the error code 6E00 is that your applet sends it upon receiving the SELECT (by DF name/AID) command:

ISOException.throwIt(ISO7816.SW_CLA_NOT_SUPPORTED);

When your applet receives its initial selection command, the process() method is called. As the class of this SELECT command is 0x00, the branch

if (cmd_apdu[ISO7816.OFFSET_CLA] == CLASS) {
   ...
}

will not be executed and instead the else branch will throw that exception and consequently cause the error code 6E00 to be returned.

Note that Anurag Sharma suggestion to change the CLA byte of the SELECT command to 0x80 will typically not work as the Java Card Runtime Environment will normally not treat a SELECT command with the proprietary flag set as an applet selection command.

So you should properly treat the applet selection command in your process() method in order to avoid the error response. You could do this, for instance, by checking selectingApplet():

public void process(APDU apdu) {
    byte[] cmd_apdu = apdu.getBuffer();

    if (selectingApplet()) return;

    [...]

Following the JCRE specification, however, it should not be a problem that the applet selection resulted in that error. Even when the SELECT command returned that error, the applet should be selected and should accept the READ command:

80 02 00 00 13
-1
votes

Because your code expect class 0x80

final static byte CLASS     = (byte) 0x80;  // Class of the APDU commands
if (cmd_apdu[ISO7816.OFFSET_CLA] == CLASS) {  // it is the rigth class
}    

Send this command

80 A4 04 00 08 01 02 01 02 01 02 01 02