Skip to content

Commit

Permalink
[#216] Initial draft of MC_DISABLED;
Browse files Browse the repository at this point in the history
  • Loading branch information
jlucas9 committed Jan 10, 2024
1 parent 5735035 commit 0875a56
Show file tree
Hide file tree
Showing 9 changed files with 112 additions and 5 deletions.
5 changes: 3 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ 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(MC_DISABLED "Monitoring and Control - Disabled" ON)
option(MC_INTERNAL "Monitoring and Control - Internal" OFF)
option(SA_CUSTOM "Security Association - Custom" OFF)
option(SA_INTERNAL "Security Association - Internal" ON)
option(SA_MARIADB "Security Association - MariaDB" OFF)
option(SUPPORT "Support" OFF)
Expand Down
1 change: 1 addition & 0 deletions include/crypto_config_structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ typedef enum
{
MC_TYPE_UNITIALIZED = 0,
MC_TYPE_CUSTOM,
MC_TYPE_DISABLED,
MC_TYPE_INTERNAL
} McType;
typedef enum
Expand Down
1 change: 1 addition & 0 deletions include/mc_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ typedef struct

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

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

if(MC_DISABLED)
aux_source_directory(mc/disabled MC_DISABLED_FILES)
list(APPEND LIB_SRC_FILES ${MC_DISABLED_FILES})
else()
aux_source_directory(mc/disabled_stub MC_DISABLED_FILES)
list(APPEND LIB_SRC_FILES ${MC_DISABLED_FILES})
endif()

if(MC_INTERNAL)
aux_source_directory(mc/internal MC_INTERNAL_FILES)
list(APPEND LIB_SRC_FILES ${MC_INTERNAL_FILES})
Expand Down
6 changes: 5 additions & 1 deletion src/core/crypto_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,14 @@ int32_t Crypto_Init(void)
{
mc_if = get_mc_interface_custom();
}
else // MC_TYPE_INTERNAL
else if (crypto_config.mc_type == MC_TYPE_INTERNAL)
{
mc_if = get_mc_interface_internal();
}
else // MC_TYPE_DISABLED
{
mc_if = get_mc_interface_disabled();
}
mc_if->mc_initialize();
// TODO: Check and return status on error

Expand Down
63 changes: 63 additions & 0 deletions src/mc/disabled/mc_interface_disabled.template.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/* 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]
*/
#include "mc_interface.h"

/* Variables */
static McInterfaceStruct mc_if_struct;

/* Prototypes */
static int32_t mc_initialize(void);
static void mc_log(int32_t error_code);
static int32_t mc_shutdown(void);

/* Functions */
McInterface get_mc_interface_disabled(void)
{
/* MC Interface, SDLS */
mc_if_struct.mc_initialize = mc_initialize;
mc_if_struct.mc_log = mc_log;
mc_if_struct.mc_shutdown = mc_shutdown;

/* MC Interface, SDLS-EP */
/*
mc_if_struct.mc_ping = mc_ping;
mc_if_struct.mc_log_status = mc_log_status;
mc_if_struct.mc_dump_log = mc_dump_log;
mc_if_struct.mc_erase_log = mc_erase_log;
mc_if_struct.mc_self_test = mc_self_test;
mc_if_struct.mc_alarm_reset_flag = mc_alarm_reset_flag;
*/

return &mc_if_struct;
}

static int32_t mc_initialize(void)
{
return CRYPTO_LIB_SUCCESS;
}

static void mc_log(int32_t error_code)
{
error_code = error_code;
return;
}

static int32_t mc_shutdown(void)
{
return CRYPTO_LIB_SUCCESS;
}
29 changes: 29 additions & 0 deletions src/mc/disabled_stub/mc_interface_disabled_stub.template.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/* 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]
*/

#include "mc_interface.h"

/* Variables */
static McInterfaceStruct mc_if_struct;

/* Functions */
McInterface get_mc_interface_disabled(void)
{
fprintf(stderr,"ERROR: Loading disabled monitoring and control interface stub source code. Rebuild CryptoLib with -DMC_DISABLED=ON to use implementation.\n");
return &mc_if_struct;
}
2 changes: 1 addition & 1 deletion support/scripts/build_internal.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
source $SCRIPT_DIR/env.sh

cmake $BASE_DIR -DCODECOV=1 -DDEBUG=1 -DTEST=1 -DTEST_ENC=1 && make && make test
cmake $BASE_DIR -DCODECOV=1 -DDEBUG=1 -DMC_INTERNAL=1 -DTEST=1 -DTEST_ENC=1 && make && make test
2 changes: 1 addition & 1 deletion support/scripts/build_kmc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
source $SCRIPT_DIR/env.sh

cmake $BASE_DIR -DCODECOV=1 -DDEBUG=1 -DCRYPTO_KMC=1 -DKEY_KMC=1 -DSA_MARIADB=1 -DTEST=1 -DTEST_ENC=1 && make && make test
cmake $BASE_DIR -DCODECOV=1 -DDEBUG=1 -DCRYPTO_KMC=1 -DKEY_KMC=1 -DMC_DISABLED=1 -DSA_MARIADB=1 -DTEST=1 -DTEST_ENC=1 && make && make test

0 comments on commit 0875a56

Please sign in to comment.