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 osmocom-bb[master]: layer23: cosmetic: clarify GPRS related L1CTL logging
by laforge 02 Feb '24

02 Feb '24
Attention is currently required from: fixeria. laforge has posted comments on this change. ( https://gerrit.osmocom.org/c/osmocom-bb/+/35779?usp=email ) Change subject: layer23: cosmetic: clarify GPRS related L1CTL logging ...................................................................... Patch Set 1: Code-Review+2 -- To view, visit https://gerrit.osmocom.org/c/osmocom-bb/+/35779?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: osmocom-bb Gerrit-Branch: master Gerrit-Change-Id: Idcde85c132a52b7bc6c3f2f58c2eac0a509b7b43 Gerrit-Change-Number: 35779 Gerrit-PatchSet: 1 Gerrit-Owner: fixeria <vyanitskiy(a)sysmocom.de> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-Reviewer: pespin <pespin(a)sysmocom.de> Gerrit-Attention: fixeria <vyanitskiy(a)sysmocom.de> Gerrit-Comment-Date: Fri, 02 Feb 2024 22:23:43 +0000 Gerrit-HasComments: No Gerrit-Has-Labels: Yes Gerrit-MessageType: comment
1 0
0 0
[S] Change in osmocom-bb[master]: l1gprs: minor changes to l1gprs_handle_rts_ind()
by laforge 02 Feb '24

02 Feb '24
Attention is currently required from: fixeria. laforge has posted comments on this change. ( https://gerrit.osmocom.org/c/osmocom-bb/+/35776?usp=email ) Change subject: l1gprs: minor changes to l1gprs_handle_rts_ind() ...................................................................... Patch Set 1: Code-Review+1 -- To view, visit https://gerrit.osmocom.org/c/osmocom-bb/+/35776?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: osmocom-bb Gerrit-Branch: master Gerrit-Change-Id: Ie74d1c4123715d61875c4c956eb4a1ce97ed5f24 Gerrit-Change-Number: 35776 Gerrit-PatchSet: 1 Gerrit-Owner: fixeria <vyanitskiy(a)sysmocom.de> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-Reviewer: pespin <pespin(a)sysmocom.de> Gerrit-Attention: fixeria <vyanitskiy(a)sysmocom.de> Gerrit-Comment-Date: Fri, 02 Feb 2024 22:23:10 +0000 Gerrit-HasComments: No Gerrit-Has-Labels: Yes Gerrit-MessageType: comment
1 0
0 0
[S] Change in osmocom-bb[master]: mobile: fix -Wmaybe-uninitialized in tch_csd_rx_{to,from}_l1()
by laforge 02 Feb '24

02 Feb '24
Attention is currently required from: fixeria, pespin. laforge has posted comments on this change. ( https://gerrit.osmocom.org/c/osmocom-bb/+/35788?usp=email ) Change subject: mobile: fix -Wmaybe-uninitialized in tch_csd_rx_{to,from}_l1() ...................................................................... Patch Set 1: Code-Review+1 -- To view, visit https://gerrit.osmocom.org/c/osmocom-bb/+/35788?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: osmocom-bb Gerrit-Branch: master Gerrit-Change-Id: I0a81d5c4f11feb7cf73771c23848dee9ce6ec620 Gerrit-Change-Number: 35788 Gerrit-PatchSet: 1 Gerrit-Owner: fixeria <vyanitskiy(a)sysmocom.de> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-Reviewer: pespin <pespin(a)sysmocom.de> Gerrit-Attention: fixeria <vyanitskiy(a)sysmocom.de> Gerrit-Attention: pespin <pespin(a)sysmocom.de> Gerrit-Comment-Date: Fri, 02 Feb 2024 22:22:39 +0000 Gerrit-HasComments: No Gerrit-Has-Labels: Yes Gerrit-MessageType: comment
1 0
0 0
[M] Change in pysim[master]: global_platform: implement GET STATUS command
by laforge 02 Feb '24

02 Feb '24
laforge has submitted this change. ( https://gerrit.osmocom.org/c/pysim/+/35756?usp=email ) Change subject: global_platform: implement GET STATUS command ...................................................................... global_platform: implement GET STATUS command The GlobalPlatform GET STATUS command is used to display information about ISD / Applications / ExecutabLoad Files / Modules on the card. Change-Id: Ic92f96c1c6a569aebc93a906c62a43b86fe3b811 --- M docs/shell.rst M pySim/global_platform.py 2 files changed, 107 insertions(+), 0 deletions(-) Approvals: Jenkins Builder: Verified laforge: Looks good to me, approved diff --git a/docs/shell.rst b/docs/shell.rst index 8731cfe..a917f8f 100644 --- a/docs/shell.rst +++ b/docs/shell.rst @@ -941,6 +941,12 @@ :module: pySim.global_platform :func: ADF_SD.AddlShellCommands.get_data_parser +get_status +~~~~~~~~~~ +.. argparse:: + :module: pySim.global_platform + :func: ADF_SD.AddlShellCommands.get_status_parser + store_data ~~~~~~~~~~ .. argparse:: diff --git a/pySim/global_platform.py b/pySim/global_platform.py index fe6ffb3..347399b 100644 --- a/pySim/global_platform.py +++ b/pySim/global_platform.py @@ -368,6 +368,60 @@ d = t.to_dict() return flatten_dict_lists(d['fci_template']) +# 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 = Int8ub + +# Section 11.4.3.1 Table 11-36 + Section 11.1.2 +class Privileges(BER_TLV_IE, tag=0xc5): + _construct = Struct('byte1'/FlagsEnum(Byte, security_domain=0x80, dap_verification=0x40, + delegated_management=0x20, card_lock=0x10, card_terminate=0x08, + card_reset=0x04, cvm_management=0x02, + mandated_dap_verification=0x01), + 'byte2'/COptional(FlagsEnum(Byte, trusted_path=0x80, authorized_management=0x40, + token_management=0x20, global_delete=0x10, global_lock=0x08, + global_registry=0x04, final_application=0x02, global_service=0x01)), + 'byte3'/COptional(FlagsEnum(Byte, receipt_generation=0x80, ciphered_load_file_data_block=0x40, + contactless_activation=0x20, contactless_self_activation=0x10))) + +# Section 11.4.3.1 Table 11-36 + Section 11.1.7 +class ImplicitSelectionParameter(BER_TLV_IE, tag=0xcf): + _construct = BitStruct('contactless_io'/Flag, + 'contact_io'/Flag, + '_rfu'/Flag, + 'logical_channel_number'/BitsInteger(5)) + +# Section 11.4.3.1 Table 11-36 +class ExecutableLoadFileAID(BER_TLV_IE, tag=0xc4): + _construct = HexAdapter(GreedyBytes) + +# Section 11.4.3.1 Table 11-36 +class ExecutableLoadFileVersionNumber(BER_TLV_IE, tag=0xce): + # Note: the Executable Load File Version Number format and contents are beyond the scope of this + # specification. It shall consist of the version information contained in the original Load File: on a + # Java Card based card, this version number represents the major and minor version attributes of the + # original Load File Data Block. + _construct = HexAdapter(GreedyBytes) + +# Section 11.4.3.1 Table 11-36 +class ExecutableModuleAID(BER_TLV_IE, tag=0x84): + _construct = HexAdapter(GreedyBytes) + +# Section 11.4.3.1 Table 11-36 +class AssociatedSecurityDomainAID(BER_TLV_IE, tag=0xcc): + _construct = HexAdapter(GreedyBytes) + +# Section 11.4.3.1 Table 11-36 +class GpRegistryRelatedData(BER_TLV_IE, tag=0xe3, nested=[ApplicationAID, LifeCycleState, Privileges, + ImplicitSelectionParameter, ExecutableLoadFileAID, + ExecutableLoadFileVersionNumber, + ExecutableModuleAID, AssociatedSecurityDomainAID]): + pass + # Application Dedicated File of a Security Domain class ADF_SD(CardADF): StoreData = BitStruct('last_block'/Flag, @@ -493,6 +547,41 @@ data, sw = self._cmd.lchan.scc._tp.send_apdu_checksw(hdr + b2h(key_data)) return data + get_status_parser = argparse.ArgumentParser() + get_status_parser.add_argument('subset', choices=StatusSubset.ksymapping.values(), + help='Subset of statuses to be included in the response') + get_status_parser.add_argument('--aid', type=is_hexstr, default='', + help='AID Search Qualifier (search only for given AID)') + + @cmd2.with_argparser(get_status_parser) + def do_get_status(self, opts): + """Perform GlobalPlatform GET STATUS command in order to retriev status information + on Issuer Security Domain, Executable Load File, Executable Module or Applications.""" + grd_list = self.get_status(opts.subset, opts.aid) + for grd in grd_list: + self._cmd.poutput_json(grd.to_dict()) + + def get_status(self, subset:str, aid_search_qualifier:Hexstr = '') -> List[GpRegistryRelatedData]: + subset_hex = b2h(build_construct(StatusSubset, subset)) + aid = ApplicationAID(decoded=aid_search_qualifier) + cmd_data = aid.to_tlv() + h2b('5c054f9f70c5cc') + p2 = 0x02 # TLV format according to Table 11-36 + grd_list = [] + while True: + hdr = "80F2%s%02x%02x" % (subset_hex, p2, len(cmd_data)) + data, sw = self._cmd.lchan.scc._tp.send_apdu(hdr + b2h(cmd_data)) + remainder = h2b(data) + while len(remainder): + # tlv sequence, each element is one GpRegistryRelatedData() + grd = GpRegistryRelatedData() + dec, remainder = grd.from_tlv(remainder) + grd_list.append(grd) + if sw != '6310': + return grd_list + else: + p2 |= 0x01 + return grd_list + # Card Application of a Security Domain class CardApplicationSD(CardApplication): -- To view, visit https://gerrit.osmocom.org/c/pysim/+/35756?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: Ic92f96c1c6a569aebc93a906c62a43b86fe3b811 Gerrit-Change-Number: 35756 Gerrit-PatchSet: 2 Gerrit-Owner: laforge <laforge(a)osmocom.org> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: dexter <pmaier(a)sysmocom.de> Gerrit-Reviewer: fixeria <vyanitskiy(a)sysmocom.de> Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-MessageType: merged
1 0
0 0
[S] Change in pysim[master]: move global_platform.py to global_platform/__init__.py
by laforge 02 Feb '24

02 Feb '24
laforge has submitted this change. ( https://gerrit.osmocom.org/c/pysim/+/35763?usp=email ) Change subject: move global_platform.py to global_platform/__init__.py ...................................................................... move global_platform.py to global_platform/__init__.py This will allow us to have multiple different modules for different aspects of global_platform. Change-Id: Ieca0b20c26a2e41eb11455941164474b76eb3c7a --- R pySim/global_platform/__init__.py 1 file changed, 12 insertions(+), 0 deletions(-) Approvals: laforge: Looks good to me, approved Jenkins Builder: Verified diff --git a/pySim/global_platform.py b/pySim/global_platform/__init__.py similarity index 100% rename from pySim/global_platform.py rename to pySim/global_platform/__init__.py -- To view, visit https://gerrit.osmocom.org/c/pysim/+/35763?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: Ieca0b20c26a2e41eb11455941164474b76eb3c7a Gerrit-Change-Number: 35763 Gerrit-PatchSet: 3 Gerrit-Owner: laforge <laforge(a)osmocom.org> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: dexter <pmaier(a)sysmocom.de> Gerrit-Reviewer: fixeria <vyanitskiy(a)sysmocom.de> Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-MessageType: merged
1 0
0 0
[M] Change in pysim[master]: commands.py: Wrap the transport send_apdu* methods
by laforge 02 Feb '24

02 Feb '24
laforge has submitted this change. ( https://gerrit.osmocom.org/c/pysim/+/35762?usp=email ) Change subject: commands.py: Wrap the transport send_apdu* methods ...................................................................... commands.py: Wrap the transport send_apdu* methods Let's not have higher level code directly call the transports send_apdu* methods. We do this as a precursor to introducing secure channel support, where the secure channel driver would add MAC and/or encrypt APDUs before they are sent to the transport. Change-Id: I1b870140959aa8241cda2246e74576390123cb2d --- M pySim-shell.py M pySim/commands.py M pySim/euicc.py M pySim/global_platform.py M pySim/legacy/cards.py M pySim/transport/__init__.py 6 files changed, 135 insertions(+), 104 deletions(-) Approvals: laforge: Looks good to me, approved Jenkins Builder: Verified diff --git a/pySim-shell.py b/pySim-shell.py index 5b80588..70eaee2 100755 --- a/pySim-shell.py +++ b/pySim-shell.py @@ -245,7 +245,7 @@ # noted that the apdu command plays an exceptional role since it is the only card accessing command that # can be executed without the presence of a runtime state (self.rs) object. However, this also means that # self.lchan is also not present (see method equip). - data, sw = self.card._scc._tp.send_apdu(opts.APDU) + data, sw = self.card._scc.send_apdu(opts.APDU) if data: self.poutput("SW: %s, RESP: %s" % (sw, data)) else: diff --git a/pySim/commands.py b/pySim/commands.py index d785251..2d0736e 100644 --- a/pySim/commands.py +++ b/pySim/commands.py @@ -5,7 +5,7 @@ # # Copyright (C) 2009-2010 Sylvain Munaut <tnt(a)246tNt.com> -# Copyright (C) 2010-2023 Harald Welte <laforge(a)gnumonks.org> +# Copyright (C) 2010-2024 Harald Welte <laforge(a)gnumonks.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 @@ -25,8 +25,8 @@ import typing # construct also has a Union, so we do typing.Union below from construct import * -from pySim.construct import LV -from pySim.utils import rpad, lpad, b2h, h2b, sw_match, bertlv_encode_len, Hexstr, h2i, i2h, str_sanitize, expand_hex +from pySim.construct import LV, filter_dict +from pySim.utils import rpad, lpad, b2h, h2b, sw_match, bertlv_encode_len, Hexstr, h2i, i2h, str_sanitize, expand_hex, SwMatchstr from pySim.utils import Hexstr, SwHexstr, ResTuple from pySim.exceptions import SwMatchError from pySim.transport import LinkBase @@ -100,6 +100,81 @@ else: return cla_with_lchan(cla, self.lchan_nr) + def send_apdu(self, pdu: Hexstr) -> ResTuple: + """Sends an APDU and auto fetch response data + + Args: + pdu : string of hexadecimal characters (ex. "A0A40000023F00") + Returns: + tuple(data, sw), where + data : string (in hex) of returned data (ex. "074F4EFFFF") + sw : string (in hex) of status word (ex. "9000") + """ + return self._tp.send_apdu(pdu) + + def send_apdu_checksw(self, pdu: Hexstr, sw: SwMatchstr = "9000") -> ResTuple: + """Sends an APDU and check returned SW + + Args: + pdu : string of hexadecimal characters (ex. "A0A40000023F00") + sw : string of 4 hexadecimal characters (ex. "9000"). The user may mask out certain + digits using a '?' to add some ambiguity if needed. + Returns: + tuple(data, sw), where + data : string (in hex) of returned data (ex. "074F4EFFFF") + sw : string (in hex) of status word (ex. "9000") + """ + return self._tp.send_apdu_checksw(pdu, sw) + + def send_apdu_constr(self, cla: Hexstr, ins: Hexstr, p1: Hexstr, p2: Hexstr, cmd_constr: Construct, + cmd_data: Hexstr, resp_constr: Construct) -> Tuple[dict, SwHexstr]: + """Build and sends an APDU using a 'construct' definition; parses response. + + Args: + cla : string (in hex) ISO 7816 class byte + ins : string (in hex) ISO 7816 instruction byte + p1 : string (in hex) ISO 7116 Parameter 1 byte + 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 + Returns: + Tuple of (decoded_data, sw) + """ + cmd = cmd_constr.build(cmd_data) if cmd_data else '' + p3 = i2h([len(cmd)]) + pdu = ''.join([cla, ins, p1, p2, p3, b2h(cmd)]) + (data, sw) = self.send_apdu(pdu) + if data: + # filter the resulting dict to avoid '_io' members inside + rsp = filter_dict(resp_constr.parse(h2b(data))) + else: + rsp = None + return (rsp, sw) + + def send_apdu_constr_checksw(self, cla: Hexstr, ins: Hexstr, p1: Hexstr, p2: Hexstr, + cmd_constr: Construct, cmd_data: Hexstr, resp_constr: Construct, + sw_exp: SwMatchstr="9000") -> Tuple[dict, SwHexstr]: + """Build and sends an APDU using a 'construct' definition; parses response. + + Args: + cla : string (in hex) ISO 7816 class byte + ins : string (in hex) ISO 7816 instruction byte + p1 : string (in hex) ISO 7116 Parameter 1 byte + 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 + exp_sw : string (in hex) of status word (ex. "9000") + Returns: + Tuple of (decoded_data, sw) + """ + (rsp, sw) = self.send_apdu_constr(cla, ins, + p1, p2, cmd_constr, cmd_data, resp_constr) + if not sw_match(sw, sw_exp): + raise SwMatchError(sw, sw_exp.lower(), self._tp.sw_interpreter) + return (rsp, sw) + # Extract a single FCP item from TLV def __parse_fcp(self, fcp: Hexstr): # see also: ETSI TS 102 221, chapter 11.1.1.3.1 Response for MF, @@ -170,8 +245,7 @@ if type(dir_list) is not list: dir_list = [dir_list] for i in dir_list: - data, sw = self._tp.send_apdu( - self.cla_byte + "a4" + self.sel_ctrl + "02" + i) + data, sw = self.send_apdu(self.cla_byte + "a4" + self.sel_ctrl + "02" + i) rv.append((data, sw)) if sw != '9000': return rv @@ -201,11 +275,11 @@ fid : file identifier as hex string """ - return self._tp.send_apdu_checksw(self.cla_byte + "a4" + self.sel_ctrl + "02" + fid) + return self.send_apdu_checksw(self.cla_byte + "a4" + self.sel_ctrl + "02" + fid) def select_parent_df(self) -> ResTuple: """Execute SELECT to switch to the parent DF """ - return self._tp.send_apdu_checksw(self.cla_byte + "a4030400") + return self.send_apdu_checksw(self.cla_byte + "a4030400") def select_adf(self, aid: Hexstr) -> ResTuple: """Execute SELECT a given Applicaiton ADF. @@ -215,7 +289,7 @@ """ aidlen = ("0" + format(len(aid) // 2, 'x'))[-2:] - return self._tp.send_apdu_checksw(self.cla_byte + "a4" + "0404" + aidlen + aid) + return self.send_apdu_checksw(self.cla_byte + "a4" + "0404" + aidlen + aid) def read_binary(self, ef: Path, length: int = None, offset: int = 0) -> ResTuple: """Execute READD BINARY. @@ -240,7 +314,7 @@ pdu = self.cla_byte + \ 'b0%04x%02x' % (offset + chunk_offset, chunk_len) try: - data, sw = self._tp.send_apdu_checksw(pdu) + data, sw = self.send_apdu_checksw(pdu) except Exception as e: raise ValueError('%s, failed to read (offset %d)' % (str_sanitize(str(e)), offset)) @@ -300,7 +374,7 @@ 'd6%04x%02x' % (offset + chunk_offset, chunk_len) + \ data[chunk_offset*2: (chunk_offset+chunk_len)*2] try: - chunk_data, chunk_sw = self._tp.send_apdu_checksw(pdu) + chunk_data, chunk_sw = self.send_apdu_checksw(pdu) except Exception as e: raise ValueError('%s, failed to write chunk (chunk_offset %d, chunk_len %d)' % (str_sanitize(str(e)), chunk_offset, chunk_len)) @@ -320,7 +394,7 @@ r = self.select_path(ef) rec_length = self.__record_len(r) pdu = self.cla_byte + 'b2%02x04%02x' % (rec_no, rec_length) - return self._tp.send_apdu_checksw(pdu) + return self.send_apdu_checksw(pdu) def __verify_record(self, ef: Path, rec_no: int, data: str): """Verify record against given data @@ -383,7 +457,7 @@ pass pdu = (self.cla_byte + 'dc%02x04%02x' % (rec_no, rec_length)) + data - res = self._tp.send_apdu_checksw(pdu) + res = self.send_apdu_checksw(pdu) if verify: self.__verify_record(ef, rec_no, data) return res @@ -421,7 +495,7 @@ pdu = self.cla4lchan('80') + 'cb008001%02x' % (tag) else: pdu = self.cla4lchan('80') + 'cb000000' - return self._tp.send_apdu_checksw(pdu) + return self.send_apdu_checksw(pdu) def retrieve_data(self, ef: Path, tag: int) -> ResTuple: """Execute RETRIEVE DATA, see also TS 102 221 Section 11.3.1. @@ -451,7 +525,7 @@ if isinstance(data, bytes) or isinstance(data, bytearray): data = b2h(data) pdu = self.cla4lchan('80') + 'db00%02x%02x%s' % (p1, len(data)//2, data) - return self._tp.send_apdu_checksw(pdu) + return self.send_apdu_checksw(pdu) def set_data(self, ef, tag: int, value: str, verify: bool = False, conserve: bool = False) -> ResTuple: """Execute SET DATA. @@ -493,7 +567,7 @@ if len(rand) != 32: raise ValueError('Invalid rand') self.select_path(['3f00', '7f20']) - return self._tp.send_apdu_checksw(self.cla4lchan('a0') + '88000010' + rand, sw='9000') + return self.send_apdu_checksw(self.cla4lchan('a0') + '88000010' + rand, sw='9000') def authenticate(self, rand: Hexstr, autn: Hexstr, context: str = '3g') -> ResTuple: """Execute AUTHENTICATE (USIM/ISIM). @@ -515,7 +589,7 @@ p2 = '81' elif context == 'gsm': p2 = '80' - (data, sw) = self._tp.send_apdu_constr_checksw( + (data, sw) = self.send_apdu_constr_checksw( self.cla_byte, '88', '00', p2, AuthCmd3G, cmd_data, AuthResp3G) if 'auts' in data: ret = {'synchronisation_failure': data} @@ -525,11 +599,11 @@ def status(self) -> ResTuple: """Execute a STATUS command as per TS 102 221 Section 11.1.2.""" - return self._tp.send_apdu_checksw(self.cla4lchan('80') + 'F20000ff') + return self.send_apdu_checksw(self.cla4lchan('80') + 'F20000ff') def deactivate_file(self) -> ResTuple: """Execute DECATIVATE FILE command as per TS 102 221 Section 11.1.14.""" - return self._tp.send_apdu_constr_checksw(self.cla_byte, '04', '00', '00', None, None, None) + return self.send_apdu_constr_checksw(self.cla_byte, '04', '00', '00', None, None, None) def activate_file(self, fid: Hexstr) -> ResTuple: """Execute ACTIVATE FILE command as per TS 102 221 Section 11.1.15. @@ -537,31 +611,31 @@ Args: fid : file identifier as hex string """ - return self._tp.send_apdu_checksw(self.cla_byte + '44000002' + fid) + return self.send_apdu_checksw(self.cla_byte + '44000002' + fid) def create_file(self, payload: Hexstr) -> ResTuple: """Execute CREEATE FILE command as per TS 102 222 Section 6.3""" - return self._tp.send_apdu_checksw(self.cla_byte + 'e00000%02x%s' % (len(payload)//2, payload)) + return self.send_apdu_checksw(self.cla_byte + 'e00000%02x%s' % (len(payload)//2, payload)) def resize_file(self, payload: Hexstr) -> ResTuple: """Execute RESIZE FILE command as per TS 102 222 Section 6.10""" - return self._tp.send_apdu_checksw(self.cla4lchan('80') + 'd40000%02x%s' % (len(payload)//2, payload)) + return self.send_apdu_checksw(self.cla4lchan('80') + 'd40000%02x%s' % (len(payload)//2, payload)) def delete_file(self, fid: Hexstr) -> ResTuple: """Execute DELETE FILE command as per TS 102 222 Section 6.4""" - return self._tp.send_apdu_checksw(self.cla_byte + 'e4000002' + fid) + return self.send_apdu_checksw(self.cla_byte + 'e4000002' + fid) def terminate_df(self, fid: Hexstr) -> ResTuple: """Execute TERMINATE DF command as per TS 102 222 Section 6.7""" - return self._tp.send_apdu_checksw(self.cla_byte + 'e6000002' + fid) + return self.send_apdu_checksw(self.cla_byte + 'e6000002' + fid) def terminate_ef(self, fid: Hexstr) -> ResTuple: """Execute TERMINATE EF command as per TS 102 222 Section 6.8""" - return self._tp.send_apdu_checksw(self.cla_byte + 'e8000002' + fid) + return self.send_apdu_checksw(self.cla_byte + 'e8000002' + fid) def terminate_card_usage(self) -> ResTuple: """Execute TERMINATE CARD USAGE command as per TS 102 222 Section 6.9""" - return self._tp.send_apdu_checksw(self.cla_byte + 'fe000000') + return self.send_apdu_checksw(self.cla_byte + 'fe000000') def manage_channel(self, mode: str = 'open', lchan_nr: int =0) -> ResTuple: """Execute MANAGE CHANNEL command as per TS 102 221 Section 11.1.17. @@ -575,7 +649,7 @@ else: p1 = 0x00 pdu = self.cla_byte + '70%02x%02x00' % (p1, lchan_nr) - return self._tp.send_apdu_checksw(pdu) + return self.send_apdu_checksw(pdu) def reset_card(self) -> Hexstr: """Physically reset the card""" @@ -596,8 +670,7 @@ code : chv code as hex string """ fc = rpad(b2h(code), 16) - data, sw = self._tp.send_apdu( - self.cla_byte + '2000' + ('%02X' % chv_no) + '08' + fc) + data, sw = self.send_apdu(self.cla_byte + '2000' + ('%02X' % chv_no) + '08' + fc) self._chv_process_sw('verify', chv_no, code, sw) return (data, sw) @@ -610,8 +683,7 @@ pin_code : new chv code as hex string """ fc = rpad(b2h(puk_code), 16) + rpad(b2h(pin_code), 16) - data, sw = self._tp.send_apdu( - self.cla_byte + '2C00' + ('%02X' % chv_no) + '10' + fc) + data, sw = self.send_apdu(self.cla_byte + '2C00' + ('%02X' % chv_no) + '10' + fc) self._chv_process_sw('unblock', chv_no, pin_code, sw) return (data, sw) @@ -624,8 +696,7 @@ new_pin_code : new chv code as hex string """ fc = rpad(b2h(pin_code), 16) + rpad(b2h(new_pin_code), 16) - data, sw = self._tp.send_apdu( - self.cla_byte + '2400' + ('%02X' % chv_no) + '10' + fc) + data, sw = self.send_apdu(self.cla_byte + '2400' + ('%02X' % chv_no) + '10' + fc) self._chv_process_sw('change', chv_no, pin_code, sw) return (data, sw) @@ -638,8 +709,7 @@ new_pin_code : new chv code as hex string """ fc = rpad(b2h(pin_code), 16) - data, sw = self._tp.send_apdu( - self.cla_byte + '2600' + ('%02X' % chv_no) + '08' + fc) + data, sw = self.send_apdu(self.cla_byte + '2600' + ('%02X' % chv_no) + '08' + fc) self._chv_process_sw('disable', chv_no, pin_code, sw) return (data, sw) @@ -651,8 +721,7 @@ pin_code : chv code as hex string """ fc = rpad(b2h(pin_code), 16) - data, sw = self._tp.send_apdu( - self.cla_byte + '2800' + ('%02X' % chv_no) + '08' + fc) + data, sw = self.send_apdu(self.cla_byte + '2800' + ('%02X' % chv_no) + '08' + fc) self._chv_process_sw('enable', chv_no, pin_code, sw) return (data, sw) @@ -662,7 +731,7 @@ Args: payload : payload as hex string """ - return self._tp.send_apdu_checksw('80c20000%02x%s' % (len(payload)//2, payload)) + return self.send_apdu_checksw('80c20000%02x%s' % (len(payload)//2, payload)) def terminal_profile(self, payload: Hexstr) -> ResTuple: """Send TERMINAL PROFILE to card @@ -671,7 +740,7 @@ payload : payload as hex string """ data_length = len(payload) // 2 - data, sw = self._tp.send_apdu(('80100000%02x' % data_length) + payload) + data, sw = self.send_apdu(('80100000%02x' % data_length) + payload) return (data, sw) # ETSI TS 102 221 11.1.22 @@ -711,8 +780,7 @@ raise ValueError('Time unit must be 0x00..0x04') min_dur_enc = encode_duration(min_len_secs) max_dur_enc = encode_duration(max_len_secs) - data, sw = self._tp.send_apdu_checksw( - '8076000004' + min_dur_enc + max_dur_enc) + data, sw = self.send_apdu_checksw('8076000004' + min_dur_enc + max_dur_enc) negotiated_duration_secs = decode_duration(data[:4]) resume_token = data[4:] return (negotiated_duration_secs, resume_token, sw) @@ -722,14 +790,14 @@ """Send SUSPEND UICC (resume) to the card.""" if len(h2b(token)) != 8: raise ValueError("Token must be 8 bytes long") - data, sw = self._tp.send_apdu_checksw('8076010008' + token) + data, sw = self.send_apdu_checksw('8076010008' + token) return (data, sw) def get_data(self, tag: int, cla: int = 0x00): - data, sw = self._tp.send_apdu('%02xca%04x00' % (cla, tag)) + data, sw = self.send_apdu('%02xca%04x00' % (cla, tag)) return (data, sw) # TS 31.102 Section 7.5.2 def get_identity(self, context: int) -> Tuple[Hexstr, SwHexstr]: - data, sw = self._tp.send_apdu_checksw('807800%02x00' % (context)) + data, sw = self.send_apdu_checksw('807800%02x00' % (context)) return (data, sw) diff --git a/pySim/euicc.py b/pySim/euicc.py index e249f4f..068fb72 100644 --- a/pySim/euicc.py +++ b/pySim/euicc.py @@ -319,7 +319,7 @@ """Perform STORE DATA according to Table 47+48 in Section 5.7.2 of SGP.22. Only single-block store supported for now.""" capdu = '%sE29100%02x%s' % (scc.cla4lchan('80'), len(tx_do)//2, tx_do) - return scc._tp.send_apdu_checksw(capdu) + return scc.send_apdu_checksw(capdu) @staticmethod def store_data_tlv(scc: SimCardCommands, cmd_do, resp_cls, exp_sw='9000'): diff --git a/pySim/global_platform.py b/pySim/global_platform.py index 347399b..6793f71 100644 --- a/pySim/global_platform.py +++ b/pySim/global_platform.py @@ -495,7 +495,7 @@ {'last_block': len(remainder) == 0, 'encryption': encryption, 'structure': structure, 'response': response_permitted}) hdr = "80E2%02x%02x%02x" % (p1b[0], block_nr, len(chunk)) - data, sw = self._cmd.lchan.scc._tp.send_apdu_checksw(hdr + b2h(chunk)) + data, sw = self._cmd.lchan.scc.send_apdu_checksw(hdr + b2h(chunk)) block_nr += 1 response += data return data @@ -532,7 +532,7 @@ else: kcv = '' kdb.append({'key_type': opts.key_type[i], 'kcb': opts.key_data[i], 'kcv': kcv}) - return self.put_key(opts.old_key_version_nr, opts.key_version_nr, opts.key_id, kdb) + self.put_key(opts.old_key_version_nr, opts.key_version_nr, opts.key_id, kdb) # Table 11-68: Key Data Field - Format 1 (Basic Format) KeyDataBasic = GreedyRange(Struct('key_type'/KeyType, @@ -544,7 +544,7 @@ See GlobalPlatform CardSpecification v2.3 Section 11.8 for details.""" key_data = kvn.to_bytes(1, 'big') + build_construct(ADF_SD.AddlShellCommands.KeyDataBasic, key_dict) hdr = "80D8%02x%02x%02x" % (old_kvn, kid, len(key_data)) - data, sw = self._cmd.lchan.scc._tp.send_apdu_checksw(hdr + b2h(key_data)) + data, sw = self._cmd.lchan.scc.send_apdu_checksw(hdr + b2h(key_data)) return data get_status_parser = argparse.ArgumentParser() @@ -569,7 +569,7 @@ grd_list = [] while True: hdr = "80F2%s%02x%02x" % (subset_hex, p2, len(cmd_data)) - data, sw = self._cmd.lchan.scc._tp.send_apdu(hdr + b2h(cmd_data)) + data, sw = self._cmd.lchan.scc.send_apdu(hdr + b2h(cmd_data)) remainder = h2b(data) while len(remainder): # tlv sequence, each element is one GpRegistryRelatedData() diff --git a/pySim/legacy/cards.py b/pySim/legacy/cards.py index 9d1e2c1..5e64e95 100644 --- a/pySim/legacy/cards.py +++ b/pySim/legacy/cards.py @@ -753,7 +753,7 @@ # Set the Ki using proprietary command pdu = '80d4020010' + p['ki'] - data, sw = self._scc._tp.send_apdu(pdu) + data, sw = self._scc.send_apdu(pdu) # EF.HPLMN r = self._scc.select_path(['3f00', '7f20', '6f30']) @@ -803,7 +803,7 @@ # TODO: check if verify_chv could be used or what it needs # self._scc.verify_chv(0x0A, [0x33,0x32,0x32,0x31,0x33,0x32,0x33,0x32]) # Unlock the card.. - data, sw = self._scc._tp.send_apdu_checksw( + data, sw = self._scc.send_apdu_checksw( "0020000A083332323133323332") # TODO: move into SimCardCommands @@ -812,7 +812,7 @@ enc_iccid(p['iccid']) + # 10b ICCID enc_imsi(p['imsi']) # 9b IMSI_len + id_type(9) + IMSI ) - data, sw = self._scc._tp.send_apdu_checksw("0099000033" + par) + data, sw = self._scc.send_apdu_checksw("0099000033" + par) class SysmoSIMgr2(SimCard): @@ -851,7 +851,7 @@ pin = h2b("4444444444444444") pdu = 'A0D43A0508' + b2h(pin) - data, sw = self._scc._tp.send_apdu(pdu) + data, sw = self._scc.send_apdu(pdu) # authenticate as ADM (enough to write file, and can set PINs) diff --git a/pySim/transport/__init__.py b/pySim/transport/__init__.py index 59d4554..dcecfdd 100644 --- a/pySim/transport/__init__.py +++ b/pySim/transport/__init__.py @@ -10,7 +10,6 @@ from construct import Construct from pySim.exceptions import * -from pySim.construct import filter_dict from pySim.utils import sw_match, b2h, h2b, i2h, Hexstr, SwHexstr, SwMatchstr, ResTuple from pySim.cat import ProactiveCommand, CommandDetails, DeviceIdentities, Result @@ -219,56 +218,6 @@ raise SwMatchError(rv[1], sw.lower(), self.sw_interpreter) return rv - def send_apdu_constr(self, cla: Hexstr, ins: Hexstr, p1: Hexstr, p2: Hexstr, cmd_constr: Construct, - cmd_data: Hexstr, resp_constr: Construct) -> Tuple[dict, SwHexstr]: - """Build and sends an APDU using a 'construct' definition; parses response. - - Args: - cla : string (in hex) ISO 7816 class byte - ins : string (in hex) ISO 7816 instruction byte - p1 : string (in hex) ISO 7116 Parameter 1 byte - 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 - Returns: - Tuple of (decoded_data, sw) - """ - cmd = cmd_constr.build(cmd_data) if cmd_data else '' - p3 = i2h([len(cmd)]) - pdu = ''.join([cla, ins, p1, p2, p3, b2h(cmd)]) - (data, sw) = self.send_apdu(pdu) - if data: - # filter the resulting dict to avoid '_io' members inside - rsp = filter_dict(resp_constr.parse(h2b(data))) - else: - rsp = None - return (rsp, sw) - - def send_apdu_constr_checksw(self, cla: Hexstr, ins: Hexstr, p1: Hexstr, p2: Hexstr, - cmd_constr: Construct, cmd_data: Hexstr, resp_constr: Construct, - sw_exp: SwMatchstr="9000") -> Tuple[dict, SwHexstr]: - """Build and sends an APDU using a 'construct' definition; parses response. - - Args: - cla : string (in hex) ISO 7816 class byte - ins : string (in hex) ISO 7816 instruction byte - p1 : string (in hex) ISO 7116 Parameter 1 byte - 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 - exp_sw : string (in hex) of status word (ex. "9000") - Returns: - Tuple of (decoded_data, sw) - """ - (rsp, sw) = self.send_apdu_constr(cla, ins, - p1, p2, cmd_constr, cmd_data, resp_constr) - if not sw_match(sw, sw_exp): - raise SwMatchError(sw, sw_exp.lower(), self.sw_interpreter) - return (rsp, sw) - - def argparse_add_reader_args(arg_parser: argparse.ArgumentParser): """Add all reader related arguments to the given argparse.Argumentparser instance.""" from pySim.transport.serial import SerialSimLink -- To view, visit https://gerrit.osmocom.org/c/pysim/+/35762?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: I1b870140959aa8241cda2246e74576390123cb2d Gerrit-Change-Number: 35762 Gerrit-PatchSet: 3 Gerrit-Owner: laforge <laforge(a)osmocom.org> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: dexter <pmaier(a)sysmocom.de> Gerrit-Reviewer: fixeria <vyanitskiy(a)sysmocom.de> Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-MessageType: merged
1 0
0 0
[S] Change in pysim[master]: move global_platform.py to global_platform/__init__.py
by laforge 02 Feb '24

02 Feb '24
Attention is currently required from: dexter, fixeria. laforge has posted comments on this change. ( https://gerrit.osmocom.org/c/pysim/+/35763?usp=email ) Change subject: move global_platform.py to global_platform/__init__.py ...................................................................... Patch Set 3: Code-Review+2 -- To view, visit https://gerrit.osmocom.org/c/pysim/+/35763?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: Ieca0b20c26a2e41eb11455941164474b76eb3c7a Gerrit-Change-Number: 35763 Gerrit-PatchSet: 3 Gerrit-Owner: laforge <laforge(a)osmocom.org> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: dexter <pmaier(a)sysmocom.de> Gerrit-Reviewer: fixeria <vyanitskiy(a)sysmocom.de> Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-Attention: fixeria <vyanitskiy(a)sysmocom.de> Gerrit-Attention: dexter <pmaier(a)sysmocom.de> Gerrit-Comment-Date: Fri, 02 Feb 2024 22:16:59 +0000 Gerrit-HasComments: No Gerrit-Has-Labels: Yes Gerrit-MessageType: comment
1 0
0 0
[M] Change in pysim[master]: commands.py: Wrap the transport send_apdu* methods
by laforge 02 Feb '24

02 Feb '24
Attention is currently required from: dexter, fixeria. laforge has posted comments on this change. ( https://gerrit.osmocom.org/c/pysim/+/35762?usp=email ) Change subject: commands.py: Wrap the transport send_apdu* methods ...................................................................... Patch Set 3: Code-Review+2 -- To view, visit https://gerrit.osmocom.org/c/pysim/+/35762?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: I1b870140959aa8241cda2246e74576390123cb2d Gerrit-Change-Number: 35762 Gerrit-PatchSet: 3 Gerrit-Owner: laforge <laforge(a)osmocom.org> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: dexter <pmaier(a)sysmocom.de> Gerrit-Reviewer: fixeria <vyanitskiy(a)sysmocom.de> Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-Attention: fixeria <vyanitskiy(a)sysmocom.de> Gerrit-Attention: dexter <pmaier(a)sysmocom.de> Gerrit-Comment-Date: Fri, 02 Feb 2024 22:16:51 +0000 Gerrit-HasComments: No Gerrit-Has-Labels: Yes Gerrit-MessageType: comment
1 0
0 0
[M] Change in pysim[master]: global_platform: implement GET STATUS command
by laforge 02 Feb '24

02 Feb '24
Attention is currently required from: dexter, fixeria. laforge has posted comments on this change. ( https://gerrit.osmocom.org/c/pysim/+/35756?usp=email ) Change subject: global_platform: implement GET STATUS command ...................................................................... Patch Set 2: Code-Review+2 -- To view, visit https://gerrit.osmocom.org/c/pysim/+/35756?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: Ic92f96c1c6a569aebc93a906c62a43b86fe3b811 Gerrit-Change-Number: 35756 Gerrit-PatchSet: 2 Gerrit-Owner: laforge <laforge(a)osmocom.org> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: dexter <pmaier(a)sysmocom.de> Gerrit-Reviewer: fixeria <vyanitskiy(a)sysmocom.de> Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-Attention: fixeria <vyanitskiy(a)sysmocom.de> Gerrit-Attention: dexter <pmaier(a)sysmocom.de> Gerrit-Comment-Date: Fri, 02 Feb 2024 22:16:42 +0000 Gerrit-HasComments: No Gerrit-Has-Labels: Yes Gerrit-MessageType: comment
1 0
0 0
[S] Change in pysim[master]: global_platform: Add install_for_personalization command
by laforge 02 Feb '24

02 Feb '24
Attention is currently required from: laforge. Hello Jenkins Builder, I'd like you to reexamine a change. Please visit https://gerrit.osmocom.org/c/pysim/+/35771?usp=email to look at the new patch set (#4). The following approvals got outdated and were removed: Verified-1 by Jenkins Builder Change subject: global_platform: Add install_for_personalization command ...................................................................... global_platform: Add install_for_personalization command This allows us to perform STORE DATA on applications like ARA-M/ARA-D after establishing SCP02 to the related security domain. Change-Id: I2ce766b97bba42c64c4d4492b505be66c24f471e --- M docs/shell.rst M pySim/global_platform/__init__.py 2 files changed, 32 insertions(+), 0 deletions(-) git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/71/35771/4 -- To view, visit https://gerrit.osmocom.org/c/pysim/+/35771?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: I2ce766b97bba42c64c4d4492b505be66c24f471e Gerrit-Change-Number: 35771 Gerrit-PatchSet: 4 Gerrit-Owner: laforge <laforge(a)osmocom.org> Gerrit-Reviewer: Jenkins Builder Gerrit-Attention: laforge <laforge(a)osmocom.org> Gerrit-MessageType: newpatchset
1 0
0 0
  • ← Newer
  • 1
  • ...
  • 163
  • 164
  • 165
  • 166
  • 167
  • 168
  • 169
  • ...
  • 175
  • Older →

HyperKitty Powered by HyperKitty version 1.3.12.