Skip to content

Commit

Permalink
Merge pull request #374 from nasa/367-examine-ep-modification-calls
Browse files Browse the repository at this point in the history
367 examine ep modification calls
  • Loading branch information
Donnie-Ice authored Dec 18, 2024
2 parents c7cb887 + cdeebfe commit f4d8552
Show file tree
Hide file tree
Showing 7 changed files with 205 additions and 46 deletions.
14 changes: 7 additions & 7 deletions include/sa_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ typedef struct
int32_t (*sa_get_operational_sa_from_gvcid)(uint8_t, uint16_t, uint16_t, uint8_t, SecurityAssociation_t **);
int32_t (*sa_save_sa)(SecurityAssociation_t *);
// Security Association Utility Functions
int32_t (*sa_stop)(void);
int32_t (*sa_stop)(TC_t *tc_frame);
int32_t (*sa_start)(TC_t *tc_frame);
int32_t (*sa_expire)(void);
int32_t (*sa_rekey)(void);
int32_t (*sa_expire)(TC_t *tc_frame);
int32_t (*sa_rekey)(TC_t *tc_frame);
int32_t (*sa_status)(uint8_t *);
int32_t (*sa_create)(void);
int32_t (*sa_setARSN)(void);
int32_t (*sa_setARSNW)(void);
int32_t (*sa_delete)(void);
int32_t (*sa_create)(TC_t *tc_frame);
int32_t (*sa_setARSN)(TC_t *tc_frame);
int32_t (*sa_setARSNW)(TC_t *tc_frame);
int32_t (*sa_delete)(TC_t *tc_frame);

} SaInterfaceStruct, *SaInterface;

Expand Down
14 changes: 7 additions & 7 deletions src/core/crypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -529,37 +529,37 @@ int32_t Crypto_SG_SA_MGMT(uint8_t *ingest, TC_t *tc_frame)
#ifdef PDU_DEBUG
printf(KGRN "SA Create\n" RESET);
#endif
status = sa_if->sa_create();
status = sa_if->sa_create(tc_frame);
break;
case PID_DELETE_SA:
#ifdef PDU_DEBUG
printf(KGRN "SA Delete\n" RESET);
#endif
status = sa_if->sa_delete();
status = sa_if->sa_delete(tc_frame);
break;
case PID_SET_ARSNW:
#ifdef PDU_DEBUG
printf(KGRN "SA setARSNW\n" RESET);
#endif
status = sa_if->sa_setARSNW();
status = sa_if->sa_setARSNW(tc_frame);
break;
case PID_REKEY_SA:
#ifdef PDU_DEBUG
printf(KGRN "SA Rekey\n" RESET);
#endif
status = sa_if->sa_rekey();
status = sa_if->sa_rekey(tc_frame);
break;
case PID_EXPIRE_SA:
#ifdef PDU_DEBUG
printf(KGRN "SA Expire\n" RESET);
#endif
status = sa_if->sa_expire();
status = sa_if->sa_expire(tc_frame);
break;
case PID_SET_ARSN:
#ifdef PDU_DEBUG
printf(KGRN "SA SetARSN\n" RESET);
#endif
status = sa_if->sa_setARSN();
status = sa_if->sa_setARSN(tc_frame);
break;
case PID_START_SA:
#ifdef PDU_DEBUG
Expand All @@ -571,7 +571,7 @@ int32_t Crypto_SG_SA_MGMT(uint8_t *ingest, TC_t *tc_frame)
#ifdef PDU_DEBUG
printf(KGRN "SA Stop\n" RESET);
#endif
status = sa_if->sa_stop();
status = sa_if->sa_stop(tc_frame);
break;
case PID_READ_ARSN:
#ifdef PDU_DEBUG
Expand Down
152 changes: 127 additions & 25 deletions src/sa/internal/sa_interface_inmemory.template.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ static int32_t sa_get_from_spi(uint16_t, SecurityAssociation_t **);
static int32_t sa_get_operational_sa_from_gvcid(uint8_t, uint16_t, uint16_t, uint8_t, SecurityAssociation_t **);
static int32_t sa_save_sa(SecurityAssociation_t *sa);
// Security Association Utility Functions
static int32_t sa_stop(void);
static int32_t sa_stop(TC_t *tc_frame);
static int32_t sa_start(TC_t *tc_frame);
static int32_t sa_expire(void);
static int32_t sa_rekey(void);
static int32_t sa_expire(TC_t *tc_frame);
static int32_t sa_rekey(TC_t *tc_frame);
static int32_t sa_status(uint8_t *);
static int32_t sa_create(void);
static int32_t sa_setARSN(void);
static int32_t sa_setARSNW(void);
static int32_t sa_delete(void);
static int32_t sa_create(TC_t *tc_frame);
static int32_t sa_setARSN(TC_t *tc_frame);
static int32_t sa_setARSNW(TC_t *tc_frame);
static int32_t sa_delete(TC_t *tc_frame);

/*
** Global Variables
Expand Down Expand Up @@ -1072,12 +1072,16 @@ static int32_t sa_start(TC_t *tc_frame)
}
else
{
#ifdef DEBUG
printf(KRED "ERROR: SPI %d is not in the KEYED state.\n" RESET, spi);
#endif
}
}
else
{
#ifdef DEBUG
printf(KRED "ERROR: SPI %d does not exist.\n" RESET, spi);
#endif
}

#ifdef DEBUG
Expand All @@ -1091,15 +1095,31 @@ static int32_t sa_start(TC_t *tc_frame)
* @brief Function: sa_stop
* @return int32: Success/Failure
**/
static int32_t sa_stop(void)
static int32_t sa_stop(TC_t *tc_frame)
{
// Local variables
uint16_t spi = 0x0000;
int32_t status = CRYPTO_LIB_SUCCESS;
uint16_t spi = 0x0000;
uint16_t control_spi = 0x0000;
int x;

// Read ingest
spi = ((uint8_t)sdls_frame.pdu.data[0] << BYTE_LEN) | (uint8_t)sdls_frame.pdu.data[1];
spi = ((uint8_t)sdls_frame.pdu.data[0] << BYTE_LEN) | (uint8_t)sdls_frame.pdu.data[1];
control_spi = tc_frame->tc_sec_header.spi;

#ifdef DEBUG
printf("control_spi = %d \n", spi);
printf("spi = %d \n", spi);
#endif

if (spi == control_spi)
{
#ifdef DEBUG
printf(KRED "ERROR: Cannot modify SA in use\n" RESET);
#endif
status = CRYPTO_LIB_ERR_SDLS_EP_WRONG_SPI;
return status;
}

// Check SPI exists and in 'Active' state
if (spi < NUM_SA)
Expand Down Expand Up @@ -1137,36 +1157,52 @@ static int32_t sa_stop(void)
}
else
{
#ifdef DEBUG
printf(KRED "ERROR: SPI %d is not in the OPERATIONAL state.\n" RESET, spi);
#endif
}
}
else
{
#ifdef DEBUG
printf(KRED "ERROR: SPI %d does not exist.\n" RESET, spi);
#endif
}

#ifdef DEBUG
printf("\t spi = %d \n", spi);
#endif

return CRYPTO_LIB_SUCCESS;
return status;
}

/**
* @brief Function: sa_rekey
* @return int32: Success/Failure
**/
static int32_t sa_rekey(void)
static int32_t sa_rekey(TC_t *tc_frame)
{
// Local variables
uint16_t spi = 0x0000;
int count = 0;
int x = 0;
uint16_t spi = 0x0000;
uint16_t control_spi = 0x0000;
int32_t status = CRYPTO_LIB_SUCCESS;
int count = 0;
int x = 0;

// Read ingest
spi = ((uint8_t)sdls_frame.pdu.data[count] << BYTE_LEN) | (uint8_t)sdls_frame.pdu.data[count + 1];
count = count + 2;

control_spi = tc_frame->tc_sec_header.spi;
if (spi == control_spi)
{
#ifdef DEBUG
printf(KRED "ERROR: Cannot modify SA in use\n" RESET);
#endif
status = CRYPTO_LIB_ERR_SDLS_EP_WRONG_SPI;
return status;
}

// Check SPI exists and in 'Unkeyed' state
if (spi < NUM_SA)
{
Expand Down Expand Up @@ -1245,14 +1281,25 @@ static int32_t sa_rekey(void)
* @brief Function: sa_expire
* @return int32: Success/Failure
**/
static int32_t sa_expire(void)
static int32_t sa_expire(TC_t *tc_frame)
{
// Local variables
uint16_t spi = 0x0000;
uint16_t spi = 0x0000;
uint16_t control_spi = 0x0000;
int32_t status = CRYPTO_LIB_SUCCESS;

// Read ingest
spi = ((uint8_t)sdls_frame.pdu.data[0] << BYTE_LEN) | (uint8_t)sdls_frame.pdu.data[1];
printf("spi = %d \n", spi);

control_spi = tc_frame->tc_sec_header.spi;
if (spi == control_spi)
{
#ifdef DEBUG
printf(KRED "ERROR: Cannot modify SA in use\n" RESET);
#endif
status = CRYPTO_LIB_ERR_SDLS_EP_WRONG_SPI;
return status;
}

// Check SPI exists and in 'Keyed' state
if (spi < NUM_SA)
Expand All @@ -1275,12 +1322,16 @@ static int32_t sa_expire(void)
}
else
{
#ifdef DEBUG
printf(KRED "ERROR: SPI %d is not in the KEYED state.\n" RESET, spi);
#endif
}
}
else
{
#ifdef DEBUG
printf(KRED "ERROR: SPI %d does not exist.\n" RESET, spi);
#endif
}

return CRYPTO_LIB_SUCCESS;
Expand All @@ -1290,11 +1341,13 @@ static int32_t sa_expire(void)
* @brief Function: sa_create
* @return int32: Success/Failure
**/
static int32_t sa_create(void)
static int32_t sa_create(TC_t *tc_frame)
{
// Local variables
uint8_t count = 6;
uint16_t spi = 0x0000;
uint16_t control_spi = 0x0000;
int32_t status = CRYPTO_LIB_SUCCESS;
int x;

// Read sdls_frame.pdu.data
Expand All @@ -1303,6 +1356,16 @@ static int32_t sa_create(void)
printf("spi = %d \n", spi);
#endif

control_spi = tc_frame->tc_sec_header.spi;
if (spi == control_spi)
{
#ifdef DEBUG
printf(KRED "ERROR: Cannot modify SA in use\n" RESET);
#endif
status = CRYPTO_LIB_ERR_SDLS_EP_WRONG_SPI;
return status;
}

// Check if valid SPI
if (spi < NUM_SA)
{
Expand Down Expand Up @@ -1377,17 +1440,29 @@ static int32_t sa_create(void)
* @brief Function: sa_delete
* @return int32: Success/Failure
**/
static int32_t sa_delete(void)
static int32_t sa_delete(TC_t *tc_frame)
{
// Local variables
uint16_t spi = 0x0000;
uint16_t control_spi = 0x0000;
int32_t status = CRYPTO_LIB_SUCCESS;

// Read ingest
spi = ((uint8_t)sdls_frame.pdu.data[0] << BYTE_LEN) | (uint8_t)sdls_frame.pdu.data[1];
#ifdef DEBUG
printf("spi = %d \n", spi);
#endif

control_spi = tc_frame->tc_sec_header.spi;
if (spi == control_spi)
{
#ifdef DEBUG
printf(KRED "ERROR: Cannot modify SA in use\n" RESET);
#endif
status = CRYPTO_LIB_ERR_SDLS_EP_WRONG_SPI;
return status;
}

// Check SPI exists and in 'Unkeyed' state
if (spi < NUM_SA)
{
Expand All @@ -1411,12 +1486,16 @@ static int32_t sa_delete(void)
}
else
{
#ifdef DEBUG
printf(KRED "ERROR: SPI %d is not in the UNKEYED state.\n" RESET, spi);
#endif
}
}
else
{
#ifdef DEBUG
printf(KRED "ERROR: SPI %d does not exist.\n" RESET, spi);
#endif
}

return CRYPTO_LIB_SUCCESS;
Expand All @@ -1426,15 +1505,26 @@ static int32_t sa_delete(void)
* @brief Function: sa_setASRN
* @return int32: Success/Failure
**/
static int32_t sa_setARSN(void)
static int32_t sa_setARSN(TC_t *tc_frame)
{
// Local variables
uint16_t spi = 0x0000;
uint16_t spi = 0x0000;
uint16_t control_spi = 0x0000;
int32_t status = CRYPTO_LIB_SUCCESS;
int x;

// Read ingest
spi = ((uint8_t)sdls_frame.pdu.data[0] << BYTE_LEN) | (uint8_t)sdls_frame.pdu.data[1];
printf("spi = %d \n", spi);

control_spi = tc_frame->tc_sec_header.spi;
if (spi == control_spi)
{
#ifdef DEBUG
printf(KRED "ERROR: Cannot modify SA in use\n" RESET);
#endif
status = CRYPTO_LIB_ERR_SDLS_EP_WRONG_SPI;
return status;
}

// TODO: Check SA type (authenticated, encrypted, both) and set appropriately
// TODO: Add more checks on bounds
Expand Down Expand Up @@ -1485,17 +1575,29 @@ static int32_t sa_setARSN(void)
* @brief Function: sa_setARSNW
* @return int32: Success/Failure
**/
static int32_t sa_setARSNW(void)
static int32_t sa_setARSNW(TC_t *tc_frame)
{
// Local variables
uint16_t spi = 0x0000;
uint16_t spi = 0x0000;
uint16_t control_spi = 0x0000;
int32_t status = CRYPTO_LIB_SUCCESS;

// Read ingest
spi = ((uint8_t)sdls_frame.pdu.data[0] << BYTE_LEN) | (uint8_t)sdls_frame.pdu.data[1];
#ifdef PDU_DEBUG
printf("spi = %d \n", spi);
#endif

control_spi = tc_frame->tc_sec_header.spi;
if (spi == control_spi)
{
#ifdef DEBUG
printf(KRED "ERROR: Cannot modify SA in use\n" RESET);
#endif
status = CRYPTO_LIB_ERR_SDLS_EP_WRONG_SPI;
return status;
}

// Check SPI exists
if (spi < NUM_SA)
{
Expand Down
Empty file modified support/scripts/build_ep.sh
100644 → 100755
Empty file.
Empty file modified support/scripts/update_env.sh
100644 → 100755
Empty file.
Loading

0 comments on commit f4d8552

Please sign in to comment.