Attention is currently required from: dexter.
laforge has posted comments on this change by dexter. ( https://gerrit.osmocom.org/c/pysim/+/42736?usp=email )
Change subject: card_key_provider: add a static method to parse --column-keys args
......................................................................
Patch Set 1: Code-Review+1
--
To view, visit https://gerrit.osmocom.org/c/pysim/+/42736?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: comment
Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: Ic955f271b1de1b1b855b21c82ed10343044e45fa
Gerrit-Change-Number: 42736
Gerrit-PatchSet: 1
Gerrit-Owner: dexter <pmaier(a)sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
Gerrit-Attention: dexter <pmaier(a)sysmocom.de>
Gerrit-Comment-Date: Thu, 07 May 2026 19:14:20 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
Attention is currently required from: dexter.
laforge has posted comments on this change by dexter. ( https://gerrit.osmocom.org/c/pysim/+/42734?usp=email )
Change subject: card_key_provider: move boiler-plate code into helper functions
......................................................................
Patch Set 1:
(2 comments)
File pySim/card_key_provider.py:
https://gerrit.osmocom.org/c/pysim/+/42734/comment/a171cd51_581e4a6c?usp=em… :
PS1, Line 337: def argparse_add_card_key_provider_args(arg_parser: argparse.ArgumentParser):
to be consistent with other methods I would call it card_key_provider_argparse_add_args or something like that. Then all methods have the same prefix
https://gerrit.osmocom.org/c/pysim/+/42734/comment/e78c1b9e_8d4d5e12?usp=em… :
PS1, Line 344: init_card_key_provider
likewise here I'd call it card_key_provider_init similar to card_key_provider_{get,get_field} above
--
To view, visit https://gerrit.osmocom.org/c/pysim/+/42734?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: comment
Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: I6d095cbb644e608f4a751a1d0749b1484cdc781d
Gerrit-Change-Number: 42734
Gerrit-PatchSet: 1
Gerrit-Owner: dexter <pmaier(a)sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-CC: laforge <laforge(a)osmocom.org>
Gerrit-Attention: dexter <pmaier(a)sysmocom.de>
Gerrit-Comment-Date: Thu, 07 May 2026 19:13:45 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Attention is currently required from: dexter.
laforge has posted comments on this change by dexter. ( https://gerrit.osmocom.org/c/pysim/+/42733?usp=email )
Change subject: cosmetic: remove excess linebreaks
......................................................................
Patch Set 1: Code-Review+1
(2 comments)
File pySim-shell.py:
https://gerrit.osmocom.org/c/pysim/+/42733/comment/690729c8_33315b07?usp=em… :
PS1, Line 1131:
I think it's useful to sepaate the "main" block from class definitions with an extra line. Not sure why you think this needs our attention or "fixing".
File pySim/transport/__init__.py:
https://gerrit.osmocom.org/c/pysim/+/42733/comment/94822749_fa7eabef?usp=em… :
PS1, Line 28:
I'm not quite sure what you are trying to achieve here. I think it's not uncommon to have an empty line to separate imporst from foreign modules to imports from within a project (pysim here).
--
To view, visit https://gerrit.osmocom.org/c/pysim/+/42733?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: comment
Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: I2272abcdbba0e57c5118b69bc9398cd909a469b5
Gerrit-Change-Number: 42733
Gerrit-PatchSet: 1
Gerrit-Owner: dexter <pmaier(a)sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
Gerrit-Attention: dexter <pmaier(a)sysmocom.de>
Gerrit-Comment-Date: Thu, 07 May 2026 19:11:16 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
dexter has uploaded this change for review. ( https://gerrit.osmocom.org/c/pysim/+/42736?usp=email )
Change subject: card_key_provider: add a static method to parse --column-keys args
......................................................................
card_key_provider: add a static method to parse --column-keys args
The contents of the --column-keys arguments are currently parsed
in init_card_key_provider. Let's add a static method in
CardKeyFieldCryptor to simplify re-usage of the CardKeyFieldCryptor
Related: SYS#6959
Change-Id: Ic955f271b1de1b1b855b21c82ed10343044e45fa
---
M pySim/card_key_provider.py
1 file changed, 18 insertions(+), 4 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/36/42736/1
diff --git a/pySim/card_key_provider.py b/pySim/card_key_provider.py
index ecf8c40..7c89b6b 100644
--- a/pySim/card_key_provider.py
+++ b/pySim/card_key_provider.py
@@ -140,6 +140,23 @@
arg_parser.add_argument('--csv-column-key', metavar='FIELD:AES_KEY_HEX', default=[], action='append',
help=argparse.SUPPRESS, dest='column_key')
+ @staticmethod
+ def transport_keys_from_opts(opts: argparse.Namespace) -> dict:
+ """
+ Transport keys are passed via the commandline using the '--column-key' option. Each column requires a
+ dedicated transport key. This method can be used to extract the column keys parameters from the commandline
+ options into a dict that can be directly passed to the construtor with the transport_keys argument.
+
+ Args:
+ opts: parsed commandline options (Namespace)
+ """
+
+ transport_keys = {}
+ for par in opts.column_key:
+ name, key = par.split(':')
+ transport_keys[name] = key
+ return transport_keys
+
class CardKeyProvider(abc.ABC):
"""Base class, not containing any concrete implementation."""
@@ -343,10 +360,7 @@
def init_card_key_provider(opts: argparse.Namespace):
"""Initialize card key provider depending on the user provided commandline options"""
- column_keys = {}
- for par in opts.column_key:
- name, key = par.split(':')
- column_keys[name] = key
+ transport_keys = CardKeyFieldCryptor.transport_keys_from_opts(opts)
card_key_field_cryptor = CardKeyFieldCryptor(transport_keys)
if os.path.isfile(os.path.expanduser(opts.csv)):
card_key_provider_register(CardKeyProviderCsv(os.path.expanduser(opts.csv), card_key_field_cryptor))
--
To view, visit https://gerrit.osmocom.org/c/pysim/+/42736?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: newchange
Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: Ic955f271b1de1b1b855b21c82ed10343044e45fa
Gerrit-Change-Number: 42736
Gerrit-PatchSet: 1
Gerrit-Owner: dexter <pmaier(a)sysmocom.de>
dexter has uploaded this change for review. ( https://gerrit.osmocom.org/c/pysim/+/42737?usp=email )
Change subject: pySimLogger: fix default log format string
......................................................................
pySimLogger: fix default log format string
In format string we prepend when we log in verbose mode. We use %(module)s
as format string quaifier. This qualifier is replaced with the name of the
module from where the logger was called. This is mostly equal to the logger
name (__name__) we pass when we create the logger.
However, this is not the behavior we actually want. We want to log the
logger name that we passed when the logger was created. For this, we must
use %(name)s as qualifier.
Related: SYS#6959
Change-Id: I3951a70ad6ce864a7158b093cba46ae9fc1cb5bd
---
M pySim/log.py
1 file changed, 1 insertion(+), 1 deletion(-)
git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/37/42737/1
diff --git a/pySim/log.py b/pySim/log.py
index 801ad69..345cf78 100644
--- a/pySim/log.py
+++ b/pySim/log.py
@@ -44,7 +44,7 @@
"""
LOG_FMTSTR = "%(levelname)s: %(message)s"
- LOG_FMTSTR_VERBOSE = "%(module)s.%(lineno)d -- " + LOG_FMTSTR
+ LOG_FMTSTR_VERBOSE = "%(name)s.%(lineno)d -- " + LOG_FMTSTR
__formatter = logging.Formatter(LOG_FMTSTR)
__formatter_verbose = logging.Formatter(LOG_FMTSTR_VERBOSE)
--
To view, visit https://gerrit.osmocom.org/c/pysim/+/42737?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: newchange
Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: I3951a70ad6ce864a7158b093cba46ae9fc1cb5bd
Gerrit-Change-Number: 42737
Gerrit-PatchSet: 1
Gerrit-Owner: dexter <pmaier(a)sysmocom.de>
dexter has uploaded this change for review. ( https://gerrit.osmocom.org/c/pysim/+/42738?usp=email )
Change subject: pySim/app: use pySimLogger instead of print
......................................................................
pySim/app: use pySimLogger instead of print
let's replace the stray print statements with proper logger calls.
Related: SYS#6959
Change-Id: I95b4536cc8853e7ba6a5dd573b903dfb85e56b9a
---
M pySim/app.py
1 file changed, 7 insertions(+), 4 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/38/42738/1
diff --git a/pySim/app.py b/pySim/app.py
index 23a4c3c..4e88788 100644
--- a/pySim/app.py
+++ b/pySim/app.py
@@ -26,6 +26,9 @@
from pySim.ts_102_221 import CardProfileUICC
from pySim.utils import all_subclasses
from pySim.exceptions import SwMatchError
+from pySim.log import PySimLogger
+
+log = PySimLogger.get(__name__)
# we need to import this module so that the SysmocomSJA2 sub-class of
# CardModel is created, which will add the ATR-based matching and
@@ -54,7 +57,7 @@
# Wait up to three seconds for a card in reader and try to detect
# the card type.
- print("Waiting for card...")
+ log.info("Waiting for card...")
sl.wait_for_card(3)
# The user may opt to skip all card initialization. In this case only the
@@ -66,7 +69,7 @@
generic_card = False
card = card_detect(scc)
if card is None:
- print("Warning: Could not detect card type - assuming a generic card type...")
+ log.warning("Could not detect card type - assuming a generic card type...")
card = SimCardBase(scc)
generic_card = True
@@ -76,7 +79,7 @@
# just means that pySim was unable to recognize the card profile. This
# may happen in particular with unprovisioned cards that do not have
# any files on them yet.
- print("Unsupported card type!")
+ log.warning("Unsupported card type!")
return None, card
# ETSI TS 102 221, Table 9.3 specifies a default for the PIN key
@@ -87,7 +90,7 @@
if generic_card and isinstance(profile, CardProfileUICC):
card._adm_chv_num = 0x0A
- print("Info: Card is of type: %s" % str(profile))
+ log.info("Card is of type: %s", str(profile))
# FIXME: this shouldn't really be here but somewhere else/more generic.
# We cannot do it within pySim/profile.py as that would create circular
--
To view, visit https://gerrit.osmocom.org/c/pysim/+/42738?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: newchange
Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: I95b4536cc8853e7ba6a5dd573b903dfb85e56b9a
Gerrit-Change-Number: 42738
Gerrit-PatchSet: 1
Gerrit-Owner: dexter <pmaier(a)sysmocom.de>
dexter has uploaded this change for review. ( https://gerrit.osmocom.org/c/pysim/+/42739?usp=email )
Change subject: pySim/filesystem: use pySimLogger instead of print
......................................................................
pySim/filesystem: use pySimLogger instead of print
let's replace the stray print statements with proper logger calls.
Related: SYS#6959
Change-Id: I3a7188ad33706df66b2113e15cc7d06004c9bc39
---
M pySim/filesystem.py
1 file changed, 5 insertions(+), 2 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/39/42739/1
diff --git a/pySim/filesystem.py b/pySim/filesystem.py
index 95fae36..04806cb 100644
--- a/pySim/filesystem.py
+++ b/pySim/filesystem.py
@@ -44,6 +44,7 @@
from pySim.jsonpath import js_path_modify
from pySim.commands import SimCardCommands
from pySim.exceptions import SwMatchError
+from pySim.log import PySimLogger
# int: a single service is associated with this file
# list: any of the listed services requires this file
@@ -52,6 +53,8 @@
Size = Tuple[int, Optional[int]]
+log = PySimLogger.get(__name__)
+
class CardFile:
"""Base class for all objects in the smart card filesystem.
Serve as a common ancestor to all other file types; rarely used directly.
@@ -1609,14 +1612,14 @@
card_atr = scc.get_atr()
for atr in cls._atrs:
if atr == card_atr:
- print("Detected CardModel:", cls.__name__)
+ log.info("Detected CardModel: %s", cls.__name__)
return True
# if nothing found try to just compare the Historical Bytes of the ATR
card_atr_hb = decomposeATR(card_atr)['hb']
for atr in cls._atrs:
atr_hb = decomposeATR(atr)['hb']
if atr_hb == card_atr_hb:
- print("Detected CardModel:", cls.__name__)
+ log.info("Detected CardModel: %s", cls.__name__)
return True
return False
--
To view, visit https://gerrit.osmocom.org/c/pysim/+/42739?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: newchange
Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: I3a7188ad33706df66b2113e15cc7d06004c9bc39
Gerrit-Change-Number: 42739
Gerrit-PatchSet: 1
Gerrit-Owner: dexter <pmaier(a)sysmocom.de>
dexter has uploaded this change for review. ( https://gerrit.osmocom.org/c/pysim/+/42733?usp=email )
Change subject: cosmetic: remove excess linebreaks
......................................................................
cosmetic: remove excess linebreaks
We should not use double-line breaks to separate things as it is very
difficult to maintain consistence with that scheme.
Change-Id: I2272abcdbba0e57c5118b69bc9398cd909a469b5
---
M pySim-shell.py
M pySim/card_key_provider.py
M pySim/global_platform/__init__.py
M pySim/transport/__init__.py
4 files changed, 0 insertions(+), 11 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/33/42733/1
diff --git a/pySim-shell.py b/pySim-shell.py
index 29ed3a5..bd7d0c0 100755
--- a/pySim-shell.py
+++ b/pySim-shell.py
@@ -1121,15 +1121,12 @@
fcp_dec = self._cmd.lchan.status()
self._cmd.poutput_json(fcp_dec)
-
class Proact(ProactiveHandler):
def receive_fetch(self, pcmd: ProactiveCommand):
# print its parsed representation
print(pcmd.decoded)
# TODO: implement the basics, such as SMS Sending, ...
-
-
option_parser = argparse.ArgumentParser(description='interactive SIM card shell',
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
argparse_add_reader_args(option_parser)
diff --git a/pySim/card_key_provider.py b/pySim/card_key_provider.py
index 06a6b2b..2403694 100644
--- a/pySim/card_key_provider.py
+++ b/pySim/card_key_provider.py
@@ -264,7 +264,6 @@
raise ValueError("provider is not a card data provider")
provider_list.append(provider)
-
def card_key_provider_get(fields: list[str], key: str, value: str, provider_list=card_key_providers) -> Dict[str, str]:
"""Query all registered card data providers for card-individual [key] data.
@@ -289,7 +288,6 @@
raise ValueError("Unable to find card key data (key=%s, value=%s, fields=%s)" % (key, value, str(fields)))
-
def card_key_provider_get_field(field: str, key: str, value: str, provider_list=card_key_providers) -> str:
"""Query all registered card data providers for a single field.
diff --git a/pySim/global_platform/__init__.py b/pySim/global_platform/__init__.py
index 6ff4b28..306746f 100644
--- a/pySim/global_platform/__init__.py
+++ b/pySim/global_platform/__init__.py
@@ -460,7 +460,6 @@
# 11.4.2.1
StatusSubset = Enum(Byte, isd=0x80, applications=0x40, files=0x20, files_and_modules=0x10)
-
# Section 11.4.3.1 Table 11-36
class LifeCycleState(BER_TLV_IE, tag=0x9f70):
_construct = CLifeCycleState
@@ -1010,7 +1009,6 @@
self._cmd.lchan.scc.scp = None
self._cmd.update_prompt()
-
# Card Application of a Security Domain
class CardApplicationSD(CardApplication):
__intermediate = True
@@ -1048,7 +1046,6 @@
return "%s(KVN=%u, ENC=%s, MAC=%s, DEK=%s)" % (self.__class__.__name__,
self.kvn, b2h(self.enc), b2h(self.mac), b2h(self.dek))
-
def compute_kcv_des(key:bytes) -> bytes:
# GP Card Spec B.6: For a DES key, the key check value is computed by encrypting 8 bytes, each with
# value '00', with the key to be checked and retaining the 3 highest-order bytes of the encrypted
diff --git a/pySim/transport/__init__.py b/pySim/transport/__init__.py
index d689a0a..d3cf8d0 100644
--- a/pySim/transport/__init__.py
+++ b/pySim/transport/__init__.py
@@ -25,7 +25,6 @@
from typing import Optional, Tuple
from construct import Construct
from osmocom.utils import b2h, h2b, i2h, Hexstr
-
from pySim.exceptions import *
from pySim.utils import SwHexstr, SwMatchstr, ResTuple, sw_match, parse_command_apdu
from pySim.cat import ProactiveCommand, CommandDetails, DeviceIdentities, Result
@@ -244,7 +243,6 @@
raise SwMatchError(rv[1], sw.lower(), self.sw_interpreter)
return rv
-
class LinkBaseTpdu(LinkBase):
# Use the T=0 TPDU format by default as this is the most commonly used transport protocol.
@@ -373,7 +371,6 @@
return arg_parser
-
def init_reader(opts, **kwargs) -> LinkBase:
"""
Init card reader driver
--
To view, visit https://gerrit.osmocom.org/c/pysim/+/42733?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: newchange
Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: I2272abcdbba0e57c5118b69bc9398cd909a469b5
Gerrit-Change-Number: 42733
Gerrit-PatchSet: 1
Gerrit-Owner: dexter <pmaier(a)sysmocom.de>