Skip to content

Commit

Permalink
Merge pull request #3 from IbraheemYSaleh/main
Browse files Browse the repository at this point in the history
AKMC-111: Enable standalone build & testing of CryptoLib external to NOS3/cFS dependencies
  • Loading branch information
dccutrig authored Oct 1, 2021
2 parents cbfa007 + 70a1c04 commit 15d4125
Show file tree
Hide file tree
Showing 24 changed files with 861 additions and 24 deletions.
21 changes: 21 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
.idea
vgcore*
core
*.so
build
venv

#CMake.gitignore
CMakeLists.txt.user
CMakeCache.txt
CMakeFiles
CMakeScripts
Testing
Makefile
cmake_install.cmake
install_manifest.txt
compile_commands.json
CTestTestfile.cmake
_deps

DartConfiguration.tcl
36 changes: 27 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,38 @@
# NASA IV&V
# [email protected]

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

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

OPTION(DEBUG "Debug" OFF) # Disabled by default
IF(DEBUG)
ADD_DEFINITIONS(-DDEBUG)
add_compile_options(-ggdb)
ENDIF(DEBUG)

if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
include(CTest)
enable_testing()
endif()

include_directories(fsw/public_inc)

# The shared OSAL and cFE include directories should always be used
# Note that this intentionally does NOT include PSP-specific includes, just the generic
include_directories(${CFECORE_SOURCE_DIR}/src/inc)
include_directories(${CFEPSP_SOURCE_DIR}/fsw/inc)

aux_source_directory(fsw/src LIB_SRC_FILES)
# 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
endif()

# Create the app module
add_cfe_app(crypto ${LIB_SRC_FILES})
if(NOT DEFINED ${PROJECT_BINARY_DIR})
set(PROJECT_BINARY_DIR ${CMAKE_CURRENT_SOURCE_DIR}/build)
endif()

# Add libgcrypt
target_link_libraries(crypto libgcrypt)
add_subdirectory(fsw)
48 changes: 48 additions & 0 deletions fsw/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Copyright (C) 2009 - 2017 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 express, 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_directories(public_inc)

aux_source_directory(src LIB_SRC_FILES)

if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
include(CTest)
enable_testing()
endif()

# Create the app module
if(DEFINED ENV{CFECORE_SOURCE_DIR}) #if ${CFECORE_SOURCE_DIR} is set, expect cFS build infrastructure to be in place.
add_cfe_app(Crypto ${LIB_SRC_FILES})
else() #standalone build
add_library(Crypto SHARED ${LIB_SRC_FILES})
endif()

# Add libgcrypt
target_link_libraries(Crypto gcrypt)

#Include cmake install module - todo
#include(GNUInstallDirs)

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"
)

add_subdirectory(crypto_util)

if((CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME OR MYPROJECT_BUILD_TESTING) AND BUILD_TESTING)
add_subdirectory(crypto_tests)
endif()
20 changes: 20 additions & 0 deletions fsw/crypto_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright (C) 2009 - 2017 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 express, 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]
set(PROJECT_TEST_DIR ${CMAKE_CURRENT_SOURCE_DIR})

add_test(NAME Process_Security
COMMAND ${PROJECT_BINARY_DIR}/bin/process_security tc ${PROJECT_TEST_DIR}/data/tc4.1.dat
WORKING_DIRECTORY ${PROJECT_TEST_DIR})
Binary file added fsw/crypto_tests/data/tc4.1.dat
Binary file not shown.
41 changes: 41 additions & 0 deletions fsw/crypto_util/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Copyright (C) 2009 - 2017 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 express, 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_directories(include)
include_directories(../crypto/public_inc)

aux_source_directory(src UTIL_SRC_FILES)
aux_source_directory(app APP_SRC_FILES)

file( GLOB SOURCE_FILES app/*.c )
foreach(SOURCE_PATH ${SOURCE_FILES})

get_filename_component(EXECUTABLE_NAME ${SOURCE_PATH} NAME_WE)

add_executable(${EXECUTABLE_NAME} ${SOURCE_PATH})

target_sources(${EXECUTABLE_NAME} PRIVATE src/shared_util.c)
target_link_libraries(${EXECUTABLE_NAME} LINK_PUBLIC Crypto)

add_custom_command(TARGET ${EXECUTABLE_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:${EXECUTABLE_NAME}> ${PROJECT_BINARY_DIR}/bin/${EXECUTABLE_NAME}
COMMAND ${CMAKE_COMMAND} -E rm $<TARGET_FILE:${EXECUTABLE_NAME}>
COMMENT "Created ${PROJECT_BINARY_DIR}/bin/${EXECUTABLE_NAME}"
)
endforeach(SOURCE_PATH ${SOURCE_FILES})

target_include_directories (Crypto PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})

66 changes: 66 additions & 0 deletions fsw/crypto_util/app/apply_security.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/* Copyright (C) 2009 - 2017 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 express, 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]
*/

/*
* Simple apply security program that reads a file into memory and calls the Crypto_TC_ApplySecurity function on the data.
*/

#include "apply_security.h"

int main(int argc, char *argv[]) {
char *buffer;
char const *filename;
long buffer_size;
char *security_type;

if (argc == 3) {
security_type = argv[1];
filename = argv[2];
} else {
fprintf(stderr,"Command line usage: \n"\
"\t%s <tc|tm|aos> <filename>\n"\
"<tc|tm|aos> : Apply TeleCommand (tc) | Telemetry (tm) | Advanced Orbiting Systems (aos) Security T\n"\
"<filename> : binary file with telecommand transfer frame bits\n",argv[0]);

return OS_ERROR;
}
buffer = c_read_file(filename,&buffer_size);
debug_printf("File buffer size:%lu\n",buffer_size);
int buffer_size_i = (int) buffer_size;
debug_printf("File buffer size int:%d\n",buffer_size_i);
debug_printf("File content: \n");
debug_hexprintf(buffer,buffer_size_i);


//Setup & Initialize CryptoLib
Crypto_Init();

//Call ApplySecurity on buffer contents depending on type.
if (strcmp(security_type,"tc")==0){
Crypto_TC_ApplySecurity(&buffer, &buffer_size_i);
} else if (strcmp(security_type,"tm")==0){
Crypto_TM_ApplySecurity(buffer, &buffer_size_i);
} else if (strcmp(security_type,"aos")==0){
Crypto_AOS_ApplySecurity(buffer, &buffer_size_i);
}

debug_printf("Applied Security buffer size int:%d\n",buffer_size_i);
debug_printf("File content: \n");
debug_hexprintf(buffer,buffer_size_i);

free(buffer);
}
73 changes: 73 additions & 0 deletions fsw/crypto_util/app/crypto_sequence.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/* Copyright (C) 2009 - 2017 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 express, 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]
*/


/*
* Simple crypto security program that reads files into memory and calls the appropriate Crypto* function on the data.
*/

#include "crypto_sequence.h"

int main(int argc, char *argv[]) {
char *buffer;
char const *filename;
long buffer_size;
char *security_type;

if (argc < 3 || argc % 2 == 0) {
fprintf(stderr,"Command line usage: \n"\
"\t%s [<tc|tm|aos> <filename>]+\n"\
"specify as many [<tc_a|tm_a|aos_a|tc_p|tm_p|aos_p> <filename>] pairs as necessary to complete your crypto sequence test. Each file will be loaded and processed in sequence. \n"\
"<tc_a|tm_a|aos_a> : Apply TeleCommand (tc_a) | Telemetry (tm_a) | Advanced Orbiting Systems (aos_a) Security T\n"\
"<tc_p|tm_p|aos_p> : Process TeleCommand (tc_p) | Telemetry (tm_p) | Advanced Orbiting Systems (aos_p) Security T\n"\
"<filename> : binary file with telecommand transfer frame bits\n",argv[0]);

return OS_ERROR;
}
//Setup & Initialize CryptoLib
Crypto_Init();

int arg_index = 0;
while(arg_index != argc-1){
security_type = argv[++arg_index];
debug_printf("Security Type: %s\n",security_type);
filename = argv[++arg_index];
debug_printf("Filename: %s\n",filename);
buffer = c_read_file(filename,&buffer_size);
debug_printf("File buffer size:%lu\n",buffer_size);
int buffer_size_i = (int) buffer_size;
debug_printf("File buffer size int:%d\n",buffer_size_i);
debug_printf("File content: \n");
debug_hexprintf(buffer,buffer_size_i);

//Call Apply/ProcessSecurity on buffer contents depending on type.
if (strcmp(security_type,"tc_a")==0){
Crypto_TC_ApplySecurity(&buffer, &buffer_size_i);
} else if (strcmp(security_type,"tm_a")==0){
Crypto_TM_ApplySecurity(buffer, &buffer_size_i);
} else if (strcmp(security_type,"aos_a")==0){
Crypto_AOS_ApplySecurity(buffer, &buffer_size_i);
} else if (strcmp(security_type,"tc_p")==0){
Crypto_TC_ProcessSecurity(buffer, &buffer_size_i);
} else if (strcmp(security_type,"tm_p")==0){
Crypto_TM_ProcessSecurity(buffer, &buffer_size_i);
} else if (strcmp(security_type,"aos_p")==0){
Crypto_AOS_ProcessSecurity(buffer, &buffer_size_i);
}
free(buffer);
}
}
63 changes: 63 additions & 0 deletions fsw/crypto_util/app/process_security.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/* Copyright (C) 2009 - 2017 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 express, 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]
*/


/*
* Simple Process security program that reads a file into memory and calls the Crypto_TC_ProcessSecurity function on the data.
*/

#include "process_security.h"

int main(int argc, char *argv[]) {
char *buffer;
char const *filename;
long buffer_size;
char *security_type;

if (argc == 3) {
security_type = argv[1];
filename = argv[2];
} else {
fprintf(stderr,"Command line usage: \n"\
"\t%s <tc|tm|aos> <filename>\n"\
"<tc|tm|aos> : Process TeleCommand (tc) | Telemetry (tm) | Advanced Orbiting Systems (aos) Security T\n"\
"<filename> : binary file with telecommand transfer frame bits\n",argv[0]);

return OS_ERROR;
}
buffer = c_read_file(filename,&buffer_size);
debug_printf("File buffer size:%lu\n",buffer_size);
int buffer_size_i = (int) buffer_size;
debug_printf("File buffer size int:%d\n",buffer_size_i);
debug_printf("File content: \n");
debug_hexprintf(buffer,buffer_size_i);


//Setup & Initialize CryptoLib
Crypto_Init();

//Call ProcessSecurity on buffer contents depending on type.
if (strcmp(security_type,"tc")==0){
Crypto_TC_ProcessSecurity(buffer, &buffer_size_i);
} else if (strcmp(security_type,"tm")==0){
Crypto_TM_ProcessSecurity(buffer, &buffer_size_i);
} else if (strcmp(security_type,"aos")==0){
Crypto_AOS_ProcessSecurity(buffer, &buffer_size_i);
}

free(buffer);
}
Loading

0 comments on commit 15d4125

Please sign in to comment.