From 0b81e8ab1454b3dd4db9e9103e71fa79d2ced5e2 Mon Sep 17 00:00:00 2001 From: Root-Core Date: Sun, 5 Jan 2025 02:36:44 +0100 Subject: [PATCH] euicc: added support for custom AIDs (#181) - Added env variable "LPAC_CUSTOM_ISD_R_AID" for user defined AIDs - Added documentation for new env var --- docs/ENVVARS.md | 1 + src/main.c | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/docs/ENVVARS.md b/docs/ENVVARS.md index 800d808..f86cf1f 100644 --- a/docs/ENVVARS.md +++ b/docs/ENVVARS.md @@ -2,6 +2,7 @@ ## General +* `LPAC_CUSTOM_ISD_R_AID`: specify which AID will be used to open the logic channel. (hex string, 32 chars) * `LPAC_APDU`: specify which APDU backend will be used. Values: - `at`: use AT commands interface used by LTE module - `pcsc`: use PC/SC Smart Card API diff --git a/src/main.c b/src/main.c index f7ead78..82f9e29 100644 --- a/src/main.c +++ b/src/main.c @@ -6,6 +6,7 @@ #include #include +#include #include #include @@ -23,6 +24,8 @@ #include #endif +#define ISD_R_AID_STR_LENGTH 16 + static int driver_applet_main(int argc, char **argv) { const struct applet_entry *applets[] = { @@ -58,6 +61,21 @@ struct euicc_ctx euicc_ctx = {0}; void main_init_euicc() { + const char *custom_aid_str = getenv("LPAC_CUSTOM_ISD_R_AID"); + if (custom_aid_str) + { + unsigned char custom_aid[ISD_R_AID_STR_LENGTH]; + const int custom_aid_len = euicc_hexutil_hex2bin(custom_aid, ISD_R_AID_STR_LENGTH, custom_aid_str); + if (custom_aid_len != ISD_R_AID_STR_LENGTH) + { + jprint_error("euicc_init", "invalid custom AID given"); + exit(-1); + } + + euicc_ctx.aid = custom_aid; + euicc_ctx.aid_len = custom_aid_len; + } + if (euicc_init(&euicc_ctx)) { jprint_error("euicc_init", NULL);