lists.osmocom.org
Sign In Sign Up
Manage this list Sign In Sign Up

Keyboard Shortcuts

Thread View

  • j: Next unread message
  • k: Previous unread message
  • j a: Jump to all threads
  • j l: Jump to MailingList overview

gerrit-log

Thread Start a new thread
Download
Threads by month
  • ----- 2026 -----
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2025 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2024 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2023 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2022 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
gerrit-log@lists.osmocom.org

February 2024

  • 1 participants
  • 1748 discussions
[S] Change in pysim[master]: pylint: transport/serial.py
by laforge 05 Feb '24

05 Feb '24
laforge has uploaded this change for review. ( https://gerrit.osmocom.org/c/pysim/+/35823?usp=email ) Change subject: pylint: transport/serial.py ...................................................................... pylint: transport/serial.py pySim/transport/serial.py:54:0: C0325: Unnecessary parens after 'if' keyword (superfluous-parens) pySim/transport/serial.py:89:0: C0325: Unnecessary parens after 'if' keyword (superfluous-parens) pySim/transport/serial.py:225:0: C0325: Unnecessary parens after 'while' keyword (superfluous-parens) pySim/transport/serial.py:63:12: R1705: Unnecessary "else" after "return", remove the "else" and de-indent the code inside it (no-else-return) pySim/transport/serial.py:106:8: R1720: Unnecessary "elif" after "raise", remove the leading "el" from "elif" (no-else-raise) pySim/transport/serial.py:124:12: W0707: Consider explicitly re-raising using 'except Exception as exc' and 'raise ValueError('Invalid reset pin %s' % self._rst_pin) from exc' (raise-missing-from) pySim/transport/serial.py:204:12: R1723: Unnecessary "elif" after "break", remove the leading "el" from "elif" (no-else-break) pySim/transport/serial.py:20:0: C0411: standard import "import time" should be placed before "import serial" (wrong-import-order) pySim/transport/serial.py:21:0: C0411: standard import "import os" should be placed before "import serial" (wrong-import-order) pySim/transport/serial.py:22:0: C0411: standard import "import argparse" should be placed before "import serial" (wrong-import-order) pySim/transport/serial.py:23:0: C0411: standard import "from typing import Optional" should be placed before "import serial" (wrong-import-order) Change-Id: I82ef12492615a18a13cbdecf0371b3a5d02bbd5c --- M pySim/transport/serial.py 1 file changed, 30 insertions(+), 10 deletions(-) git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/23/35823/1 diff --git a/pySim/transport/serial.py b/pySim/transport/serial.py index 06a082a..b4eddcd 100644 --- a/pySim/transport/serial.py +++ b/pySim/transport/serial.py @@ -16,11 +16,11 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. # -import serial import time import os import argparse from typing import Optional +import serial from pySim.exceptions import NoCardError, ProtocolError from pySim.transport import LinkBase @@ -51,7 +51,7 @@ self._atr = None def __del__(self): - if (hasattr(self, "_sl")): + if hasattr(self, "_sl"): self._sl.close() def wait_for_card(self, timeout: Optional[int] = None, newcardonly: bool = False): @@ -62,8 +62,7 @@ self.reset_card() if not newcardonly: return - else: - existing = True + existing = True except NoCardError: pass @@ -86,7 +85,7 @@ # Tolerate a couple of protocol error ... can happen if # we try when the card is 'half' inserted pe += 1 - if (pe > 2): + if pe > 2: raise # Timed out ... @@ -105,7 +104,7 @@ rv = self._reset_card() if rv == 0: raise NoCardError() - elif rv < 0: + if rv < 0: raise ProtocolError() return rv @@ -120,8 +119,8 @@ try: rst_meth = rst_meth_map[self._rst_pin[1:]] rst_val = rst_val_map[self._rst_pin[0]] - except: - raise ValueError('Invalid reset pin %s' % self._rst_pin) + except Exception as exc: + raise ValueError('Invalid reset pin %s' % self._rst_pin) from exc rst_meth(rst_val) time.sleep(0.1) # 100 ms @@ -203,7 +202,7 @@ b = self._rx_byte() if ord(b) == pdu[1]: break - elif b != '\x60': + if b != '\x60': # Ok, it 'could' be SW1 sw1 = b sw2 = self._rx_byte() @@ -222,7 +221,7 @@ to_recv = data_len - len(pdu) + 5 + 2 data = bytes(0) - while (len(data) < to_recv): + while len(data) < to_recv: b = self._rx_byte() if (to_recv == 2) and (b == '\x60'): # Ignore NIL if we have no RX data (hack ?) continue -- To view, visit https://gerrit.osmocom.org/c/pysim/+/35823?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: I82ef12492615a18a13cbdecf0371b3a5d02bbd5c Gerrit-Change-Number: 35823 Gerrit-PatchSet: 1 Gerrit-Owner: laforge <laforge(a)osmocom.org> Gerrit-MessageType: newchange
1 0
0 0
[S] Change in pysim[master]: pylint: apdu_source/gsmtap.py
by laforge 05 Feb '24

05 Feb '24
laforge has uploaded this change for review. ( https://gerrit.osmocom.org/c/pysim/+/35826?usp=email ) Change subject: pylint: apdu_source/gsmtap.py ...................................................................... pylint: apdu_source/gsmtap.py pySim/apdu_source/gsmtap.py:48:8: R1705: Unnecessary "elif" after "return", remove the leading "el" from "elif" (no-else-return) pySim/apdu_source/gsmtap.py:44:20: W0612: Unused variable 'addr' (unused-variable) pySim/apdu_source/gsmtap.py:22:0: C0411: first party import "from pySim.apdu.ts_102_221 import ApduCommands as UiccApduCommands" should be placed before "from . import ApduSource, PacketType, CardReset" (wrong-import-order) pySim/apdu_source/gsmtap.py:23:0: C0411: first party import "from pySim.apdu.ts_31_102 import ApduCommands as UsimApduCommands" should be placed before "from . import ApduSource, PacketType, CardReset" (wrong-import-order) pySim/apdu_source/gsmtap.py:24:0: C0411: first party import "from pySim.apdu.global_platform import ApduCommands as GpApduCommands" should be placed before "from . import ApduSource, PacketType, CardReset" (wrong-import-order) pySim/apdu_source/gsmtap.py:19:0: W0611: Unused GsmtapMessage imported from pySim.gsmtap (unused-import) Change-Id: I672e8838ebe11015863fd4fd6047181a3f184658 --- M pySim/apdu_source/gsmtap.py 1 file changed, 23 insertions(+), 5 deletions(-) git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/26/35826/1 diff --git a/pySim/apdu_source/gsmtap.py b/pySim/apdu_source/gsmtap.py index aaf97ad..bcfb66d 100644 --- a/pySim/apdu_source/gsmtap.py +++ b/pySim/apdu_source/gsmtap.py @@ -16,12 +16,14 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. -from pySim.gsmtap import GsmtapMessage, GsmtapSource -from . import ApduSource, PacketType, CardReset +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 GsmtapApduSource(ApduSource): @@ -41,16 +43,16 @@ self.gsmtap = GsmtapSource(bind_ip, bind_port) def read_packet(self) -> PacketType: - gsmtap_msg, addr = self.gsmtap.read_packet() + gsmtap_msg, _addr = self.gsmtap.read_packet() if gsmtap_msg['type'] != 'sim': raise ValueError('Unsupported GSMTAP type %s' % gsmtap_msg['type']) sub_type = gsmtap_msg['sub_type'] if sub_type == 'apdu': return ApduCommands.parse_cmd_bytes(gsmtap_msg['body']) - elif sub_type == 'atr': + if sub_type == 'atr': # card has been reset return CardReset(gsmtap_msg['body']) - elif sub_type in ['pps_req', 'pps_rsp']: + if sub_type in ['pps_req', 'pps_rsp']: # simply ignore for now pass else: -- To view, visit https://gerrit.osmocom.org/c/pysim/+/35826?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: I672e8838ebe11015863fd4fd6047181a3f184658 Gerrit-Change-Number: 35826 Gerrit-PatchSet: 1 Gerrit-Owner: laforge <laforge(a)osmocom.org> Gerrit-MessageType: newchange
1 0
0 0
[S] Change in pysim[master]: pylint: apdu_source/__init__.py
by laforge 05 Feb '24

05 Feb '24
laforge has uploaded this change for review. ( https://gerrit.osmocom.org/c/pysim/+/35825?usp=email ) Change subject: pylint: apdu_source/__init__.py ...................................................................... pylint: apdu_source/__init__.py pySim/apdu_source/__init__.py:1:0: C0114: Missing module docstring (missing-module-docstring) pySim/apdu_source/__init__.py:17:8: W0107: Unnecessary pass statement (unnecessary-pass) pySim/apdu_source/__init__.py:34:16: W0133: Exception statement has no effect (pointless-exception-statement) Change-Id: Iec552afd6004b849132132642910a4c7f91e3473 --- M pySim/apdu_source/__init__.py 1 file changed, 14 insertions(+), 2 deletions(-) git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/25/35825/1 diff --git a/pySim/apdu_source/__init__.py b/pySim/apdu_source/__init__.py index 098d3ca..99df865 100644 --- a/pySim/apdu_source/__init__.py +++ b/pySim/apdu_source/__init__.py @@ -14,7 +14,6 @@ @abc.abstractmethod def read_packet(self) -> PacketType: """Read one packet from the source.""" - pass def read(self) -> Union[Apdu, CardReset]: """Main function to call by the user: Blocking read, returns Apdu or CardReset.""" @@ -31,5 +30,5 @@ elif isinstance(r, CardReset): apdu = r else: - ValueError('Unknown read_packet() return %s' % r) + raise ValueError('Unknown read_packet() return %s' % r) return apdu -- To view, visit https://gerrit.osmocom.org/c/pysim/+/35825?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: Iec552afd6004b849132132642910a4c7f91e3473 Gerrit-Change-Number: 35825 Gerrit-PatchSet: 1 Gerrit-Owner: laforge <laforge(a)osmocom.org> Gerrit-MessageType: newchange
1 0
0 0
[S] Change in pysim[master]: pylint: apdu_source/pyshark_rspro
by laforge 05 Feb '24

05 Feb '24
laforge has uploaded this change for review. ( https://gerrit.osmocom.org/c/pysim/+/35828?usp=email ) Change subject: pylint: apdu_source/pyshark_rspro ...................................................................... pylint: apdu_source/pyshark_rspro pySim/apdu_source/pyshark_rspro.py:19:0: W0611: Unused import sys (unused-import) pySim/apdu_source/pyshark_rspro.py:21:0: W0611: Unused pprint imported from pprint as pp (unused-import) pySim/apdu_source/pyshark_rspro.py:25:0: W0611: Unused b2h imported from pySim.utils (unused-import) Change-Id: Ibe8482d8adbb82a74f36b0d64bc5dae27da02b73 --- M pySim/apdu_source/pyshark_rspro.py 1 file changed, 14 insertions(+), 3 deletions(-) git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/28/35828/1 diff --git a/pySim/apdu_source/pyshark_rspro.py b/pySim/apdu_source/pyshark_rspro.py index 039326a..a0e30ed 100644 --- a/pySim/apdu_source/pyshark_rspro.py +++ b/pySim/apdu_source/pyshark_rspro.py @@ -16,13 +16,11 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. -import sys import logging -from pprint import pprint as pp from typing import Tuple import pyshark -from pySim.utils import h2b, b2h +from pySim.utils import h2b from pySim.apdu import Tpdu from . import ApduSource, PacketType, CardReset -- To view, visit https://gerrit.osmocom.org/c/pysim/+/35828?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: Ibe8482d8adbb82a74f36b0d64bc5dae27da02b73 Gerrit-Change-Number: 35828 Gerrit-PatchSet: 1 Gerrit-Owner: laforge <laforge(a)osmocom.org> Gerrit-MessageType: newchange
1 0
0 0
[S] Change in pysim[master]: pylint: apdu_source/pyshark_gsmtap
by laforge 05 Feb '24

05 Feb '24
laforge has uploaded this change for review. ( https://gerrit.osmocom.org/c/pysim/+/35827?usp=email ) Change subject: pylint: apdu_source/pyshark_gsmtap ...................................................................... pylint: apdu_source/pyshark_gsmtap pySim/apdu_source/pyshark_gsmtap.py:90:0: C0305: Trailing newlines (trailing-newlines) pySim/apdu_source/pyshark_gsmtap.py:68:8: R1705: Unnecessary "elif" after "return", remove the leading "el" from "elif" (no-else-return) pySim/apdu_source/pyshark_gsmtap.py:30:0: C0411: first party import "from pySim.apdu.ts_102_221 import ApduCommands as UiccApduCommands" should be placed before "from . import ApduSource, PacketType, CardReset" (wrong-import-order) pySim/apdu_source/pyshark_gsmtap.py:31:0: C0411: first party import "from pySim.apdu.ts_31_102 import ApduCommands as UsimApduCommands" should be placed before "from . import ApduSource, PacketType, CardReset" (wrong-import-order) pySim/apdu_source/pyshark_gsmtap.py:32:0: C0411: first party import "from pySim.apdu.global_platform import ApduCommands as GpApduCommands" should be placed before "from . import ApduSource, PacketType, CardReset" (wrong-import-order) pySim/apdu_source/pyshark_gsmtap.py:19:0: W0611: Unused import sys (unused-import) pySim/apdu_source/pyshark_gsmtap.py:21:0: W0611: Unused pprint imported from pprint as pp (unused-import) pySim/apdu_source/pyshark_gsmtap.py:25:0: W0611: Unused b2h imported from pySim.utils (unused-import) pySim/apdu_source/pyshark_gsmtap.py:26:0: W0611: Unused Tpdu imported from pySim.apdu (unused-import) Change-Id: I0f2bfed2f671e02fc48bcc2a03c785edc691584f --- M pySim/apdu_source/pyshark_gsmtap.py 1 file changed, 25 insertions(+), 8 deletions(-) git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/27/35827/1 diff --git a/pySim/apdu_source/pyshark_gsmtap.py b/pySim/apdu_source/pyshark_gsmtap.py index aa7b624..83745e9 100644 --- a/pySim/apdu_source/pyshark_gsmtap.py +++ b/pySim/apdu_source/pyshark_gsmtap.py @@ -16,20 +16,19 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. -import sys import logging -from pprint import pprint as pp from typing import Tuple import pyshark -from pySim.utils import h2b, b2h -from pySim.apdu import Tpdu +from pySim.utils import h2b from pySim.gsmtap import GsmtapMessage -from . import ApduSource, PacketType, CardReset 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 logger = logging.getLogger(__name__) @@ -67,10 +66,10 @@ sub_type = gsmtap_msg['sub_type'] if sub_type == 'apdu': return ApduCommands.parse_cmd_bytes(gsmtap_msg['body']) - elif sub_type == 'atr': + if sub_type == 'atr': # card has been reset return CardReset(gsmtap_msg['body']) - elif sub_type in ['pps_req', 'pps_rsp']: + if sub_type in ['pps_req', 'pps_rsp']: # simply ignore for now pass else: @@ -87,4 +86,3 @@ """ pyshark_inst = pyshark.FileCapture(pcap_filename, display_filter='gsm_sim', use_json=True, keep_packets=False) super().__init__(pyshark_inst) - -- To view, visit https://gerrit.osmocom.org/c/pysim/+/35827?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: I0f2bfed2f671e02fc48bcc2a03c785edc691584f Gerrit-Change-Number: 35827 Gerrit-PatchSet: 1 Gerrit-Owner: laforge <laforge(a)osmocom.org> Gerrit-MessageType: newchange
1 0
0 0
[S] Change in pysim[master]: pylint: apdu/ts_31_102.py
by laforge 05 Feb '24

05 Feb '24
laforge has uploaded this change for review. ( https://gerrit.osmocom.org/c/pysim/+/35829?usp=email ) Change subject: pylint: apdu/ts_31_102.py ...................................................................... pylint: apdu/ts_31_102.py pySim/apdu/ts_31_102.py:12:0: W0401: Wildcard import construct (wildcard-import) pySim/apdu/ts_31_102.py:38:0: W0404: Reimport 'ApduCommand' (imported line 18) (reimported) pySim/apdu/ts_31_102.py:38:0: W0404: Reimport 'ApduCommandSet' (imported line 18) (reimported) Change-Id: I191147af95142adcd7d768d7dae6480b0c7513fc --- M pySim/apdu/ts_31_102.py 1 file changed, 15 insertions(+), 4 deletions(-) git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/29/35829/1 diff --git a/pySim/apdu/ts_31_102.py b/pySim/apdu/ts_31_102.py index 2200388..c335773 100644 --- a/pySim/apdu/ts_31_102.py +++ b/pySim/apdu/ts_31_102.py @@ -9,12 +9,12 @@ """ from typing import Dict -from construct import * +from construct import BitStruct, Enum, BitsInteger, Int8ub, Bytes, this, Struct, If, Switch, Const from construct import Optional as COptional + from pySim.filesystem import * from pySim.construct import * from pySim.ts_31_102 import SUCI_TlvDataObject - from pySim.apdu import ApduCommand, ApduCommandSet # Copyright (C) 2022 Harald Welte <laforge(a)osmocom.org> @@ -35,8 +35,6 @@ # Mapping between USIM Service Number and its description -from pySim.apdu import ApduCommand, ApduCommandSet - # TS 31.102 Section 7.1 class UsimAuthenticateEven(ApduCommand, n='AUTHENTICATE', ins=0x88, cla=['0X', '4X', '6X']): _apdu_case = 4 -- To view, visit https://gerrit.osmocom.org/c/pysim/+/35829?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: I191147af95142adcd7d768d7dae6480b0c7513fc Gerrit-Change-Number: 35829 Gerrit-PatchSet: 1 Gerrit-Owner: laforge <laforge(a)osmocom.org> Gerrit-MessageType: newchange
1 0
0 0
[M] Change in pysim[master]: pylint: apdu/__init__.py
by laforge 05 Feb '24

05 Feb '24
laforge has uploaded this change for review. ( https://gerrit.osmocom.org/c/pysim/+/35830?usp=email ) Change subject: pylint: apdu/__init__.py ...................................................................... pylint: apdu/__init__.py pySim/apdu/__init__.py:41:0: W0105: String statement has no effect (pointless-string-statement) pySim/apdu/__init__.py:55:4: C0204: Metaclass class method __new__ should have 'mcs' as first argument (bad-mcs-classmethod-argument) pySim/apdu/__init__.py:187:8: R1705: Unnecessary "elif" after "return", remove the leading "el" from "elif" (no-else-return) pySim/apdu/__init__.py:200:8: R1705: Unnecessary "else" after "return", remove the "else" and de-indent the code inside it (no-else-return) pySim/apdu/__init__.py:208:8: R1705: Unnecessary "else" after "return", remove the "else" and de-indent the code inside it (no-else-return) pySim/apdu/__init__.py:216:8: R1705: Unnecessary "else" after "return", remove the "else" and de-indent the code inside it (no-else-return) pySim/apdu/__init__.py:224:8: R1705: Unnecessary "else" after "return", remove the "else" and de-indent the code inside it (no-else-return) pySim/apdu/__init__.py:239:11: C0117: Consider changing "not 'p1' in self.cmd_dict" to "'p1' not in self.cmd_dict" (unnecessary-negation) pySim/apdu/__init__.py:295:8: R1705: Unnecessary "else" after "return", remove the "else" and de-indent the code inside it (no-else-return) pySim/apdu/__init__.py:313:8: R1705: Unnecessary "else" after "return", remove the "else" and de-indent the code inside it (no-else-return) pySim/apdu/__init__.py:416:8: R1705: Unnecessary "else" after "return", remove the "else" and de-indent the code inside it (no-else-return) pySim/apdu/__init__.py:429:12: R1705: Unnecessary "else" after "return", remove the "else" and de-indent the code inside it (no-else-return) pySim/apdu/__init__.py:455:8: R1705: Unnecessary "else" after "return", remove the "else" and de-indent the code inside it (no-else-return) pySim/apdu/__init__.py:31:0: C0411: standard import "import typing" should be placed before "from termcolor import colored" (wrong-import-order) pySim/apdu/__init__.py:32:0: C0411: standard import "from typing import List, Dict, Optional" should be placed before "from termcolor import colored" (wrong-import-order) Change-Id: I5657912df474f3ed0e277458a8eb33e28aeb2927 --- M pySim/apdu/__init__.py 1 file changed, 40 insertions(+), 22 deletions(-) git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/30/35830/1 diff --git a/pySim/apdu/__init__.py b/pySim/apdu/__init__.py index b884e23..f5b7852 100644 --- a/pySim/apdu/__init__.py +++ b/pySim/apdu/__init__.py @@ -1,4 +1,3 @@ -# coding=utf-8 """APDU (and TPDU) parser for UICC/USIM/ISIM cards. The File (and its classes) represent the structure / hierarchy @@ -27,12 +26,13 @@ import abc -from termcolor import colored import typing from typing import List, Dict, Optional +from termcolor import colored -from construct import * +from construct import Byte, GreedyBytes from construct import Optional as COptional + from pySim.construct import * from pySim.utils import * from pySim.runtime import RuntimeLchan, RuntimeState, lchan_nr_from_cla @@ -52,8 +52,8 @@ class ApduCommandMeta(abc.ABCMeta): """A meta-class that we can use to set some class variables when declaring a derived class of ApduCommand.""" - def __new__(metacls, name, bases, namespace, **kwargs): - x = super().__new__(metacls, name, bases, namespace) + def __new__(mcs, name, bases, namespace, **kwargs): + x = super().__new__(mcs, name, bases, namespace) x._name = namespace.get('name', kwargs.get('n', None)) x._ins = namespace.get('ins', kwargs.get('ins', None)) x._cla = namespace.get('cla', kwargs.get('cla', None)) @@ -187,44 +187,39 @@ if apdu_case in [1, 2]: # data is part of response return cls(buffer[:5], buffer[5:]) - elif apdu_case in [3, 4]: + if apdu_case in [3, 4]: # data is part of command lc = buffer[4] return cls(buffer[:5+lc], buffer[5+lc:]) - else: - raise ValueError('%s: Invalid APDU Case %u' % (cls.__name__, apdu_case)) + raise ValueError('%s: Invalid APDU Case %u' % (cls.__name__, apdu_case)) @property def path(self) -> List[str]: """Return (if known) the path as list of files to the file on which this command operates.""" if self.file: return self.file.fully_qualified_path() - else: - return [] + return [] @property def path_str(self) -> str: """Return (if known) the path as string to the file on which this command operates.""" if self.file: return self.file.fully_qualified_path_str() - else: - return '' + return '' @property def col_sw(self) -> str: """Return the ansi-colorized status word. Green==OK, Red==Error""" if self.successful: return colored(b2h(self.sw), 'green') - else: - return colored(b2h(self.sw), 'red') + return colored(b2h(self.sw), 'red') @property def lchan_nr(self) -> int: """Logical channel number over which this ApduCommand was transmitted.""" if self.lchan: return self.lchan.lchan_nr - else: - return lchan_nr_from_cla(self.cla) + return lchan_nr_from_cla(self.cla) def __str__(self) -> str: return '%02u %s(%s): %s' % (self.lchan_nr, type(self).__name__, self.path_str, self.to_dict()) @@ -236,7 +231,7 @@ """Fall-back function to be called if there is no derived-class-specific process_global or process_on_lchan method. Uses information from APDU decode.""" self.processed = {} - if not 'p1' in self.cmd_dict: + if 'p1' not in self.cmd_dict: self.processed = self.to_dict() else: self.processed['p1'] = self.cmd_dict['p1'] @@ -428,8 +423,7 @@ apdu = Apdu(icmd, tpdu.rsp) if self.apdu_handler: return self.apdu_handler.input(apdu) - else: - return Apdu(icmd, tpdu.rsp) + return Apdu(icmd, tpdu.rsp) def input(self, cmd: bytes, rsp: bytes): if isinstance(cmd, str): @@ -452,7 +446,6 @@ self.atr = atr def __str__(self): - if (self.atr): + if self.atr: return '%s(%s)' % (type(self).__name__, b2h(self.atr)) - else: - return '%s' % (type(self).__name__) + return '%s' % (type(self).__name__) -- To view, visit https://gerrit.osmocom.org/c/pysim/+/35830?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: I5657912df474f3ed0e277458a8eb33e28aeb2927 Gerrit-Change-Number: 35830 Gerrit-PatchSet: 1 Gerrit-Owner: laforge <laforge(a)osmocom.org> Gerrit-MessageType: newchange
1 0
0 0
[S] Change in pysim[master]: pylint: pySim/esim/bsp.py
by laforge 05 Feb '24

05 Feb '24
laforge has uploaded this change for review. ( https://gerrit.osmocom.org/c/pysim/+/35831?usp=email ) Change subject: pylint: pySim/esim/bsp.py ...................................................................... pylint: pySim/esim/bsp.py pySim/esim/bsp.py:1:0: C0114: Missing module docstring (missing-module-docstring) pySim/esim/bsp.py:28:0: C0413: Import "import abc" should be placed at the top of the module (wrong-import-position) pySim/esim/bsp.py:29:0: C0413: Import "from typing import List" should be placed at the top of the module (wrong-import-position) pySim/esim/bsp.py:30:0: C0413: Import "import logging" should be placed at the top of the module (wrong-import-position) pySim/esim/bsp.py:33:0: C0413: Import "from cryptography.hazmat.primitives import hashes" should be placed at the top of the module (wrong-import-position) pySim/esim/bsp.py:34:0: C0413: Import "from cryptography.hazmat.primitives.kdf.x963kdf import X963KDF" should be placed at the top of the module (wrong-import-position) pySim/esim/bsp.py:36:0: C0413: Import "from Cryptodome.Cipher import AES" should be placed at the top of the module (wrong-import-position) pySim/esim/bsp.py:37:0: C0413: Import "from Cryptodome.Hash import CMAC" should be placed at the top of the module (wrong-import-position) pySim/esim/bsp.py:39:0: C0413: Import "from pySim.utils import bertlv_encode_len, bertlv_parse_one, b2h" should be placed at the top of the module (wrong-import-position) pySim/esim/bsp.py:48:55: W0613: Unused argument 'padding' (unused-argument) pySim/esim/bsp.py:55:45: W0613: Unused argument 'multiple' (unused-argument) pySim/esim/bsp.py:84:8: W0107: Unnecessary pass statement (unnecessary-pass) pySim/esim/bsp.py:89:8: W0107: Unnecessary pass statement (unnecessary-pass) pySim/esim/bsp.py:94:8: W0107: Unnecessary pass statement (unnecessary-pass) pySim/esim/bsp.py:169:8: W0107: Unnecessary pass statement (unnecessary-pass) pySim/esim/bsp.py:292:8: W0612: Unused variable 'tdict' (unused-variable) pySim/esim/bsp.py:292:15: W0612: Unused variable 'l' (unused-variable) pySim/esim/bsp.py:292:23: W0612: Unused variable 'remain' (unused-variable) Change-Id: I64bd634606c375e767676a4b5ba7c2cc042350c2 --- M pySim/esim/bsp.py 1 file changed, 33 insertions(+), 8 deletions(-) git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/31/35831/1 diff --git a/pySim/esim/bsp.py b/pySim/esim/bsp.py index cf2104a..2afbd46 100644 --- a/pySim/esim/bsp.py +++ b/pySim/esim/bsp.py @@ -23,7 +23,6 @@ # SGP.22 v3.0 Section 2.5.3: # That block of data is split into segments of a maximum size of 1020 bytes (including the tag, length field and MAC). -MAX_SEGMENT_SIZE = 1020 import abc from typing import List @@ -42,6 +41,8 @@ logger = logging.getLogger(__name__) logger.addHandler(logging.NullHandler()) +MAX_SEGMENT_SIZE = 1020 + class BspAlgo(abc.ABC): blocksize: int @@ -50,11 +51,11 @@ if in_len % multiple == 0: return b'' pad_cnt = multiple - (in_len % multiple) - return b'\x00' * pad_cnt + return bytes([padding]) * pad_cnt def _pad_to_multiple(self, indat: bytes, multiple: int, padding: int = 0) -> bytes: """Pad the input data to multiples of 'multiple'.""" - return indat + self._get_padding(len(indat), self.blocksize, padding) + return indat + self._get_padding(len(indat), multiple, padding) def __str__(self): return self.__class__.__name__ @@ -81,17 +82,14 @@ @abc.abstractmethod def _unpad(self, padded: bytes) -> bytes: """Remove the padding from padded data.""" - pass @abc.abstractmethod def _encrypt(self, data:bytes) -> bytes: """Actual implementation, to be implemented by derived class.""" - pass @abc.abstractmethod def _decrypt(self, data:bytes) -> bytes: """Actual implementation, to be implemented by derived class.""" - pass class BspAlgoCryptAES128(BspAlgoCrypt): name = 'AES-CBC-128' @@ -166,7 +164,6 @@ @abc.abstractmethod def _auth(self, temp_data: bytes) -> bytes: """To be implemented by algorithm specific derived class.""" - pass class BspAlgoMacAES128(BspAlgoMac): name = 'AES-CMAC-128' @@ -289,7 +286,7 @@ def demac_only_one(self, ciphertext: bytes) -> bytes: payload = self.m_algo.verify(ciphertext) - tdict, l, val, remain = bertlv_parse_one(payload) + _tdict, _l, val, _remain = bertlv_parse_one(payload) return val def demac_only(self, ciphertext_list: List[bytes]) -> bytes: -- To view, visit https://gerrit.osmocom.org/c/pysim/+/35831?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: I64bd634606c375e767676a4b5ba7c2cc042350c2 Gerrit-Change-Number: 35831 Gerrit-PatchSet: 1 Gerrit-Owner: laforge <laforge(a)osmocom.org> Gerrit-MessageType: newchange
1 0
0 0
[S] Change in pysim[master]: pylint: esim/x509_cert.py
by laforge 05 Feb '24

05 Feb '24
laforge has uploaded this change for review. ( https://gerrit.osmocom.org/c/pysim/+/35832?usp=email ) Change subject: pylint: esim/x509_cert.py ...................................................................... pylint: esim/x509_cert.py pySim/esim/x509_cert.py:70:4: W0107: Unnecessary pass statement (unnecessary-pass) pySim/esim/x509_cert.py:91:20: C0123: Use isinstance() rather than type() for a typecheck. (unidiomatic-typecheck) pySim/esim/x509_cert.py:105:28: W3101: Missing timeout argument for method 'requests.get' can cause your program to hang indefinitely (missing-timeout) pySim/esim/x509_cert.py:163:0: C0413: Import "from cryptography.hazmat.primitives.asymmetric.utils import decode_dss_signature" should be placed at the top of the module (wrong-import-position) pySim/esim/x509_cert.py:20:0: C0411: standard import "from typing import Optional, List" should be placed before "import requests" (wrong-import-order) pySim/esim/x509_cert.py:163:0: C0411: third party import "from cryptography.hazmat.primitives.asymmetric.utils import decode_dss_signature" should be placed before "from pySim.utils import b2h" (wrong-import-order) pySim/esim/x509_cert.py:163:0: C0412: Imports from package cryptography are not grouped (ungrouped-imports) pySim/esim/x509_cert.py:22:0: W0611: Unused padding imported from cryptography.hazmat.primitives.asymmetric (unused-import) pySim/esim/x509_cert.py:24:0: W0611: Unused InvalidSignature imported from cryptography.exceptions (unused-import) Change-Id: Ic435c9a7cfcc18cacec3a3d872925bd737fb5cd9 --- M pySim/esim/x509_cert.py 1 file changed, 23 insertions(+), 6 deletions(-) git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/32/35832/1 diff --git a/pySim/esim/x509_cert.py b/pySim/esim/x509_cert.py index 9f6c8e6..3bcf8a2 100644 --- a/pySim/esim/x509_cert.py +++ b/pySim/esim/x509_cert.py @@ -19,11 +19,11 @@ import requests from typing import Optional, List -from cryptography.hazmat.primitives.asymmetric import ec, padding +from cryptography.hazmat.primitives.asymmetric import ec from cryptography.hazmat.primitives import hashes -from cryptography.exceptions import InvalidSignature from cryptography import x509 from cryptography.hazmat.primitives.serialization import load_pem_private_key, Encoding +from cryptography.hazmat.primitives.asymmetric.utils import decode_dss_signature from pySim.utils import b2h @@ -67,7 +67,6 @@ class VerifyError(Exception): """An error during certificate verification,""" - pass class CertificateSet: """A set of certificates consisting of a trusted [self-signed] CA root certificate, @@ -88,7 +87,7 @@ self.crl = None def load_crl(self, urls: Optional[List[str]] = None): - if urls and type(urls) is str: + if urls and isinstance(urls, str): urls = [urls] if not urls: # generate list of CRL URLs from root CA certificate @@ -102,7 +101,7 @@ for url in urls: try: - crl_bytes = requests.get(url) + crl_bytes = requests.get(url, timeout=10) except requests.exceptions.ConnectionError: continue crl = x509.load_der_x509_crl(crl_bytes) @@ -160,7 +159,6 @@ if depth > max_depth: raise VerifyError('Maximum depth %u exceeded while verifying certificate chain' % max_depth) -from cryptography.hazmat.primitives.asymmetric.utils import decode_dss_signature def ecdsa_dss_to_tr03111(sig: bytes) -> bytes: """convert from DER format to BSI TR-03111; first get long integers; then convert those to bytes.""" -- To view, visit https://gerrit.osmocom.org/c/pysim/+/35832?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: Ic435c9a7cfcc18cacec3a3d872925bd737fb5cd9 Gerrit-Change-Number: 35832 Gerrit-PatchSet: 1 Gerrit-Owner: laforge <laforge(a)osmocom.org> Gerrit-MessageType: newchange
1 0
0 0
[S] Change in pysim[master]: pylint: esim/rsp.py
by laforge 05 Feb '24

05 Feb '24
laforge has uploaded this change for review. ( https://gerrit.osmocom.org/c/pysim/+/35833?usp=email ) Change subject: pylint: esim/rsp.py ...................................................................... pylint: esim/rsp.py pySim/esim/rsp.py:101:4: W0107: Unnecessary pass statement (unnecessary-pass) pySim/esim/rsp.py:27:0: C0411: standard import "from collections.abc import MutableMapping" should be placed before "from cryptography.hazmat.primitives.asymmetric import ec" (wrong-import-order) pySim/esim/rsp.py:22:0: W0611: Unused import copyreg (unused-import) pySim/esim/rsp.py:27:0: W0611: Unused MutableMapping imported from collections.abc (unused-import) Change-Id: Id87dbf82cd41ce6e5276e5bdd7af1877d77e3fab --- M pySim/esim/rsp.py 1 file changed, 14 insertions(+), 3 deletions(-) git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/33/35833/1 diff --git a/pySim/esim/rsp.py b/pySim/esim/rsp.py index 1f8e989..ec317fc 100644 --- a/pySim/esim/rsp.py +++ b/pySim/esim/rsp.py @@ -19,12 +19,10 @@ from typing import Optional import shelve -import copyreg from cryptography.hazmat.primitives.asymmetric import ec from cryptography.hazmat.primitives.serialization import Encoding from cryptography import x509 -from collections.abc import MutableMapping from pySim.esim import compile_asn1_subdir @@ -98,4 +96,3 @@ class RspSessionStore(shelve.DbfilenameShelf): """A derived class as wrapper around the database-backed non-volatile storage 'shelve', in case we might need to extend it in the future. We use it to store RspSessionState objects indexed by transactionId.""" - pass -- To view, visit https://gerrit.osmocom.org/c/pysim/+/35833?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: Id87dbf82cd41ce6e5276e5bdd7af1877d77e3fab Gerrit-Change-Number: 35833 Gerrit-PatchSet: 1 Gerrit-Owner: laforge <laforge(a)osmocom.org> Gerrit-MessageType: newchange
1 0
0 0
  • ← Newer
  • 1
  • ...
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • ...
  • 175
  • Older →

HyperKitty Powered by HyperKitty version 1.3.12.