[M] Change in onomondo-ipa[master]: Add option to forbid polling given eIM(s)
jolly has submitted this change. ( https://gerrit.osmocom.org/c/onomondo-ipa/+/43705?usp=email ) Change subject: Add option to forbid polling given eIM(s) ...................................................................... Add option to forbid polling given eIM(s) An eUICC may have eIM configuration data of one or more eIMs that cannot be removed. Prevent polling theses eIMs by adding an option that blocks one or multiple eIM IDs. Prevent redundant reading of eIM configuration data for every iteration of the loop that runs through all eIMs and that skips forbidden eIMs. Therefore move ipa_es10b_get_eim_cfg_data (and ipa_es10b_get_eim_cfg_data_free) outside that loop. Related: SYS#8101 Change-Id: Ic6489207e54cdfff57cd214482ac4a071e154c94 --- M include/onomondo/ipa/ipad.h M src/ipa/libipa/ipad.c M src/ipa/main.c 3 files changed, 48 insertions(+), 21 deletions(-) Approvals: dexter: Looks good to me, approved Jenkins Builder: Verified diff --git a/include/onomondo/ipa/ipad.h b/include/onomondo/ipa/ipad.h index af8de91..4aecb65 100644 --- a/include/onomondo/ipa/ipad.h +++ b/include/onomondo/ipa/ipad.h @@ -12,6 +12,7 @@ #define IPA_LEN_TAC 4 #define IPA_LEN_ALLOWED_CA 20 #define IPE_LEN_EIM_ID 256 +#define IPA_MAX_FORBIDDEN_IDS 5 struct ipa_context; struct ipa_buf; @@ -45,6 +46,8 @@ * used.) */ char *preferred_eim_id; + char *forbidden_eim_ids[IPA_MAX_FORBIDDEN_IDS]; + /*! force the IPAd to process only one eUICC package (debug, use with caution) */ bool one_euicc_pkg_only; diff --git a/src/ipa/libipa/ipad.c b/src/ipa/libipa/ipad.c index fa91961..7427884 100644 --- a/src/ipa/libipa/ipad.c +++ b/src/ipa/libipa/ipad.c @@ -354,31 +354,34 @@ return -EINVAL; } -static int eim_init(struct ipa_context *ctx, int index) +static int eim_init(struct ipa_context *ctx, struct ipa_es10b_eim_cfg_data *eim_cfg_data, int index) { - struct ipa_es10b_eim_cfg_data *eim_cfg_data = NULL; struct EimConfigurationData *eim_cfg_data_item = NULL; - int rc = -EINVAL; - - eim_cfg_data = ipa_es10b_get_eim_cfg_data(ctx); - if (!eim_cfg_data) { - IPA_LOGP(SIPA, LERROR, "cannot read EimConfigurationData from eUICC\n"); - goto error; - } + int rc; /* In case no preferred_eim_id is set, the eIM configuration item of the given index will be pulled from the list */ rc = ipa_es10b_get_eim_cfg_data_filter(&eim_cfg_data_item, eim_cfg_data, ctx->cfg->preferred_eim_id, index); if (rc) { if (rc != -ENOENT) IPA_LOGP(SIPA, LERROR, "no suitable EimConfigurationData item present.\n"); - goto error; + return rc; + } + /* Skip blocked eIM IDs. Return -EACCES in this case. */ + if (!ctx->cfg->preferred_eim_id || ctx->cfg->preferred_eim_id[0] == '\0') { + int i; + const char *eim_id; + + for (i = 0; (eim_id = ctx->cfg->forbidden_eim_ids[i]) && i < IPA_MAX_FORBIDDEN_IDS; i++) { + if (IPA_ASN_STR_CMP_BUF(&eim_cfg_data_item->eimId, eim_id, strlen(eim_id))) + return -EACCES; + } } IPA_FREE(ctx->eim_id); ctx->eim_id = IPA_STR_FROM_ASN(&eim_cfg_data_item->eimId); if (!ctx->eim_id) { IPA_LOGP(SIPA, LERROR, "unable to allocate memory\n"); - goto error; + return -ENOMEM; } IPA_FREE(ctx->eim_fqdn); @@ -386,13 +389,10 @@ ctx->eim_fqdn = IPA_STR_FROM_ASN(eim_cfg_data_item->eimFqdn); } else { IPA_LOGP(SIPA, LERROR, "unable to allocate memory\n"); - goto error; + return -ENOMEM; } - rc = 0; -error: - ipa_es10b_get_eim_cfg_data_free(eim_cfg_data); - return rc; + return 0; } static int ipa_poll_eim_package(struct ipa_context *ctx) @@ -499,35 +499,49 @@ * \returns positive on success or when polling all eIMs, negative on error (see also enum ipa_poll_rc). */ int ipa_poll(struct ipa_context *ctx) { + struct ipa_es10b_eim_cfg_data *eim_cfg_data = NULL; int rc, index; ctx->poll_running = true; + eim_cfg_data = ipa_es10b_get_eim_cfg_data(ctx); + if (!eim_cfg_data) { + IPA_LOGP(SIPA, LERROR, "cannot read EimConfigurationData from eUICC\n"); + rc = -EIO; + goto error; + } + /* Loop through all eIM, if no preferred eIM ID is specified. */ for (index = 0; ; index++) { IPA_LOGP(SIPA, LINFO, "-----------------------------8<-----------------------------\n"); - rc = eim_init(ctx, index); + rc = eim_init(ctx, eim_cfg_data, index); if (rc < 0) { + if (rc == -EACCES) + continue; if (rc == -ENOENT) { IPA_LOGP(SIPA, LINFO, "all eIMs polled!\n"); + rc = 0; break; } IPA_LOGP(SIPA, LERROR, "eIM initialization failed!\n"); - return rc; + break; } rc = ipa_poll_eim(ctx, index); if (!ctx->poll_running) { IPA_LOGP(SIPA, LINFO, "polling aborted by user!\n"); + rc = 0; break; } if (ctx->cfg->preferred_eim_id) - return rc; + break; } - return 0; +error: + ipa_es10b_get_eim_cfg_data_free(eim_cfg_data); + return rc; } /*! abort IPAd polling (may be called from signal handler). */ diff --git a/src/ipa/main.c b/src/ipa/main.c index 183a584..a937e78 100644 --- a/src/ipa/main.c +++ b/src/ipa/main.c @@ -45,6 +45,7 @@ printf(" -h .......................... print this text.\n"); printf(" -t TAC ...................... set TAC (default: %s)\n", DEFAULT_TAC); printf(" -e eimId .................... set preferred eIM (in case the eUICC has multiple)\n"); + printf(" -f eimId .................... set forbidden eIMs (may call this option multiple times)\n"); printf(" -r N ........................ set reader number (default: %d)\n", DEFAULT_READER_NUMBER); printf(" -c N ........................ set logical channel number (default: %d)\n", DEFAULT_CHANNEL_NUMBER); printf(" -R .......................... Make eUICC send a CAT refresh after switching profile\n"); @@ -152,6 +153,7 @@ char *getopt_nvstate_path = DEFAULT_NVSTATE_PATH; struct ipa_buf *nvstate_load = NULL; struct ipa_buf *nvstate_save = NULL; + int forbidden_eim_index = 0; signal(SIGUSR1, sig_usr1); @@ -165,7 +167,7 @@ /* Overwrite configuration values with user defined parameters */ while (1) { - opt = getopt(argc, argv, "ht:e:r:c:Rn:C:SIEy:a1D:"); + opt = getopt(argc, argv, "ht:e:f:r:c:Rn:C:SIEy:a1D:"); if (opt == -1) break; @@ -180,6 +182,14 @@ case 'e': cfg.preferred_eim_id = optarg; break; + case 'f': + if (forbidden_eim_index < IPA_MAX_FORBIDDEN_IDS) { + cfg.forbidden_eim_ids[forbidden_eim_index++] = optarg; + break; + } + printf("Too many forbidden eIM IDs given!\n"); + opt = -1; + break; case 'r': cfg.reader_num = atoi(optarg); break; -- To view, visit https://gerrit.osmocom.org/c/onomondo-ipa/+/43705?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email Gerrit-MessageType: merged Gerrit-Project: onomondo-ipa Gerrit-Branch: master Gerrit-Change-Id: Ic6489207e54cdfff57cd214482ac4a071e154c94 Gerrit-Change-Number: 43705 Gerrit-PatchSet: 3 Gerrit-Owner: jolly <andreas@eversberg.eu> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: dexter <pmaier@sysmocom.de> Gerrit-Reviewer: jolly <andreas@eversberg.eu> Gerrit-CC: laforge <laforge@osmocom.org>
participants (1)
-
jolly