From 8e8192362c2c583976fafaa9d28e5d71064ccaf3 Mon Sep 17 00:00:00 2001 From: Pol Henarejos Date: Wed, 17 Apr 2024 19:43:10 +0200 Subject: [PATCH] Use macros for referring system fids. Signed-off-by: Pol Henarejos --- src/hsm/cmd_initialize.c | 2 +- src/hsm/files.c | 12 ++++++------ src/hsm/files.h | 8 +++++++- src/hsm/sc_hsm.c | 12 ++++++------ 4 files changed, 20 insertions(+), 14 deletions(-) diff --git a/src/hsm/cmd_initialize.c b/src/hsm/cmd_initialize.c index 083d60a..6906481 100644 --- a/src/hsm/cmd_initialize.c +++ b/src/hsm/cmd_initialize.c @@ -77,7 +77,7 @@ int cmd_initialize() { } } else if (tag == 0x91) { //retries user pin - file_t *tf = search_file(0x1082); + file_t *tf = search_file(EF_PIN1_MAX_RETRIES); if (tf && tf->data) { file_put_data(tf, tag_data, tag_len); } diff --git a/src/hsm/files.c b/src/hsm/files.c index 8a5fb4b..dba2367 100644 --- a/src/hsm/files.c +++ b/src/hsm/files.c @@ -41,22 +41,22 @@ file_t file_entries[] = { .ef_structure = FILE_EF_TRANSPARENT, .acl = { 0 } }, //EF.TokenInfo /* 8 */ { .fid = 0x5033, .parent = 0, .name = NULL, .type = FILE_TYPE_WORKING_EF, .data = NULL, .ef_structure = FILE_EF_TRANSPARENT, .acl = { 0 } }, //EF.UnusedSpace - /* 9 */ { .fid = 0x1081, .parent = 5, .name = NULL, + /* 9 */ { .fid = EF_PIN1, .parent = 5, .name = NULL, .type = FILE_TYPE_INTERNAL_EF | FILE_DATA_FLASH, .data = NULL, .ef_structure = FILE_EF_TRANSPARENT, .acl = { 0xff } }, //PIN (PIN1) - /* 10 */ { .fid = 0x1082, .parent = 5, .name = NULL, + /* 10 */ { .fid = EF_PIN1_MAX_RETRIES, .parent = 5, .name = NULL, .type = FILE_TYPE_INTERNAL_EF | FILE_DATA_FLASH, .data = NULL, .ef_structure = FILE_EF_TRANSPARENT, .acl = { 0xff } }, //max retries PIN (PIN1) - /* 11 */ { .fid = 0x1083, .parent = 5, .name = NULL, + /* 11 */ { .fid = EF_PIN1_RETRIES, .parent = 5, .name = NULL, .type = FILE_TYPE_INTERNAL_EF | FILE_DATA_FLASH, .data = NULL, .ef_structure = FILE_EF_TRANSPARENT, .acl = { 0xff } }, //retries PIN (PIN1) - /* 12 */ { .fid = 0x1088, .parent = 5, .name = NULL, + /* 12 */ { .fid = EF_SOPIN, .parent = 5, .name = NULL, .type = FILE_TYPE_INTERNAL_EF | FILE_DATA_FLASH, .data = NULL, .ef_structure = FILE_EF_TRANSPARENT, .acl = { 0xff } }, //PIN (SOPIN) - /* 13 */ { .fid = 0x1089, .parent = 5, .name = NULL, + /* 13 */ { .fid = EF_SOPIN_MAX_RETRIES, .parent = 5, .name = NULL, .type = FILE_TYPE_INTERNAL_EF | FILE_DATA_FLASH, .data = NULL, .ef_structure = FILE_EF_TRANSPARENT, .acl = { 0xff } }, //max retries PIN (SOPIN) - /* 14 */ { .fid = 0x108A, .parent = 5, .name = NULL, + /* 14 */ { .fid = EF_SOPIN_RETRIES, .parent = 5, .name = NULL, .type = FILE_TYPE_INTERNAL_EF | FILE_DATA_FLASH, .data = NULL, .ef_structure = FILE_EF_TRANSPARENT, .acl = { 0xff } }, //retries PIN (SOPIN) /* 15 */ { .fid = EF_DEVOPS, .parent = 5, .name = NULL, diff --git a/src/hsm/files.h b/src/hsm/files.h index 8637fc8..e436c92 100644 --- a/src/hsm/files.h +++ b/src/hsm/files.h @@ -24,7 +24,13 @@ #define EF_DEVOPS 0x100E #define EF_MKEK 0x100A #define EF_MKEK_SO 0x100B -#define EF_XKEK 0x1080 +#define EF_XKEK 0x1070 +#define EF_PIN1 0x1081 +#define EF_PIN1_MAX_RETRIES 0x1082 +#define EF_PIN1_RETRIES 0x1083 +#define EF_SOPIN 0x1088 +#define EF_SOPIN_MAX_RETRIES 0x1089 +#define EF_SOPIN_RETRIES 0x108A #define EF_DKEK 0x1090 #define EF_KEY_DOMAIN 0x10A0 #define EF_PUKAUT 0x10C0 diff --git a/src/hsm/sc_hsm.c b/src/hsm/sc_hsm.c index 8a426dd..b0498e1 100644 --- a/src/hsm/sc_hsm.c +++ b/src/hsm/sc_hsm.c @@ -94,7 +94,7 @@ INITIALIZER( sc_hsm_ctor ) { } void scan_files() { - file_pin1 = search_file(0x1081); + file_pin1 = search_file(EF_PIN1); if (file_pin1) { if (!file_pin1->data) { printf("PIN1 is empty. Initializing with default password\n"); @@ -105,7 +105,7 @@ void scan_files() { else { printf("FATAL ERROR: PIN1 not found in memory!\n"); } - file_sopin = search_file(0x1088); + file_sopin = search_file(EF_SOPIN); if (file_sopin) { if (!file_sopin->data) { printf("SOPIN is empty. Initializing with default password\n"); @@ -116,7 +116,7 @@ void scan_files() { else { printf("FATAL ERROR: SOPIN not found in memory!\n"); } - file_retries_pin1 = search_file(0x1083); + file_retries_pin1 = search_file(EF_PIN1_RETRIES); if (file_retries_pin1) { if (!file_retries_pin1->data) { printf("Retries PIN1 is empty. Initializing with default retriesr\n"); @@ -127,7 +127,7 @@ void scan_files() { else { printf("FATAL ERROR: Retries PIN1 not found in memory!\n"); } - file_retries_sopin = search_file(0x108A); + file_retries_sopin = search_file(EF_SOPIN_RETRIES); if (file_retries_sopin) { if (!file_retries_sopin->data) { printf("Retries SOPIN is empty. Initializing with default retries\n"); @@ -140,7 +140,7 @@ void scan_files() { } file_t *tf = NULL; - tf = search_file(0x1082); + tf = search_file(EF_PIN1_MAX_RETRIES); if (tf) { if (!tf->data) { printf("Max retries PIN1 is empty. Initializing with default max retriesr\n"); @@ -151,7 +151,7 @@ void scan_files() { else { printf("FATAL ERROR: Max Retries PIN1 not found in memory!\n"); } - tf = search_file(0x1089); + tf = search_file(EF_SOPIN_MAX_RETRIES); if (tf) { if (!tf->data) { printf("Max Retries SOPIN is empty. Initializing with default max retries\n");