Jenkins Builder has posted comments on this change by dexter. ( https://gerrit.osmocom.org/c/pysim/+/38603?usp=email )
Change subject: pySim-shell_test/utils: print logfile on all types of errors
......................................................................
Patch Set 1:
(1 comment)
File tests/pySim-shell_test/utils.py:
Robot Comment from checkpatch (run ID jenkins-gerrit-lint-19566):
https://gerrit.osmocom.org/c/pysim/+/38603/comment/9cca1a85_d8bf001e?usp=em… :
PS1, Line 295:
trailing whitespace
--
To view, visit https://gerrit.osmocom.org/c/pysim/+/38603?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: Ic0f34eda32a7c557810abcb05a84e343741fdb8a
Gerrit-Change-Number: 38603
Gerrit-PatchSet: 1
Gerrit-Owner: dexter <pmaier(a)sysmocom.de>
Gerrit-CC: Jenkins Builder
Gerrit-Comment-Date: Fri, 01 Nov 2024 18:20:42 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
dexter has uploaded this change for review. ( https://gerrit.osmocom.org/c/pysim/+/38601?usp=email )
Change subject: commands: fix double space character in apidoc
......................................................................
commands: fix double space character in apidoc
Change-Id: Id0dbe4578fd212bc240aac80e1e416cb57e92cc7
---
M pySim/commands.py
1 file changed, 1 insertion(+), 1 deletion(-)
git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/01/38601/1
diff --git a/pySim/commands.py b/pySim/commands.py
index 61e2554..03f0935 100644
--- a/pySim/commands.py
+++ b/pySim/commands.py
@@ -136,7 +136,7 @@
p2 : string (in hex) ISO 7116 Parameter 2 byte
cmd_cosntr : defining how to generate binary APDU command data
cmd_data : command data passed to cmd_constr
- resp_cosntr : defining how to decode binary APDU response data
+ resp_cosntr : defining how to decode binary APDU response data
apply_lchan : apply the currently selected lchan to the CLA byte before sending
Returns:
Tuple of (decoded_data, sw)
--
To view, visit https://gerrit.osmocom.org/c/pysim/+/38601?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: Id0dbe4578fd212bc240aac80e1e416cb57e92cc7
Gerrit-Change-Number: 38601
Gerrit-PatchSet: 1
Gerrit-Owner: dexter <pmaier(a)sysmocom.de>
dexter has uploaded this change for review. ( https://gerrit.osmocom.org/c/pysim/+/38603?usp=email )
Change subject: pySim-shell_test/utils: print logfile on all types of errors
......................................................................
pySim-shell_test/utils: print logfile on all types of errors
When pySim-shell has problems starting up, it exits with an error
code. This is detected by the testsuite, but it also causes an
early exit, so that the log file content are not printed.
Change-Id: Ic0f34eda32a7c557810abcb05a84e343741fdb8a
---
M tests/pySim-shell_test/utils.py
1 file changed, 9 insertions(+), 5 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/03/38603/1
diff --git a/tests/pySim-shell_test/utils.py b/tests/pySim-shell_test/utils.py
index 348c9b1..b93424e 100644
--- a/tests/pySim-shell_test/utils.py
+++ b/tests/pySim-shell_test/utils.py
@@ -265,11 +265,9 @@
# Execute commandline
cmdline += " > " + logfile_name + " 2>&1"
print("Executing: " + cmdline)
- rc = os.system(cmdline)
- if rc:
- raise RuntimeError("pySim-shell exits with error code %u" % rc)
+ py_sim_shell_rc = os.system(cmdline)
- # Check for exceptions
+ # Read logfile
logfile = open(logfile_name)
logfile_content = logfile.read()
if self.print_content:
@@ -278,6 +276,12 @@
print(logfile_content)
print("-----------------------8<-----------------------")
logfile.close()
+
+ # Exit early in case pySim-shell ran into a fundamental error
+ if py_sim_shell_rc:
+ raise RuntimeError("pySim-shell exits with error code %u" % rc)
+
+ # Check log for exceptions
exception_regex_compiled = re.compile('.*EXCEPTION.*')
exceptions_strings = re.findall(exception_regex_compiled, logfile_content)
if exceptions_strings != []:
@@ -288,7 +292,7 @@
self.assertTrue(False, "Unexpected exceptions occurred!")
else:
print("Note: the occurrence of exceptions may be expected, the sheer presence of exceptions is not necessarly an error.")
-
+
def __filter_lines(self, text:str, ignore_regex_list:list[str],
mask_regex_list:list[str], interesting_regex_list:list[str]):
""" Filter data from text lines using regex_lists """
--
To view, visit https://gerrit.osmocom.org/c/pysim/+/38603?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: Ic0f34eda32a7c557810abcb05a84e343741fdb8a
Gerrit-Change-Number: 38603
Gerrit-PatchSet: 1
Gerrit-Owner: dexter <pmaier(a)sysmocom.de>
dexter has uploaded this change for review. ( https://gerrit.osmocom.org/c/pysim/+/38602?usp=email )
Change subject: commands: fix apidoc (wrong order of parameters)
......................................................................
commands: fix apidoc (wrong order of parameters)
Change-Id: I4d17c71c7f992ecd795dd214d34f2e094c0a5b53
---
M pySim/commands.py
1 file changed, 2 insertions(+), 2 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/02/38602/1
diff --git a/pySim/commands.py b/pySim/commands.py
index 03f0935..0173f70 100644
--- a/pySim/commands.py
+++ b/pySim/commands.py
@@ -110,9 +110,9 @@
Args:
pdu : string of hexadecimal characters (ex. "A0A40000023F00")
- apply_lchan : apply the currently selected lchan to the CLA byte before sending
sw : string of 4 hexadecimal characters (ex. "9000"). The user may mask out certain
- digits using a '?' to add some ambiguity if needed.
+ digits using a '?' to add some ambiguity if needed.
+ apply_lchan : apply the currently selected lchan to the CLA byte before sending
Returns:
tuple(data, sw), where
data : string (in hex) of returned data (ex. "074F4EFFFF")
--
To view, visit https://gerrit.osmocom.org/c/pysim/+/38602?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: I4d17c71c7f992ecd795dd214d34f2e094c0a5b53
Gerrit-Change-Number: 38602
Gerrit-PatchSet: 1
Gerrit-Owner: dexter <pmaier(a)sysmocom.de>
dexter has uploaded this change for review. ( https://gerrit.osmocom.org/c/pysim/+/38605?usp=email )
Change subject: global_platform/scp: mapdu may be undeclared
......................................................................
global_platform/scp: mapdu may be undeclared
when we sign and encrypt the APDU in _wrap_cmd_apdu (SCP03) we return an "mapdu"
at the end. However, in the (unlikely?) case where self.do_cencand
self.do_cmac are false, mapdu will be undeclared. In _wrap_cmd_apdu for SCP02
we just re-use the apdu variable and return it at the end, so when no
encryption and no signing is applied, the APDU falls just through without any
modifications. We should have the same mechanism for the SCP03 wrapping as
well.
Related: OS#6367
Change-Id: Ic7089a69dffd7313572c5b3e5953200be5925766
---
M pySim/global_platform/scp.py
1 file changed, 4 insertions(+), 4 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/05/38605/1
diff --git a/pySim/global_platform/scp.py b/pySim/global_platform/scp.py
index 2cf8b63..0b1f6a9 100644
--- a/pySim/global_platform/scp.py
+++ b/pySim/global_platform/scp.py
@@ -508,11 +508,11 @@
# channel number shall be set to zero, bit 4 shall be set to 0 and bit 3 shall be set to 1 to indicate
# GlobalPlatform proprietary secure messaging.
mcla = (cla & 0xF0) | CLA_SM
- mapdu = bytes([mcla, ins, p1, p2, mlc]) + cmd_data
- cmac = self.sk.calc_cmac(mapdu)
- mapdu += cmac[:self.s_mode]
+ apdu = bytes([mcla, ins, p1, p2, mlc]) + cmd_data
+ cmac = self.sk.calc_cmac(apdu)
+ apdu += cmac[:self.s_mode]
- return mapdu
+ return apdu
def unwrap_rsp_apdu(self, sw: bytes, rsp_apdu: bytes) -> bytes:
# No R-MAC shall be generated and no protection shall be applied to a response that includes an error
--
To view, visit https://gerrit.osmocom.org/c/pysim/+/38605?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: Ic7089a69dffd7313572c5b3e5953200be5925766
Gerrit-Change-Number: 38605
Gerrit-PatchSet: 1
Gerrit-Owner: dexter <pmaier(a)sysmocom.de>
dexter has uploaded this change for review. ( https://gerrit.osmocom.org/c/pysim/+/38606?usp=email )
Change subject: pySim-shell: allow checking of APDU responses
......................................................................
pySim-shell: allow checking of APDU responses
The "apdu" command allows us to send custom APDUs to a card. This command is
often used in low level initialization scripts or tests. To stop the script
execution in case of an error, the command allows us to specify a status word
that must match the status word of the response. But we have no such mechanism
for the response itsself. Let's add another parameter where we can pass a regex
that the response must match.
Related: OS#6367
Change-Id: I97bbcdf37bdcf00ad50a875b96940c211de7073d
---
M pySim-shell.py
1 file changed, 6 insertions(+), 0 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/06/38606/1
diff --git a/pySim-shell.py b/pySim-shell.py
index 37d58ae..f53efd3 100755
--- a/pySim-shell.py
+++ b/pySim-shell.py
@@ -21,6 +21,7 @@
import json
import traceback
+import re
import cmd2
from packaging import version
@@ -239,6 +240,7 @@
apdu_cmd_parser = argparse.ArgumentParser()
apdu_cmd_parser.add_argument('--expect-sw', help='expect a specified status word', type=str, default=None)
+ apdu_cmd_parser.add_argument('--expect-response-regex', help='match response against regex', type=str, default=None)
apdu_cmd_parser.add_argument('--raw', help='Bypass the logical channel (and secure channel)', action='store_true')
apdu_cmd_parser.add_argument('APDU', type=is_hexstr, help='APDU as hex string')
@@ -264,6 +266,10 @@
if opts.expect_sw:
if not sw_match(sw, opts.expect_sw):
raise SwMatchError(sw, opts.expect_sw)
+ if opts.expect_response_regex:
+ response_regex_compiled = re.compile(opts.expect_response_regex)
+ if re.match(response_regex_compiled, data) is None:
+ raise ValueError("RESP does not match regex \'%s\'" % opts.expect_response_regex)
@cmd2.with_category(CUSTOM_CATEGORY)
def do_reset(self, opts):
--
To view, visit https://gerrit.osmocom.org/c/pysim/+/38606?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: I97bbcdf37bdcf00ad50a875b96940c211de7073d
Gerrit-Change-Number: 38606
Gerrit-PatchSet: 1
Gerrit-Owner: dexter <pmaier(a)sysmocom.de>
dexter has uploaded this change for review. ( https://gerrit.osmocom.org/c/pysim/+/38607?usp=email )
Change subject: pySim-shell: fix reset command for no-profile mode
......................................................................
pySim-shell: fix reset command for no-profile mode
There are situations where no card profile can be determined. In this case no
RuntimeState will be present. This is in particular the case when pySim-shell
is used on a card that is not provisioned/initialized yet. In those cases we
have to go the direct route and reset the card directly.
Related: OS#6367
Change-Id: I27bf9fdb131d8bdeba07f4dfd2b76b38f9bfdd17
---
M pySim-shell.py
1 file changed, 6 insertions(+), 1 deletion(-)
git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/07/38607/1
diff --git a/pySim-shell.py b/pySim-shell.py
index f53efd3..413d3f7 100755
--- a/pySim-shell.py
+++ b/pySim-shell.py
@@ -274,7 +274,12 @@
@cmd2.with_category(CUSTOM_CATEGORY)
def do_reset(self, opts):
"""Reset the Card."""
- atr = self.rs.reset(self)
+ if self.rs is None:
+ # In case no runtime state is available we go the direct route
+ self.card._scc.reset_card()
+ atr = b2h(self.card._scc.get_atr())
+ else:
+ atr = self.rs.reset(self)
self.poutput('Card ATR: %s' % atr)
self.update_prompt()
--
To view, visit https://gerrit.osmocom.org/c/pysim/+/38607?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: I27bf9fdb131d8bdeba07f4dfd2b76b38f9bfdd17
Gerrit-Change-Number: 38607
Gerrit-PatchSet: 1
Gerrit-Owner: dexter <pmaier(a)sysmocom.de>