19
19
*/
20
20
package pro .javacard .gp ;
21
21
22
+ import apdu4j .CommandAPDU ;
22
23
import apdu4j .HexUtils ;
24
+ import apdu4j .ResponseAPDU ;
23
25
import pro .javacard .AID ;
24
26
25
- import javax .smartcardio .CardException ;
26
- import javax .smartcardio .CommandAPDU ;
27
- import javax .smartcardio .ResponseAPDU ;
27
+ import java .io .IOException ;
28
28
import java .io .PrintStream ;
29
29
30
30
// Middle layer between GPTool (CLI) and GlobalPlatform (session)
31
31
public class GPCommands {
32
32
33
- private static void storeDGI (GlobalPlatform gp , byte [] payload ) throws GPException , CardException {
33
+ private static void storeDGI (GPSession gp , byte [] payload ) throws GPException , IOException {
34
34
// Single DGI. 0x90 should work as well but 0x80 is actually respected by cards.
35
- CommandAPDU cmd = new CommandAPDU (GlobalPlatform .CLA_GP , GlobalPlatform .INS_STORE_DATA , 0x80 , 0x00 , payload );
35
+ CommandAPDU cmd = new CommandAPDU (GPSession .CLA_GP , GPSession .INS_STORE_DATA , 0x80 , 0x00 , payload );
36
36
ResponseAPDU response = gp .transmit (cmd );
37
37
GPException .check (response , "STORE DATA failed" );
38
38
}
39
39
40
- public static void setPrePerso (GlobalPlatform gp , byte [] data ) throws GPException , CardException {
40
+ public static void setPrePerso (GPSession gp , byte [] data ) throws GPException , IOException {
41
41
if (data == null || data .length != 8 )
42
42
throw new IllegalArgumentException ("PrePerso data must be 8 bytes" );
43
43
byte [] payload = GPUtils .concatenate (new byte []{(byte ) 0x9f , 0x67 , (byte ) data .length }, data );
44
44
storeDGI (gp , payload );
45
45
}
46
46
47
- public static void setPerso (GlobalPlatform gp , byte [] data ) throws GPException , CardException {
47
+ public static void setPerso (GPSession gp , byte [] data ) throws GPException , IOException {
48
48
if (data == null || data .length != 8 )
49
49
throw new IllegalArgumentException ("Perso data must be 8 bytes" );
50
50
byte [] payload = GPUtils .concatenate (new byte []{(byte ) 0x9f , 0x66 , (byte ) data .length }, data );
@@ -66,11 +66,10 @@ public static void listRegistry(GPRegistry reg, PrintStream out, boolean verbose
66
66
out .println (tab + "Parent: " + e .getDomain ());
67
67
}
68
68
if (e .getType () == GPRegistryEntry .Kind .ExecutableLoadFile ) {
69
- GPRegistryEntryPkg pkg = (GPRegistryEntryPkg ) e ;
70
- if (pkg .getVersion () != null ) {
71
- out .println (tab + "Version: " + pkg .getVersionString ());
69
+ if (e .getVersion () != null ) {
70
+ out .println (tab + "Version: " + e .getVersionString ());
72
71
}
73
- for (AID a : pkg .getModules ()) {
72
+ for (AID a : e .getModules ()) {
74
73
out .print (tab + "Applet: " + HexUtils .bin2hex (a .getBytes ()));
75
74
if (verbose ) {
76
75
out .println (" (" + GPUtils .byteArrayToReadableString (a .getBytes ()) + ")" );
@@ -79,12 +78,11 @@ public static void listRegistry(GPRegistry reg, PrintStream out, boolean verbose
79
78
}
80
79
}
81
80
} else {
82
- GPRegistryEntryApp app = (GPRegistryEntryApp ) e ;
83
- if (app .getLoadFile () != null ) {
84
- out .println (tab + "From: " + app .getLoadFile ());
81
+ if (e .getLoadFile () != null ) {
82
+ out .println (tab + "From: " + e .getLoadFile ());
85
83
}
86
84
//if (!app.getPrivileges().isEmpty()) {
87
- out .println (tab + "Privs: " + app .getPrivileges ());
85
+ out .println (tab + "Privs: " + e .getPrivileges ());
88
86
//}
89
87
}
90
88
out .println ();
0 commit comments