dexter has submitted this change. ( https://gerrit.osmocom.org/c/android-apdu-proxy/+/41797?usp=email )
Change subject: OmapiCallbackHandlerVpcd: fix typo
......................................................................
OmapiCallbackHandlerVpcd: fix typo
Change-Id: I113757e5ee547c20d3557a9080386592a1919954
---
M app/src/main/java/org/osmocom/androidApduProxy/OmapiCallbackHandlerVpcd.java
1 file changed, 1 insertion(+), 1 deletion(-)
Approvals:
Jenkins Builder: Verified
dexter: Looks good to me, approved
diff --git a/app/src/main/java/org/osmocom/androidApduProxy/OmapiCallbackHandlerVpcd.java b/app/src/main/java/org/osmocom/androidApduProxy/OmapiCallbackHandlerVpcd.java
index 088edf5..d5b4043 100644
--- a/app/src/main/java/org/osmocom/androidApduProxy/OmapiCallbackHandlerVpcd.java
+++ b/app/src/main/java/org/osmocom/androidApduProxy/OmapiCallbackHandlerVpcd.java
@@ -104,7 +104,7 @@
Log.i("PROXY", "Exchanging TPDU...\n");
//In case the TPDU contains a SELECT by DF-Name, which is forbidden by OMAPI by design, we must
//find an alternative solution: In case the SELECT targets the currently selected application,
- //we just use the FID 7FFF, which is an alias for the currently selected application. In cas the
+ //we just use the FID 7FFF, which is an alias for the currently selected application. In case the
//AID is different, we close the OMAPI channel and re-open it with the new AID. If this fails, we
//we just pretend that we haven't found the file.
if (Arrays.equals(Arrays.copyOf( tpdu,3), Utils.h2b("00A404") ) ) {
--
To view, visit https://gerrit.osmocom.org/c/android-apdu-proxy/+/41797?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: merged
Gerrit-Project: android-apdu-proxy
Gerrit-Branch: master
Gerrit-Change-Id: I113757e5ee547c20d3557a9080386592a1919954
Gerrit-Change-Number: 41797
Gerrit-PatchSet: 1
Gerrit-Owner: dexter <pmaier(a)sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: dexter <pmaier(a)sysmocom.de>
dexter has uploaded this change for review. ( https://gerrit.osmocom.org/c/android-apdu-proxy/+/41797?usp=email )
Change subject: OmapiCallbackHandlerVpcd: fix typo
......................................................................
OmapiCallbackHandlerVpcd: fix typo
Change-Id: I113757e5ee547c20d3557a9080386592a1919954
---
M app/src/main/java/org/osmocom/androidApduProxy/OmapiCallbackHandlerVpcd.java
1 file changed, 1 insertion(+), 1 deletion(-)
git pull ssh://gerrit.osmocom.org:29418/android-apdu-proxy refs/changes/97/41797/1
diff --git a/app/src/main/java/org/osmocom/androidApduProxy/OmapiCallbackHandlerVpcd.java b/app/src/main/java/org/osmocom/androidApduProxy/OmapiCallbackHandlerVpcd.java
index 088edf5..d5b4043 100644
--- a/app/src/main/java/org/osmocom/androidApduProxy/OmapiCallbackHandlerVpcd.java
+++ b/app/src/main/java/org/osmocom/androidApduProxy/OmapiCallbackHandlerVpcd.java
@@ -104,7 +104,7 @@
Log.i("PROXY", "Exchanging TPDU...\n");
//In case the TPDU contains a SELECT by DF-Name, which is forbidden by OMAPI by design, we must
//find an alternative solution: In case the SELECT targets the currently selected application,
- //we just use the FID 7FFF, which is an alias for the currently selected application. In cas the
+ //we just use the FID 7FFF, which is an alias for the currently selected application. In case the
//AID is different, we close the OMAPI channel and re-open it with the new AID. If this fails, we
//we just pretend that we haven't found the file.
if (Arrays.equals(Arrays.copyOf( tpdu,3), Utils.h2b("00A404") ) ) {
--
To view, visit https://gerrit.osmocom.org/c/android-apdu-proxy/+/41797?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: newchange
Gerrit-Project: android-apdu-proxy
Gerrit-Branch: master
Gerrit-Change-Id: I113757e5ee547c20d3557a9080386592a1919954
Gerrit-Change-Number: 41797
Gerrit-PatchSet: 1
Gerrit-Owner: dexter <pmaier(a)sysmocom.de>
dexter has uploaded this change for review. ( https://gerrit.osmocom.org/c/android-apdu-proxy/+/41800?usp=email )
Change subject: OmapiCallbackHandlerVpcd: use appropriate status word to reject MANAGE CHANNEL
......................................................................
OmapiCallbackHandlerVpcd: use appropriate status word to reject MANAGE CHANNEL
ISO/IEC 7816-4 specifies a status word to reject MANAGE CHANNEL instructions
in case the card does not support multiple channels.
Let's also print an error message in the log to simplify debugging for users
who aren't aware of OMAPI's logical channel limitation.
Change-Id: I42529a6ae61378e41f33f1ec34124e346d4805df
---
M app/src/main/java/org/osmocom/androidApduProxy/OmapiCallbackHandlerVpcd.java
1 file changed, 4 insertions(+), 1 deletion(-)
git pull ssh://gerrit.osmocom.org:29418/android-apdu-proxy refs/changes/00/41800/1
diff --git a/app/src/main/java/org/osmocom/androidApduProxy/OmapiCallbackHandlerVpcd.java b/app/src/main/java/org/osmocom/androidApduProxy/OmapiCallbackHandlerVpcd.java
index 7b2f63f..f443ac2 100644
--- a/app/src/main/java/org/osmocom/androidApduProxy/OmapiCallbackHandlerVpcd.java
+++ b/app/src/main/java/org/osmocom/androidApduProxy/OmapiCallbackHandlerVpcd.java
@@ -147,8 +147,11 @@
//Block all attempts to manage a channel, this is a feature we do not support here.
//(OMAPI also does not support the MANAGE CHANNEL command)
- return (Utils.h2b("6D00"));
if (Arrays.equals(Arrays.copyOf(tpdu, 2), Utils.h2b("0070") ) ) {
+ Log.e("PROXY", String.format("Rejecting unsupported MANAGE CHANNEL (%s) command...\n",
+ Utils.b2h(tpdu)));
+ //see also ISO/IEC 7816-4, table 6 (logical channel not supported)
+ return (Utils.h2b("6881"));
}
//Normal APDU/TPDU exchange
--
To view, visit https://gerrit.osmocom.org/c/android-apdu-proxy/+/41800?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: newchange
Gerrit-Project: android-apdu-proxy
Gerrit-Branch: master
Gerrit-Change-Id: I42529a6ae61378e41f33f1ec34124e346d4805df
Gerrit-Change-Number: 41800
Gerrit-PatchSet: 1
Gerrit-Owner: dexter <pmaier(a)sysmocom.de>
dexter has uploaded this change for review. ( https://gerrit.osmocom.org/c/android-apdu-proxy/+/41798?usp=email )
Change subject: cosmetic: fix sourcecode formatting
......................................................................
cosmetic: fix sourcecode formatting
Change-Id: Iab233cdff33d686d6715abe3cb2b0c4f2a74dd0d
---
M app/src/main/java/org/osmocom/androidApduProxy/Omapi.java
M app/src/main/java/org/osmocom/androidApduProxy/OmapiCallbackHandlerVpcd.java
M app/src/main/java/org/osmocom/androidApduProxy/Vpcd.java
3 files changed, 5 insertions(+), 6 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/android-apdu-proxy refs/changes/98/41798/1
diff --git a/app/src/main/java/org/osmocom/androidApduProxy/Omapi.java b/app/src/main/java/org/osmocom/androidApduProxy/Omapi.java
index 765d888..afd4515 100644
--- a/app/src/main/java/org/osmocom/androidApduProxy/Omapi.java
+++ b/app/src/main/java/org/osmocom/androidApduProxy/Omapi.java
@@ -135,7 +135,7 @@
}
session.close();
} else {
- Log.d("OMAPI","found reader: " + reader.getName() + " (empty)\n");
+ Log.d("OMAPI", "found reader: " + reader.getName() + " (empty)\n");
}
}
return usable_readers;
diff --git a/app/src/main/java/org/osmocom/androidApduProxy/OmapiCallbackHandlerVpcd.java b/app/src/main/java/org/osmocom/androidApduProxy/OmapiCallbackHandlerVpcd.java
index d5b4043..7b2f63f 100644
--- a/app/src/main/java/org/osmocom/androidApduProxy/OmapiCallbackHandlerVpcd.java
+++ b/app/src/main/java/org/osmocom/androidApduProxy/OmapiCallbackHandlerVpcd.java
@@ -16,7 +16,6 @@
private String remoteHost = null;
private int remotePort = 0;
private Handler uiHandler = null;
-
private int omapiChannel = -1;
private byte[] omapiAid = null;
@@ -107,7 +106,7 @@
//we just use the FID 7FFF, which is an alias for the currently selected application. In case the
//AID is different, we close the OMAPI channel and re-open it with the new AID. If this fails, we
//we just pretend that we haven't found the file.
- if (Arrays.equals(Arrays.copyOf( tpdu,3), Utils.h2b("00A404") ) ) {
+ if (Arrays.equals(Arrays.copyOf(tpdu, 3), Utils.h2b("00A404"))) {
byte[] aidReq = Arrays.copyOfRange(tpdu, 5, tpdu.length - 1);
int compareLength = 0;
if (omapiAid != null) {
@@ -148,8 +147,8 @@
//Block all attempts to manage a channel, this is a feature we do not support here.
//(OMAPI also does not support the MANAGE CHANNEL command)
- if (Arrays.equals(Arrays.copyOf( tpdu,2), Utils.h2b("0070") ) ) {
return (Utils.h2b("6D00"));
+ if (Arrays.equals(Arrays.copyOf(tpdu, 2), Utils.h2b("0070") ) ) {
}
//Normal APDU/TPDU exchange
diff --git a/app/src/main/java/org/osmocom/androidApduProxy/Vpcd.java b/app/src/main/java/org/osmocom/androidApduProxy/Vpcd.java
index 002803b..d4b65d0 100644
--- a/app/src/main/java/org/osmocom/androidApduProxy/Vpcd.java
+++ b/app/src/main/java/org/osmocom/androidApduProxy/Vpcd.java
@@ -204,7 +204,7 @@
//TPDU data
byte[] reqTpdu = new byte[messageLen];
byte[] resTpdu;
- System.arraycopy(message, 0, reqTpdu,0, messageLen);
+ System.arraycopy(message, 0, reqTpdu, 0, messageLen);
Log.d("VPCD", String.format("remote end asks to send TPDU: %s\n",
Utils.b2h(reqTpdu)));
resTpdu = callback.vpcdTransact(reqTpdu);
@@ -243,4 +243,4 @@
this.receiving = false;
}
-}
\ No newline at end of file
+}
--
To view, visit https://gerrit.osmocom.org/c/android-apdu-proxy/+/41798?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: newchange
Gerrit-Project: android-apdu-proxy
Gerrit-Branch: master
Gerrit-Change-Id: Iab233cdff33d686d6715abe3cb2b0c4f2a74dd0d
Gerrit-Change-Number: 41798
Gerrit-PatchSet: 1
Gerrit-Owner: dexter <pmaier(a)sysmocom.de>
dexter has uploaded this change for review. ( https://gerrit.osmocom.org/c/android-apdu-proxy/+/41801?usp=email )
Change subject: OmapiCallbackHandlerVpcd: add check to filter short TPDUs
......................................................................
OmapiCallbackHandlerVpcd: add check to filter short TPDUs
Related: OS#6836
Change-Id: I4e76afd7cf4d63c67b1525202fbe74e0796b2ba3
---
M app/src/main/java/org/osmocom/androidApduProxy/OmapiCallbackHandlerVpcd.java
1 file changed, 10 insertions(+), 0 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/android-apdu-proxy refs/changes/01/41801/1
diff --git a/app/src/main/java/org/osmocom/androidApduProxy/OmapiCallbackHandlerVpcd.java b/app/src/main/java/org/osmocom/androidApduProxy/OmapiCallbackHandlerVpcd.java
index f443ac2..b33d28c 100644
--- a/app/src/main/java/org/osmocom/androidApduProxy/OmapiCallbackHandlerVpcd.java
+++ b/app/src/main/java/org/osmocom/androidApduProxy/OmapiCallbackHandlerVpcd.java
@@ -101,6 +101,16 @@
@Override
public byte[] vpcdTransact(byte[] tpdu) {
Log.i("PROXY", "Exchanging TPDU...\n");
+
+ //All TPDUs that we receive here should have a minimum length of 5 bytes. Under normal conditins, short
+ //TPDUs should not occurr as they should already be filtered out by the layers that call this method.
+ //To ensure seamless operation, let's check the TPDU length and reject short TPDUs immediately.
+ if (tpdu.length < 5) {
+ Log.e("PROXY", String.format("Rejecting short TPDU (%s)...\n", Utils.b2h(tpdu)));
+ //see also ISO/IEC 7816-4, table 5 (wrong length; no further indication)
+ return (Utils.h2b("6700"));
+ }
+
//In case the TPDU contains a SELECT by DF-Name, which is forbidden by OMAPI by design, we must
//find an alternative solution: In case the SELECT targets the currently selected application,
//we just use the FID 7FFF, which is an alias for the currently selected application. In case the
--
To view, visit https://gerrit.osmocom.org/c/android-apdu-proxy/+/41801?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: newchange
Gerrit-Project: android-apdu-proxy
Gerrit-Branch: master
Gerrit-Change-Id: I4e76afd7cf4d63c67b1525202fbe74e0796b2ba3
Gerrit-Change-Number: 41801
Gerrit-PatchSet: 1
Gerrit-Owner: dexter <pmaier(a)sysmocom.de>
dexter has uploaded this change for review. ( https://gerrit.osmocom.org/c/android-apdu-proxy/+/41802?usp=email )
Change subject: OmapiCallbackHandlerVpcd: improve log output
......................................................................
OmapiCallbackHandlerVpcd: improve log output
When we select the currently selected ADF, we actually select 7fff,
which is an alias for the currently selected ADF. Let's express this
also more clearly in the log output.
Change-Id: I7004bec25f07b1a7498003231070205d2d659717
---
M app/src/main/java/org/osmocom/androidApduProxy/OmapiCallbackHandlerVpcd.java
1 file changed, 1 insertion(+), 1 deletion(-)
git pull ssh://gerrit.osmocom.org:29418/android-apdu-proxy refs/changes/02/41802/1
diff --git a/app/src/main/java/org/osmocom/androidApduProxy/OmapiCallbackHandlerVpcd.java b/app/src/main/java/org/osmocom/androidApduProxy/OmapiCallbackHandlerVpcd.java
index b33d28c..57c5035 100644
--- a/app/src/main/java/org/osmocom/androidApduProxy/OmapiCallbackHandlerVpcd.java
+++ b/app/src/main/java/org/osmocom/androidApduProxy/OmapiCallbackHandlerVpcd.java
@@ -126,7 +126,7 @@
compareLength = omapiAid.length;
}
if (omapiAid != null && Arrays.equals(Arrays.copyOf(omapiAid, compareLength), Arrays.copyOf(aidReq, compareLength))) {
- Log.i("PROXY", String.format("Selecting the currently selected ADF (%s), as a replacement for SELECT by DF-Name...\n",
+ Log.i("PROXY", String.format("Selecting the currently selected ADF (%s->7fff), as a replacement for SELECT by DF-Name...\n",
Utils.b2h(aidReq)));
try {
return omapi.transact(omapiChannel, Utils.h2b("00a40004027fff"));
--
To view, visit https://gerrit.osmocom.org/c/android-apdu-proxy/+/41802?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: newchange
Gerrit-Project: android-apdu-proxy
Gerrit-Branch: master
Gerrit-Change-Id: I7004bec25f07b1a7498003231070205d2d659717
Gerrit-Change-Number: 41802
Gerrit-PatchSet: 1
Gerrit-Owner: dexter <pmaier(a)sysmocom.de>
dexter has uploaded this change for review. ( https://gerrit.osmocom.org/c/android-apdu-proxy/+/41803?usp=email )
Change subject: OmapiCallbackHandlerVpcd: fix extration of DF-Name (AID)
......................................................................
OmapiCallbackHandlerVpcd: fix extration of DF-Name (AID)
When the DF-Name (AID) is extracted from the SELECT TPDU, the length
of the TPDU is not checked properly, which may lead to an exception
in case no DF-Name (AID) is supplied. Let's put proper length checks
in place to filter corner cases and to ensure that the DF-Name (AID)
is properly extracted in case it is supplied.
Related: OS#6836
Change-Id: Idf08d752d046e012680c872552960cc069272777
---
M app/src/main/java/org/osmocom/androidApduProxy/OmapiCallbackHandlerVpcd.java
1 file changed, 24 insertions(+), 1 deletion(-)
git pull ssh://gerrit.osmocom.org:29418/android-apdu-proxy refs/changes/03/41803/1
diff --git a/app/src/main/java/org/osmocom/androidApduProxy/OmapiCallbackHandlerVpcd.java b/app/src/main/java/org/osmocom/androidApduProxy/OmapiCallbackHandlerVpcd.java
index 57c5035..8f1d8c7 100644
--- a/app/src/main/java/org/osmocom/androidApduProxy/OmapiCallbackHandlerVpcd.java
+++ b/app/src/main/java/org/osmocom/androidApduProxy/OmapiCallbackHandlerVpcd.java
@@ -117,8 +117,31 @@
//AID is different, we close the OMAPI channel and re-open it with the new AID. If this fails, we
//we just pretend that we haven't found the file.
if (Arrays.equals(Arrays.copyOf(tpdu, 3), Utils.h2b("00A404"))) {
- byte[] aidReq = Arrays.copyOfRange(tpdu, 5, tpdu.length - 1);
int compareLength = 0;
+
+ //Make sure that the Lc field of the TPDU does not exceed the TPDU length
+ if (tpdu[4] > tpdu.length - 5) {
+ Log.e("PROXY", String.format("SELECT by DF-Name with invalid length field, rejecting TPDU (%s)...\n",
+ Utils.b2h(tpdu)));
+ //see also ISO/IEC 7816-4, table 5 (wrong length; no further indication)
+ return (Utils.h2b("6700"));
+ }
+
+ //Extract the DF-Name (AID) from the TPDU.
+ byte[] aidReq;
+ if (tpdu[4] > 0) {
+ //The DF-Name (AID) does not have to represent a full AID, a shortened (right truncated) AID
+ //is sufficient (see also ETSI TS 102 221, section 11.1.1.2).
+ aidReq = Arrays.copyOfRange(tpdu, 5, tpdu[4] + 5);
+ } else {
+ //ETSI TS 102 221, section 11.1.1.2 vaguely indicates that the DF-Name (AID) may also be
+ //left out entirely. GlobalPlatform Card Specification 2.1.1, section 9.9.2.3 is more
+ //concrete. According to GlobalPlatform, the ISD shall be selected in case no DF-Name is
+ //supplied. This is also coherent to Open Mobile API Specification – Public Review
+ //v3.2.0.13, section 4.2.7.8.
+ aidReq = new byte[0];
+ }
+
if (omapiAid != null) {
if (aidReq.length < omapiAid.length)
compareLength = aidReq.length;
--
To view, visit https://gerrit.osmocom.org/c/android-apdu-proxy/+/41803?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: newchange
Gerrit-Project: android-apdu-proxy
Gerrit-Branch: master
Gerrit-Change-Id: Idf08d752d046e012680c872552960cc069272777
Gerrit-Change-Number: 41803
Gerrit-PatchSet: 1
Gerrit-Owner: dexter <pmaier(a)sysmocom.de>