Skip to content

402 quickfix kmc should not call get key #440

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

Merged
merged 22 commits into from
Mar 25, 2025
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
f04173c
[nasa/cryptolib#402] Wrap all get_key and direct ekp/akp access in KE…
Donnie-Ice Feb 5, 2025
2748d1e
[nasa/cryptolib#402] Updated function signatures for mariadb
Donnie-Ice Feb 6, 2025
6d76cbf
[nasa/cryptolib#402] Don't validate SA index with MariaDB
Donnie-Ice Feb 11, 2025
f01b5b2
[nasa/cryptolib#402] Move SA_MARIADB checks inside of validate_sa_index
Donnie-Ice Feb 12, 2025
2f27fd1
[nasa/cryptolib#402] Move SA_MARIADB checks inside of validate_sa_ind…
Donnie-Ice Feb 12, 2025
78e7e99
[nasa/cryptolib#402] Add missing KMC check before referencing key
Donnie-Ice Feb 12, 2025
446ff2f
[nasa/cryptolib#402] Add config based approach for KMC sa_validate_index
Donnie-Ice Feb 12, 2025
da826dc
[nasa/cryptolib#402] Modify how cryptography_type gets set, Currently…
Donnie-Ice Feb 14, 2025
5ba7fe3
[nasa/cryptolib#402] Reordered ECS Enum to line up with KMC
Donnie-Ice Mar 3, 2025
d798804
[nasa/cryptolib#402] Reorganize crypto_shutdown
Donnie-Ice Mar 7, 2025
3a7e69c
[nasa/cryptolib#402] Added bounds checking for ingest of mariadb SA's
Donnie-Ice Mar 13, 2025
8a11286
[nasa/cryptolib#402] Reworked default values for build flags
Donnie-Ice Mar 13, 2025
6b383fc
[nasa/cryptolib#428] Added status check to fecf calculation
Donnie-Ice Mar 19, 2025
af2f18b
[nasa/cryptolib#402] Replace accidental mariadb sa parser ast removal
Donnie-Ice Mar 21, 2025
95fe05a
[nasa/cryptolib#402] Only free encrypt_payload if aad_bool is true, o…
Donnie-Ice Mar 21, 2025
8903793
[nasa/cryptolib#402] Fix incorrect Internal SA stub error message
Donnie-Ice Mar 21, 2025
7959fd7
[nasa/cryptolib#402] Attempt to fix build scripts
Donnie-Ice Mar 25, 2025
3460556
[nasa/cryptolib#402] Fix wolf/rhel build scripts
Donnie-Ice Mar 25, 2025
a2e4847
[nasa/cryptolib#402] Add status checks to Crypto_init in UTs, prevent…
Donnie-Ice Mar 25, 2025
ab5b517
Merge branch 'dev' into 402-quickfix-kmc-should-not-call-get_key
Donnie-Ice Mar 25, 2025
4ee3f57
style: auto-format via clang-format
Donnie-Ice Mar 25, 2025
2a938a0
[nasa/cryptolib#402] fix UTs
Donnie-Ice Mar 25, 2025
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
9 changes: 4 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,23 @@ set(CRYPTO_CUSTOM_PATH_DEFAULT "../../crypto/custom")
# 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_LIBGCRYPT "Cryptography Module - Libgcrypt" OFF)
option(CRYPTO_KMC "Cryptography Module - KMC" OFF)
option(CRYPTO_WOLFSSL "Cryptography Module - WolfSSL" OFF)
option(CRYPTO_CUSTOM "Cryptography Module - CUSTOM" OFF)
option(CRYPTO_CUSTOM_PATH "Cryptography Module - CUSTOM PATH" OFF)
option(DEBUG "Debug" OFF)
option(KEY_CUSTOM "Key Module - Custom" OFF)
option(KEY_CUSTOM_PATH "Custom Key Path" OFF)
option(KEY_INTERNAL "Key Module - Internal" ON)
option(KEY_INTERNAL "Key Module - Internal" OFF)
option(KEY_KMC "Key Module - KMC" OFF)
option(MC_CUSTOM "Monitoring and Control - Custom" OFF)
option(MC_CUSTOM_PATH "Custom Monitoring and Control path" OFF)
option(MC_DISABLED "Monitoring and Control - Disabled" OFF)
option(MC_INTERNAL "Monitoring and Control - Internal" ON)
option(MC_INTERNAL "Monitoring and Control - Internal" OFF)
option(SA_CUSTOM "Security Association - Custom" OFF)
option(SA_CUSTOM_PATH "Custom Security Association Path" OFF)
option(SA_INTERNAL "Security Association - Internal" ON)
option(SA_INTERNAL "Security Association - Internal" OFF)
option(SA_MARIADB "Security Association - MariaDB" OFF)
option(SUPPORT "Support" OFF)
option(SYSTEM_INSTALL "SystemInstall" OFF)
Expand Down Expand Up @@ -142,7 +142,6 @@ ENDIF(KMC_MDB_DB)
IF(CRYPTO_EPROC)
ADD_DEFINITIONS(-DCRYPTO_EPROC)
message(WARNING "Cryptolib Extended Procedures NOT complete. NOT Fully tested. Use at own risk!")

ENDIF(CRYPTO_EPROC)

if(SYSTEM_INSTALL)
Expand Down
4 changes: 2 additions & 2 deletions include/crypto_config_structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,10 @@
{
CRYPTO_CIPHER_NONE,
CRYPTO_CIPHER_AES256_GCM,
CRYPTO_CIPHER_AES256_GCM_SIV,
CRYPTO_CIPHER_AES256_CBC,
CRYPTO_CIPHER_AES256_CBC_MAC,
CRYPTO_CIPHER_AES256_CCM
CRYPTO_CIPHER_AES256_CCM,
CRYPTO_CIPHER_AES256_GCM_SIV
} EncCipherSuite;

/*
Expand Down Expand Up @@ -222,7 +222,7 @@
#define CRYPTO_CONFIG_SIZE (sizeof(CryptoConfig_t))

typedef struct _GvcidManagedParameters_t GvcidManagedParameters_t;
struct _GvcidManagedParameters_t

Check warning on line 225 in include/crypto_config_structs.h

View workflow job for this annotation

GitHub Actions / cpp-linter

include/crypto_config_structs.h:225:16 [bugprone-reserved-identifier]

declaration uses identifier '_GvcidManagedParameters_t', which is a reserved identifier
{
uint8_t tfvn : 4; // Transfer Frame Version Number
uint16_t scid : 10; // SpacecraftID
Expand Down
3 changes: 2 additions & 1 deletion include/crypto_error.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#define SADB_QUERY_FAILED 301
#define SADB_QUERY_EMPTY_RESULTS 302
#define SADB_INSERT_FAILED 303
#define SADB_INVALID_SA_FIELD_VALUE 304

#define CRYPTOGRAPHY_INVALID_CRYPTO_INTERFACE_TYPE 400
#define CRYPTOGRAPHY_UNSUPPORTED_OPERATION_FOR_KEY_RING 401
Expand Down Expand Up @@ -150,11 +151,11 @@
#define KMC_ERROR_CODES 500
#define KMC_ERROR_CODES_MAX 515

#define CRYPTO_INTERFACE_ERROR_CODES 400

Check warning on line 154 in include/crypto_error.h

View workflow job for this annotation

GitHub Actions / cpp-linter

include/crypto_error.h:154:37 [bugprone-macro-parentheses]

macro replacement list should be enclosed in parentheses
#define CRYPTO_INTERFACE_ERROR_CODES_MAX 402

#define SADB_ERROR_CODES 300
#define SADB_ERROR_CODES_MAX 303
#define SADB_ERROR_CODES_MAX 304

#define SADB_INTERFACE_ERROR_CODES 200
#define SADB_INTERFACE_ERROR_CODES_MAX 201
Expand All @@ -171,2 +172,2 @@
extern char *crypto_enum_errlist_crypto_cam[];

Expand Down
91 changes: 50 additions & 41 deletions src/core/crypto_aos.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/** Copyright (C) 2009 - 2022 National Aeronautics and Space Administration.
All Foreign Rights are Reserved to the U.S. Government.

Expand Down Expand Up @@ -360,31 +360,34 @@
// Get Key
crypto_key_t *ekp = NULL;
crypto_key_t *akp = NULL;
ekp = key_if->get_key(sa_ptr->ekid);
akp = key_if->get_key(sa_ptr->akid);

if (ekp == NULL || akp == NULL)
if (crypto_config.key_type != KEY_TYPE_KMC)
{
status = CRYPTO_LIB_ERR_KEY_ID_ERROR;
mc_if->mc_log(status);
return status;
}
if (sa_ptr->est == 1)
{
if (ekp->key_state != KEY_ACTIVE)
ekp = key_if->get_key(sa_ptr->ekid);
akp = key_if->get_key(sa_ptr->akid);

if (ekp == NULL || akp == NULL)
{
status = CRYPTO_LIB_ERR_KEY_STATE_INVALID;
status = CRYPTO_LIB_ERR_KEY_ID_ERROR;
mc_if->mc_log(status);
return status;
}
}
if (sa_ptr->ast == 1)
{
if (akp->key_state != KEY_ACTIVE)
if (sa_ptr->est == 1)
{
status = CRYPTO_LIB_ERR_KEY_STATE_INVALID;
mc_if->mc_log(status);
return status;
if (ekp->key_state != KEY_ACTIVE)
{
status = CRYPTO_LIB_ERR_KEY_STATE_INVALID;
mc_if->mc_log(status);
return status;
}
}
if (sa_ptr->ast == 1)
{
if (akp->key_state != KEY_ACTIVE)
{
status = CRYPTO_LIB_ERR_KEY_STATE_INVALID;
mc_if->mc_log(status);
return status;
}
}
}

Expand Down Expand Up @@ -1216,34 +1219,40 @@

if (sa_ptr->est == 1)
{
ekp = key_if->get_key(sa_ptr->ekid);
if (ekp == NULL)
{
status = CRYPTO_LIB_ERR_KEY_ID_ERROR;
mc_if->mc_log(status);
return status;
}
if (ekp->key_state != KEY_ACTIVE)
if (crypto_config.key_type != KEY_TYPE_KMC)
{
status = CRYPTO_LIB_ERR_KEY_STATE_INVALID;
mc_if->mc_log(status);
return status;
ekp = key_if->get_key(sa_ptr->ekid);
if (ekp == NULL)
{
status = CRYPTO_LIB_ERR_KEY_ID_ERROR;
mc_if->mc_log(status);
return status;
}
if (ekp->key_state != KEY_ACTIVE)
{
status = CRYPTO_LIB_ERR_KEY_STATE_INVALID;
mc_if->mc_log(status);
return status;
}
}
}
if (sa_ptr->ast == 1)
{
akp = key_if->get_key(sa_ptr->akid);
if (akp == NULL)
{
status = CRYPTO_LIB_ERR_KEY_ID_ERROR;
mc_if->mc_log(status);
return status;
}
if (akp->key_state != KEY_ACTIVE)
if (crypto_config.key_type != KEY_TYPE_KMC)
{
status = CRYPTO_LIB_ERR_KEY_STATE_INVALID;
mc_if->mc_log(status);
return status;
akp = key_if->get_key(sa_ptr->akid);
if (akp == NULL)
{
status = CRYPTO_LIB_ERR_KEY_ID_ERROR;
mc_if->mc_log(status);
return status;
}
if (akp->key_state != KEY_ACTIVE)
{
status = CRYPTO_LIB_ERR_KEY_STATE_INVALID;
mc_if->mc_log(status);
return status;
}
}
}

Expand Down
21 changes: 12 additions & 9 deletions src/core/crypto_config.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/* Copyright (C) 2009 - 2022 National Aeronautics and Space Administration.
All Foreign Rights are Reserved to the U.S. Government.

Expand Down Expand Up @@ -297,29 +297,32 @@
// Determine which cryptographic module is in use
if (cryptography_if == NULL)
{
cryptography_if = get_cryptography_interface_libgcrypt();
if (cryptography_if == NULL)
if (crypto_config.cryptography_type == CRYPTOGRAPHY_TYPE_LIBGCRYPT)
{
cryptography_if = get_cryptography_interface_libgcrypt();
}
else if (crypto_config.cryptography_type == CRYPTOGRAPHY_TYPE_WOLFSSL)
{
cryptography_if = get_cryptography_interface_wolfssl();
}
if (cryptography_if == NULL)
else if (crypto_config.cryptography_type == CRYPTOGRAPHY_TYPE_CUSTOM)
{
cryptography_if = get_cryptography_interface_custom();
}
if (cryptography_if == NULL)
{ // Note this needs to be the last option in the chain due to addition configuration required
else if (crypto_config.cryptography_type == CRYPTOGRAPHY_TYPE_KMCCRYPTO)
{
if (cryptography_kmc_crypto_config != NULL)
{
cryptography_if = get_cryptography_interface_kmc_crypto_service();
}
}
if (cryptography_if == NULL)
else
{
#ifdef DEBUG
printf("Fatal Error: Unable to identify Cryptography Interface!\n");
#endif
status = CRYPTOGRAPHY_INVALID_CRYPTO_INTERFACE_TYPE;
}
}
}

if (status == CRYPTO_LIB_SUCCESS)
Expand Down Expand Up @@ -388,8 +391,6 @@
{
int32_t status = CRYPTO_LIB_SUCCESS;

crypto_free_config_structs();

// current_managed_parameters = NULL;
current_managed_parameters_struct = gvcid_null_struct;
for (int i = 0; i <= gvcid_counter; i++)
Expand Down Expand Up @@ -423,6 +424,8 @@
cryptography_if = NULL;
}

crypto_free_config_structs();

return status;
}

Expand Down
1 change: 1 addition & 0 deletions src/core/crypto_error.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/* Copyright (C) 2009 - 2022 National Aeronautics and Space Administration.
All Foreign Rights are Reserved to the U.S. Government.

Expand Down Expand Up @@ -108,6 +108,7 @@
(char *)"SADB_QUERY_FAILED",
(char *)"SADB_QUERY_EMPTY_RESULTS",
(char *)"SADB_INSERT_FAILED",
(char *)"SADB_INVALID_SA_FIELD_VALUE",
};
char *crypto_enum_errlist_crypto_if[] = {
(char *)"CRYPTOGRAPHY_INVALID_CRYPTO_INTERFACE_TYPE",
Expand Down
Loading
Loading