Skip to content

Commit

Permalink
Adjustments for the response parsing with older G&D-s
Browse files Browse the repository at this point in the history
  • Loading branch information
martinpaljak committed Apr 14, 2016
1 parent 9fc7f23 commit 6f05e60
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
1 change: 1 addition & 0 deletions src/pro/javacard/gp/CapFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -342,5 +342,6 @@ public void dump(PrintStream out) {
}
out.println("Total code size: " + getCodeLength(false) + " bytes (" + getCodeLength(true) + " with debug)");
out.println("SHA256 (code): " + HexUtils.bin2hex(getLoadFileDataHash("SHA-256", false)));
out.println("SHA1 (code): " + HexUtils.bin2hex(getLoadFileDataHash("SHA-1", false)));
}
}
9 changes: 5 additions & 4 deletions src/pro/javacard/gp/GPRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public AID getDefaultSelectedPackageAID() {
return null;
}

private void populate_legacy(byte[] data, Kind type, GPSpec spec) throws GPDataException {
private void populate_legacy(int p1, byte[] data, Kind type, GPSpec spec) throws GPDataException {
int offset = 0;
try {
while (offset < data.length) {
Expand All @@ -199,7 +199,7 @@ private void populate_legacy(byte[] data, Kind type, GPSpec spec) throws GPDataE
pkg.setLifeCycle(lifecycle);
pkg.setType(type);
// Modules TODO: remove
if (spec != GPSpec.OP201) {
if (spec != GPSpec.OP201 && p1 != 0x20) {
int num = data[offset++];
for (int i = 0; i < num; i++) {
len = data[offset++] & 0xFF;
Expand Down Expand Up @@ -282,11 +282,12 @@ private void populate_tags(byte[] data, Kind type) throws GPDataException {
}
}

public void parse(byte[] data, Kind type, GPSpec spec) throws GPDataException {
// FIXME: this is ugly
public void parse(int p1, byte[] data, Kind type, GPSpec spec) throws GPDataException {
if (tags) {
populate_tags(data, type);
} else {
populate_legacy(data, type, spec);
populate_legacy(p1, data, type, spec);
}
}
}
21 changes: 10 additions & 11 deletions src/pro/javacard/gp/GlobalPlatform.java
Original file line number Diff line number Diff line change
Expand Up @@ -1011,13 +1011,12 @@ private byte[] getConcatenatedStatus(GPRegistry reg, int p1, byte[] data) throws

int sw = response.getSW();
if ((sw != ISO7816.SW_NO_ERROR) && (sw != 0x6310)) {
if (sw == 0x6A88) { // Referenced data not found
return response.getData(); // Should be empty array
}
if (sw == 0x6A86) { // if ISD is requested from SSD XXX
return response.getData();
}
throw new GPException(sw, "GET STATUS failed for " + HexUtils.bin2hex(cmd.getBytes()));
// Possible values:
// 0x6A88 - referenced data not found
// 0x6A86 - no tags support or ISD asked from SSD
// 0a6A81 - Same as 6A88 ?
logger.warn("GET STATUS failed for " + HexUtils.bin2hex(cmd.getBytes()) + " with " + Integer.toHexString(sw));
return response.getData();
}

ByteArrayOutputStream bo = new ByteArrayOutputStream();
Expand Down Expand Up @@ -1049,20 +1048,20 @@ private GPRegistry getStatus() throws CardException, GPException {
}
// Issuer security domain
byte[] data = getConcatenatedStatus(registry, 0x80, new byte[] { 0x4F, 0x00 });
registry.parse(data, Kind.IssuerSecurityDomain, spec);
registry.parse(0x80, data, Kind.IssuerSecurityDomain, spec);

// Apps and security domains
data = getConcatenatedStatus(registry, 0x40, new byte[] { 0x4F, 0x00 });
registry.parse(data, Kind.Application, spec);
registry.parse(0x40, data, Kind.Application, spec);

// Load files
data = getConcatenatedStatus(registry, 0x20, new byte[] { 0x4F, 0x00 });
registry.parse(data, Kind.ExecutableLoadFile, spec);
registry.parse(0x20, data, Kind.ExecutableLoadFile, spec);

if (spec != GPSpec.OP201) { // TODO: remove
// Load files with modules
data = getConcatenatedStatus(registry, 0x10, new byte[] { 0x4F, 0x00 });
registry.parse(data, Kind.ExecutableLoadFile, spec);
registry.parse(0x10, data, Kind.ExecutableLoadFile, spec);
}
return registry;
}
Expand Down

0 comments on commit 6f05e60

Please sign in to comment.