|
30 | 30 | from pySim.utils import ResTuple
|
31 | 31 | from pySim.card_key_provider import card_key_provider_get_field
|
32 | 32 | from pySim.global_platform.scp import SCP02, SCP03
|
| 33 | +from pySim.global_platform.install_param import gen_install_parameters |
33 | 34 | from pySim.filesystem import *
|
34 | 35 | from pySim.profile import CardProfile
|
35 | 36 | from pySim.ota import SimFileAccessAndToolkitAppSpecParams
|
@@ -858,6 +859,58 @@ def load(self, contents:bytes, chunk_len:int = 240):
|
858 | 859 | _rsp_hex, _sw = self._cmd.lchan.scc.send_apdu_checksw(cmd_hex)
|
859 | 860 | self._cmd.poutput("Loaded a total of %u bytes in %u blocks. Don't forget install_for_install (and make selectable) now!" % (total_size, block_nr))
|
860 | 861 |
|
| 862 | + install_cap_parser = argparse.ArgumentParser() |
| 863 | + install_cap_parser.add_argument('cap_file', type=str, metavar='FILE', |
| 864 | + help='JAVA-CARD CAP file to install') |
| 865 | + install_cap_parser_inst_prm_g = install_cap_parser.add_mutually_exclusive_group() |
| 866 | + install_cap_parser_inst_prm_g.add_argument('--install-parameters', type=is_hexstr, default=None, |
| 867 | + help='install Parameters (GPC_SPE_034, section 11.5.2.3.7, table 11-49)') |
| 868 | + install_cap_parser_inst_prm_g_grp = install_cap_parser_inst_prm_g.add_argument_group() |
| 869 | + install_cap_parser_inst_prm_g_grp.add_argument('--install-parameters-volatile-memory-quota', |
| 870 | + type=int, default=None, |
| 871 | + help='volatile memory quota (GPC_SPE_034, section 11.5.2.3.7, table 11-49)') |
| 872 | + install_cap_parser_inst_prm_g_grp.add_argument('--install-parameters-non-volatile-memory-quota', |
| 873 | + type=int, default=None, |
| 874 | + help='non volatile memory quota (GPC_SPE_034, section 11.5.2.3.7, table 11-49)') |
| 875 | + install_cap_parser_inst_prm_g_grp.add_argument('--install-parameters-stk', |
| 876 | + type=is_hexstr, default=None, |
| 877 | + help='Load Parameters (ETSI TS 102 226, section 8.2.1.3.2.1)') |
| 878 | + |
| 879 | + @cmd2.with_argparser(install_cap_parser) |
| 880 | + def do_install_cap(self, opts): |
| 881 | + """Perform a .cap file installation using GlobalPlatform LOAD and INSTALL commands.""" |
| 882 | + |
| 883 | + self._cmd.poutput("loading cap file: %s ..." % opts.cap_file) |
| 884 | + cap = CapFile(opts.cap_file) |
| 885 | + |
| 886 | + security_domain_aid = self._cmd.lchan.selected_file.aid |
| 887 | + load_file = cap.get_loadfile() |
| 888 | + load_file_aid = cap.get_loadfile_aid() |
| 889 | + module_aid = cap.get_applet_aid() |
| 890 | + application_aid = module_aid |
| 891 | + if opts.install_parameters: |
| 892 | + install_parameters = opts.install_parameters; |
| 893 | + else: |
| 894 | + install_parameters = gen_install_parameters(opts.install_parameters_non_volatile_memory_quota, |
| 895 | + opts.install_parameters_volatile_memory_quota, |
| 896 | + opts.install_parameters_stk) |
| 897 | + self._cmd.poutput("parameters:") |
| 898 | + self._cmd.poutput(" security-domain-aid: %s" % security_domain_aid) |
| 899 | + self._cmd.poutput(" load-file: %u bytes" % len(load_file)) |
| 900 | + self._cmd.poutput(" load-file-aid: %s" % load_file_aid) |
| 901 | + self._cmd.poutput(" module-aid: %s" % module_aid) |
| 902 | + self._cmd.poutput(" application-aid: %s" % application_aid) |
| 903 | + self._cmd.poutput(" install-parameters: %s" % install_parameters) |
| 904 | + |
| 905 | + self._cmd.poutput("step #1: install for load...") |
| 906 | + self.do_install_for_load("--load-file-aid %s --security-domain-aid %s" % (load_file_aid, security_domain_aid)) |
| 907 | + self._cmd.poutput("step #2: load...") |
| 908 | + self.load(load_file) |
| 909 | + self._cmd.poutput("step #3: install_for_install (and make selectable)...") |
| 910 | + self.do_install_for_install("--load-file-aid %s --module-aid %s --application-aid %s --install-parameters %s --make-selectable" % |
| 911 | + (load_file_aid, module_aid, application_aid, install_parameters)) |
| 912 | + self._cmd.poutput("done.") |
| 913 | + |
861 | 914 | est_scp02_parser = argparse.ArgumentParser()
|
862 | 915 | est_scp02_parser.add_argument('--key-ver', type=auto_uint8, default=0, help='Key Version Number (KVN)')
|
863 | 916 | est_scp02_parser.add_argument('--host-challenge', type=is_hexstr,
|
|
0 commit comments