Skip to content

Commit

Permalink
Merge pull request #188 from #186-SA-Custom
Browse files Browse the repository at this point in the history
cryptolib#186 - SA Custom
  • Loading branch information
jlucas9 authored Jul 21, 2023
2 parents b10805f + 7f8777a commit 7b8637e
Show file tree
Hide file tree
Showing 43 changed files with 1,055 additions and 1,005 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ option(DEBUG "Debug" OFF)
option(KEY_CUSTOM "Key Module - Custom" OFF)
option(KEY_INTERNAL "Key Module - Internal" ON)
option(KEY_KMC "Key Module - KMC OFF")
option(SA_CUSTOM "Security Association - Custom" OFF)
option(MC_CUSTOM "Monitoring and Control - Custom" OFF)
option(MC_INTERNAL "Monitoring and Control - Internal" ON)
option(SA_INTERNAL "Security Association - Internal" ON)
Expand Down
4 changes: 2 additions & 2 deletions codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ ignore:
- "src/sa/internal_stub/*"
- "src/sa/mariadb/*"
- "src/sa/mariadb_stub/*"
- "src/sa/sadb_mariadb_sql/*"
- "src/sa/test_sadb_mariadb_sql/*"
- "src/sa/sa_mariadb_sql/*"
- "src/sa/test_sa_mariadb_sql/*"
- "support/*"
- "test/*"
13 changes: 7 additions & 6 deletions include/crypto.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,11 @@
#include "crypto_events.h"
#include "crypto_print.h"
#include "crypto_structs.h"
#include "sadb_routine.h"
#include "sa_interface.h"
#include "cryptography_interface.h"
#include "key_interface.h"
#include "mc_interface.h"
#include "sa_interface.h"

/*
** Crypto Version
Expand All @@ -59,7 +60,7 @@
*/

// Crypto Library Configuration functions
extern int32_t Crypto_Config_CryptoLib(uint8_t key_type, uint8_t mc_type, uint8_t sadb_type, uint8_t cryptography_type,
extern int32_t Crypto_Config_CryptoLib(uint8_t key_type, uint8_t mc_type, uint8_t sa_type, uint8_t cryptography_type,
uint8_t iv_type, uint8_t crypto_create_fecf, uint8_t process_sdls_pdus,
uint8_t has_pus_hdr, uint8_t ignore_sa_state, uint8_t ignore_anti_replay,
uint8_t unique_sa_per_mapid, uint8_t crypto_check_fecf, uint8_t vcid_bitmask,
Expand All @@ -82,7 +83,7 @@ extern int32_t Crypto_Config_Add_Gvcid_Managed_Parameter(uint8_t tfvn, uint16_t
extern int32_t Crypto_Init(void); // Initialize CryptoLib After Configuration Calls
extern int32_t Crypto_Init_With_Configs(
CryptoConfig_t* crypto_config_p, GvcidManagedParameters_t* gvcid_managed_parameters_p,
SadbMariaDBConfig_t* sadb_mariadb_config_p,
SadbMariaDBConfig_t* sa_mariadb_config_p,
CryptographyKmcCryptoServiceConfig_t* cryptography_kmc_crypto_config_p); // Initialize CryptoLib With Application Defined Configuration
extern int32_t Crypto_Init_TC_Unit_Test(void); // Initialize CryptoLib with unit test default Configurations
extern int32_t Crypto_Init_TM_Unit_Test(void); // Initialize CryptoLib with unit test default Configurations
Expand Down Expand Up @@ -186,19 +187,19 @@ extern TM_FrameSecurityHeader_t tm_frame_sec_hdr; // Used to reduce bit math dup

// Global configuration structs
extern CryptoConfig_t* crypto_config;
extern SadbMariaDBConfig_t* sadb_mariadb_config;
extern SadbMariaDBConfig_t* sa_mariadb_config;
extern CryptographyKmcCryptoServiceConfig_t* cryptography_kmc_crypto_config;
extern CamConfig_t* cam_config;
extern GvcidManagedParameters_t* gvcid_managed_parameters;
extern GvcidManagedParameters_t* current_managed_parameters;
extern KeyInterface key_if;
extern McInterface mc_if;
extern SadbRoutine sadb_routine;
extern SaInterface sa_if;
extern CryptographyInterface cryptography_if;

// extern crypto_key_t ak_ring[NUM_KEYS];
extern CCSDS_t sdls_frame;
extern SadbMariaDBConfig_t* sadb_mariadb_config;
extern SadbMariaDBConfig_t* sa_mariadb_config;
extern GvcidManagedParameters_t* gvcid_managed_parameters;
extern GvcidManagedParameters_t* current_managed_parameters;
// OCF
Expand Down
7 changes: 4 additions & 3 deletions include/crypto_config_structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ typedef enum
} McType;
typedef enum
{
SADB_TYPE_INMEMORY,
SADB_TYPE_MARIADB
SA_TYPE_CUSTOM,
SA_TYPE_INMEMORY,
SA_TYPE_MARIADB
} SadbType;
typedef enum
{
Expand Down Expand Up @@ -164,7 +165,7 @@ typedef struct
{
KeyType key_type;
McType mc_type;
SadbType sadb_type;
SadbType sa_type;
CryptographyType cryptography_type;
IvType iv_type; // Whether or not CryptoLib should generate the IV
CreateFecfBool crypto_create_fecf; // Whether or not CryptoLib is expected to calculate TC FECFs and return
Expand Down
4 changes: 2 additions & 2 deletions include/crypto_error.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@

extern char *crypto_enum_errlist_core[];
extern char *crypto_enum_errlist_config[];
extern char *crypto_enum_errlist_sadb_if[];
extern char *crypto_enum_errlist_sadb_mariadb[];
extern char *crypto_enum_errlist_sa_if[];
extern char *crypto_enum_errlist_sa_mariadb[];
extern char *crypto_enum_errlist_crypto_if[];
extern char *crypto_enum_errlist_crypto_kmc[];
extern char *crypto_enum_errlist_crypto_cam[];
Expand Down
45 changes: 23 additions & 22 deletions include/sadb_routine.h → include/sa_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
* foreign persons.
*/

#ifndef CRYPTOLIB_SADB_ROUTINE_H
#define CRYPTOLIB_SADB_ROUTINE_H
#ifndef CRYPTOLIB_SA_INTERFACE_H
#define CRYPTOLIB_SA_INTERFACE_H

#ifdef NOS3 // NOS3/cFS build is ready
#include "common_types.h"
Expand All @@ -29,28 +29,29 @@
typedef struct
{
// Security Association Initialization & Management Functions
int32_t (*sadb_config)(void);
int32_t (*sadb_init)(void);
int32_t (*sadb_close)(void);
int32_t (*sa_config)(void);
int32_t (*sa_init)(void);
int32_t (*sa_close)(void);
// Security Association Interaction Functions
int32_t (*sadb_get_sa_from_spi)(uint16_t, SecurityAssociation_t** );
int32_t (*sadb_get_operational_sa_from_gvcid)(uint8_t, uint16_t, uint16_t, uint8_t, SecurityAssociation_t**);
int32_t (*sadb_save_sa)(SecurityAssociation_t* );
int32_t (*sa_get_from_spi)(uint16_t, SecurityAssociation_t** );
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 (*sadb_sa_stop)(void);
int32_t (*sadb_sa_start)(TC_t* tc_frame);
int32_t (*sadb_sa_expire)(void);
int32_t (*sadb_sa_rekey)(void);
int32_t (*sadb_sa_status)(uint8_t* );
int32_t (*sadb_sa_create)(void);
int32_t (*sadb_sa_setARSN)(void);
int32_t (*sadb_sa_setARSNW)(void);
int32_t (*sadb_sa_delete)(void);
int32_t (*sa_stop)(void);
int32_t (*sa_start)(TC_t* tc_frame);
int32_t (*sa_expire)(void);
int32_t (*sa_rekey)(void);
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);

} SadbRoutineStruct, *SadbRoutine;
} SaInterfaceStruct, *SaInterface;

SadbRoutine get_sadb_routine_mariadb(void);
SadbRoutine get_sadb_routine_inmemory(void);
// SadbRoutine init_parse_sadb_routine(uint8_t* );
SaInterface get_sa_interface_custom(void);
SaInterface get_sa_interface_inmemory(void);
SaInterface get_sa_interface_mariadb(void);
// SaInterface init_parse_sa_routine(uint8_t* );

#endif //CRYPTOLIB_SADB_ROUTINE_H
#endif //CRYPTOLIB_SA_INTERFACE_H
17 changes: 13 additions & 4 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,15 @@ else()
list(APPEND LIB_SRC_FILES ${MC_INTERNAL_FILES})
endif()

if(SA_CUSTOM)
# Assumes CryptoLib is a Git submodule to project and custom directories and definitions exist at top level
aux_source_directory(../../sa/custom SA_CUSTOM_FILES)
list(APPEND LIB_SRC_FILES ${SA_CUSTOM_FILES})
else()
aux_source_directory(sa/custom_stub SA_CUSTOM_FILES)
list(APPEND LIB_SRC_FILES ${SA_CUSTOM_FILES})
endif()

if(SA_INTERNAL)
aux_source_directory(sa/internal SA_INTERNAL_FILES)
list(APPEND LIB_SRC_FILES ${SA_INTERNAL_FILES})
Expand Down Expand Up @@ -137,10 +146,10 @@ else()
endif()

if(SA_MARIADB)
file(GLOB MYSQL_SCRIPTS sa/sadb_mariadb_sql/*.sql)
file(GLOB MYSQL_TEST_SCRIPTS sa/test_sadb_mariadb_sql/*.sql)
file(GLOB MYSQL_SCRIPTS sa/sa_mariadb_sql/*.sql)
file(GLOB MYSQL_TEST_SCRIPTS sa/test_sa_mariadb_sql/*.sql)
install(FILES ${MYSQL_SCRIPTS}
DESTINATION ${CMAKE_INSTALL_PREFIX}/etc/sadb_mariadb_sql)
DESTINATION ${CMAKE_INSTALL_PREFIX}/etc/sa_mariadb_sql)
install(FILES ${MYSQL_TEST_SCRIPTS}
DESTINATION ${CMAKE_INSTALL_PREFIX}/test/test_sadb_mariadb_sql)
DESTINATION ${CMAKE_INSTALL_PREFIX}/test/test_sa_mariadb_sql)
endif()
18 changes: 9 additions & 9 deletions src/core/crypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -459,49 +459,49 @@ int32_t Crypto_PDU(uint8_t* ingest, TC_t* tc_frame)
#ifdef PDU_DEBUG
printf(KGRN "SA Create\n" RESET);
#endif
status = sadb_routine->sadb_sa_create();
status = sa_if->sa_create();
break;
case PID_DELETE_SA:
#ifdef PDU_DEBUG
printf(KGRN "SA Delete\n" RESET);
#endif
status = sadb_routine->sadb_sa_delete();
status = sa_if->sa_delete();
break;
case PID_SET_ARSNW:
#ifdef PDU_DEBUG
printf(KGRN "SA setARSNW\n" RESET);
#endif
status = sadb_routine->sadb_sa_setARSNW();
status = sa_if->sa_setARSNW();
break;
case PID_REKEY_SA:
#ifdef PDU_DEBUG
printf(KGRN "SA Rekey\n" RESET);
#endif
status = sadb_routine->sadb_sa_rekey();
status = sa_if->sa_rekey();
break;
case PID_EXPIRE_SA:
#ifdef PDU_DEBUG
printf(KGRN "SA Expire\n" RESET);
#endif
status = sadb_routine->sadb_sa_expire();
status = sa_if->sa_expire();
break;
case PID_SET_ARSN:
#ifdef PDU_DEBUG
printf(KGRN "SA SetARSN\n" RESET);
#endif
status = sadb_routine->sadb_sa_setARSN();
status = sa_if->sa_setARSN();
break;
case PID_START_SA:
#ifdef PDU_DEBUG
printf(KGRN "SA Start\n" RESET);
#endif
status = sadb_routine->sadb_sa_start(tc_frame);
status = sa_if->sa_start(tc_frame);
break;
case PID_STOP_SA:
#ifdef PDU_DEBUG
printf(KGRN "SA Stop\n" RESET);
#endif
status = sadb_routine->sadb_sa_stop();
status = sa_if->sa_stop();
break;
case PID_READ_ARSN:
#ifdef PDU_DEBUG
Expand All @@ -513,7 +513,7 @@ int32_t Crypto_PDU(uint8_t* ingest, TC_t* tc_frame)
#ifdef PDU_DEBUG
printf(KGRN "SA Status\n" RESET);
#endif
status = sadb_routine->sadb_sa_status(ingest);
status = sa_if->sa_status(ingest);
break;
default:
printf(KRED "Error: Crypto_PDU failed interpreting SA Procedure Identification Field! \n" RESET);
Expand Down
Loading

0 comments on commit 7b8637e

Please sign in to comment.