dexter has submitted this change. ( https://gerrit.osmocom.org/c/onomondo-ipa/+/43413?usp=email )
Change subject: main: load addInitialEimRequest from hex-file ......................................................................
main: load addInitialEimRequest from hex-file
We currently load the addInitialEimRequest binary blob from a binary file. Unfortunately this is very user-unfriendly since onomondo-eim generates the eimConfigurationData as hex string (REST API), which means the user has to convert this data into a binary file first.
Let's eliminate those extra conversion steps by changing the input format to a textfile containing a hex-string. Then users can simply copy+paste the hex string they got from onomdon-eim.
Related: SYS#8101 Change-Id: Ib2095e5042f42ce77af498831be9c8bd1af32401 --- M README.md D contrib/sample_eim_cfg.ber A contrib/sample_eim_cfg.txt M include/onomondo/ipa/utils.h M src/ipa/libipa/utils.c M src/ipa/main.c M tests/utils/utils_test.c 7 files changed, 84 insertions(+), 23 deletions(-)
Approvals: laforge: Looks good to me, but someone else must approve jolly: Looks good to me, but someone else must approve Jenkins Builder: Verified dexter: Looks good to me, approved
diff --git a/README.md b/README.md index 44d76ea..864c6b4 100644 --- a/README.md +++ b/README.md @@ -106,9 +106,9 @@
In case the IoT eUICC is not yet provisioned with an eIM configuration, onomondo-ipa can be used to perform the provisioning. The configuration must be supplied as a file that contains an AddInitialEimRequest (see also GSMA SGP.32, -section 5.9.18) data object in its encoded form. It is up to the user to compile the data object using appropriate tools -and the ASN specification presented in GSMA SGP.32. For testing purposes onomondo-ipa ships with a sample configuration -(contrib/sample_eim_cfg.ber) that expects the eIM to be running at 127.0.0.1:8000. +section 5.9.18) data object in its encoded form (as a hex-string). It is up to the user to compile the data object using +appropriate tools (e.g. onomondo-eim). For testing purposes onomondo-ipa ships with a sample configuration +(contrib/sample_eim_cfg.txt) which expects the eIM to be running at 127.0.0.1:8000.
Example: load the initial eIM configuration onto the eUICC in PCSC reader 2 ``` diff --git a/contrib/sample_eim_cfg.ber b/contrib/sample_eim_cfg.ber deleted file mode 100644 index 0c0d00f..0000000 --- a/contrib/sample_eim_cfg.ber +++ /dev/null Binary files differ diff --git a/contrib/sample_eim_cfg.txt b/contrib/sample_eim_cfg.txt new file mode 100644 index 0000000..af7d842 --- /dev/null +++ b/contrib/sample_eim_cfg.txt @@ -0,0 +1 @@ +BF578183A08180307E800365494D810E3132372E302E302E313A383030308301018401FFA55BA059301306072A8648CE3D020106082A8648CE3D03010703420004FE584A6F450459574AECA195D0299737F74C89BA2D36DF9286EC25D973037A0FBA70D14DF3E1F7D0A305E57B95B731C4DE218D2D7F9F22113ED5D18C2E3DDF1C870207808900 diff --git a/include/onomondo/ipa/utils.h b/include/onomondo/ipa/utils.h index 8b849dd..f35a5a9 100644 --- a/include/onomondo/ipa/utils.h +++ b/include/onomondo/ipa/utils.h @@ -38,6 +38,7 @@ __ptr; \ })
+struct ipa_buf *ipa_hexparse(char *hexstr); char *ipa_hexdump(const uint8_t *data, size_t len);
struct ipa_buf { diff --git a/src/ipa/libipa/utils.c b/src/ipa/libipa/utils.c index 4017e3b..7520018 100644 --- a/src/ipa/libipa/utils.c +++ b/src/ipa/libipa/utils.c @@ -34,6 +34,42 @@ return def; }
+/*! Decode a human readable hexstring to binary. + * \param[in] hexstr pointer to hexstring. + * \returns pointer to ipa_buf containing the decoded binary data. */ +struct ipa_buf *ipa_hexparse(char *hexstr) +{ + struct ipa_buf *bin = NULL; + size_t i; + uint8_t byte; + int digit; + int digit_counter = 0; + size_t hexstr_len = strlen(hexstr); + + bin = ipa_buf_alloc(hexstr_len / 2); + for (i = 0; i < hexstr_len; i++) { + digit = -1; + if (*hexstr >= 0x30 && *hexstr <= 0x39) + digit = *hexstr & 0x0F; + else if (*hexstr >= 0x41 && *hexstr <= 0x46) + digit = (*hexstr & 0x0F) + 9; + else if (*hexstr >= 0x61 && *hexstr <= 0x66) + digit = (*hexstr & 0x0F) + 9; + hexstr++; + + if (digit >= 0) { + if (digit_counter % 2) { + byte |= digit; + bin->data[bin->len] = byte; + bin->len++; + } else + byte = (digit << 4); + digit_counter++; + } + } + return bin; +} + /*! Generate a hexdump string from the input data. * \param[in] data pointer to binary data. * \param[in] len length of binary data. diff --git a/src/ipa/main.c b/src/ipa/main.c index 13b034d..bf2e386 100644 --- a/src/ipa/main.c +++ b/src/ipa/main.c @@ -81,31 +81,31 @@ printf(" get-connectivity-parameters . Get connectivity parameters from acurrently active profile\n"); }
-struct ipa_buf *load_ber_from_file(char *dir, char *file) +struct ipa_buf *load_ber_from_file(char *file) { - char path[PATH_MAX] = { 0 }; - FILE *ber_file = NULL; - struct ipa_buf *ber = NULL; - size_t ber_size; + FILE *hex_file = NULL; + struct ipa_buf *hex = NULL; + struct ipa_buf *bin = NULL; + size_t hex_size;
- if (dir) - strcpy(path, dir); - strcat(path, file); + hex_file = fopen(file, "r"); + assert(hex_file);
- ber_file = fopen(path, "r"); - assert(ber_file); + fseek(hex_file, 0L, SEEK_END); + hex_size = ftell(hex_file); + rewind(hex_file);
- fseek(ber_file, 0L, SEEK_END); - ber_size = ftell(ber_file); - rewind(ber_file); + hex = ipa_buf_alloc(hex_size + 1); + assert(hex); + hex->len = fread(hex->data, sizeof(char), hex->data_len - 1, hex_file); + hex->data[hex->len] = '\0'; + fclose(hex_file);
- ber = ipa_buf_alloc(ber_size + 1); - assert(ber); + bin = ipa_hexparse((char *)hex->data); + ipa_buf_free(hex);
- ber->len = fread(ber->data, sizeof(char), ber->data_len, ber_file); - fclose(ber_file); - IPA_LOGP(SMAIN, LINFO, "loaded BER data from file %s, size: %zu\n", path, ber->len); - return ber; + IPA_LOGP(SMAIN, LINFO, "loaded binary data from hex file %s, size: %zu\n", file, bin->len); + return bin; }
struct ipa_buf *load_nvstate_from_file(char *path) @@ -364,7 +364,7 @@ break; case OPER_ADD_INITIAL_EIM: /* Load initial eIM configuration */ - struct ipa_buf *eim_cfg = load_ber_from_file(NULL, initial_eim_cfg_file); + struct ipa_buf *eim_cfg = load_ber_from_file(initial_eim_cfg_file); ipa_add_init_eim_cfg(ctx, eim_cfg); IPA_FREE(eim_cfg); break; diff --git a/tests/utils/utils_test.c b/tests/utils/utils_test.c index 517f0d7..eeadde2 100644 --- a/tests/utils/utils_test.c +++ b/tests/utils/utils_test.c @@ -51,9 +51,32 @@ IPA_FREE(tag_list); }
+void ipa_hexparse_test(void) +{ + char hexstr[] = + "bf:57:81:83:A0 81 80 30 7E 80.03.65.494D81////0E31kkk32372En302E302E313A38303oooo0308301018401FFA55BA059301306072A8648CE3D020106082A8648CE3D0301070342...0004FE584A6F450459574A-E-C-A19 5 D0299737F74C89BA2D36DFOOOO9286EC25D973037:A0FBA70D14DF3E1F7D0A305E57B95B731C4DE218D2D7F9F22113ed5d18c2e3ddf1c870207808900"; + char expected_data[] = { 0xBF, 0x57, 0x81, 0x83, 0xA0, 0x81, 0x80, 0x30, 0x7E, 0x80, 0x03, + 0x65, 0x49, 0x4D, 0x81, 0x0E, 0x31, 0x32, 0x37, 0x2E, 0x30, 0x2E, 0x30, 0x2E, + 0x31, 0x3A, 0x38, 0x30, 0x30, 0x30, 0x83, 0x01, 0x01, 0x84, 0x01, 0xFF, 0xA5, + 0x5B, 0xA0, 0x59, 0x30, 0x13, 0x06, 0x07, 0x2A, 0x86, 0x48, 0xCE, 0x3D, 0x02, + 0x01, 0x06, 0x08, 0x2A, 0x86, 0x48, 0xCE, 0x3D, 0x03, 0x01, 0x07, 0x03, 0x42, + 0x00, 0x04, 0xFE, 0x58, 0x4A, 0x6F, 0x45, 0x04, 0x59, 0x57, 0x4A, 0xEC, 0xA1, + 0x95, 0xD0, 0x29, 0x97, 0x37, 0xF7, 0x4C, 0x89, 0xBA, 0x2D, 0x36, 0xDF, 0x92, + 0x86, 0xEC, 0x25, 0xD9, 0x73, 0x03, 0x7A, 0x0F, 0xBA, 0x70, 0xD1, 0x4D, 0xF3, + 0xE1, 0xF7, 0xD0, 0xA3, 0x05, 0xE5, 0x7B, 0x95, 0xB7, 0x31, 0xC4, 0xDE, 0x21, + 0x8D, 0x2D, 0x7F, 0x9F, 0x22, 0x11, 0x3E, 0xD5, 0xD1, 0x8C, 0x2E, 0x3D, 0xDF, + 0x1C, 0x87, 0x02, 0x07, 0x80, 0x89, 0x00 + }; + struct ipa_buf *bin; + bin = ipa_hexparse(hexstr); + assert(memcmp(bin->data, expected_data, bin->len) == 0); + ipa_buf_free(bin); +} + int main(int argc, char **argv) { ipa_tag_in_taglist_test(); + ipa_hexparse_test(); return 0; }