laforge has uploaded this change for review. ( 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(-)
git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/30/37130/1
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@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