Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

283 confirm sa operational before decrypting #286

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/crypto_error.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@
#define CRYPTO_LIB_ERR_EXCEEDS_MANAGED_PARAMETER_MAX_LIMIT (-54)
#define CRYPTO_LIB_ERR_KEY_VALIDATION (-55)
#define CRYPTO_LIB_ERR_SPI_INDEX_OOB (-56)
#define CRYPTO_LIB_ERR_SA_NOT_OPERATIONAL (-57)

extern char *crypto_enum_errlist_core[];
extern char *crypto_enum_errlist_config[];
Expand Down
4 changes: 4 additions & 0 deletions src/core/crypto_tc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1977,6 +1977,10 @@ uint8_t* Crypto_Prepare_TC_AAD(uint8_t* buffer, uint16_t len_aad, uint8_t* abm_b
**/
static int32_t crypto_tc_validate_sa(SecurityAssociation_t* sa)
{
if (sa->sa_state != SA_OPERATIONAL)
{
return CRYPTO_LIB_ERR_SA_NOT_OPERATIONAL;
}
if (sa->shivf_len > 0 && crypto_config.iv_type == IV_CRYPTO_MODULE && crypto_config.cryptography_type != CRYPTOGRAPHY_TYPE_KMCCRYPTO)
{
return CRYPTO_LIB_ERR_NULL_IV;
Expand Down
37 changes: 37 additions & 0 deletions test/unit/ut_tc_process.c
Original file line number Diff line number Diff line change
Expand Up @@ -1059,4 +1059,41 @@ UTEST(TC_PROCESS, TC_SA_SEGFAULT_TEST)
Crypto_Shutdown();
}

UTEST(TC_PROCESS, TC_SA_NOT_OPERATIONAL)
{
// Local Variables
int32_t status = CRYPTO_LIB_SUCCESS;

// Configure Parameters
Crypto_Config_CryptoLib(KEY_TYPE_INTERNAL, MC_TYPE_INTERNAL, SA_TYPE_INMEMORY, CRYPTOGRAPHY_TYPE_LIBGCRYPT,
IV_INTERNAL, CRYPTO_TC_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,
TC_CHECK_FECF_TRUE, 0x3F, SA_INCREMENT_NONTRANSMITTED_IV_TRUE);
// AOS Tests
//Crypto_Config_Add_Gvcid_Managed_Parameter(0, 0x0003, 0, TC_HAS_FECF, TC_HAS_SEGMENT_HDRS, TC_OCF_NA, 1024, AOS_FHEC_NA, AOS_IZ_NA, 0);
GvcidManagedParameters_t AOS_Managed_Parameters = {0, 0x0003, 0, TC_NO_FECF, AOS_FHEC_NA, AOS_IZ_NA, 0, TC_NO_SEGMENT_HDRS, 1024, TC_OCF_NA, 1};
Crypto_Config_Add_Gvcid_Managed_Parameters(AOS_Managed_Parameters);

status = Crypto_Init();

TC_t* tc_sdls_processed_frame;
tc_sdls_processed_frame = malloc(sizeof(uint8_t) * TC_SIZE);
memset(tc_sdls_processed_frame, 0, (sizeof(uint8_t) * TC_SIZE));

// Test frame setup
char* test_frame_pt_h = "2003000C00002C414243444546";
uint8_t *test_frame_pt_b = NULL;
int test_frame_pt_len = 0;

// Convert input test frame
hex_conversion(test_frame_pt_h, (char**) &test_frame_pt_b, &test_frame_pt_len);

status = Crypto_TC_ProcessSecurity(test_frame_pt_b, &test_frame_pt_len, tc_sdls_processed_frame);

ASSERT_EQ(CRYPTO_LIB_ERR_SA_NOT_OPERATIONAL, status);
free(test_frame_pt_b);
free(tc_sdls_processed_frame);
Crypto_Shutdown();
}

UTEST_MAIN();
Loading