Attention is currently required from: laforge.
pespin has posted comments on this change. ( https://gerrit.osmocom.org/c/pysim/+/34936?usp=email )
Change subject: docs: shell: By now we have encoders/decoders for most files
......................................................................
Patch Set 1: Code-Review+1
--
To view, visit https://gerrit.osmocom.org/c/pysim/+/34936?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: Ia771f9969ae7eb0094d1768af3f7f54cc9d0d581
Gerrit-Change-Number: 34936
Gerrit-PatchSet: 1
Gerrit-Owner: laforge <laforge(a)osmocom.org>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: pespin <pespin(a)sysmocom.de>
Gerrit-Attention: laforge <laforge(a)osmocom.org>
Gerrit-Comment-Date: Thu, 02 Nov 2023 09:11:09 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment
laforge has uploaded this change for review. ( https://gerrit.osmocom.org/c/pysim/+/34947?usp=email )
Change subject: pySim-shell: permit string with spaces for 'echo' command
......................................................................
pySim-shell: permit string with spaces for 'echo' command
before this patch:
pySIM-shell (00:MF)> echo foo bar baz
usage: echo [-h] string
echo: error: unrecognized arguments: bar baz
after this patch:
pySIM-shell (00:MF)> echo foo bar baz
foo bar baz
Change-Id: I1369bc3aa975865e3a8a574c132e469813a9f6b9
---
M pySim-shell.py
1 file changed, 22 insertions(+), 2 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/47/34947/1
diff --git a/pySim-shell.py b/pySim-shell.py
index d9c9f8c..306dd40 100755
--- a/pySim-shell.py
+++ b/pySim-shell.py
@@ -510,13 +510,13 @@
first = False
echo_parser = argparse.ArgumentParser()
- echo_parser.add_argument('string', help="string to echo on the shell")
+ echo_parser.add_argument('string', help="string to echo on the shell", nargs='+')
@cmd2.with_argparser(echo_parser)
@cmd2.with_category(CUSTOM_CATEGORY)
def do_echo(self, opts):
"""Echo (print) a string on the console"""
- self.poutput(opts.string)
+ self.poutput(' '.join(opts.string))
@cmd2.with_category(CUSTOM_CATEGORY)
def do_version(self, opts):
--
To view, visit https://gerrit.osmocom.org/c/pysim/+/34947?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: I1369bc3aa975865e3a8a574c132e469813a9f6b9
Gerrit-Change-Number: 34947
Gerrit-PatchSet: 1
Gerrit-Owner: laforge <laforge(a)osmocom.org>
Gerrit-MessageType: newchange
laforge has uploaded this change for review. ( https://gerrit.osmocom.org/c/pysim/+/34946?usp=email )
Change subject: pySim-shell: Validate that argument to 'apdu' command is proper hexstr
......................................................................
pySim-shell: Validate that argument to 'apdu' command is proper hexstr
Let's not even send anything to the card if it's not an even number
of hexadecimal digits
Change-Id: I58465244101cc1a976e5a17af2aceea1cf9f9b54
---
M pySim-shell.py
M pySim/utils.py
2 files changed, 23 insertions(+), 2 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/46/34946/1
diff --git a/pySim-shell.py b/pySim-shell.py
index c2bb15c..d9c9f8c 100755
--- a/pySim-shell.py
+++ b/pySim-shell.py
@@ -53,7 +53,7 @@
from pySim.cards import card_detect, SimCardBase, UiccCardBase
from pySim.utils import h2b, b2h, i2h, swap_nibbles, rpad, JsonEncoder, bertlv_parse_one, sw_match
from pySim.utils import sanitize_pin_adm, tabulate_str_list, boxed_heading_str, Hexstr, dec_iccid
-from pySim.utils import is_hexstr_or_decimal
+from pySim.utils import is_hexstr_or_decimal, is_hexstr
from pySim.card_handler import CardHandler, CardHandlerAuto
from pySim.filesystem import CardDF, CardADF, CardModel, CardApplication
@@ -322,7 +322,7 @@
self.equip(card, rs)
apdu_cmd_parser = argparse.ArgumentParser()
- apdu_cmd_parser.add_argument('APDU', type=str, help='APDU as hex string')
+ apdu_cmd_parser.add_argument('APDU', type=is_hexstr, help='APDU as hex string')
apdu_cmd_parser.add_argument('--expect-sw', help='expect a specified status word', type=str, default=None)
@cmd2.with_argparser(apdu_cmd_parser)
diff --git a/pySim/utils.py b/pySim/utils.py
index 92bf70f..ea1c9e6 100644
--- a/pySim/utils.py
+++ b/pySim/utils.py
@@ -1478,3 +1478,12 @@
if len(instr) & 1:
raise ValueError('Input has un-even number of hex digits')
return instr
+
+def is_hexstr(instr: str) -> str:
+ """Method that can be used as 'type' in argparse.add_argument() to validate the value consists of
+ an even sequence of hexadecimal digits only."""
+ if not all(c in string.hexdigits for c in instr):
+ raise ValueError('Input must be hexadecimal')
+ if len(instr) & 1:
+ raise ValueError('Input has un-even number of hex digits')
+ return instr
--
To view, visit https://gerrit.osmocom.org/c/pysim/+/34946?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: I58465244101cc1a976e5a17af2aceea1cf9f9b54
Gerrit-Change-Number: 34946
Gerrit-PatchSet: 1
Gerrit-Owner: laforge <laforge(a)osmocom.org>
Gerrit-MessageType: newchange
Hello Jenkins Builder,
I'd like you to reexamine a change. Please visit
https://gerrit.osmocom.org/c/pysim/+/34945?usp=email
to look at the new patch set (#2).
The following approvals got outdated and were removed:
Verified+1 by Jenkins Builder
Change subject: pySim-shell: Improved argument validation for verify_adm argument
......................................................................
pySim-shell: Improved argument validation for verify_adm argument
Let's make sure we don't even bother to ask the card to verify
anything as ADM1 pin which is not either a sequence of decimal digits
or an even number of hex digits (even number of bytes).
Change-Id: I4a193a3cf63462fad73d145ab1481070ddf767ca
---
M pySim-shell.py
M pySim/utils.py
2 files changed, 26 insertions(+), 1 deletion(-)
git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/45/34945/2
--
To view, visit https://gerrit.osmocom.org/c/pysim/+/34945?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: I4a193a3cf63462fad73d145ab1481070ddf767ca
Gerrit-Change-Number: 34945
Gerrit-PatchSet: 2
Gerrit-Owner: laforge <laforge(a)osmocom.org>
Gerrit-Reviewer: Jenkins Builder
Gerrit-MessageType: newpatchset
laforge has uploaded this change for review. ( https://gerrit.osmocom.org/c/pysim/+/34948?usp=email )
Change subject: pySim-shell: Reject any non-decimal PIN values
......................................................................
pySim-shell: Reject any non-decimal PIN values
Don't even send any non-decimal PIN values to the card, but reject
them when parsing the command arguments.
Change-Id: Icec1698851471af7f76f20201dcdcfcd48ddf365
---
M pySim-shell.py
M pySim/utils.py
2 files changed, 27 insertions(+), 8 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/48/34948/1
diff --git a/pySim-shell.py b/pySim-shell.py
index 306dd40..0c559f9 100755
--- a/pySim-shell.py
+++ b/pySim-shell.py
@@ -53,7 +53,7 @@
from pySim.cards import card_detect, SimCardBase, UiccCardBase
from pySim.utils import h2b, b2h, i2h, swap_nibbles, rpad, JsonEncoder, bertlv_parse_one, sw_match
from pySim.utils import sanitize_pin_adm, tabulate_str_list, boxed_heading_str, Hexstr, dec_iccid
-from pySim.utils import is_hexstr_or_decimal, is_hexstr
+from pySim.utils import is_hexstr_or_decimal, is_hexstr, is_decimal
from pySim.card_handler import CardHandler, CardHandlerAuto
from pySim.filesystem import CardDF, CardADF, CardModel, CardApplication
@@ -864,7 +864,7 @@
verify_chv_parser.add_argument(
'--pin-nr', type=int, default=1, help='PIN Number, 1=PIN1, 2=PIN2 or custom value (decimal)')
verify_chv_parser.add_argument(
- 'pin_code', type=str, help='PIN code digits, \"PIN1\" or \"PIN2\" to get PIN code from external data source')
+ 'pin_code', type=is_decimal, help='PIN code digits, \"PIN1\" or \"PIN2\" to get PIN code from external data source')
@cmd2.with_argparser(verify_chv_parser)
def do_verify_chv(self, opts):
@@ -879,9 +879,9 @@
unblock_chv_parser.add_argument(
'--pin-nr', type=int, default=1, help='PUK Number, 1=PIN1, 2=PIN2 or custom value (decimal)')
unblock_chv_parser.add_argument(
- 'puk_code', type=str, help='PUK code digits \"PUK1\" or \"PUK2\" to get PUK code from external data source')
+ 'puk_code', type=is_decimal, help='PUK code digits \"PUK1\" or \"PUK2\" to get PUK code from external data source')
unblock_chv_parser.add_argument(
- 'new_pin_code', type=str, help='PIN code digits \"PIN1\" or \"PIN2\" to get PIN code from external data source')
+ 'new_pin_code', type=is_decimal, help='PIN code digits \"PIN1\" or \"PIN2\" to get PIN code from external data source')
@cmd2.with_argparser(unblock_chv_parser)
def do_unblock_chv(self, opts):
@@ -896,9 +896,9 @@
change_chv_parser.add_argument(
'--pin-nr', type=int, default=1, help='PUK Number, 1=PIN1, 2=PIN2 or custom value (decimal)')
change_chv_parser.add_argument(
- 'pin_code', type=str, help='PIN code digits \"PIN1\" or \"PIN2\" to get PIN code from external data source')
+ 'pin_code', type=is_decimal, help='PIN code digits \"PIN1\" or \"PIN2\" to get PIN code from external data source')
change_chv_parser.add_argument(
- 'new_pin_code', type=str, help='PIN code digits \"PIN1\" or \"PIN2\" to get PIN code from external data source')
+ 'new_pin_code', type=is_decimal, help='PIN code digits \"PIN1\" or \"PIN2\" to get PIN code from external data source')
@cmd2.with_argparser(change_chv_parser)
def do_change_chv(self, opts):
@@ -913,7 +913,7 @@
disable_chv_parser.add_argument(
'--pin-nr', type=int, default=1, help='PIN Number, 1=PIN1, 2=PIN2 or custom value (decimal)')
disable_chv_parser.add_argument(
- 'pin_code', type=str, help='PIN code digits, \"PIN1\" or \"PIN2\" to get PIN code from external data source')
+ 'pin_code', type=is_decimal, help='PIN code digits, \"PIN1\" or \"PIN2\" to get PIN code from external data source')
@cmd2.with_argparser(disable_chv_parser)
def do_disable_chv(self, opts):
@@ -926,7 +926,7 @@
enable_chv_parser.add_argument(
'--pin-nr', type=int, default=1, help='PIN Number, 1=PIN1, 2=PIN2 or custom value (decimal)')
enable_chv_parser.add_argument(
- 'pin_code', type=str, help='PIN code digits, \"PIN1\" or \"PIN2\" to get PIN code from external data source')
+ 'pin_code', type=is_decimal, help='PIN code digits, \"PIN1\" or \"PIN2\" to get PIN code from external data source')
@cmd2.with_argparser(enable_chv_parser)
def do_enable_chv(self, opts):
diff --git a/pySim/utils.py b/pySim/utils.py
index ea1c9e6..44800fb 100644
--- a/pySim/utils.py
+++ b/pySim/utils.py
@@ -1487,3 +1487,10 @@
if len(instr) & 1:
raise ValueError('Input has un-even number of hex digits')
return instr
+
+def is_decimal(instr: str) -> str:
+ """Method that can be used as 'type' in argparse.add_argument() to validate the value consists of
+ an even sequence of decimal digits only."""
+ if not instr.isdecimal():
+ raise ValueError('Input must decimal')
+ return instr
--
To view, visit https://gerrit.osmocom.org/c/pysim/+/34948?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: Icec1698851471af7f76f20201dcdcfcd48ddf365
Gerrit-Change-Number: 34948
Gerrit-PatchSet: 1
Gerrit-Owner: laforge <laforge(a)osmocom.org>
Gerrit-MessageType: newchange
laforge has uploaded this change for review. ( https://gerrit.osmocom.org/c/pysim/+/34945?usp=email )
Change subject: pySim-shell: Improved argument validation for verify_adm argument
......................................................................
pySim-shell: Improved argument validation for verify_adm argument
Let's make sure we don't even bother to ask the card to verify
anything as ADM1 pin which is not either a sequence of decimal digits
or an even number of hex digits (even number of bytes).
Change-Id: I4a193a3cf63462fad73d145ab1481070ddf767ca
---
M pySim-shell.py
M pySim/utils.py
2 files changed, 26 insertions(+), 1 deletion(-)
git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/45/34945/1
diff --git a/pySim-shell.py b/pySim-shell.py
index 7aaa234..c59d18b 100755
--- a/pySim-shell.py
+++ b/pySim-shell.py
@@ -53,6 +53,7 @@
from pySim.cards import card_detect, SimCardBase, UiccCardBase
from pySim.utils import h2b, b2h, i2h, swap_nibbles, rpad, JsonEncoder, bertlv_parse_one, sw_match
from pySim.utils import sanitize_pin_adm, tabulate_str_list, boxed_heading_str, Hexstr, dec_iccid
+from pySim.utils import hexstr_or_decimal
from pySim.card_handler import CardHandler, CardHandlerAuto
from pySim.filesystem import CardDF, CardADF, CardModel, CardApplication
@@ -777,7 +778,7 @@
self._cmd.poutput("no description available")
verify_adm_parser = argparse.ArgumentParser()
- verify_adm_parser.add_argument('ADM1', nargs='?', type=str,
+ verify_adm_parser.add_argument('ADM1', nargs='?', type=hexstr_or_decimal,
help='ADM1 pin value. If none given, CSV file will be queried')
@cmd2.with_argparser(verify_adm_parser)
diff --git a/pySim/utils.py b/pySim/utils.py
index 7459a3f..e6a6d2d 100644
--- a/pySim/utils.py
+++ b/pySim/utils.py
@@ -1467,3 +1467,14 @@
def all_subclasses(cls) -> set:
"""Recursively get all subclasses of a specified class"""
return set(cls.__subclasses__()).union([s for c in cls.__subclasses__() for s in all_subclasses(c)])
+
+def hexstr_or_decimal(instr: str):
+ """Method that can be used as 'type' in argparse.add_argument() to validate the value consists of
+ [hexa]decimal digits only."""
+ if instr.isdecimal():
+ return instr
+ if not all(c in string.hexdigits for c in instr):
+ raise ValueError('Input must be [hexa]decimal')
+ if len(instr) & 1:
+ raise ValueError('Input has un-even number of hex digits')
+ return instr
--
To view, visit https://gerrit.osmocom.org/c/pysim/+/34945?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: I4a193a3cf63462fad73d145ab1481070ddf767ca
Gerrit-Change-Number: 34945
Gerrit-PatchSet: 1
Gerrit-Owner: laforge <laforge(a)osmocom.org>
Gerrit-MessageType: newchange