pySim.apdu.global_platform: Decode the INSTALL command parameters
Change-Id: I1c323c1cb1be504c6ad5b7efb0fa85d87eaa8cf7
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
# coding=utf-8
|
||||
"""APDU definition/decoder of GlobalPLatform Card Spec (currently 2.1.1)
|
||||
|
||||
(C) 2022 by Harald Welte <laforge@osmocom.org>
|
||||
(C) 2022-2024 by Harald Welte <laforge@osmocom.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
|
||||
@@ -17,7 +17,11 @@ You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
"""
|
||||
|
||||
from construct import FlagsEnum, Struct
|
||||
from pySim.tlv import flatten_dict_lists
|
||||
from pySim.apdu import ApduCommand, ApduCommandSet
|
||||
from pySim.construct import *
|
||||
from pySim.global_platform import InstallParameters
|
||||
|
||||
class GpDelete(ApduCommand, n='DELETE', ins=0xE4, cla=['8X', 'CX', 'EX']):
|
||||
_apdu_case = 4
|
||||
@@ -40,8 +44,29 @@ class GpGetDataCB(ApduCommand, n='GET DATA', ins=0xCB, cla=['8X', 'CX', 'EX']):
|
||||
class GpGetStatus(ApduCommand, n='GET STATUS', ins=0xF2, cla=['8X', 'CX', 'EX']):
|
||||
_apdu_case = 4
|
||||
|
||||
# GPCS Section 11.5.2
|
||||
class GpInstall(ApduCommand, n='INSTALL', ins=0xE6, cla=['8X', 'CX', 'EX']):
|
||||
_apdu_case = 4
|
||||
_construct_p1 = FlagsEnum(Byte, more_commands=0x80, for_registry_update=0x40,
|
||||
for_personalization=0x20, for_extradition=0x10,
|
||||
for_make_selectable=0x08, for_install=0x04, for_load=0x02)
|
||||
_construct_p2 = Enum(Byte, no_info_provided=0x00, beginning_of_combined=0x01,
|
||||
end_of_combined=0x03)
|
||||
_construct = Struct('load_file_aid'/Prefixed(Int8ub, GreedyBytes),
|
||||
'module_aid'/Prefixed(Int8ub, GreedyBytes),
|
||||
'application_aid'/Prefixed(Int8ub, GreedyBytes),
|
||||
'privileges'/Prefixed(Int8ub, GreedyBytes),
|
||||
'install_parameters'/Prefixed(Int8ub, GreedyBytes), # TODO: InstallParameters
|
||||
'install_token'/Prefixed(Int8ub, GreedyBytes))
|
||||
def _decode_cmd(self):
|
||||
# first use _construct* above
|
||||
res = self._cmd_to_dict()
|
||||
# then do TLV decode of install_parameters
|
||||
ip = InstallParameters()
|
||||
ip.from_tlv(res['body']['install_parameters'])
|
||||
res['body']['install_parameters'] = flatten_dict_lists(ip.to_dict())
|
||||
return res
|
||||
|
||||
|
||||
class GpLoad(ApduCommand, n='LOAD', ins=0xE8, cla=['8X', 'CX', 'EX']):
|
||||
_apdu_case = 4
|
||||
|
||||
@@ -30,6 +30,80 @@ from pySim.utils import *
|
||||
from pySim.filesystem import *
|
||||
from pySim.tlv import *
|
||||
from pySim.profile import CardProfile
|
||||
from pySim.ota import SimFileAccessAndToolkitAppSpecParams
|
||||
|
||||
# GPCS Table 11-48 Load Parameter Tags
|
||||
class NonVolatileCodeMinMemoryReq(BER_TLV_IE, tag=0xC6):
|
||||
_construct = GreedyInteger()
|
||||
|
||||
# GPCS Table 11-48 Load Parameter Tags
|
||||
class VolatileMinMemoryReq(BER_TLV_IE, tag=0xC7):
|
||||
_construct = GreedyInteger()
|
||||
|
||||
# GPCS Table 11-48 Load Parameter Tags
|
||||
class NonVolatileDataMinMemoryReq(BER_TLV_IE, tag=0xC8):
|
||||
_construct = GreedyInteger()
|
||||
|
||||
# GPCS Table 11-49: Install Parameter Tags
|
||||
class GlobalServiceParams(BER_TLV_IE, tag=0xCB):
|
||||
pass
|
||||
|
||||
# GPCS Table 11-49: Install Parameter Tags
|
||||
class VolatileReservedMemory(BER_TLV_IE, tag=0xD7):
|
||||
_construct = GreedyInteger()
|
||||
|
||||
# GPCS Table 11-49: Install Parameter Tags
|
||||
class NonVolatileReservedMemory(BER_TLV_IE, tag=0xD8):
|
||||
_construct = GreedyInteger()
|
||||
|
||||
# GPCS Table 11-49: Install Parameter Tags
|
||||
class Ts102226SpecificParameter(BER_TLV_IE, tag=0xCA):
|
||||
_construct = SimFileAccessAndToolkitAppSpecParams
|
||||
|
||||
# GPCS Table 11-48 Load Parameter Tags
|
||||
class LoadFileDataBlockFormatId(BER_TLV_IE, tag=0xCD):
|
||||
pass
|
||||
|
||||
# GPCS Table 11-50: Make Selectable Parameter Tags
|
||||
class ImplicitSelectionParam(BER_TLV_IE, tag=0xCF):
|
||||
pass
|
||||
|
||||
# GPCS Table 11-48 Load Parameter Tags
|
||||
class LoadFileDtaBlockParameters(BER_TLV_IE, tag=0xDD):
|
||||
pass
|
||||
|
||||
# GPCS Table 11-48 Load Parameter Tags / 11-49: Install Parameter Tags
|
||||
class SystemSpecificParams(BER_TLV_IE, tag=0xEF,
|
||||
nested=[NonVolatileCodeMinMemoryReq,
|
||||
VolatileMinMemoryReq,
|
||||
NonVolatileDataMinMemoryReq,
|
||||
GlobalServiceParams,
|
||||
VolatileReservedMemory,
|
||||
NonVolatileReservedMemory,
|
||||
Ts102226SpecificParameter,
|
||||
LoadFileDataBlockFormatId,
|
||||
ImplicitSelectionParam,
|
||||
LoadFileDtaBlockParameters]):
|
||||
pass
|
||||
|
||||
# GPCS Table 11-49: Install Parameter Tags
|
||||
class ApplicationSpecificParams(BER_TLV_IE, tag=0xC9):
|
||||
_construct = GreedyBytes
|
||||
|
||||
class Ts102226SpecificTemplate(BER_TLV_IE, tag=0xEA):
|
||||
pass
|
||||
|
||||
class CrtForDigitalSignature(BER_TLV_IE, tag=0xB6):
|
||||
# FIXME: nested
|
||||
pass
|
||||
|
||||
|
||||
class InstallParameters(TLV_IE_Collection, nested=[ApplicationSpecificParams,
|
||||
SystemSpecificParams,
|
||||
Ts102226SpecificTemplate,
|
||||
CrtForDigitalSignature]):
|
||||
pass
|
||||
|
||||
|
||||
sw_table = {
|
||||
'Warnings': {
|
||||
|
||||
Reference in New Issue
Block a user