Skip to content

Commit

Permalink
Merge pull request #170 from #164-TM-Multiple-Packets
Browse files Browse the repository at this point in the history
CryptoLib#164 - TM Multiple Packets and Pre-allocation of SA
  • Loading branch information
dccutrig authored Jun 22, 2023
2 parents d00dfbc + 0b113dd commit 67dfb76
Show file tree
Hide file tree
Showing 103 changed files with 3,200 additions and 3,130 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
- name: Configure CMake
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: cmake -B ${{github.workspace}}/build -DDEBUG=1 -DMYSQL=0 -DLIBGCRYPT=1 -DKMCCRYPTO=0
run: cmake -B ${{github.workspace}}/build -DDEBUG=1 -DSA_MARIADB=0 -DCRYPTO_LIBGCRYPT=1 -DCRYPTO_KMC=0 -DTEST=1

- name: Build
# Build your program with the given configuration
Expand All @@ -49,7 +49,7 @@ jobs:
- name: Configure CMake
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: cmake -B ${{github.workspace}}/build -DDEBUG=0 -DMYSQL=0 -DLIBGCRYPT=1 -DKMCCRYPTO=0
run: cmake -B ${{github.workspace}}/build -DDEBUG=0 -DSA_MARIADB=0 -DCRYPTO_LIBGCRYPT=1 -DCRYPTO_KMC=0 -DTEST=1

- name: Build
# Build your program with the given configuration
Expand All @@ -75,7 +75,7 @@ jobs:
- name: Configure CMake
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: cmake -B ${{github.workspace}}/build -DDEBUG=1 -DMYSQL=1 -DLIBGCRYPT=1 -DKMCCRYPTO=0
run: cmake -B ${{github.workspace}}/build -DDEBUG=1 -DSA_MARIADB=1 -DCRYPTO_LIBGCRYPT=1 -DCRYPTO_KMC=0 -DTEST=1

- name: Build
# Build your program with the given configuration
Expand All @@ -101,7 +101,7 @@ jobs:
- name: Configure CMake
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: cmake -B ${{github.workspace}}/build -DDEBUG=0 -DMYSQL=1 -DLIBGCRYPT=1 -DKMCCRYPTO=0
run: cmake -B ${{github.workspace}}/build -DDEBUG=0 -DSA_MARIADB=1 -DCRYPTO_LIBGCRYPT=1 -DCRYPTO_KMC=0 -DTEST=1

- name: Build
# Build your program with the given configuration
Expand All @@ -127,7 +127,7 @@ jobs:
- name: Configure CMake
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: cmake -B ${{github.workspace}}/build -DDEBUG=1 -DMYSQL=1 -DLIBGCRYPT=1 -DKMCCRYPTO=1
run: cmake -B ${{github.workspace}}/build -DDEBUG=1 -DSA_MARIADB=1 -DCRYPTO_LIBGCRYPT=1 -DCRYPTO_KMC=1 -DTEST=1

- name: Build
# Build your program with the given configuration
Expand All @@ -153,7 +153,7 @@ jobs:
- name: Configure CMake
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: cmake -B ${{github.workspace}}/build -DDEBUG=0 -DMYSQL=1 -DLIBGCRYPT=1 -DKMCCRYPTO=1
run: cmake -B ${{github.workspace}}/build -DDEBUG=0 -DSA_MARIADB=1 -DCRYPTO_LIBGCRYPT=1 -DCRYPTO_KMC=1 -DTEST=1

- name: Build
# Build your program with the given configuration
Expand Down
42 changes: 0 additions & 42 deletions .github/workflows/mariadb.yml

This file was deleted.

5 changes: 1 addition & 4 deletions .github/workflows/utest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
- name: Configure CMake
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DTEST=1

- name: Build
# Build your program with the given configuration
Expand Down Expand Up @@ -81,6 +81,3 @@ jobs:
# Execute tests defined by the CMake configuration.
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
run: ${{github.workspace}}/build/bin/ut_crypto_mc



2 changes: 1 addition & 1 deletion .github/workflows/validation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
- name: Configure CMake
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DENCTEST=1 -DDEBUG=1 -DCODECOV=1
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DTEST=1 -DTEST_ENC=1 -DDEBUG=1 -DCODECOV=1

- name: Build
# Build your program with the given configuration
Expand Down
39 changes: 14 additions & 25 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,28 +1,17 @@
#
# Metadata
#
.vagrant
.vscode
.idea
vgcore*
**core

#
# Packages and Build Files
#
__pycache__
*.dat
*.so
build
build*
venv
*.dat
.vscode
__pycache__

#CMake.gitignore
CMakeLists.txt.user
CMakeCache.txt
CMakeFiles
CMakeScripts
Testing
Makefile
cmake_install.cmake
install_manifest.txt
compile_commands.json
CTestTestfile.cmake
cmake-build-debug
**.cbp
_deps

DartConfiguration.tcl

install
vgcore*
core.*
101 changes: 49 additions & 52 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,43 +15,42 @@
# NASA IV&V
# [email protected]


#cmake_minimum_required(VERSION 2.6.4)
cmake_minimum_required(VERSION 3.14.0)
project(CRYPTO C)

#
# Define Build Flags
# The default value is captured in line, change with flag `-DXYZ=1`
# For flags with the same prefix, one or more may be enabled
#
option(CODECOV "Code Coverage" OFF)
option(CRYPTO_LIBGCRYPT "Cryptography Module - Libgcrypt" ON)
option(CRYPTO_KMC "Cryptography Module - KMC" OFF)
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_INTERNAL "Security Association - Internal" ON)
option(SA_MARIADB "Security Association - MariaDB" OFF)
option(SUPPORT "Support" OFF)
option(SYSTEM_INSTALL "SystemInstall" OFF)
option(TEST "Test" OFF)
option(TEST_ENC "Tests - Encryption" OFF)

OPTION(DEBUG "Debug" OFF) # Disabled by default, enable with: -DDEBUG=ON
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
OPTION(SYSTEM_INSTALL "SystemInstall" OFF) #Disabled by default, enable with: -DSYSTEM_INSTALL=ON
OPTION(KMC_MDB_RH "KMC-MDB-RedHat-Integration-Testing" OFF) #Disabled by default, enable with: -DKMC_MDB_RH=ON
OPTION(KMC_MDB_DB "KMC-MDB-Debian-Integration-Testing" OFF) #Disabled by default, enable with: -DKMC_MDB_DB=ON

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

set(CMAKE_INSTALL_RPATH "$ORIGIN/../lib")
set(CMAKE_INSTALL_PREFIX ${PROJECT_SOURCE_DIR}/install)

IF(CRYPTO_SUBMODULE_INSTALL) #If building CryptoLib as a submodule of another build system (EG, JPL KMC, Nasa NOS3, etc...)
set(CMAKE_INSTALL_PREFIX ${CRYPTO_SUBMODULE_INSTALL})
ENDIF()

IF(SYSTEM_INSTALL)
set(CMAKE_INSTALL_PREFIX /usr/local)
ENDIF()


IF(DEBUG)
ADD_DEFINITIONS(-DDEBUG -DOCF_DEBUG -DFECF_DEBUG -DSA_DEBUG -DPDU_DEBUG -DCCSDS_DEBUG -DTC_DEBUG -DMAC_DEBUG -DTM_DEBUG)
if(DEBUG)
add_definitions(-DDEBUG -DOCF_DEBUG -DFECF_DEBUG -DSA_DEBUG -DPDU_DEBUG -DCCSDS_DEBUG -DTC_DEBUG -DMAC_DEBUG -DTM_DEBUG)
add_compile_options(-ggdb)
ENDIF(DEBUG)

IF(ENCTEST)
ADD_DEFINITIONS(-DENCTEST)
ENDIF(ENCTEST)
endif()

IF(KMC_MDB_RH)
ADD_DEFINITIONS(-DKMC_MDB_RH)
Expand All @@ -61,38 +60,36 @@ IF(KMC_MDB_DB)
ADD_DEFINITIONS(-DKMC_MDB_DB)
ENDIF(KMC_MDB_DB)

if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
include(CTest)
enable_testing()
if(SYSTEM_INSTALL)
set(CMAKE_INSTALL_PREFIX /usr/local)
elseif(NOT DEFINED CFE_SYSTEM_PSPNAME)
# Not cFE / cFS
set(CMAKE_INSTALL_RPATH "$ORIGIN/../lib")
set(CMAKE_INSTALL_PREFIX ${PROJECT_SOURCE_DIR}/install)
endif()

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pthread -Wall -Wextra -Werror -g -O0")

if(CODECOV)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage")
if(TEST_ENC)
# Can't run an additional set of tests without `TEST` enabled
set(TEST ON)
endif()

include_directories(include)

# The shared OSAL and cFE include directories should always be used
# Note that this intentionally does NOT include PSP-specific includes, just the generic
# Only include cFS/NOS3 directories if env var is defined
if(DEFINED ENV{CFECORE_SOURCE_DIR}) #if ${CFECORE_SOURCE_DIR} is set, expect cFS build infrastructure to be in place.
include_directories(${CFECORE_SOURCE_DIR}/src/inc)
include_directories(${CFEPSP_SOURCE_DIR}/fsw/inc)
ADD_DEFINITIONS(-DNOS3)
else()
#pass
if(TEST)
include(CTest)
enable_testing()
endif()

if(NOT DEFINED ${PROJECT_BINARY_DIR})
set(PROJECT_BINARY_DIR ${CMAKE_CURRENT_SOURCE_DIR}/build)
endif()
#
# Project Specifics
#
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Werror -g -O0")

include_directories(include)
add_subdirectory(src)

if((CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME OR MYPROJECT_BUILD_TESTING) AND BUILD_TESTING)
add_subdirectory(test)
if(SUPPORT)
add_subdirectory(support)
endif()

add_subdirectory(util)
if(TEST)
add_subdirectory(test)
endif()
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
![Build](https://github.com/nasa/CryptoLib/actions/workflows/build.yml/badge.svg) ![Unit Tests](https://github.com/nasa/CryptoLib/actions/workflows/utest.yml/badge.svg) ![Validation Tests](https://github.com/nasa/CryptoLib/actions/workflows/validation.yml/badge.svg) ![MariaDB Tests](https://github.com/nasa/CryptoLib/actions/workflows/mariadb.yml/badge.svg) [![CodeCov](https://codecov.io/gh/nasa/CryptoLib/branch/collab_main/graph/badge.svg?token=KCOMCQO0ZU)](https://codecov.io/gh/nasa/CryptoLib)
![Build](https://github.com/nasa/CryptoLib/actions/workflows/build.yml/badge.svg)
![Unit Tests](https://github.com/nasa/CryptoLib/actions/workflows/utest.yml/badge.svg)
![Validation Tests](https://github.com/nasa/CryptoLib/actions/workflows/validation.yml/badge.svg)
![MariaDB Tests](https://github.com/nasa/CryptoLib/actions/workflows/mariadb.yml/badge.svg)
[![CodeCov](https://codecov.io/gh/nasa/CryptoLib/branch/main/graph/badge.svg?token=KCOMCQO0ZU)](https://codecov.io/gh/nasa/CryptoLib)

# CryptoLib

Expand Down
22 changes: 10 additions & 12 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
ignore:
- "util/src_util/process_security.c"
- "util/src_util/ut_mysql_tls_connection.c"
- "util/src_util/ut_mysql_m_tls_connection.c"
- "util/src_util/ut_kmc_crypto.c"
- "util/src_util/ut_kmc_crypto_aes_cmac.c"
- "util/src_util/apply_security.c"
- "util/src_util/crypto_sequence.c"
- "util/include/utest.h"
- "util/core/shared_util.c"
- "src/src_main/crypto_print.c"
- "src/src_feature_stubs/cryptography_kmc_stub/cryptography_interface_kmc.stub.c"
- "src/src_feature_stubs/mysql_stub/sadb_routine_mariadb.stub.c"
- "src/crypto/kmc/*"
- "src/crypto/kmc_stub/*"
- "src/crypto/libgcrypt_stub/*"
- "src/sa/internal_stub/*"
- "src/sa/mariadb/*"
- "src/sa/mariadb_stub/*"
- "src/sa/sadb_mariadb_sql/*"
- "src/sa/test_sadb_mariadb_sql/*"
- "support/*"
- "test/*"
12 changes: 8 additions & 4 deletions include/crypto.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,14 @@
#include "crypto_structs.h"
#include "sadb_routine.h"
#include "cryptography_interface.h"
#include "key_interface.h"

/*
** Crypto Version
*/
#define CRYPTO_LIB_MAJOR_VERSION 1
#define CRYPTO_LIB_MINOR_VERSION 2
#define CRYPTO_LIB_REVISION 1
#define CRYPTO_LIB_REVISION 2
#define CRYPTO_LIB_MISSION_REV 0

/*
Expand All @@ -57,9 +58,11 @@
*/

// Crypto Library Configuration functions
extern int32_t Crypto_Config_CryptoLib(uint8_t sadb_type, uint8_t cryptography_type, uint8_t crypto_create_fecf, uint8_t process_sdls_pdus,
extern int32_t Crypto_Config_CryptoLib(uint8_t key_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);
uint8_t unique_sa_per_mapid, uint8_t crypto_check_fecf, uint8_t vcid_bitmask,
uint8_t crypto_increment_nontransmitted_iv);
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,
Expand Down Expand Up @@ -95,7 +98,7 @@ extern int32_t Crypto_TC_ApplySecurity_Cam(const uint8_t* p_in_frame, const uint
extern int32_t Crypto_TC_ProcessSecurity_Cam(uint8_t* ingest, int *len_ingest, TC_t* tc_sdls_processed_frame, char* cam_cookies);
// Telemetry (TM)
extern int32_t Crypto_TM_ApplySecurity(SecurityAssociation_t *sa_ptr);
extern int32_t Crypto_TM_ProcessSecurity(const uint8_t* p_ingest, const uint16_t len_ingest, uint8_t** pp_processed_frame, uint16_t *p_decrypted_length);
extern int32_t Crypto_TM_ProcessSecurity(uint8_t* p_ingest, uint16_t len_ingest, uint8_t** pp_processed_frame, uint16_t *p_decrypted_length);
// 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);
Expand Down Expand Up @@ -187,6 +190,7 @@ 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 SadbRoutine sadb_routine;
extern CryptographyInterface cryptography_if;

Expand Down
2 changes: 1 addition & 1 deletion include/crypto_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@
#define FECF_SIZE 2
#define SEGMENT_HDR_SIZE 1
#define ECS_SIZE 4 /* bytes */
#define ABM_SIZE 1024 // 20 /* bytes */
#define ABM_SIZE 1786 // 20 /* bytes */
#define ARSN_SIZE 20 /* total messages */
#define ARSNW_SIZE 1 /* bytes */
#define SN_SIZE 0
Expand Down
Loading

0 comments on commit 67dfb76

Please sign in to comment.