From 7d96442d0bc2b37ecfb4e5285c59f248d9eef9a1 Mon Sep 17 00:00:00 2001 From: "Lucas, John P" Date: Thu, 11 May 2023 16:42:26 -0400 Subject: [PATCH 1/2] [nasa/cryptolib#160] Add in protections when changing VCID to CryptoLib Standalone; --- src/src_main/sadb_routine_inmemory.template.c | 2 +- util/src_util/standalone.c | 33 +++++++++++++++++-- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/src/src_main/sadb_routine_inmemory.template.c b/src/src_main/sadb_routine_inmemory.template.c index 545249b3..5e787df5 100644 --- a/src/src_main/sadb_routine_inmemory.template.c +++ b/src/src_main/sadb_routine_inmemory.template.c @@ -518,7 +518,7 @@ static int32_t sadb_get_operational_sa_from_gvcid(uint8_t tfvn, uint16_t scid, u printf(KYEL "\tscid %d\n" RESET, scid); printf(KYEL "\tvcid %d\n" RESET, vcid); printf(KYEL "\tmapid %02X\n" RESET, mapid); - printf(KYEL "***FYI TM_SIZE set to %ld\n" RESET, TM_SIZE); + printf(KYEL "***FYI TM_SIZE set to %d\n" RESET, TM_SIZE); #endif } diff --git a/util/src_util/standalone.c b/util/src_util/standalone.c index 5b0913d7..0e5c0573 100644 --- a/util/src_util/standalone.c +++ b/util/src_util/standalone.c @@ -134,8 +134,37 @@ int32_t crypto_standalone_process_command(int32_t cc, int32_t num_tokens, char* case CRYPTO_CMD_VCID: if (crypto_standalone_check_number_arguments(num_tokens, 1) == CRYPTO_LIB_SUCCESS) { - tc_vcid = (uint8_t) atoi(&tokens[0]); - printf("Changed active virtual channel (VCID) to %d \n", tc_vcid); + uint8_t vcid = (uint8_t) atoi(&tokens[0]); + /* Confirm new VCID valid */ + if (vcid < 64) + { + SadbRoutine sadb_routine = get_sadb_routine_inmemory(); + SecurityAssociation_t* test_association = NULL; + sadb_routine->sadb_get_sa_from_spi(vcid, &test_association); + + /* Handle special case for VCID */ + if(vcid == 1) + { + printf("Special case for VCID 1! \n"); + vcid = 0; + } + + if ((test_association->sa_state == SA_OPERATIONAL) && + (test_association->gvcid_blk.mapid == TYPE_TC) && + (test_association->gvcid_blk.scid == SCID)) + { + tc_vcid = vcid; + printf("Changed active virtual channel (VCID) to %d \n", tc_vcid); + } + else + { + printf("Error - virtual channel (VCID) %d is invalid! Sticking with prior vcid %d \n", vcid, tc_vcid); + } + } + else + { + printf("Error - virtual channl (VCID) %d must be less than 64! Sticking with prior vcid %d \n", vcid, tc_vcid); + } } break; From df676aa27d3a6f20afd99048a5a313c84b837b65 Mon Sep 17 00:00:00 2001 From: "Lucas, John P" Date: Fri, 12 May 2023 09:51:18 -0400 Subject: [PATCH 2/2] [nasa/cryptolib#160] Removed change to printf due to build issue with debug enabled; --- src/src_main/sadb_routine_inmemory.template.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/src_main/sadb_routine_inmemory.template.c b/src/src_main/sadb_routine_inmemory.template.c index 257b2f65..f4b78f4a 100644 --- a/src/src_main/sadb_routine_inmemory.template.c +++ b/src/src_main/sadb_routine_inmemory.template.c @@ -518,7 +518,7 @@ static int32_t sadb_get_operational_sa_from_gvcid(uint8_t tfvn, uint16_t scid, u printf(KYEL "\tscid %d\n" RESET, scid); printf(KYEL "\tvcid %d\n" RESET, vcid); printf(KYEL "\tmapid %02X\n" RESET, mapid); - printf(KYEL "***FYI TM_SIZE set to %d\n" RESET, TM_SIZE); + printf(KYEL "***FYI TM_SIZE set to %ld\n" RESET, TM_SIZE); #endif }