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/+/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/+/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/+/41806?usp=email )
Change subject: OmapiCallbackHandlerVpcd: simplify/fix SELECT by DF-Name (aid)
......................................................................
OmapiCallbackHandlerVpcd: simplify/fix SELECT by DF-Name (aid)
When a TPDU with a SELECT by DF-Name is received from the VPCD end,
it cannot be transparently passed through the OMAPI channel as OMAPI
will block those TDPUs for security reasons. To overcome this, we
close the current OMAPI channel and re-open a new one under the new
DF-Name (AID).
To reduce the likelyhood for unexpected behaviour and possible loss
of state we have replaced the SELECT by DF-Name with a SELECT to
7fff (alias for the currently selected application), in case the
SELECT by DF-Name would target the currently selected application.
This workaround requires preceise tracking of which application is
currently selected. Unfortunately this has proven as difficult and
error prone.
After looking closer at the problem we noticed that we do not even
need the aforementioned workaround. The opening and closing of the
OMAPI channel just opens and closes logical channels on the card.
It does not perform a reset. This in particular means that the ADM
or PIN verification state is retained. (states like the currently
selected file, the current tag and the current record are reset by
SELECT anyway).
So let's remove the workaround and re-open the OMAPI channel each
time a SELECT by DF-Name is received.
Related: OS#6836
Change-Id: Ib4873b18d233e549e075b9384906a536907c6260
---
M app/src/main/java/org/osmocom/androidApduProxy/OmapiCallbackHandlerVpcd.java
1 file changed, 24 insertions(+), 44 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/android-apdu-proxy refs/changes/06/41806/1
diff --git a/app/src/main/java/org/osmocom/androidApduProxy/OmapiCallbackHandlerVpcd.java b/app/src/main/java/org/osmocom/androidApduProxy/OmapiCallbackHandlerVpcd.java
index d82a23a..973361e 100644
--- a/app/src/main/java/org/osmocom/androidApduProxy/OmapiCallbackHandlerVpcd.java
+++ b/app/src/main/java/org/osmocom/androidApduProxy/OmapiCallbackHandlerVpcd.java
@@ -17,7 +17,6 @@
private int remotePort = 0;
private Handler uiHandler = null;
private int omapiChannel = -1;
- private byte[] omapiAid = null;
//When we open the OMPI channel the first time, we must provide an AID. The following AID is
//the prefix (RID) of 3GPP (see also ETSI TS 101 220, section 4.1) This prefix should select
@@ -74,7 +73,6 @@
sendErrorMessage(e);
return;
}
- omapiAid = DEFAULT_AID;
sendMessageInd(MainActivity.IND_CHANNEL_OPEN);
}
@Override
@@ -89,14 +87,12 @@
return;
}
sendMessageInd(MainActivity.IND_CHANNEL_OPEN);
- omapiAid = DEFAULT_AID;
}
@Override
public void vpcdPwrOff() {
Log.i("PROXY", "Closing OMAPI channel as an alternative to power-off...\n");
omapi.close(omapiChannel);
sendMessageInd(MainActivity.IND_CHANNEL_CLOSE);
- omapiAid = null;
}
@Override
public byte[] vpcdTransact(byte[] tpdu) {
@@ -111,14 +107,11 @@
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
- //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.
+ //In case the TPDU contains a SELECT by DF-Name (AID), we cannot transparently pass on the TPDU through
+ //the OMAPI channel since OMAPI will block such TPDUs for security reasons. The only way to archive a
+ //similar result is to close the existing OMAPI channel to and re-open a new OMAPI channel under the
+ //DF-Name (AID) given in in the TPDU.
if (Arrays.equals(Arrays.copyOf(tpdu, 3), Utils.h2b("00A404"))) {
- 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",
@@ -142,39 +135,26 @@
aidReq = new byte[0];
}
- if (omapiAid != null) {
- if (aidReq.length < omapiAid.length)
- compareLength = aidReq.length;
- else
- 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->7fff), as a replacement for SELECT by DF-Name...\n",
- Utils.b2h(aidReq)));
- try {
- return omapi.transact(omapiChannel, Utils.h2b("00a40004027fff"));
- } catch (Exception e) {
- sendErrorMessage(e);
- }
- } else {
- Log.i("PROXY", String.format("Opening new channel for AID (%s) as a replacement for SELECT by DF-Name...\n",
- Utils.b2h(aidReq)));
- try {
- int newOmapiChannel;
- byte[] response;
- newOmapiChannel = omapi.open(omapiReader, aidReq, tpdu[3]);
- 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);
- omapiAid = aidReq;
- omapiChannel = newOmapiChannel;
- return response;
- } catch (Exception e) {
- Log.i("PROXY", String.format("Opening new channel for new AID (%s) was not successful, pretending that the file was not found...\n",
- Utils.b2h(aidReq)));
- return (Utils.h2b("6A82"));
- }
+ //Compare the given DF-Name to the AID of the current OMAPI channel. If the DF-Name still matches
+ //the AID of the current OMAPI channel, we stay on the current OMAPI channel. If the DF-Name
+ //references the AID of a different application, we will close the current OMAPI channel and open a
+ //new one.
+ Log.i("PROXY", String.format("Opening new channel for AID (%s) as a replacement for SELECT by DF-Name...\n",
+ Utils.b2h(aidReq)));
+ try {
+ int newOmapiChannel;
+ byte[] response;
+ newOmapiChannel = omapi.open(omapiReader, aidReq, tpdu[3]);
+ 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);
+ omapiChannel = newOmapiChannel;
+ return response;
+ } catch (Exception e) {
+ Log.i("PROXY", String.format("Opening new channel for new AID (%s) was not successful, pretending that the file was not found...\n",
+ Utils.b2h(aidReq)));
+ return (Utils.h2b("6A82"));
}
}
--
To view, visit https://gerrit.osmocom.org/c/android-apdu-proxy/+/41806?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: Ib4873b18d233e549e075b9384906a536907c6260
Gerrit-Change-Number: 41806
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/+/41805?usp=email )
Change subject: OmapiCallbackHandlerVpcd: pass SELECT parameter P2 to OMAPI
......................................................................
OmapiCallbackHandlerVpcd: pass SELECT parameter P2 to OMAPI
The OMAPI method openLogicalChannel may take an optional parameter p2,
This parameter. Among other function, this paramter in particular
controls how to deal with short DF-Names that match the AIDs of several
applications.
Since we always know this parameter from the TPDU that we receive from
VPCD, let's pass it on to OMAPI when we create a new channel.
Related OS#6836
Change-Id: Ibab2cc197284e6177a83338007a0b7f77e0ab8b9
---
M app/src/main/java/org/osmocom/androidApduProxy/Omapi.java
M app/src/main/java/org/osmocom/androidApduProxy/OmapiCallbackHandlerVpcd.java
2 files changed, 14 insertions(+), 3 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/android-apdu-proxy refs/changes/05/41805/1
diff --git a/app/src/main/java/org/osmocom/androidApduProxy/Omapi.java b/app/src/main/java/org/osmocom/androidApduProxy/Omapi.java
index 6d88273..c814a0e 100644
--- a/app/src/main/java/org/osmocom/androidApduProxy/Omapi.java
+++ b/app/src/main/java/org/osmocom/androidApduProxy/Omapi.java
@@ -170,13 +170,14 @@
* Open a channel on the specified reader to the specified AID.
* @param readerName string that contains the reader name (e.g. "SIM1")
* @param aid array of bytes that contains the AID of the application to access
+ * @param p2 parameter value to use with the SELECT APDU
* @return OMAPI Channel number on success, throws Exception on error
*/
- public int open(String readerName, byte[] aid) throws Exception {
+ public int open(String readerName, byte[] aid, byte p2) throws Exception {
try {
ensureSeService();
Session session = getOrCreateSession(readerName);
- Channel channel = session.openLogicalChannel(aid);
+ Channel channel = session.openLogicalChannel(aid, p2);
if (channel == null)
throw new Exception(String.format("could not open channel for AID (%s) on reader: %s!\n",
Utils.b2h(aid), readerName));
@@ -192,6 +193,16 @@
}
/**
+ * Open a channel on the specified reader to the specified AID.
+ * @param readerName string that contains the reader name (e.g. "SIM1")
+ * @param aid array of bytes that contains the AID of the application to access
+ * @return OMAPI Channel number on success, throws Exception on error
+ */
+ public int open(String readerName, byte[] aid) throws Exception {
+ return open(readerName, aid, (byte)0x04);
+ }
+
+ /**
* 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
diff --git a/app/src/main/java/org/osmocom/androidApduProxy/OmapiCallbackHandlerVpcd.java b/app/src/main/java/org/osmocom/androidApduProxy/OmapiCallbackHandlerVpcd.java
index 8bb41ac..d82a23a 100644
--- a/app/src/main/java/org/osmocom/androidApduProxy/OmapiCallbackHandlerVpcd.java
+++ b/app/src/main/java/org/osmocom/androidApduProxy/OmapiCallbackHandlerVpcd.java
@@ -162,7 +162,7 @@
try {
int newOmapiChannel;
byte[] response;
- newOmapiChannel = omapi.open(omapiReader, aidReq);
+ newOmapiChannel = omapi.open(omapiReader, aidReq, tpdu[3]);
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));
--
To view, visit https://gerrit.osmocom.org/c/android-apdu-proxy/+/41805?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: Ibab2cc197284e6177a83338007a0b7f77e0ab8b9
Gerrit-Change-Number: 41805
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/+/41804?usp=email )
Change subject: OmapiCallbackHandlerVpcd: fetch SELECT response from OMAPI
......................................................................
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 https://gerrit.osmocom.org/c/android-apdu-proxy/+/41804?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: Iacbc907ef157f20bed88325fcf6b58717990005a
Gerrit-Change-Number: 41804
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>
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>
pespin has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-bts/+/41796?usp=email )
Change subject: ta_power_control: reset during lchan activation
......................................................................
ta_power_control: reset during lchan activation
This way lchan->ta_ctrl.skip_block_num is also reset to 0 during chan
re-activation case, in which case we allow the TA control loop to kick
in during first input after re-activation.
Change-Id: I149fffa73ef651fd21e52e5423b31f8e95e57941
---
M src/common/rsl.c
M src/common/ta_control.c
2 files changed, 2 insertions(+), 2 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/osmo-bts refs/changes/96/41796/1
diff --git a/src/common/rsl.c b/src/common/rsl.c
index 07d5e6d..3a52167 100644
--- a/src/common/rsl.c
+++ b/src/common/rsl.c
@@ -2056,10 +2056,9 @@
}
/* 9.3.24 Timing Advance */
+ lchan_ms_ta_ctrl_reset(lchan);
if (TLVP_PRES_LEN(&tp, RSL_IE_TIMING_ADVANCE, 1))
lchan->ta_ctrl.current = *TLVP_VAL(&tp, RSL_IE_TIMING_ADVANCE);
- else /* assume TA=0 if not indicated by the BSC */
- lchan->ta_ctrl.current = 0;
/* 9.3.31 (TLV) MS Power Parameters IE (vendor specific) */
if ((ie = TLVP_GET(&tp, RSL_IE_MS_POWER_PARAM)) != NULL) {
diff --git a/src/common/ta_control.c b/src/common/ta_control.c
index b5d9cb2..85e5f81 100644
--- a/src/common/ta_control.c
+++ b/src/common/ta_control.c
@@ -46,6 +46,7 @@
{
/* Trigger loop on first TA input: */
lchan->ta_ctrl.skip_block_num = 0;
+ /* Assume TA=0 if not indicated by the BSC */
lchan->ta_ctrl.current = 0;
}
--
To view, visit https://gerrit.osmocom.org/c/osmo-bts/+/41796?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: newchange
Gerrit-Project: osmo-bts
Gerrit-Branch: master
Gerrit-Change-Id: I149fffa73ef651fd21e52e5423b31f8e95e57941
Gerrit-Change-Number: 41796
Gerrit-PatchSet: 1
Gerrit-Owner: pespin <pespin(a)sysmocom.de>