From 6f05e60206cdd932341e08829a35982df3b28bdf Mon Sep 17 00:00:00 2001 From: Martin Paljak Date: Thu, 14 Apr 2016 16:36:52 +0300 Subject: [PATCH] Adjustments for the response parsing with older G&D-s --- src/pro/javacard/gp/CapFile.java | 1 + src/pro/javacard/gp/GPRegistry.java | 9 +++++---- src/pro/javacard/gp/GlobalPlatform.java | 21 ++++++++++----------- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/pro/javacard/gp/CapFile.java b/src/pro/javacard/gp/CapFile.java index 3a3854fe..f3a14a21 100644 --- a/src/pro/javacard/gp/CapFile.java +++ b/src/pro/javacard/gp/CapFile.java @@ -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))); } } diff --git a/src/pro/javacard/gp/GPRegistry.java b/src/pro/javacard/gp/GPRegistry.java index 32333fe0..096ae392 100644 --- a/src/pro/javacard/gp/GPRegistry.java +++ b/src/pro/javacard/gp/GPRegistry.java @@ -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) { @@ -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; @@ -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); } } } diff --git a/src/pro/javacard/gp/GlobalPlatform.java b/src/pro/javacard/gp/GlobalPlatform.java index 8488c50a..d9a85bb6 100644 --- a/src/pro/javacard/gp/GlobalPlatform.java +++ b/src/pro/javacard/gp/GlobalPlatform.java @@ -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(); @@ -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; }