dexter has uploaded this change for review.

View Change

OmapiCallbackHandlerVpcd: fetch SELECT response from OMAPI

At the moment we get the select response by selecting 7FFF, which
is an alias for the currently selected application. This returns a
select response when an ISIM or USIM application is selected. Other
applications may react differently here.

OMAPI has a getSelectResponse method through which we can get the
actual response that was received from the card when the application
was selected when openLogicalChannel was called. This is far more
accurate, so lets use getSelectResponse instead of selecting 7FFF.

Change-Id: Iacbc907ef157f20bed88325fcf6b58717990005a
---
M app/src/main/java/org/osmocom/androidApduProxy/Omapi.java
M app/src/main/java/org/osmocom/androidApduProxy/OmapiCallbackHandlerVpcd.java
2 files changed, 23 insertions(+), 1 deletion(-)

git pull ssh://gerrit.osmocom.org:29418/android-apdu-proxy refs/changes/04/41804/1
diff --git a/app/src/main/java/org/osmocom/androidApduProxy/Omapi.java b/app/src/main/java/org/osmocom/androidApduProxy/Omapi.java
index afd4515..6d88273 100644
--- a/app/src/main/java/org/osmocom/androidApduProxy/Omapi.java
+++ b/app/src/main/java/org/osmocom/androidApduProxy/Omapi.java
@@ -192,6 +192,28 @@
}

/**
+ * Read the SELECT response after method open was called successfully.
+ * @param channelId id-number of the OMAPI Channel
+ * @return array of bytes that contains the SELECT response or, throws Exception on error
+ */
+ public byte[] getSelRes(int channelId) throws Exception {
+ try {
+ ensureSeService();
+ if (!channels.containsKey(channelId))
+ throw new Exception(String.format("no channel open under channelId = %d", channelId));
+ Channel channel = channels.get(channelId);
+ byte[] response = channel.getSelectResponse();
+ if (response == null)
+ throw new Exception("unresponsive card!");
+ Log.d("OMAPI","SELECT RESPONSE: " + Utils.b2h(response) + "\n");
+ return response;
+ } catch (Exception e) {
+ Log.e("OMAPI",e.getMessage() + "\n");
+ throw e;
+ }
+ }
+
+ /**
* Perform an APDU transaction on the card.
* @param channelId id-number of the OMAPI Channel
* @param apdu array of bytes that contains the command APDU (to card)
diff --git a/app/src/main/java/org/osmocom/androidApduProxy/OmapiCallbackHandlerVpcd.java b/app/src/main/java/org/osmocom/androidApduProxy/OmapiCallbackHandlerVpcd.java
index 8f1d8c7..8bb41ac 100644
--- a/app/src/main/java/org/osmocom/androidApduProxy/OmapiCallbackHandlerVpcd.java
+++ b/app/src/main/java/org/osmocom/androidApduProxy/OmapiCallbackHandlerVpcd.java
@@ -163,7 +163,7 @@
int newOmapiChannel;
byte[] response;
newOmapiChannel = omapi.open(omapiReader, aidReq);
- response = omapi.transact(newOmapiChannel, Utils.h2b("00a40004027fff"));
+ response = omapi.getSelRes(newOmapiChannel);
Log.i("PROXY", String.format("Opening new channel (%d) for AID (%s) was successful, now closing the old channel (%d)...\n",
newOmapiChannel, Utils.b2h(aidReq), omapiChannel));
omapi.close(omapiChannel);

To view, visit change 41804. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-MessageType: newchange
Gerrit-Project: android-apdu-proxy
Gerrit-Branch: master
Gerrit-Change-Id: Iacbc907ef157f20bed88325fcf6b58717990005a
Gerrit-Change-Number: 41804
Gerrit-PatchSet: 1
Gerrit-Owner: dexter <pmaier@sysmocom.de>