laforge has submitted this change. ( https://gerrit.osmocom.org/c/pysim/+/37131?usp=email )
Change subject: pySim.apdu: Allow TLV based decoders for APDU command and response body
......................................................................
pySim.apdu: Allow TLV based decoders for APDU command and response body
So far we only supported construct.
Change-Id: Ibb80d328c9a1f464aa5338ca0ca1d6bfb00734e1
---
M pySim/apdu/__init__.py
1 file changed, 26 insertions(+), 3 deletions(-)
Approvals:
laforge: Looks good to me, approved
fixeria: Looks good to me, but someone else must approve
Jenkins Builder: Verified
diff --git a/pySim/apdu/__init__.py b/pySim/apdu/__init__.py
index f5b7852..02ccbad 100644
--- a/pySim/apdu/__init__.py
+++ b/pySim/apdu/__init__.py
@@ -9,7 +9,7 @@
we already know in pySim about the filesystem structure, file encoding, etc.
"""
-# (C) 2022 by Harald Welte <laforge(a)osmocom.org>
+# (C) 2022-2024 by Harald Welte <laforge(a)osmocom.org>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -152,6 +152,8 @@
_construct_p2 = Byte
_construct = HexAdapter(GreedyBytes)
_construct_rsp = HexAdapter(GreedyBytes)
+ _tlv = None
+ _tlv_rsp = None
def __init__(self, cmd: BytesOrHex, rsp: Optional[BytesOrHex] = None):
"""Instantiate a new ApduCommand from give cmd + resp."""
@@ -299,7 +301,12 @@
r['p2'] = parse_construct(self._construct_p2, self.p2.to_bytes(1, 'big'))
r['p3'] = self.p3
if self.cmd_data:
- r['body'] = parse_construct(self._construct, self.cmd_data)
+ if self._tlv:
+ ie = self._tlv()
+ ie.from_tlv(self.cmd_data)
+ r['body'] = ie.to_dict()
+ else:
+ r['body'] = parse_construct(self._construct, self.cmd_data)
return r
def rsp_to_dict(self) -> Dict:
@@ -310,7 +317,12 @@
else:
r = {}
if self.rsp_data:
- r['body'] = parse_construct(self._construct_rsp, self.rsp_data)
+ if self._tlv_rsp:
+ ie = self._tlv_rsp()
+ ie.from_tlv(self.rsp_data)
+ r['body'] = ie.to_dict()
+ else:
+ r['body'] = parse_construct(self._construct_rsp, self.rsp_data)
r['sw'] = b2h(self.sw)
return r
--
To view, visit https://gerrit.osmocom.org/c/pysim/+/37131?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings
Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: Ibb80d328c9a1f464aa5338ca0ca1d6bfb00734e1
Gerrit-Change-Number: 37131
Gerrit-PatchSet: 1
Gerrit-Owner: laforge <laforge(a)osmocom.org>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: fixeria <vyanitskiy(a)sysmocom.de>
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
Gerrit-MessageType: merged
laforge has submitted this change. ( https://gerrit.osmocom.org/c/pysim/+/37130?usp=email )
Change subject: pySim-trace: Add support for the TCA Loader log file format
......................................................................
pySim-trace: Add support for the TCA Loader log file format
The "TCA Loader" is a freeware utility program published by the
Trusted Connectivity Alliance for testing SCP80, SCP81, SCP02 and SCP03
in UICCs. It can generate text log files of the APDUs it exchanges;
let's add this file format to pySim-trace
Change-Id: Ie76d36bb18c6bd8968d2a5b74ec1b8c5ccaaa409
---
M pySim-trace.py
A pySim/apdu_source/tca_loader_log.py
2 files changed, 70 insertions(+), 0 deletions(-)
Approvals:
fixeria: Looks good to me, but someone else must approve
Jenkins Builder: Verified
laforge: Looks good to me, approved
diff --git a/pySim-trace.py b/pySim-trace.py
index 165e338..3257cb7 100755
--- a/pySim-trace.py
+++ b/pySim-trace.py
@@ -20,6 +20,7 @@
from pySim.apdu_source.gsmtap import GsmtapApduSource
from pySim.apdu_source.pyshark_rspro import PysharkRsproPcap, PysharkRsproLive
from pySim.apdu_source.pyshark_gsmtap import PysharkGsmtapPcap
+from pySim.apdu_source.tca_loader_log import TcaLoaderLogApduSource
from pySim.apdu.ts_102_221 import UiccSelect, UiccStatus
@@ -181,6 +182,11 @@
parser_rspro_pyshark_live.add_argument('-i', '--interface', required=True,
help='Name of the network interface to capture on')
+parser_tcaloader_log = subparsers.add_parser('tca-loader-log', help="""
+ Read APDUs from a TCA Loader log file.""")
+parser_tcaloader_log.add_argument('-f', '--log-file', required=True,
+ help='Name of te log file to be read')
+
if __name__ == '__main__':
opts = option_parser.parse_args()
@@ -194,6 +200,8 @@
s = PysharkRsproLive(opts.interface)
elif opts.source == 'gsmtap-pyshark-pcap':
s = PysharkGsmtapPcap(opts.pcap_file)
+ elif opts.source == 'tca-loader-log':
+ s = TcaLoaderLogApduSource(opts.log_file)
else:
raise ValueError("unsupported source %s", opts.source)
diff --git a/pySim/apdu_source/tca_loader_log.py b/pySim/apdu_source/tca_loader_log.py
new file mode 100644
index 0000000..6efc605
--- /dev/null
+++ b/pySim/apdu_source/tca_loader_log.py
@@ -0,0 +1,48 @@
+# coding=utf-8
+
+# (C) 2024 by Harald Welte <laforge(a)osmocom.org>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+
+from pySim.utils import h2b
+from pySim.gsmtap import GsmtapSource
+
+from pySim.apdu.ts_102_221 import ApduCommands as UiccApduCommands
+from pySim.apdu.ts_31_102 import ApduCommands as UsimApduCommands
+from pySim.apdu.global_platform import ApduCommands as GpApduCommands
+
+from . import ApduSource, PacketType, CardReset
+
+ApduCommands = UiccApduCommands + UsimApduCommands + GpApduCommands
+
+class TcaLoaderLogApduSource(ApduSource):
+ """ApduSource for reading log files created by TCALoader."""
+ def __init__(self, filename:str):
+ super().__init__()
+ self.logfile = open(filename, 'r')
+
+ def read_packet(self) -> PacketType:
+ command = None
+ response = None
+ for line in self.logfile:
+ if line.startswith('Command'):
+ command = line.split()[1]
+ print("Command: '%s'" % command)
+ pass
+ elif command and line.startswith('Response'):
+ response = line.split()[1]
+ print("Response: '%s'" % response)
+ return ApduCommands.parse_cmd_bytes(h2b(command) + h2b(response))
+ raise StopIteration
--
To view, visit https://gerrit.osmocom.org/c/pysim/+/37130?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings
Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: Ie76d36bb18c6bd8968d2a5b74ec1b8c5ccaaa409
Gerrit-Change-Number: 37130
Gerrit-PatchSet: 1
Gerrit-Owner: laforge <laforge(a)osmocom.org>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: fixeria <vyanitskiy(a)sysmocom.de>
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
Gerrit-MessageType: merged
laforge has posted comments on this change. ( https://gerrit.osmocom.org/c/pysim/+/37131?usp=email )
Change subject: pySim.apdu: Allow TLV based decoders for APDU command and response body
......................................................................
Patch Set 1: Code-Review+2
--
To view, visit https://gerrit.osmocom.org/c/pysim/+/37131?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings
Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: Ibb80d328c9a1f464aa5338ca0ca1d6bfb00734e1
Gerrit-Change-Number: 37131
Gerrit-PatchSet: 1
Gerrit-Owner: laforge <laforge(a)osmocom.org>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: fixeria <vyanitskiy(a)sysmocom.de>
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
Gerrit-Comment-Date: Sat, 08 Jun 2024 18:14:38 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment
laforge has posted comments on this change. ( https://gerrit.osmocom.org/c/pysim/+/37130?usp=email )
Change subject: pySim-trace: Add support for the TCA Loader log file format
......................................................................
Patch Set 1: Code-Review+2
--
To view, visit https://gerrit.osmocom.org/c/pysim/+/37130?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings
Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: Ie76d36bb18c6bd8968d2a5b74ec1b8c5ccaaa409
Gerrit-Change-Number: 37130
Gerrit-PatchSet: 1
Gerrit-Owner: laforge <laforge(a)osmocom.org>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: fixeria <vyanitskiy(a)sysmocom.de>
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
Gerrit-Comment-Date: Sat, 08 Jun 2024 18:14:35 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment
Attention is currently required from: laforge.
fixeria has posted comments on this change. ( https://gerrit.osmocom.org/c/pysim/+/37134?usp=email )
Change subject: pySim.apdu.ts_102_221: Decode FETCH and TERMINAL RESPONSE body
......................................................................
Patch Set 1: Code-Review+1
--
To view, visit https://gerrit.osmocom.org/c/pysim/+/37134?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings
Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: Ifa410e1fefc25e87ffa8e3a2230af80180a36a18
Gerrit-Change-Number: 37134
Gerrit-PatchSet: 1
Gerrit-Owner: laforge <laforge(a)osmocom.org>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: fixeria <vyanitskiy(a)sysmocom.de>
Gerrit-Attention: laforge <laforge(a)osmocom.org>
Gerrit-Comment-Date: Sat, 08 Jun 2024 18:05:10 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment