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

AMMOSGH29 : Add install target, update RPATH #90

Merged
merged 4 commits into from
Mar 18, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,5 @@ cmake-build-debug
_deps

DartConfiguration.tcl

install
14 changes: 13 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,26 @@
cmake_minimum_required(VERSION 3.14.0)
project(CRYPTO C)

set(CMAKE_INSTALL_RPATH "$ORIGIN/../lib")

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

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)
Expand Down
14 changes: 11 additions & 3 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,19 @@ if(MYSQL)
target_link_libraries(Crypto ${MYSQL_LIBS})
endif()


#Include cmake install module - todo
#include(GNUInstallDirs)
set_target_properties(Crypto PROPERTIES PUBLIC_HEADER "../include/crypto.h;../include/crypto_config_structs.h;../include/crypto_error.h;../include/crypto_print.h;../include/crypto_structs.h;")

add_custom_command(TARGET Crypto POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:Crypto> ${PROJECT_BINARY_DIR}/lib/libCrypto.so
COMMENT "Created ${PROJECT_BINARY_DIR}/lib/libCrypto.so"
)

install(TARGETS Crypto
DESTINATION ${CMAKE_INSTALL_PREFIX}/lib
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_PREFIX}/include)

IF(MYSQL)
file(GLOB MYSQL_SCRIPTS crypto_sadb/sadb_mariadb_admin_scripts/*.sql)
install(FILES ${MYSQL_SCRIPTS}
DESTINATION ${CMAKE_INSTALL_PREFIX}/etc/sadb_mariadb_admin_scripts)
endif()
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,6 @@ static int32_t cryptography_authenticate(uint8_t* data_out, size_t len_data_out,
iv = iv;
iv_len = iv_len;
ecs = ecs;
acs = acs;

curl_easy_reset(curl);
configure_curl_connect_opts(curl);
Expand All @@ -275,6 +274,13 @@ static int32_t cryptography_authenticate(uint8_t* data_out, size_t len_data_out,
uint8_t* auth_payload = aad;
size_t auth_payload_len = aad_len;

// Verify valid acs enum
int32_t algo = cryptography_get_acs_algo(acs);
if (algo == CRYPTO_LIB_ERR_UNSUPPORTED_ACS)
{
return CRYPTO_LIB_ERR_UNSUPPORTED_ACS;
}

// Need to copy the data over, since authentication won't change/move the data directly
if(data_out != NULL){
memcpy(data_out, data_in, len_data_in);
Expand Down Expand Up @@ -488,7 +494,13 @@ static int32_t cryptography_validate_authentication(uint8_t* data_out, size_t le
iv = iv;
iv_len = iv_len;
ecs = ecs;
acs = acs;

// Verify valid acs enum
int32_t algo = cryptography_get_acs_algo(acs);
if (algo == CRYPTO_LIB_ERR_UNSUPPORTED_ACS)
{
return CRYPTO_LIB_ERR_UNSUPPORTED_ACS;
}

// Need to copy the data over, since authentication won't change/move the data directly
if(data_out != NULL){
Expand Down Expand Up @@ -1253,9 +1265,9 @@ int32_t cryptography_get_acs_algo(int8_t algo_enum)
int32_t algo = CRYPTO_LIB_ERR_UNSUPPORTED_ACS; // All valid algo enums will be positive
switch (algo_enum)
{
// case CRYPTO_AES256_CMAC:
// algo = GCRY_MAC_CMAC_AES;
// break;
case CRYPTO_AES256_CMAC:
algo = CRYPTO_AES256_CMAC;
break;

default:
#ifdef DEBUG
Expand All @@ -1264,5 +1276,5 @@ int32_t cryptography_get_acs_algo(int8_t algo_enum)
break;
}

return (int)algo;
return (int32_t)algo;
}