Skip to content

Commit

Permalink
AMMOSGH-73: Add test for misconfigured SA for with seg headers
Browse files Browse the repository at this point in the history
  • Loading branch information
IbraheemYSaleh committed Apr 13, 2022
1 parent 7b93189 commit 863bce3
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ VALUES (2,'kmc/test/key130',1,X'01',1,1,12,12,16,X'000000000000000000000001',19,
INSERT INTO security_associations (spi,ekid,sa_state,ecs,est,ast,shivf_len,iv_len,stmacf_len,iv,abm_len,abm,arsnw,arsn_len,tfvn,scid,vcid,mapid)
VALUES (3,NULL,3,'',1,1,12,12,16,X'000000000000000000000001',19,X'00000000000000000000000000000000000000',5,0,0,44,34,0);

-- SA 4 - Invalid Frame Length with Seg Headers Config Set (VC 28)
INSERT INTO security_associations (spi,ekid,sa_state,ecs,est,ast,shivf_len,iv_len,stmacf_len,iv,abm_len,abm,arsnw,arsn_len,tfvn,scid,vcid,mapid)
VALUES (4,'kmc/test/key128',3,X'01',1,1,12,12,16,X'000000000000000000000001',19,X'0000000000000000000000000000000000000000',5,0,0,44,28,1);


-- SA 2 - OPERATIONAL; ENC + AUTH - ARSNW:5; AES-GCM; IV:00...01; IV-len:12; MAC-len:16; Key-ID: 130, SCID 44, VC-1
-- INSERT INTO security_associations (spi,ekid,sa_state,ecs,est,ast,shivf_len,iv_len,stmacf_len,iv,abm_len,abm,arsnw,arsn_len,tfvn,scid,vcid,mapid)
Expand Down
57 changes: 57 additions & 0 deletions util/src_util/ut_sadb_err_cases_kmc_crypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,5 +202,62 @@ UTEST(KMC_CRYPTO, NULL_EKID_BLANK_ECS_ERROR)
free(ptr_enc_frame);
}

UTEST(KMC_CRYPTO, INVALID_ABM_LENGTH_FOR_FRAME_WITH_SEG_HEADERS)
{
// Setup & Initialize CryptoLib
Crypto_Config_CryptoLib(SADB_TYPE_MARIADB, CRYPTOGRAPHY_TYPE_KMCCRYPTO, CRYPTO_TC_CREATE_FECF_TRUE, TC_PROCESS_SDLS_PDUS_FALSE, TC_NO_PUS_HDR,
TC_IGNORE_SA_STATE_FALSE, TC_IGNORE_ANTI_REPLAY_TRUE, TC_UNIQUE_SA_PER_MAP_ID_FALSE,
TC_CHECK_FECF_TRUE, 0x3F, SA_INCREMENT_NONTRANSMITTED_IV_TRUE);
Crypto_Config_MariaDB("localhost", "sadb", 3306, CRYPTO_FALSE, 0, NULL, NULL, NULL, NULL, NULL, "sadb_user",
"sadb_password");
Crypto_Config_Kmc_Crypto_Service("https", "asec-cmdenc-srv1.jpl.nasa.gov", 8443, "crypto-service",
"/home/isaleh/git/KMC/CryptoLib-IbraheemYSaleh/util/etc/ammos-ca-bundle.crt", NULL,
CRYPTO_FALSE,
"/home/isaleh/git/KMC/CryptoLib-IbraheemYSaleh/util/etc/local-test-cert.pem",
"PEM", "/home/isaleh/git/KMC/CryptoLib-IbraheemYSaleh/util/etc/local-test-key.pem",
NULL, NULL);
// Crypto_Config_Add_Gvcid_Managed_Parameter(0, 0x002C, 0, TC_HAS_FECF, TC_NO_SEGMENT_HDRS, 1024);
// Crypto_Config_Add_Gvcid_Managed_Parameter(0, 0x002C, 1, TC_HAS_FECF, TC_NO_SEGMENT_HDRS, 1024);
// Crypto_Config_Add_Gvcid_Managed_Parameter(0, 0x002C, 2, TC_HAS_FECF, TC_NO_SEGMENT_HDRS, 1024);
// Crypto_Config_Add_Gvcid_Managed_Parameter(0, 0x002C, 3, TC_HAS_FECF, TC_NO_SEGMENT_HDRS, 1024);
Crypto_Config_Add_Gvcid_Managed_Parameter(0, 0x002C, 28, TC_HAS_FECF, TC_HAS_SEGMENT_HDRS, 1024);
int32_t status = Crypto_Init();
ASSERT_EQ(CRYPTO_LIB_SUCCESS, status);

char* raw_tc_jpl_mmt_scid44_vcid1= "202c7008000169e2df";
char* raw_tc_jpl_mmt_scid44_vcid1_expect = NULL;
int raw_tc_jpl_mmt_scid44_vcid1_expect_len = 0;

hex_conversion(raw_tc_jpl_mmt_scid44_vcid1, &raw_tc_jpl_mmt_scid44_vcid1_expect, &raw_tc_jpl_mmt_scid44_vcid1_expect_len);

uint8_t* ptr_enc_frame = NULL;
uint16_t enc_frame_len = 0;

printf("Frame before encryption:\n");
for (int i=0; i<raw_tc_jpl_mmt_scid44_vcid1_expect_len; i++)
{
printf("%02x ", (uint8_t)raw_tc_jpl_mmt_scid44_vcid1_expect[i]);
}
printf("\n");

status = Crypto_TC_ApplySecurity((uint8_t* )raw_tc_jpl_mmt_scid44_vcid1_expect, raw_tc_jpl_mmt_scid44_vcid1_expect_len, &ptr_enc_frame, &enc_frame_len);
if(status != CRYPTO_LIB_SUCCESS)
{
Crypto_Shutdown();
}
ASSERT_EQ(CRYPTO_LIB_ERR_ABM_TOO_SHORT_FOR_AAD, status);
printf("Frame after encryption:\n");
// for (int i=0; i<enc_frame_len; i++)
// {
// printf("%02x ", ptr_enc_frame[i]);
// }
// printf("\n");


Crypto_Shutdown();
free(raw_tc_jpl_mmt_scid44_vcid1_expect);
free(ptr_enc_frame);
}


UTEST_MAIN();

0 comments on commit 863bce3

Please sign in to comment.