Skip to content

Commit

Permalink
[#344] Initial KMC AOS Process
Browse files Browse the repository at this point in the history
  • Loading branch information
Donnie-Ice committed Nov 25, 2024
1 parent 353bddd commit c3985b9
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 15 deletions.
33 changes: 18 additions & 15 deletions src/core/crypto_aos.c
Original file line number Diff line number Diff line change
Expand Up @@ -904,6 +904,8 @@ int32_t Crypto_AOS_ProcessSecurity(uint8_t *p_ingest, uint16_t len_ingest, uint8
SecurityAssociation_t *sa_ptr = NULL;
uint8_t sa_service_type = -1;
uint8_t spi = -1;
crypto_key_t *ekp = NULL;
crypto_key_t *akp = NULL;

// Bit math to give concise access to values in the ingest
aos_frame_pri_hdr.tfvn = ((uint8_t)p_ingest[0] & 0xC0) >> 6;
Expand Down Expand Up @@ -1201,23 +1203,24 @@ int32_t Crypto_AOS_ProcessSecurity(uint8_t *p_ingest, uint16_t len_ingest, uint8
}
#endif

// Get Key
crypto_key_t *ekp = NULL;
ekp = key_if->get_key(sa_ptr->ekid);
if (ekp == NULL)
if (crypto_config.key_type != KEY_TYPE_KMC)
{
status = CRYPTO_LIB_ERR_KEY_ID_ERROR;
mc_if->mc_log(status);
return status;
}
// Get Key
ekp = key_if->get_key(sa_ptr->ekid);
if (ekp == NULL)
{
status = CRYPTO_LIB_ERR_KEY_ID_ERROR;
mc_if->mc_log(status);
return status;
}

crypto_key_t *akp = NULL;
akp = key_if->get_key(sa_ptr->akid);
if (akp == NULL)
{
status = CRYPTO_LIB_ERR_KEY_ID_ERROR;
mc_if->mc_log(status);
return status;
akp = key_if->get_key(sa_ptr->akid);
if (akp == NULL)
{
status = CRYPTO_LIB_ERR_KEY_ID_ERROR;
mc_if->mc_log(status);
return status;
}
}

/**
Expand Down
77 changes: 77 additions & 0 deletions test/kmc/ut_aos_kmc.c
Original file line number Diff line number Diff line change
Expand Up @@ -221,4 +221,81 @@ UTEST(AOS_APPLY_KMC, HAPPY_PATH_ENC_AOS_CBC_KMC)
ASSERT_EQ(CRYPTO_LIB_SUCCESS, return_val);
}

/**
* @brief Unit Test: Nominal Decryption CBC KMC
**/
UTEST(AOS_PROCESS_KMC, HAPPY_PATH_DEC_AOS_CBC_KMC)
{
uint8_t *ptr_processed_frame = NULL;
uint16_t processed_aos_len;

remove("sa_save_file.bin");
reload_db();
// Setup & Initialize CryptoLib
Crypto_Config_CryptoLib(KEY_TYPE_KMC, MC_TYPE_DISABLED, SA_TYPE_MARIADB, CRYPTOGRAPHY_TYPE_KMCCRYPTO,
IV_CRYPTO_MODULE, CRYPTO_AOS_CREATE_FECF_TRUE, TC_PROCESS_SDLS_PDUS_TRUE, TC_HAS_PUS_HDR,
TC_IGNORE_SA_STATE_FALSE, TC_IGNORE_ANTI_REPLAY_TRUE, TC_UNIQUE_SA_PER_MAP_ID_FALSE,
AOS_CHECK_FECF_TRUE, 0x3F, SA_INCREMENT_NONTRANSMITTED_IV_TRUE);
Crypto_Config_MariaDB(KMC_HOSTNAME, "sadb", 3306, CRYPTO_TRUE, CRYPTO_TRUE, CA_PATH, NULL, CLIENT_CERTIFICATE,
CLIENT_CERTIFICATE_KEY, NULL, "root", "changeit");
Crypto_Config_Kmc_Crypto_Service("https", "itc.kmc.nasa.gov", 8443, "crypto-service", "/certs/ammos-ca-bundle.crt",
NULL, CRYPTO_TRUE, CLIENT_CERTIFICATE, "PEM", CLIENT_CERTIFICATE_KEY, NULL, NULL);
GvcidManagedParameters_t AOS_UT_Managed_Parameters0 = {
1, 0x000C, 0, AOS_HAS_FECF, AOS_FHEC_NA, AOS_IZ_NA, 0, AOS_SEGMENT_HDRS_NA, 1786, AOS_NO_OCF, 1};
Crypto_Config_Add_Gvcid_Managed_Parameters(AOS_UT_Managed_Parameters0);

int32_t return_val = Crypto_Init();
ASSERT_EQ(CRYPTO_LIB_SUCCESS, return_val);

char *raw_aos_sdls_ping_h =
"40C0000000000007000000000000000000000001BB73A3818AB2D7C51A5A14B6674439BB9B7DC0B21A44256075B5413488F77FC590A9C5"
"21DB9A013DC0456F5FE9F99D111B1C31BABCDB7E0FB2822BEA152FAA73F5D3F06EBE6D18CC1B85D5DCF1F293E77A384916E28A7C820670"
"8C3758D87CA6BDD7FEAE2225ACDDFA1B878C3F831AD4ECB8026ACC50E58B1367455A1E5879886B414BF33B0BB5F8EE44750E15051A2554"
"A6B172BEAA92F03B90DCEB57165CC1CA8ED97A7E76968F655549B28080BF25ED4E9A6377166C137CFEB884A8D9B9405C84883F7880D60F"
"EFFDB7CA4E9F8FB4F7D77315A6E8E3F3326751F8855349EDE8797A57B7F07CD8B1531539B05A7FFEF4708864847C3EBEDFA656D6243941"
"F06B21132953BA22B5E8F3EC7079F096D2A621D29FF0625147D32A7C0F644FA557A70567579F10D461C4198A360D0BB2361E1599533A4B"
"69F8ADC8FA64174E1092B996BC01B87453EE54E961D14BE002FE7D24BE389F892D4C6967B910D650C36FA653BAF214E93CBDD813F8078D"
"534303BA8FC795CBB2292A770F9959F60DC0ED141375BBEB86ED099CC1EBCDE6488B911508B7213C9AB1346E4B90D4B9AA8EAE02EC8B8A"
"B54957309CE1266FD80907E5B16441CE0A9B2A4146A2885537688577D6C9FECFD9E9F584EC860A276684667BAE255ABC0CB808FD685EA9"
"5DC86BFCEC9EC0EA352A317DCF8AA579B0746C8B5359F6E1BB4881BAC194A6D9B3881907621C8EC65FF1AB61B6DCDA3BC9B07165FAE18A"
"BA0E849CC09B9C8BBAB5963C8EB855273DC61B4487C85C1BB88943AEFFFF08830852EE074B6DCF71146D28B4AB311A043663E9EC582442"
"6553BE583AF18E2C172A11849E70A4814F8ABFFE851F1716B16466011293161DD44FFD1F2519BA82F8B21798004EFD1F2246623CF98C92"
"323D202A7E1FF3A7EF204A729CB1EAF6F2E16FCC18FC0826D60D113A17D1BCF887461A0E79B5D0A9A3980CCD7073476D431524EE5E5FEA"
"0B3A8F037F5E95213EC3D3FBB04CA49A35D99BDD22AC41150653BD8B75F8C3CC060B0DC09BC062DDF8E3CC3C9DF13BA44A96C53EA336A1"
"9138557A23C94E508839CAA76458636B68AB5DFED7D268C1CE329BF430D4306159ECA035B079927A5597F1E80FDCE67F5B23580C85D697"
"1D9DF12D1A50556C7F612530B4A5C2C2469E0AD0FAFF88D58C466C3CD601CDCF0AF65D0219E1C94D7461B1D39CF05D1B0F2C1EC94C985E"
"4DD1B1C1AD935537B6FE53FA9581C209EDA64340F72F5738D0877ECE4FF2831B6DEE291CAC98CD385BEE07270E44A1CB5635CA36609467"
"61293B1BC238C13670D2432BC3A0227A4CF94959E6C61B391E74BB14B27B0D767BD8AE8AAB60FDD6D2593A5E3B83518283B5DF4510A47D"
"8B116229EF409F44B8A9AAF5452FB5D7A0C8DBCB8692A479A9BA1C8309E84E8989782D868AE1884150E1D645FE053C7430921514E4E763"
"58AD4CC7E096C8BD390488DA2D7AFBB5408299F892A1CFE708D918FED3D7D6BCB27EF17A1E03B50A3EE76D507B19C0AFE7178D4455A2D7"
"7A787ACF0B75DEE48757602D6D6DED0224F75B0B64D9381B39436BB9D196F31347B55E346A6C0A335C85CE4E098F07A6CC3DDAC549371D"
"DB1447DB0A02E39F96A87BF7ADE1610A51ABE79A84394DEDAAA74B61AC13E5A957079FA2841BD663CDB5CA731536034855AEBE2740248F"
"7DE86463FCA8BCC66FCE3F38CE11215FC6890874E458244AB9691818289EF7DF05A0B0C2215BA36654483E7FF73B6630811DD6237414D4"
"C7FE8863CCCDB5563FF36F534113B392BCCBE46566BCF10238C8127BCF74389674774996253EA6742242E1D62509AC1EEAB577D7149924"
"F5640BFF4EB364EEF4C2664D98824E0F0ED0D91C1065E9FEB96160925BCEB1FB48E6E8658BE8032F01FC10A63D9D79C7F5E49AFEF6C43A"
"6D665D95F9D7E46AACDB8FB3F6086EBAF56B3149C2641B4AFBCDA992C8399B915EE2D23F8DAD37023B4E40C07F3341FF3097F25D238C69"
"2C5F816E128B922A09249DCA1FE0BA4B1E77A4ECCDC53712A5CE588D688D13370163A925867CB4E1D41FDED4CE244D852ED1D3F17D48A0"
"4921973F4D8F34180AF748B6C292181FFAC33D2EEEA7BC91E993EA29E5F2798930C8B149F5478C05F59F7ACA8E862BB37B5A0A792DCE1B"
"F4E76DB82DC1408733CD8F06995746726738F3E1416792AC8F8A91532B7F9331111DF835F3A60BB2134009D6BEC469B0CA1AD6352C7E6E"
"A928332ECA13CF2862A8C845734B00B230C8EEEA10FD0FE2BC62E7304ECD40E54B8D28C78E4C44FBF535A2F59FCF2D4B4A550FB5AE7AE4"
"69B2BA9DDC08C741653A405D5BAFD0C677C8D0B43984C82F7B814CAA0989518C71DB8DD93E12C1F3EFFA453C03A11E2F338DDCD50D4C7C"
"DCFC7B32A7DCFEAEA1D66815AA1E91D1FE3D62AAECF9BF9F5CC7C02278E0C5DC0DD322BCF90FF81EC1A5BFBBE2CF708CAEBE520CB89620"
"A0AD847A405648E6A01F658313107B1E143EF2D86100F461758D";
char *raw_aos_sdls_ping_b = NULL;
int raw_aos_sdls_ping_len = 0;

hex_conversion(raw_aos_sdls_ping_h, &raw_aos_sdls_ping_b, &raw_aos_sdls_ping_len);

aos_frame_pri_hdr.tfvn = ((uint8_t)raw_aos_sdls_ping_b[0] & 0xC0) >> 6;
aos_frame_pri_hdr.scid = (((uint16_t)raw_aos_sdls_ping_b[0] & 0x3F) << 2) | (((uint16_t)raw_aos_sdls_ping_b[1] & 0xC0) >> 6);
aos_frame_pri_hdr.vcid = ((uint8_t)raw_aos_sdls_ping_b[1] & 0x3F);

return_val =
Crypto_AOS_ProcessSecurity((uint8_t *)raw_aos_sdls_ping_b, raw_aos_sdls_ping_len, &ptr_processed_frame, &processed_aos_len);

Crypto_Shutdown();
free(raw_aos_sdls_ping_b);
ASSERT_EQ(CRYPTO_LIB_SUCCESS, return_val);
}

UTEST_MAIN();

0 comments on commit c3985b9

Please sign in to comment.