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

69 rc1.0.3 #70

Merged
merged 6 commits into from
Feb 3, 2022
Merged
Show file tree
Hide file tree
Changes from 5 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
7 changes: 6 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ OPTION(MYSQL "Mysql" OFF) # Disabled by default, enable with: -DMYSQL=ON
OPTION(LIBGCRYPT "Libgcrypt" ON) # Enabled by default, disable with: -DLIBGCRYPT=OFF
OPTION(KMCCRYPTO "KmcCrypto" OFF) # Disabled by default, enable with: -DKMCCRYPTO=ON
OPTION(ENCTEST "Encryption-Tests" OFF) # Disabled by default, enable with: -DENCTEST=ON
OPTION(CODECOV "Code-Coverage" OFF) # Disabled by default, enable with: -DCODECOV=ON

IF(DEBUG)
ADD_DEFINITIONS(-DDEBUG -DOCF_DEBUG -DFECF_DEBUG -DSA_DEBUG -DPDU_DEBUG -DCCSDS_DEBUG -DTC_DEBUG -DMAC_DEBUG -DTM_DEBUG)
Expand All @@ -42,7 +43,11 @@ if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
enable_testing()
endif()

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Werror -g -O0 -fprofile-arcs -ftest-coverage")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Werror -g -O0")

if(CODECOV)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage")
endif()

include_directories(include)

Expand Down
106 changes: 53 additions & 53 deletions include/crypto.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
*/
#define CRYPTO_LIB_MAJOR_VERSION 1
#define CRYPTO_LIB_MINOR_VERSION 0
#define CRYPTO_LIB_REVISION 1
#define CRYPTO_LIB_REVISION 3
#define CRYPTO_LIB_MISSION_REV 0

/*
Expand All @@ -55,79 +55,79 @@
extern int32_t Crypto_Config_CryptoLib(uint8_t sadb_type, uint8_t cryptography_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);
extern int32_t Crypto_Config_MariaDB(char *mysql_hostname, char *mysql_database, uint16_t mysql_port,
extern int32_t Crypto_Config_MariaDB(char* mysql_hostname, char* mysql_database, uint16_t mysql_port,
uint8_t mysql_require_secure_transport, uint8_t mysql_tls_verify_server,
char *mysql_tls_ca, char *mysql_tls_capath, char *mysql_mtls_cert,
char *mysql_mtls_key,
char *mysql_mtls_client_key_password, char *mysql_username, char *mysql_password);
extern int32_t Crypto_Config_Kmc_Crypto_Service(char *protocol, char *kmc_crypto_hostname, uint16_t kmc_crypto_port,
char *kmc_crypto_app, char *kmc_tls_ca_bundle, char *kmc_tls_ca_path,
uint8_t kmc_ignore_ssl_hostname_validation, char *mtls_client_cert_path,
char *mtls_client_cert_type, char *mtls_client_key_path,
char *mtls_client_key_pass, char *mtls_issuer_cert);
char* mysql_tls_ca, char* mysql_tls_capath, char* mysql_mtls_cert,
char* mysql_mtls_key,
char* mysql_mtls_client_key_password, char* mysql_username, char* mysql_password);
extern int32_t Crypto_Config_Kmc_Crypto_Service(char* protocol, char* kmc_crypto_hostname, uint16_t kmc_crypto_port,
char* kmc_crypto_app, char* kmc_tls_ca_bundle, char* kmc_tls_ca_path,
uint8_t kmc_ignore_ssl_hostname_validation, char* mtls_client_cert_path,
char* mtls_client_cert_type, char* mtls_client_key_path,
char* mtls_client_key_pass, char* mtls_issuer_cert);
extern int32_t Crypto_Config_Add_Gvcid_Managed_Parameter(uint8_t tfvn, uint16_t scid, uint8_t vcid, uint8_t has_fecf,
uint8_t has_segmentation_hdr);

// Initialization
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,
CryptographyKmcCryptoServiceConfig_t *cryptography_kmc_crypto_config_p); // Initialize CryptoLib With Application Defined Configuration
CryptoConfig_t* crypto_config_p, GvcidManagedParameters_t* gvcid_managed_parameters_p,
SadbMariaDBConfig_t* sadb_mariadb_config_p,
CryptographyKmcCryptoServiceConfig_t* cryptography_kmc_crypto_config_p); // Initialize CryptoLib With Application Defined Configuration
extern int32_t Crypto_Init_Unit_Test(void); // Initialize CryptoLib with unit test default Configurations

// Cleanup
extern int32_t Crypto_Shutdown(void); // Free all allocated memory

// Telecommand (TC)
extern int32_t Crypto_TC_ApplySecurity(const uint8_t *p_in_frame, const uint16_t in_frame_length,
uint8_t **pp_enc_frame, uint16_t *p_enc_frame_len);
extern int32_t Crypto_TC_ProcessSecurity(uint8_t *ingest, int *len_ingest, TC_t *tc_sdls_processed_frame);
extern int32_t Crypto_TC_ApplySecurity(const uint8_t* p_in_frame, const uint16_t in_frame_length,
uint8_t* *pp_enc_frame, uint16_t* p_enc_frame_len);
extern int32_t Crypto_TC_ProcessSecurity(uint8_t* ingest, int *len_ingest, TC_t* tc_sdls_processed_frame);
// Telemetry (TM)
extern int32_t Crypto_TM_ApplySecurity(uint8_t *ingest, int *len_ingest);
extern int32_t Crypto_TM_ProcessSecurity(uint8_t *ingest, int *len_ingest);
extern int32_t Crypto_TM_ApplySecurity(uint8_t* ingest, int *len_ingest);
extern int32_t Crypto_TM_ProcessSecurity(uint8_t* ingest, int *len_ingest);
// Advanced Orbiting Systems (AOS)
extern int32_t Crypto_AOS_ApplySecurity(uint8_t *ingest, int *len_ingest);
extern int32_t Crypto_AOS_ProcessSecurity(uint8_t *ingest, int *len_ingest);
extern int32_t Crypto_AOS_ApplySecurity(uint8_t* ingest, int *len_ingest);
extern int32_t Crypto_AOS_ProcessSecurity(uint8_t* ingest, int *len_ingest);

/*
** Internal Prototypes
*/
extern uint8_t Crypto_Prep_Reply(uint8_t *ingest, uint8_t appID);
extern int32_t Crypto_increment(uint8_t *num, int length);
// int32_t Crypto_Get_tcPayloadLength(TC_t* tc_frame, SecurityAssociation_t *sa_ptr);
extern uint8_t Crypto_Prep_Reply(uint8_t* ingest, uint8_t appID);
extern int32_t Crypto_increment(uint8_t* num, int length);
// int32_t Crypto_Get_tcPayloadLength(TC_t* tc_frame, SecurityAssociation_t* sa_ptr);
int32_t Crypto_Get_tmLength(int len);
uint8_t Crypto_Is_AEAD_Algorithm(uint32_t cipher_suite_id);
uint8_t *Crypto_Prepare_TC_AAD(uint8_t *buffer, uint16_t len_aad, uint8_t *abm_buffer);
void Crypto_TM_updatePDU(uint8_t *ingest, int len_ingest);
uint8_t* Crypto_Prepare_TC_AAD(uint8_t* buffer, uint16_t len_aad, uint8_t* abm_buffer);
void Crypto_TM_updatePDU(uint8_t* ingest, int len_ingest);
void Crypto_TM_updateOCF(void);
void Crypto_Local_Config(void);
void Crypto_Local_Init(void);
// int32_t Crypto_gcm_err(int gcm_err);
int32_t Crypto_window(uint8_t *actual, uint8_t *expected, int length, int window);
// int32_t Crypto_compare_less_equal(uint8_t *actual, uint8_t *expected, int length);
int32_t Crypto_window(uint8_t* actual, uint8_t* expected, int length, int window);
// int32_t Crypto_compare_less_equal(uint8_t* actual, uint8_t* expected, int length);
// int32_t Crypto_FECF(int fecf, uint8_t* ingest, int len_ingest,TC_t* tc_frame);
uint16_t Crypto_Calc_FECF(uint8_t *ingest, int len_ingest);
uint16_t Crypto_Calc_FECF(uint8_t* ingest, int len_ingest);
void Crypto_Calc_CRC_Init_Table(void);
uint16_t Crypto_Calc_CRC16(uint8_t *data, int size);
uint16_t Crypto_Calc_CRC16(uint8_t* data, int size);

// Key Management Functions
int32_t Crypto_Key_OTAR(void);
int32_t Crypto_Key_update(uint8_t state);
int32_t Crypto_Key_inventory(uint8_t *);
int32_t Crypto_Key_verify(uint8_t *, TC_t *tc_frame);
int32_t Crypto_Key_inventory(uint8_t* );
int32_t Crypto_Key_verify(uint8_t* , TC_t* tc_frame);

// Security Monitoring & Control Procedure
int32_t Crypto_MC_ping(uint8_t *ingest);
int32_t Crypto_MC_status(uint8_t *ingest);
int32_t Crypto_MC_dump(uint8_t *ingest);
int32_t Crypto_MC_erase(uint8_t *ingest);
int32_t Crypto_MC_selftest(uint8_t *ingest);
int32_t Crypto_SA_readARSN(uint8_t *ingest);
int32_t Crypto_MC_ping(uint8_t* ingest);
int32_t Crypto_MC_status(uint8_t* ingest);
int32_t Crypto_MC_dump(uint8_t* ingest);
int32_t Crypto_MC_erase(uint8_t* ingest);
int32_t Crypto_MC_selftest(uint8_t* ingest);
int32_t Crypto_SA_readARSN(uint8_t* ingest);
int32_t Crypto_MC_resetalarm(void);

// User Functions
int32_t Crypto_User_IdleTrigger(uint8_t *ingest);
int32_t Crypto_User_IdleTrigger(uint8_t* ingest);
int32_t Crypto_User_BadSPI(void);
int32_t Crypto_User_BadIV(void);
int32_t Crypto_User_BadMAC(void);
Expand All @@ -137,17 +137,17 @@ int32_t Crypto_User_ModifyActiveTM(void);
int32_t Crypto_User_ModifyVCID(void);

// Determine Payload Data Unit
int32_t Crypto_Process_Extended_Procedure_Pdu(TC_t *tc_sdls_processed_frame, uint8_t *ingest);
int32_t Crypto_PDU(uint8_t *ingest, TC_t *tc_frame);
int32_t Crypto_Process_Extended_Procedure_Pdu(TC_t* tc_sdls_processed_frame, uint8_t* ingest);
int32_t Crypto_PDU(uint8_t* ingest, TC_t* tc_frame);

// Managed Parameter Functions
int32_t Crypto_Get_Managed_Parameters_For_Gvcid(uint8_t tfvn, uint16_t scid, uint8_t vcid,
GvcidManagedParameters_t *managed_parameters_in,
GvcidManagedParameters_t **managed_parameters_out);
GvcidManagedParameters_t* managed_parameters_in,
GvcidManagedParameters_t* *managed_parameters_out);
int32_t crypto_config_add_gvcid_managed_parameter_recursion(uint8_t tfvn, uint16_t scid, uint8_t vcid,
uint8_t has_fecf, uint8_t has_segmentation_hdr,
GvcidManagedParameters_t *managed_parameter);
void Crypto_Free_Managed_Parameters(GvcidManagedParameters_t *managed_parameters);
GvcidManagedParameters_t* managed_parameter);
void Crypto_Free_Managed_Parameters(GvcidManagedParameters_t* managed_parameters);



Expand All @@ -159,21 +159,21 @@ extern CCSDS_t sdls_frame;
extern TM_t tm_frame;

// Global configuration structs
extern CryptoConfig_t *crypto_config;
extern SadbMariaDBConfig_t *sadb_mariadb_config;
extern CryptographyKmcCryptoServiceConfig_t *cryptography_kmc_crypto_config;
extern GvcidManagedParameters_t *gvcid_managed_parameters;
extern GvcidManagedParameters_t *current_managed_parameters;
extern CryptoConfig_t* crypto_config;
extern SadbMariaDBConfig_t* sadb_mariadb_config;
extern CryptographyKmcCryptoServiceConfig_t* cryptography_kmc_crypto_config;
extern GvcidManagedParameters_t* gvcid_managed_parameters;
extern GvcidManagedParameters_t* current_managed_parameters;
extern SadbRoutine sadb_routine;
extern CryptographyInterface cryptography_if;

// extern crypto_key_t ak_ring[NUM_KEYS];
extern CCSDS_t sdls_frame;
extern TM_t tm_frame;
extern CryptoConfig_t *crypto_config;
extern SadbMariaDBConfig_t *sadb_mariadb_config;
extern GvcidManagedParameters_t *gvcid_managed_parameters;
extern GvcidManagedParameters_t *current_managed_parameters;
extern CryptoConfig_t* crypto_config;
extern SadbMariaDBConfig_t* sadb_mariadb_config;
extern GvcidManagedParameters_t* gvcid_managed_parameters;
extern GvcidManagedParameters_t* current_managed_parameters;
// OCF
extern uint8_t ocf;
extern SDLS_FSR_t report;
Expand Down
10 changes: 5 additions & 5 deletions include/crypto_config_structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ struct _GvcidManagedParameters_t
uint8_t vcid : 6; // Virtual Channel ID
TcFecfPresent has_fecf;
TcSegmentHdrsPresent has_segmentation_hdr;
GvcidManagedParameters_t *next; // Will be a list of managed parameters!
GvcidManagedParameters_t* next; // Will be a list of managed parameters!
};
#define GVCID_MANAGED_PARAMETERS_SIZE (sizeof(GvcidManagedParameters_t))

Expand All @@ -135,10 +135,10 @@ struct _GvcidManagedParameters_t
*/
typedef struct
{
char *mysql_username;
char *mysql_password;
char *mysql_hostname;
char *mysql_database;
char* mysql_username;
char* mysql_password;
char* mysql_hostname;
char* mysql_database;
uint16_t mysql_port;
char* mysql_mtls_cert;
char* mysql_mtls_key;
Expand Down
18 changes: 9 additions & 9 deletions include/crypto_print.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@
/*
** Prototypes
*/
void Crypto_tcPrint(TC_t *tc_frame);
void Crypto_tmPrint(TM_t *tm_frame);
void Crypto_clcwPrint(TM_FrameCLCW_t *clcw);
void Crypto_fsrPrint(SDLS_FSR_t *report);
void Crypto_ccsdsPrint(CCSDS_t *sdls_frame);
void Crypto_saPrint(SecurityAssociation_t *sa);
void Crypto_hexprint(void *c, size_t n);
void Crypto_binprint(void *c, size_t n);
void Crypto_mpPrint(GvcidManagedParameters_t *managed_parameters, uint8_t print_children);
void Crypto_tcPrint(TC_t* tc_frame);
void Crypto_tmPrint(TM_t* tm_frame);
void Crypto_clcwPrint(TM_FrameCLCW_t* clcw);
void Crypto_fsrPrint(SDLS_FSR_t* report);
void Crypto_ccsdsPrint(CCSDS_t* sdls_frame);
void Crypto_saPrint(SecurityAssociation_t* sa);
void Crypto_hexprint(void* c, size_t n);
void Crypto_binprint(void* c, size_t n);
void Crypto_mpPrint(GvcidManagedParameters_t* managed_parameters, uint8_t print_children);
#endif
8 changes: 4 additions & 4 deletions include/crypto_structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,15 @@ typedef struct
uint8_t shsnf_len : 6; // Sec. Header SN Field Length
uint8_t shplf_len : 2; // Sec. Header PL Field Length
uint8_t stmacf_len : 8; // Sec. Trailer MAC Field Length
uint8_t *ecs; // Encryption Cipher Suite (algorithm / mode ID)
uint8_t* ecs; // Encryption Cipher Suite (algorithm / mode ID)
uint8_t ecs_len : 8; // Encryption Cipher Suite Length
uint8_t *iv; // Initialization Vector
uint8_t* iv; // Initialization Vector
uint8_t acs_len : 8; // Authentication Cipher Suite Length
uint8_t acs : 8; // Authentication Cipher Suite (algorithm / mode ID)
uint16_t abm_len : 16; // Authentication Bit Mask Length
uint8_t *abm; // Authentication Bit Mask (Primary Hdr. through Security Hdr.)
uint8_t* abm; // Authentication Bit Mask (Primary Hdr. through Security Hdr.)
uint8_t arc_len : 8; // Anti-Replay Counter Length
uint8_t *arc; // Anti-Replay Counter
uint8_t* arc; // Anti-Replay Counter
uint8_t arcw_len : 8; // Anti-Replay Counter Window Length
uint16_t arcw; // Anti-Replay Counter Window

Expand Down
12 changes: 6 additions & 6 deletions include/sadb_routine.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ typedef struct
int32_t (*sadb_init)(void);
int32_t (*sadb_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 (*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* );
// Security Association Utility Functions
int32_t (*sadb_sa_stop)(void);
int32_t (*sadb_sa_start)(TC_t *tc_frame);
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_status)(uint8_t* );
int32_t (*sadb_sa_create)(void);
int32_t (*sadb_sa_setARSN)(void);
int32_t (*sadb_sa_setARSNW)(void);
Expand All @@ -51,6 +51,6 @@ typedef struct

SadbRoutine get_sadb_routine_mariadb(void);
SadbRoutine get_sadb_routine_inmemory(void);
// SadbRoutine init_parse_sadb_routine(uint8_t *);
// SadbRoutine init_parse_sadb_routine(uint8_t* );

#endif // CRYPTOLIB_SADB_ROUTINE_H
16 changes: 8 additions & 8 deletions src/src_cryptography/src_kmc_crypto_service/base64.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,18 @@ static const uint8_t base64DecTable[128] =
* @param[out] outputLen Length of the encoded string (optional parameter)
**/

void base64Encode(const void *input, size_t inputLen, char_t *output,
size_t *outputLen)
void base64Encode(const void* input, size_t inputLen, char_t* output,
size_t* outputLen)
{
size_t n;
uint8_t a;
uint8_t b;
uint8_t c;
uint8_t d;
const uint8_t *p;
const uint8_t* p;

//Point to the first byte of the input data
p = (const uint8_t *) input;
p = (const uint8_t* ) input;

//Divide the input stream into blocks of 3 bytes
n = inputLen / 3;
Expand Down Expand Up @@ -183,8 +183,8 @@ void base64Encode(const void *input, size_t inputLen, char_t *output,
* @return Error code
**/

int32_t base64Decode(const char_t *input, size_t inputLen, void *output,
size_t *outputLen)
int32_t base64Decode(const char_t* input, size_t inputLen, void* output,
size_t* outputLen)
{
int32_t error;
uint32_t value;
Expand All @@ -193,7 +193,7 @@ int32_t base64Decode(const char_t *input, size_t inputLen, void *output,
size_t j;
size_t n;
size_t padLen;
uint8_t *p;
uint8_t* p;

//Check parameters
if(input == NULL && inputLen != 0)
Expand All @@ -205,7 +205,7 @@ int32_t base64Decode(const char_t *input, size_t inputLen, void *output,
error = NO_ERROR;

//Point to the buffer where to write the decoded data
p = (uint8_t *) output;
p = (uint8_t* ) output;

//Initialize variables
j = 0;
Expand Down
8 changes: 4 additions & 4 deletions src/src_cryptography/src_kmc_crypto_service/base64.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ typedef char char_t;
typedef unsigned int uint_t;

//Base64 encoding related functions
void base64Encode(const void *input, size_t inputLen, char_t *output,
size_t *outputLen);
void base64Encode(const void* input, size_t inputLen, char_t* output,
size_t* outputLen);

int32_t base64Decode(const char_t *input, size_t inputLen, void *output,
size_t *outputLen);
int32_t base64Decode(const char_t* input, size_t inputLen, void* output,
size_t* outputLen);

#define ERROR_INVALID_PARAMETER 21
#define ERROR_INVALID_LENGTH 22
Expand Down
Loading