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

ManagedParameters - Add Internal logic for dynamic CryptoLib configuration from Downstream Apps #18

Merged
merged 6 commits into from
Dec 9, 2021
16 changes: 15 additions & 1 deletion fsw/public_inc/crypto.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ [email protected]
#endif

#include "crypto_structs.h"
#include "crypto_config_structs.h"

#define CRYPTO_LIB_MAJOR_VERSION 1
#define CRYPTO_LIB_MINOR_VERSION 2
Expand All @@ -37,8 +38,16 @@ [email protected]
/*
** Prototypes
*/

// Crypto Library Configuration functions
extern int32 Crypto_Config_CryptoLib(uint8 sadb_type, uint8 crypto_create_fecf, uint8 process_sdls_pdus, uint8 has_pus_hdr, uint8 ignore_sa_state, uint8 ignore_anti_replay, uint8 vcid_bitmask);
extern int32 Crypto_Config_MariaDB(char* mysql_username, char* mysql_password, char* mysql_hostname, char* mysql_database, uint16 mysql_port);
extern int32 Crypto_Config_Add_Gvcid_Managed_Parameter(uint8 tfvn, uint16 scid, uint8 vcid, uint8 has_fecf, uint8 has_segmentation_hdr);

// Initialization
extern int32 Crypto_Init(void);
extern int32 Crypto_Init(void); //Initialize CryptoLib After Configuration Calls
extern int32 Crypto_Init_With_Configs(CryptoConfig_t* crypto_config_p,GvcidManagedParameters_t* gvcid_managed_parameters_p,SadbMariaDBConfig_t* sadb_mariadb_config_p); //Initialize CryptoLib With Application Defined Configuration
extern int32 Crypto_Init_Unit_Test(void); //Initialize CryptoLib with unit test default Configurations
// Telecommand (TC)
extern int32 Crypto_TC_ApplySecurity(const uint8* p_in_frame, const uint16 in_frame_length, \
uint8 **pp_enc_frame, uint16 *p_enc_frame_len);
Expand All @@ -61,5 +70,10 @@ extern crypto_key_t ek_ring[NUM_KEYS];
extern uint8 Crypto_Prep_Reply(char* ingest, uint8 appID);
extern int32 Crypto_increment(uint8 *num, int length);

//Global configuration structs
extern CryptoConfig_t* crypto_config;
extern SadbMariaDBConfig_t* sadb_mariadb_config;
extern GvcidManagedParameters_t* gvcid_managed_parameters;
extern GvcidManagedParameters_t* current_managed_parameters;

#endif
14 changes: 2 additions & 12 deletions fsw/public_inc/crypto_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ [email protected]
#define OCF_SIZE 4
#define MAC_SIZE 16 /* bytes */
#define FECF_SIZE 2
#define SEGMENT_HDR_SIZE 1
#define ECS_SIZE 4 /* bytes */
#define ABM_SIZE 20 /* bytes */
#define ARC_SIZE 20 /* total messages */
Expand Down Expand Up @@ -164,24 +165,13 @@ [email protected]

// CCSDS PUS Defines
#define TLV_DATA_SIZE 494 /* bytes */
#define PUS_HDR 1 //(1=true,0=false)

// TM Defines
#define TM_FRAME_DATA_SIZE 1740 /* bytes */
#define TM_FILL_SIZE 1145 /* bytes */
#define TM_PAD_SIZE 2 /* bytes */

// TC Behavior Defines
#define TC_PROCESS_SDLS_PDUS 1 //(1=true,0=false)
#define TC_SDLS_EP_VCID 4 //VCID which has SDLS PDUs (JPL uses VCIDs to determine TC type, there is no space packet layer with APIDs). Set to -1 if uses SP APIDs.
#define VCID_BITMASK 0b111111 //Some JPL missions do not use the entire CCSDS 6 bit field for VCID.
#define SEGMENTATION_HDR 1 //(1=true,0=false)
#define HAS_FECF 1 //(1=true,0=false)

// MySQL - MariaDB Defines (will be dynamically loaded properties in the future)
#define MYSQL_USER "sadb_user"
#define MYSQL_PASS "sadb_password"
#define MYSQL_HOST "localhost"
#define MYSQL_DB "sadb"
#define MYSQL_PORT 0

#endif
78 changes: 78 additions & 0 deletions fsw/public_inc/crypto_config_structs.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/* 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 _crypto_config_structs_h_
#define _crypto_config_structs_h_

#include "crypto_config.h"

#ifdef NOS3 //NOS3/cFS build is ready
#include "common_types.h"
#else //Assume build outside of NOS3/cFS infrastructure
#include "common_types_minimum.h"
#endif

//main config enums
typedef enum { SADB_TYPE_INMEMORY, SADB_TYPE_MARIADB } SadbType;
//gvcid managed parameter enums
typedef enum { TC_NO_FECF, TC_HAS_FECF } TcFecfPresent;
typedef enum { TC_NO_SEGMENT_HDRS, TC_HAS_SEGMENT_HDRS } TcSegmentHdrsPresent;
typedef enum { CRYPTO_TC_CREATE_FECF_FALSE, CRYPTO_TC_CREATE_FECF_TRUE } TcCreateFecfBool;
typedef enum { TC_PROCESS_SDLS_PDUS_FALSE, TC_PROCESS_SDLS_PDUS_TRUE } TcProcessSdlsPdus;
typedef enum { TC_NO_PUS_HDR, TC_HAS_PUS_HDR } TcPusHdrPresent;
typedef enum { TC_IGNORE_SA_STATE_FALSE, TC_IGNORE_SA_STATE_TRUE } TcIgnoreSaState;
typedef enum { TC_IGNORE_ANTI_REPLAY_FALSE, TC_IGNORE_ANTI_REPLAY_TRUE } TcIgnoreAntiReplay;

/*
** Main Crypto Configuration Block
*/
typedef struct
{
SadbType sadb_type;
TcCreateFecfBool crypto_create_fecf; //Whether or not CryptoLib is expected to calculate TC FECFs and return payloads with the FECF
TcProcessSdlsPdus process_sdls_pdus; //Config to process SDLS extended procedure PDUs in CryptoLib
TcPusHdrPresent has_pus_hdr;
TcIgnoreSaState ignore_sa_state; //TODO - add logic that uses this configuration
TcIgnoreAntiReplay ignore_anti_replay; //TODO - add logic that uses this configuration
uint8 vcid_bitmask;
} CryptoConfig_t;
#define CRYPTO_CONFIG_SIZE (sizeof(CryptoConfig_t))

typedef struct _GvcidManagedParameters_t GvcidManagedParameters_t;
struct _GvcidManagedParameters_t{
uint8 tfvn :4; // Transfer Frame Version Number
uint16 scid :10; //SpacecraftID
uint8 vcid :6; //Virtual Channel ID
TcFecfPresent has_fecf;
TcSegmentHdrsPresent has_segmentation_hdr;
GvcidManagedParameters_t* next; //Will be a list of managed parameters!
};
#define GVCID_MANAGED_PARAMETERS_SIZE (sizeof(GvcidManagedParameters_t))

/*
** SaDB MariaDB Configuration Block
*/
typedef struct
{
char* mysql_username;
char* mysql_password;
char* mysql_hostname;
char* mysql_database;
uint16 mysql_port;
} SadbMariaDBConfig_t;
#define SADB_MARIADB_CONFIG_SIZE (sizeof(SadbMariaDBConfig_t))

#endif
7 changes: 7 additions & 0 deletions fsw/public_inc/crypto_error.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,12 @@ [email protected]

#include "sadb_mariadb_error.h"

#define SADB_INVALID_SADB_TYPE 201
#define CRYPTO_CONFIGURATION_NOT_COMPLETE 101
#define CRYPTO_MANAGED_PARAM_CONFIGURATION_NOT_COMPLETE 102
#define CRYPTO_MARIADB_CONFIGURATION_NOT_COMPLETE 103
#define MANAGED_PARAMETERS_FOR_GVCID_NOT_FOUND 104



#endif //_crypto_error_h_
1 change: 1 addition & 0 deletions fsw/public_inc/crypto_print.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,5 @@ void Crypto_ccsdsPrint(CCSDS_t* sdls_frame);
void Crypto_saPrint(SecurityAssociation_t* sa);
void Crypto_hexprint(void *c, size_t n);
void Crypto_binprint(void *c, size_t n);
void Crypto_mpPrint(GvcidManagedParameters_t* managed_parameters);
#endif
3 changes: 2 additions & 1 deletion fsw/public_inc/crypto_structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,8 @@ typedef struct
/*
** Telecommand (TC) Definitions
*/
typedef struct __attribute__ ((packed))
//typedef struct __attribute__ ((packed)) //__attribute__ ((packed)) is not easily supported in CFFI python. Only add when CFFI properly supports packed & nonpacked structs.
typedef struct
{
uint8 tfvn :2; // Transfer Frame Version Number
uint8 bypass :1; // Bypass
Expand Down
Loading