Skip to content

Commit

Permalink
Merge pull request #187 from #165-MC
Browse files Browse the repository at this point in the history
cryptolib#165 - Monitoring and Control
  • Loading branch information
jlucas9 authored Jul 21, 2023
2 parents ceebbcc + 6ebbba9 commit b10805f
Show file tree
Hide file tree
Showing 31 changed files with 601 additions and 276 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ 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(MC_CUSTOM "Monitoring and Control - Custom" OFF)
option(MC_INTERNAL "Monitoring and Control - Internal" ON)
option(SA_INTERNAL "Security Association - Internal" ON)
option(SA_MARIADB "Security Association - MariaDB" OFF)
option(SUPPORT "Support" OFF)
Expand Down
4 changes: 3 additions & 1 deletion include/crypto.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include "sadb_routine.h"
#include "cryptography_interface.h"
#include "key_interface.h"
#include "mc_interface.h"

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

// Crypto Library Configuration functions
extern int32_t Crypto_Config_CryptoLib(uint8_t key_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 sadb_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 Down Expand Up @@ -191,6 +192,7 @@ 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 CryptographyInterface cryptography_if;

Expand Down
6 changes: 6 additions & 0 deletions include/crypto_config_structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ typedef enum
KEY_TYPE_KMC
} KeyType;
typedef enum
{
MC_TYPE_CUSTOM,
MC_TYPE_INTERNAL
} McType;
typedef enum
{
SADB_TYPE_INMEMORY,
SADB_TYPE_MARIADB
Expand Down Expand Up @@ -158,6 +163,7 @@ typedef enum
typedef struct
{
KeyType key_type;
McType mc_type;
SadbType sadb_type;
CryptographyType cryptography_type;
IvType iv_type; // Whether or not CryptoLib should generate the IV
Expand Down
1 change: 1 addition & 0 deletions include/crypto_error.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@
#define CRYPTO_LIB_ERR_INPUT_FRAME_TOO_SHORT_FOR_TM_STANDARD (-45)
#define CRYPTO_LIB_ERR_TC_ENUM_USED_FOR_TM_CONFIG (-46)
#define CRYPTO_LIB_ERR_KEY_ID_ERROR (-47)
#define CRYPTO_LIB_ERR_MC_INIT (-48)

extern char *crypto_enum_errlist_core[];
extern char *crypto_enum_errlist_config[];
Expand Down
48 changes: 48 additions & 0 deletions include/mc_interface.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/* Copyright (C) 2009 - 2022 National Aeronautics and Space Administration.
All Foreign Rights are Reserved to the U.S. Government.
This software is provided "as is" without any warranty of any kind, either expressed, implied, or statutory,
including, but not limited to, any warranty that the software will conform to specifications, any implied warranties
of merchantability, fitness for a particular purpose, and freedom from infringement, and any warranty that the
documentation will conform to the program, or any warranty that the software will be error free.
In no event shall NASA be liable for any damages, including, but not limited to direct, indirect, special or
consequential damages, arising out of, resulting from, or in any way connected with the software or its
documentation, whether or not based upon warranty, contract, tort or otherwise, and whether or not loss was sustained
from, or arose out of the results of, or use of, the software, documentation or services provided hereunder.
ITC Team
NASA IV&V
[email protected]
*/
#ifndef MONITORING_AND_CONTROL_INTERFACE_H
#define MONITORING_AND_CONTROL_INTERFACE_H

#include "crypto_error.h"
#include "crypto_structs.h"

/* Structures */
typedef struct
{
/* MC Interface, SDLS */
int32_t (*mc_initialize)(void);
void (*mc_log)(int32_t error_code);
int32_t (*mc_shutdown)(void);

/* MC Interface, SDLS-EP */
/*
int32_t (*mc_ping)();
int32_t (*mc_log_status)(void);
int32_t (*mc_dump_log)(void);
int32_t (*mc_erase_log)(void);
int32_t (*mc_self_test)(void);
int32_t (*mc_alarm_reset_flag)(void);
*/

} McInterfaceStruct, *McInterface;

/* Prototypes */
McInterface get_mc_interface_custom(void);
McInterface get_mc_interface_internal(void);

#endif // MONITORING_AND_CONTROL_INTERFACE_H
17 changes: 17 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,23 @@ else()
list(APPEND LIB_SRC_FILES ${KEY_KMC_FILES})
endif()

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

if(MC_INTERNAL)
aux_source_directory(mc/internal MC_INTERNAL_FILES)
list(APPEND LIB_SRC_FILES ${MC_INTERNAL_FILES})
else()
aux_source_directory(mc/internal_stub MC_INTERNAL_FILES)
list(APPEND LIB_SRC_FILES ${MC_INTERNAL_FILES})
endif()

if(SA_INTERNAL)
aux_source_directory(sa/internal SA_INTERNAL_FILES)
list(APPEND LIB_SRC_FILES ${SA_INTERNAL_FILES})
Expand Down
25 changes: 22 additions & 3 deletions src/core/crypto_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
** Global Variables
*/
KeyInterface key_if = NULL;
McInterface mc_if = NULL;

SadbRoutine sadb_routine = NULL;
SadbMariaDBConfig_t* sadb_mariadb_config = NULL;
Expand Down Expand Up @@ -53,7 +54,7 @@ int32_t crypto_free_config_structs(void);
int32_t Crypto_Init_TC_Unit_Test(void)
{
int32_t status = CRYPTO_LIB_SUCCESS;
Crypto_Config_CryptoLib(KEY_TYPE_INTERNAL, SADB_TYPE_INMEMORY, CRYPTOGRAPHY_TYPE_LIBGCRYPT,
Crypto_Config_CryptoLib(KEY_TYPE_INTERNAL, MC_TYPE_INTERNAL, SADB_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_FALSE,
TC_UNIQUE_SA_PER_MAP_ID_FALSE, TC_CHECK_FECF_TRUE, 0x3F,
Expand All @@ -73,7 +74,7 @@ int32_t Crypto_Init_TC_Unit_Test(void)
int32_t Crypto_Init_TM_Unit_Test(void)
{
int32_t status = CRYPTO_LIB_SUCCESS;
Crypto_Config_CryptoLib(KEY_TYPE_INTERNAL, SADB_TYPE_INMEMORY, CRYPTOGRAPHY_TYPE_LIBGCRYPT,
Crypto_Config_CryptoLib(KEY_TYPE_INTERNAL, MC_TYPE_INTERNAL, SADB_TYPE_INMEMORY, CRYPTOGRAPHY_TYPE_LIBGCRYPT,
IV_INTERNAL, CRYPTO_TM_CREATE_FECF_TRUE, TC_PROCESS_SDLS_PDUS_TRUE, TC_HAS_PUS_HDR,
TC_IGNORE_SA_STATE_FALSE, TC_IGNORE_ANTI_REPLAY_FALSE, TC_UNIQUE_SA_PER_MAP_ID_FALSE,
TM_CHECK_FECF_TRUE, 0x3F, SA_INCREMENT_NONTRANSMITTED_IV_TRUE);
Expand Down Expand Up @@ -143,6 +144,18 @@ int32_t Crypto_Init(void)
key_if->key_init();
// TODO: Check and return status on error

/* MC Interface */
if (crypto_config->mc_type == MC_TYPE_CUSTOM)
{
mc_if = get_mc_interface_custom();
}
else // MC_TYPE_INTERNAL
{
mc_if = get_mc_interface_internal();
}
mc_if->mc_initialize();
// TODO: Check and return status on error

/* SA Interface */
// Prepare SADB type from config
if (crypto_config->sadb_type == SADB_TYPE_INMEMORY)
Expand Down Expand Up @@ -255,6 +268,11 @@ int32_t Crypto_Shutdown(void)
key_if->key_shutdown();
}

if(mc_if != NULL)
{
mc_if->mc_shutdown();
}

if (sadb_routine != NULL)
{
sadb_routine->sadb_close();
Expand Down Expand Up @@ -285,14 +303,15 @@ int32_t Crypto_Shutdown(void)
* @param vcid_bitmask: uint8
* @return int32: Success/Failure
**/
int32_t Crypto_Config_CryptoLib(uint8_t key_type, uint8_t sadb_type, uint8_t cryptography_type,
int32_t Crypto_Config_CryptoLib(uint8_t key_type, uint8_t mc_type, uint8_t sadb_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, uint8_t crypto_increment_nontransmitted_iv)
{
int32_t status = CRYPTO_LIB_SUCCESS;
crypto_config = (CryptoConfig_t* )calloc(1, CRYPTO_CONFIG_SIZE);
crypto_config->key_type = key_type;
crypto_config->mc_type = mc_type;
crypto_config->sadb_type = sadb_type;
crypto_config->cryptography_type = cryptography_type;
crypto_config->iv_type = iv_type;
Expand Down
Loading

0 comments on commit b10805f

Please sign in to comment.