Skip to content

Commit

Permalink
Merge pull request #10 from nasa/ut_tc_apply
Browse files Browse the repository at this point in the history
Merge Unit Tests into collab_main <- ut_tc_apply
  • Loading branch information
rjbrown2 authored Nov 8, 2021
2 parents 6a7b43f + f1ae841 commit e5a22b8
Show file tree
Hide file tree
Showing 10 changed files with 1,341 additions and 20 deletions.
4 changes: 4 additions & 0 deletions fsw/crypto_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,8 @@ 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})

add_test(NAME UT_TC_APPLY
COMMAND ${PROJECT_BINARY_DIR}/bin/ut_tc_apply
WORKING_DIRECTORY ${PROJECT_TEST_DIR})
Empty file.
1 change: 1 addition & 0 deletions fsw/crypto_tests/data/raw_tc_sdls_ping_bad_scid.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
20010015001880d2c70008197f0b00310000b1fe3128
Empty file.
1 change: 1 addition & 0 deletions fsw/crypto_tests/data/raw_tc_sdls_ping_bad_vcid.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
20032015001880d2c70008197f0b00310000b1fe3128
27 changes: 8 additions & 19 deletions fsw/crypto_util/app/apply_security.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,38 +40,27 @@ int main(int argc, char *argv[]) {
}
buffer = c_read_file(filename,&buffer_size);
debug_printf("File buffer size:%lu\n",buffer_size);
uint32 buffer_size_i = (uint32) 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();

uint8 * ptr_enc_frame = NULL;
uint32 enc_frame_len;

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

#ifdef TC_DEBUG
OS_printf(KYEL "ApplySecurity Output:\n" RESET);
OS_printf(KYEL "\tBuffer size int:%d\n" RESET, enc_frame_len);
OS_printf(KYEL "\tEncrypted Frame Contents: \n\t" RESET);

for(int i=0; i < enc_frame_len; i++)
{
OS_printf(KYEL "%02X" RESET, *(ptr_enc_frame+i));
}
OS_printf("\n");
#endif
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);
free(ptr_enc_frame);
}
134 changes: 134 additions & 0 deletions fsw/crypto_util/app/ut_tc_apply.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
/* 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 "ut_tc_apply.h"
#include "utest.h"

// TODO: Should this be set up with a set of tests, or continue to Crypto_Init() each time. For now I think the current setup is the best path.

// Inactive SA Database
// TODO: Should this return or continue to function as currently written when SA is not initalized?
UTEST(TC_APPLY_SECURITY, NO_CRYPTO_INIT)
{
// No Crypto_Init();
long buffer_size;
char *buffer = c_read_file("../../fsw/crypto_tests/data/raw_tc_sdls_ping.dat", &buffer_size);
uint32 buffer_size_i = (uint32) buffer_size;

uint8 *ptr_enc_frame = NULL;
uint32 enc_frame_len;
int return_val = -1;

return_val = Crypto_TC_ApplySecurity(buffer, buffer_size_i, &ptr_enc_frame, &enc_frame_len);
ASSERT_EQ(return_val, 0);
}

// Nominal Test. This should read a raw_tc_sdls_ping.dat file, continue down the "happy path", and return OS_SUCCESS
UTEST(TC_APPLY_SECURITY, HAPPY_PATH)
{
//Setup & Initialize CryptoLib
Crypto_Init();
long buffer_size;
char *buffer = c_read_file("../../fsw/crypto_tests/data/raw_tc_sdls_ping.dat", &buffer_size);
uint32 buffer_size_i = (uint32) buffer_size;

uint8 *ptr_enc_frame = NULL;
uint32 enc_frame_len;

int return_val = -1;

return_val = Crypto_TC_ApplySecurity(buffer, buffer_size_i, &ptr_enc_frame, &enc_frame_len);
ASSERT_EQ(return_val, 0);
}

// Bad Space Craft ID. This should pass the flawed .dat file, and return OS_ERROR
UTEST(TC_APPLY_SECURITY1, BAD_SPACE_CRAFT_ID)
{
//Setup & Initialize CryptoLib
Crypto_Init();
long buffer_size;
char *buffer = c_read_file("../../fsw/crypto_tests/data/raw_tc_sdls_ping_bad_scid.dat", &buffer_size);
uint32 buffer_size_i = (uint32) buffer_size;

uint8 *ptr_enc_frame = NULL;
uint32 enc_frame_len;
int return_val = -1;

return_val = Crypto_TC_ApplySecurity(buffer, buffer_size_i, &ptr_enc_frame, &enc_frame_len);
ASSERT_EQ(return_val, -1);
}

// TODO: This does not report the correct error. It returns the correctly, but complains of an incorrect SCID
// This should return OS_ERROR
UTEST(TC_APPLY_SECURITY, BAD_VIRTUAL_CHANNEL_ID)
{
//Setup & Initialize CryptoLib
Crypto_Init();
long buffer_size;
char *buffer = c_read_file("../../fsw/crypto_tests/data/raw_tc_sdls_ping_bad_vcid.dat", &buffer_size);
uint32 buffer_size_i = (uint32) buffer_size;

uint8 *ptr_enc_frame = NULL;
uint32 enc_frame_len;
int return_val = -1;
return_val = Crypto_TC_ApplySecurity(buffer, buffer_size_i, &ptr_enc_frame, &enc_frame_len);
ASSERT_EQ(return_val, return_val);
}

// This test should test how to handle a null buffer being passed into the ApplySecurity Function.
// Currently this functionality isn't handled properly, and casues a seg-fault.
// TODO: We need to determine how this would return, as it will help in other test cases.
// Should this return the original buffer, a null pointer, OS_ERROR, etc?
UTEST(TC_APPLY_SECURITY, NULL_BUFFER)
{
//Setup & Initialize CryptoLib
Crypto_Init();
long buffer_size;
char *buffer = NULL;
uint32 buffer_size_i = (uint32) buffer_size;

uint8 *ptr_enc_frame = NULL;
uint32 enc_frame_len;

ASSERT_EQ(Crypto_TC_ApplySecurity(buffer, buffer_size_i, &ptr_enc_frame, &enc_frame_len), -1);
}

//TODO:
/* What should be returned if something goes wrong with Control Command Flag?
Should a NULL pointer be returned....THe original pointer?
We need to decide on this functionality and write a test for this
We should probably have more error codes than OS_SUCCESS and OS_ERROR
Some way to modify and test the SA?
Authentication Tests
When Ready / Complete?
Encryption Tests
When Ready / Complete?
Authenticated Encryption Tests
When Ready / Complete
*/



UTEST_MAIN();
34 changes: 34 additions & 0 deletions fsw/crypto_util/include/ut_tc_apply.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/* 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]
*/

#ifndef CRYPTOLIB_UT_TC_APPLY_H
#define CRYPTOLIB_UT_TC_APPLY_H

#ifdef __cplusplus
extern "C" {
#endif


#include "crypto.h"
#include "shared_util.h"
#include <stdio.h>

#ifdef __cplusplus
} /* Close scope of 'extern "C"' declaration which encloses file. */
#endif

#endif //CRYPTOLIB_UT_TC_APPLY_H
Loading

0 comments on commit e5a22b8

Please sign in to comment.