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

AKMC-113: Add SADB Interfaces for MySQL/Inmemory configurability and basic implementation. #7

Merged
merged 11 commits into from
Nov 16, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
10 changes: 5 additions & 5 deletions fsw/crypto_sadb/sadb_mariadb_admin_scripts/create_sadb.sql
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ USE sadb;

CREATE TABLE security_associations
(
sa_id INT NOT NULL
,ekid MEDIUMINT NOT NULL DEFAULT sa_id
,akid MEDIUMINT NOT NULL DEFAULT sa_id
spi INT NOT NULL
,ekid MEDIUMINT NOT NULL DEFAULT spi
,akid MEDIUMINT NOT NULL DEFAULT spi
,sa_state SMALLINT NOT NULL DEFAULT 0
,tfvn TINYINT
,scid SMALLINT
Expand All @@ -24,13 +24,13 @@ CREATE TABLE security_associations
,ecs_len SMALLINT
,ecs SMALLINT NOT NULL DEFAULT 0
,iv_len SMALLINT NOT NULL DEFAULT 12
,iv SMALLINT
,iv BINARY(12) NOT NULL DEFAULT 0 -- IV_SIZE=12
,acs_len SMALLINT NOT NULL DEFAULT 0
,acs SMALLINT NOT NULL DEFAULT 0
,abm_len MEDIUMINT
,abm SMALLINT
,arc_len SMALLINT NOT NULL DEFAULT 0
,arc SMALLINT NOT NULL DEFAULT 5
,arc BINARY(20) NOT NULL DEFAULT 0 -- ARC_LEN=20 , TBD why so large...
,arcw_len SMALLINT
,arcw SMALLINT
);
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
USE sadb;

-- SA 1 - CLEAR MODE
INSERT INTO security_associations (sa_id,sa_state,est,ast,arc_len,arc,arcw_len,arcw,tfvn,scid,vcid,mapid)
INSERT INTO security_associations (spi,sa_state,est,ast,arc_len,arc,arcw_len,arcw,tfvn,scid,vcid,mapid)
VALUES (1,3,0,0,1,0,1,5,0,3,0,0);

-- SA 2 - KEYED; ARCW:5; AES-GCM; IV:00...00; IV-len:12; MAC-len:16; Key-ID: 128
INSERT INTO security_associations (sa_id,ekid,sa_state,est,ast,shivf_len,iv_len,iv,abm_len,abm,arcw_len,arcw,arc_len)
INSERT INTO security_associations (spi,ekid,sa_state,est,ast,shivf_len,iv_len,iv,abm_len,abm,arcw_len,arcw,arc_len)
VALUES (2,128,2,1,1,12,12,0,20,0,1,5,11);

-- SA 3 - KEYED; ARCW:5; AES-GCM; IV:00...00; IV-len:12; MAC-len:16; Key-ID: 129
INSERT INTO security_associations (sa_id,ekid,sa_state,est,ast,shivf_len,stmacf_len,iv_len,iv,abm_len,abm,arcw_len,arcw,arc_len)
INSERT INTO security_associations (spi,ekid,sa_state,est,ast,shivf_len,stmacf_len,iv_len,iv,abm_len,abm,arcw_len,arcw,arc_len)
VALUES (3,129,2,1,1,12,16,12,0,20,0,1,5,11);

-- SA 4 - KEYED; ARCW:5; AES-GCM; IV:00...00; IV-len:12; MAC-len:16; Key-ID: 130
INSERT INTO security_associations (sa_id,ekid,sa_state,est,ast,shivf_len,iv_len,iv,abm_len,abm,arcw_len,arcw,arc_len,tfvn,scid,vcid,mapid)
INSERT INTO security_associations (spi,ekid,sa_state,est,ast,shivf_len,iv_len,iv,abm_len,abm,arcw_len,arcw,arc_len,tfvn,scid,vcid,mapid)
VALUES (4,130,2,1,1,12,12,0,20,0,1,5,11,0,3,0,0);

-- SA 5 - KEYED; ARCW:5; AES-GCM; IV:00...00; IV-len:12; MAC-len:16; Key-ID: 131
INSERT INTO security_associations (sa_id,ekid,sa_state,est,ast,shivf_len,iv_len,iv,abm_len,abm,arcw_len,arcw,arc_len)
INSERT INTO security_associations (spi,ekid,sa_state,est,ast,shivf_len,iv_len,iv,abm_len,abm,arcw_len,arcw,arc_len)
VALUES (5,131,2,1,1,12,12,0,20,0,1,5,11);

-- SA 6 - UNKEYED; ARCW:5; AES-GCM; IV:00...00; IV-len:12; MAC-len:16; Key-ID: -
INSERT INTO security_associations (sa_id,sa_state,est,ast,shivf_len,iv_len,iv,abm_len,abm,arcw_len,arcw,arc_len)
INSERT INTO security_associations (spi,sa_state,est,ast,shivf_len,iv_len,iv,abm_len,abm,arcw_len,arcw,arc_len)
VALUES (6,1,1,1,12,12,0,20,0,1,5,11);

-- SA 7 - KEYED; ARCW:5; AES-GCM; IV:00...00; IV-len:12; MAC-len:16; Key-ID: 130
INSERT INTO security_associations (sa_id,ekid,sa_state,est,ast,shivf_len,iv_len,iv,abm_len,abm,arcw_len,arcw,arc_len,tfvn,scid,vcid,mapid)
INSERT INTO security_associations (spi,ekid,sa_state,est,ast,shivf_len,iv_len,iv,abm_len,abm,arcw_len,arcw,arc_len,tfvn,scid,vcid,mapid)
VALUES (7,130,2,1,1,12,12,0,20,0,1,5,11,0,3,1,0);

-- SA 8 - CLEAR MODE
INSERT INTO security_associations (sa_id,sa_state,est,ast,arc_len,arc,arcw_len,arcw,tfvn,scid,vcid,mapid)
INSERT INTO security_associations (spi,sa_state,est,ast,arc_len,arc,arcw_len,arcw,tfvn,scid,vcid,mapid)
VALUES (8,3,0,0,1,0,1,5,0,3,1,0);
10 changes: 5 additions & 5 deletions fsw/crypto_util/app/ut_tc_apply.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ UTEST(TC_APPLY_SECURITY, NO_CRYPTO_INIT)
uint32 buffer_size_i = (uint32) buffer_size;

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

return_val = Crypto_TC_ApplySecurity(buffer, buffer_size_i, &ptr_enc_frame, &enc_frame_len);
Expand All @@ -50,7 +50,7 @@ UTEST(TC_APPLY_SECURITY, HAPPY_PATH)
uint32 buffer_size_i = (uint32) buffer_size;

uint8 *ptr_enc_frame = NULL;
uint32 enc_frame_len;
uint16 enc_frame_len;

int return_val = -1;

Expand All @@ -68,7 +68,7 @@ UTEST(TC_APPLY_SECURITY1, BAD_SPACE_CRAFT_ID)
uint32 buffer_size_i = (uint32) buffer_size;

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

return_val = Crypto_TC_ApplySecurity(buffer, buffer_size_i, &ptr_enc_frame, &enc_frame_len);
Expand All @@ -86,7 +86,7 @@ UTEST(TC_APPLY_SECURITY, BAD_VIRTUAL_CHANNEL_ID)
uint32 buffer_size_i = (uint32) buffer_size;

uint8 *ptr_enc_frame = NULL;
uint32 enc_frame_len;
uint16 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);
Expand All @@ -105,7 +105,7 @@ UTEST(TC_APPLY_SECURITY, NULL_BUFFER)
uint32 buffer_size_i = (uint32) buffer_size;

uint8 *ptr_enc_frame = NULL;
uint32 enc_frame_len;
uint16 enc_frame_len;

ASSERT_EQ(Crypto_TC_ApplySecurity(buffer, buffer_size_i, &ptr_enc_frame, &enc_frame_len), -1);
}
Expand Down
46 changes: 23 additions & 23 deletions fsw/public_inc/crypto_error.h
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
/* 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_error_h_
#define _crypto_error_h_
#include "sadb_mariadb_error.h"
#endif //_crypto_error_h_
/* 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_error_h_
#define _crypto_error_h_

#include "sadb_mariadb_error.h"


#endif //_crypto_error_h_
3 changes: 2 additions & 1 deletion fsw/public_inc/crypto_print.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,6 @@ void Crypto_clcwPrint(TM_FrameCLCW_t* clcw);
void Crypto_fsrPrint(SDLS_FSR_t* report);
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);
#endif
1 change: 1 addition & 0 deletions fsw/public_inc/crypto_structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ typedef struct
typedef struct
{
// Status
uint16 spi; //Security Parameter Index
uint16 ekid; // Encryption Key ID
uint16 akid; // Authentication Key ID
uint8 sa_state:2;
Expand Down
82 changes: 41 additions & 41 deletions fsw/public_inc/itc_common_types_minimum.h
Original file line number Diff line number Diff line change
@@ -1,41 +1,41 @@
/*
* Minimal port of https://github.com/nasa-itc/osal/blob/master/src/os/inc/common_types.h
* needed to build standalone crypto library.
*
* Copyright (c) 2019 United States Government as represented by
* the Administrator of the National Aeronautics and Space Administration.
* All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef _itc_common_types_minimum_
#define _itc_common_types_minimum_
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
typedef uintptr_t cpuaddr;
typedef size_t cpusize;
typedef ptrdiff_t cpudiff;
#ifdef __cplusplus
}
#endif
#endif //itc_common_types_minimum_.h
/*
* Minimal port of https://github.com/nasa-itc/osal/blob/master/src/os/inc/common_types.h
* needed to build standalone crypto library.
*
* Copyright (c) 2019 United States Government as represented by
* the Administrator of the National Aeronautics and Space Administration.
* All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef _itc_common_types_minimum_
#define _itc_common_types_minimum_

#ifdef __cplusplus
extern "C" {
#endif

#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>

typedef uintptr_t cpuaddr;
typedef size_t cpusize;
typedef ptrdiff_t cpudiff;

#ifdef __cplusplus
}
#endif


#endif //itc_common_types_minimum_.h
38 changes: 26 additions & 12 deletions fsw/public_inc/sadb_mariadb_error.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,26 @@
//
// Created by isaleh on 11/3/2021.
//

#ifndef _sadb_mariadb_error_h_
#define _sadb_mariadb_error_h_

#define SADB_MARIADB_CONNECTION_FAILED 300
#define SADB_QUERY_BY_SPI_FAILED 301
#define SADB_QUERY_BY_SPI_EMPTY_RESULTS 302

#endif //_sadb_mariadb_error_h_
/* 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 _sadb_mariadb_error_h_
#define _sadb_mariadb_error_h_

#define SADB_MARIADB_CONNECTION_FAILED 300
#define SADB_QUERY_FAILED 301
#define SADB_QUERY_EMPTY_RESULTS 302
#define SADB_INSERT_FAILED 303

#endif //_sadb_mariadb_error_h_
2 changes: 2 additions & 0 deletions fsw/public_inc/sadb_routine.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ typedef struct {
int32 (*sadb_close)(void);
// Security Association Interaction Functions
int32 (*sadb_get_sa_from_spi)(uint16,SecurityAssociation_t**);
int32 (*sadb_get_operational_sa_from_gvcid)(uint8,uint16,uint16,uint8,SecurityAssociation_t**);
int32 (*sadb_save_sa)(SecurityAssociation_t*);
// Security Association Utility Functions
int32 (*sadb_sa_stop)(void);
int32 (*sadb_sa_start)(TC_t* tc_frame);
Expand Down
Loading