Skip to content

Commit c68e7a9

Browse files
committed
MCU8MASS-1790 Correct include path script when the whole path of the file is used and append the cryptoauthlib folder
1 parent e1353f4 commit c68e7a9

File tree

117 files changed

+36210
-36
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

117 files changed

+36210
-36
lines changed

scripts/inject_cryptoauthlib.sh

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ fi
1818

1919
echo "Injecting... "
2020

21-
# Fix the include paths so that all are relative to src since Arduino doesn't
22-
# allow us to add extra include paths for the compiler
23-
python "$SCRIPTPATH/update_include_paths.py" "$CRYPTOAUTH_PATH/cryptoauthlib" "$TEMPDIR_PATH"
21+
mkdir -p "$TEMPDIR_PATH/cryptoauthlib/app"
22+
23+
cp -r "$CRYPTOAUTH_PATH/cryptoauthlib/lib" "$TEMPDIR_PATH/cryptoauthlib/"
24+
cp -r "$CRYPTOAUTH_PATH/cryptoauthlib/app/tng" "$TEMPDIR_PATH/cryptoauthlib/app/"
2425

2526
# Prevent removing items if the temporary directory was not created, just to be
2627
# safe and not removing files from the project
@@ -29,7 +30,7 @@ if [ ! -d "$TEMPDIR_PATH" ]; then
2930
exit 1
3031
else
3132
# Remove everything we don't need, so we are only left with .h files
32-
pushd "$TEMPDIR_PATH/lib" 1> /dev/null
33+
pushd "$TEMPDIR_PATH/cryptoauthlib/lib" 1> /dev/null
3334
rm -rf mbedtls pkcs11 openssl wolfssl jwt cmake CMakeLists.txt
3435

3536
pushd hal 1> /dev/null
@@ -38,15 +39,13 @@ else
3839
popd 1> /dev/null
3940
fi
4041

41-
# Make the destination folders
42-
mkdir "$SRC_PATH/cryptoauthlib"
43-
mkdir "$SRC_PATH/cryptoauthlib/app"
42+
# Fix the include paths so that all are relative to src since Arduino doesn't
43+
# allow us to add extra include paths for the compiler
44+
python "$SCRIPTPATH/update_include_paths.py" "$TEMPDIR_PATH/cryptoauthlib" "$SRC_PATH/cryptoauthlib" -s "atca_config.h" -d "cryptoauthlib/atca_config.h"
4445

45-
# Copy sources
46-
cp -r "$TEMPDIR_PATH/lib" "$SRC_PATH/cryptoauthlib/"
47-
cp -r "$TEMPDIR_PATH/app/tng" "$SRC_PATH/cryptoauthlib/app/"
46+
# Copy over the config
4847
cp -r "$CRYPTOAUTH_PATH/atca_config.h" "$SRC_PATH/cryptoauthlib/"
4948

50-
rm -r "$TEMPDIR_PATH"
49+
rm -rf "$TEMPDIR_PATH"
5150

5251
echo "Done!"

scripts/update_include_paths.py

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,6 @@
33
import argparse
44

55

6-
def get_path_relative_to_root(root_path: Path, file_path: Path):
7-
"""Returns the relative path of the file path to the root
8-
path, appended with the root path.
9-
10-
Args:
11-
root_path (Path): Root path directory
12-
file_path (Path): File path in the root directory
13-
14-
Returns:
15-
Path: The full path to the file relative to the root path
16-
"""
17-
return Path((root_path / file_path.relative_to(root_path)).as_posix())
18-
19-
206
def get_include_paths_relative_to_root(root_path: Path):
217
"""Fetches every .h file in a directory to build a list of include paths.
228
@@ -30,7 +16,7 @@ def get_include_paths_relative_to_root(root_path: Path):
3016
include_paths = []
3117

3218
for path in root_path.rglob("*.h"):
33-
include_paths.append(get_path_relative_to_root(root_path, path))
19+
include_paths.append(Path((Path(root_path.name) / path.relative_to(root_path)).as_posix()))
3420

3521
return include_paths
3622

@@ -55,15 +41,18 @@ def find_matching_root_include_path(include_path: str, include_paths_relative_to
5541
return None
5642

5743

58-
def get_update_line(line: str, include_paths_relative_to_root):
44+
def get_update_line(line: str, include_paths_relative_to_root, source_overrides, destination_overrides):
5945
"""Given a line in a file, replaces a #include <...> or #include "..." with
6046
a path relative to the root folder given in the include paths relative
61-
to root list.
47+
to root list. If the item found is in the source overrides, it will be
48+
replaced with the corresponding item in destination overrides
6249
6350
Args:
6451
line (str): The line in the file
6552
include_paths_relative_to_root (list[Path]): List of the include paths
6653
relative to the root.
54+
source_overrides (list[str]): List of source include path overrides.
55+
destination_overrides (list[str]): List of destination include path overrides.
6756
6857
Returns:
6958
str: The updated line if "#include" was found.
@@ -75,14 +64,18 @@ def get_update_line(line: str, include_paths_relative_to_root):
7564
if r is not None and r.group(1).endswith(".h"):
7665
include_path = r.group(1)
7766

78-
include_path_relative_to_root = find_matching_root_include_path(
79-
include_path,
80-
include_paths_relative_to_root
81-
)
67+
if include_path in source_overrides:
68+
index = source_overrides.index(include_path)
69+
return line.replace(include_path, destination_overrides[index])
70+
else:
71+
include_path_relative_to_root = find_matching_root_include_path(
72+
include_path,
73+
include_paths_relative_to_root
74+
)
8275

83-
# If the match was not found, the include is likely a system header
84-
if include_path_relative_to_root is not None:
85-
return line.replace(include_path, include_path_relative_to_root.as_posix())
76+
# If the match was not found, the include is likely a system header
77+
if include_path_relative_to_root is not None:
78+
return line.replace(include_path, include_path_relative_to_root.as_posix())
8679

8780
return line
8881

@@ -97,9 +90,16 @@ def get_update_line(line: str, include_paths_relative_to_root):
9790
parser.add_argument("input_directory")
9891
parser.add_argument("output_directory")
9992
parser.add_argument("-v", "--verbose", action="store_true")
93+
parser.add_argument("-s", "--source-overrides", action="append",
94+
help="List of source overrides, the source and destination needs to be passed in pairs with the -s and -d flags. This overrides e.g. foo.h with bar/foo.h if -s foo.h and -d bar/foo.h are passed", default=[])
95+
parser.add_argument("-d", "--destination-overrides", action="append",
96+
help="List of destination overrides, the source and destination needs to be passed in pairs with the -s and -d flags. This overrides e.g. foo.h with bar/foo.h if -s foo.h and -d bar/foo.h are passed", default=[])
10097

10198
args = parser.parse_args()
10299

100+
if len(args.source_overrides) != len(args.destination_overrides):
101+
print("Error, source and destination overrides need to be passed in pairs when using the -s and -d flags")
102+
103103
root_path = Path(args.input_directory)
104104
output_root_path = Path(args.output_directory)
105105

@@ -131,7 +131,8 @@ def get_update_line(line: str, include_paths_relative_to_root):
131131
with open(output_path, "w") as output_file:
132132

133133
for line in input_file:
134-
updated_line = get_update_line(line, include_paths_relative_to_root)
134+
updated_line = get_update_line(line, include_paths_relative_to_root,
135+
args.source_overrides, args.destination_overrides)
135136

136137
if args.verbose:
137138
if line != updated_line:
Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
/**
2+
* \file
3+
* \brief TNG TLS device certificate definition
4+
*
5+
* \copyright (c) 2015-2020 Microchip Technology Inc. and its subsidiaries.
6+
*
7+
* \page License
8+
*
9+
* Subject to your compliance with these terms, you may use Microchip software
10+
* and any derivatives exclusively with Microchip products. It is your
11+
* responsibility to comply with third party license terms applicable to your
12+
* use of third party software (including open source software) that may
13+
* accompany Microchip software.
14+
*
15+
* THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER
16+
* EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY IMPLIED
17+
* WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A
18+
* PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT,
19+
* SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE
20+
* OF ANY KIND WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF
21+
* MICROCHIP HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE
22+
* FORESEEABLE. TO THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL
23+
* LIABILITY ON ALL CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED
24+
* THE AMOUNT OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR
25+
* THIS SOFTWARE.
26+
*/
27+
28+
#include "cryptoauthlib/lib/atcacert/atcacert_def.h"
29+
#include "cryptoauthlib/app/tng/tngtls_cert_def_1_signer.h"
30+
31+
const uint8_t g_tflxtls_cert_template_4_device[500] = {
32+
0x30, 0x82, 0x01, 0xF0, 0x30, 0x82, 0x01, 0x97, 0xA0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x10, 0x55,
33+
0xCE, 0x2E, 0x8F, 0xF6, 0x1C, 0x62, 0x50, 0xB7, 0xE1, 0x68, 0x03, 0x54, 0x14, 0x1C, 0x94, 0x30,
34+
0x0A, 0x06, 0x08, 0x2A, 0x86, 0x48, 0xCE, 0x3D, 0x04, 0x03, 0x02, 0x30, 0x4F, 0x31, 0x21, 0x30,
35+
0x1F, 0x06, 0x03, 0x55, 0x04, 0x0A, 0x0C, 0x18, 0x4D, 0x69, 0x63, 0x72, 0x6F, 0x63, 0x68, 0x69,
36+
0x70, 0x20, 0x54, 0x65, 0x63, 0x68, 0x6E, 0x6F, 0x6C, 0x6F, 0x67, 0x79, 0x20, 0x49, 0x6E, 0x63,
37+
0x31, 0x2A, 0x30, 0x28, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0C, 0x21, 0x43, 0x72, 0x79, 0x70, 0x74,
38+
0x6F, 0x20, 0x41, 0x75, 0x74, 0x68, 0x65, 0x6E, 0x74, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6F, 0x6E,
39+
0x20, 0x53, 0x69, 0x67, 0x6E, 0x65, 0x72, 0x20, 0x46, 0x46, 0x46, 0x46, 0x30, 0x20, 0x17, 0x0D,
40+
0x31, 0x38, 0x31, 0x31, 0x30, 0x38, 0x30, 0x35, 0x30, 0x30, 0x30, 0x30, 0x5A, 0x18, 0x0F, 0x32,
41+
0x30, 0x34, 0x36, 0x31, 0x31, 0x30, 0x38, 0x30, 0x35, 0x30, 0x30, 0x30, 0x30, 0x5A, 0x30, 0x42,
42+
0x31, 0x21, 0x30, 0x1F, 0x06, 0x03, 0x55, 0x04, 0x0A, 0x0C, 0x18, 0x4D, 0x69, 0x63, 0x72, 0x6F,
43+
0x63, 0x68, 0x69, 0x70, 0x20, 0x54, 0x65, 0x63, 0x68, 0x6E, 0x6F, 0x6C, 0x6F, 0x67, 0x79, 0x20,
44+
0x49, 0x6E, 0x63, 0x31, 0x1D, 0x30, 0x1B, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0C, 0x14, 0x73, 0x6E,
45+
0x30, 0x31, 0x32, 0x33, 0x30, 0x31, 0x30, 0x32, 0x30, 0x33, 0x30, 0x34, 0x30, 0x35, 0x30, 0x36,
46+
0x30, 0x31, 0x30, 0x59, 0x30, 0x13, 0x06, 0x07, 0x2A, 0x86, 0x48, 0xCE, 0x3D, 0x02, 0x01, 0x06,
47+
0x08, 0x2A, 0x86, 0x48, 0xCE, 0x3D, 0x03, 0x01, 0x07, 0x03, 0x42, 0x00, 0x04, 0x71, 0xF1, 0xA7,
48+
0x0D, 0xA3, 0x79, 0xA3, 0xFD, 0xED, 0x6B, 0x50, 0x10, 0xBD, 0xAD, 0x6E, 0x1F, 0xB9, 0xE8, 0xEB,
49+
0xA7, 0xDF, 0x2C, 0x4B, 0x5C, 0x67, 0xD3, 0x5E, 0xBA, 0x84, 0xDA, 0x09, 0xE7, 0x7A, 0xE8, 0xDB,
50+
0x2C, 0xCB, 0x96, 0x28, 0xEE, 0xEB, 0x85, 0xCD, 0xAA, 0xB3, 0x5C, 0x92, 0xE5, 0x3E, 0x1C, 0x44,
51+
0xD5, 0x5A, 0x2B, 0xA7, 0xA0, 0x24, 0xAA, 0x92, 0x60, 0x3B, 0x68, 0x94, 0x8A, 0xA3, 0x60, 0x30,
52+
0x5E, 0x30, 0x0C, 0x06, 0x03, 0x55, 0x1D, 0x13, 0x01, 0x01, 0xFF, 0x04, 0x02, 0x30, 0x00, 0x30,
53+
0x0E, 0x06, 0x03, 0x55, 0x1D, 0x0F, 0x01, 0x01, 0xFF, 0x04, 0x04, 0x03, 0x02, 0x03, 0x88, 0x30,
54+
0x1D, 0x06, 0x03, 0x55, 0x1D, 0x0E, 0x04, 0x16, 0x04, 0x14, 0x1A, 0x90, 0xB2, 0x22, 0x37, 0xA4,
55+
0x51, 0xB7, 0x57, 0xDD, 0x36, 0xD1, 0x3A, 0x85, 0x2B, 0xE1, 0x3D, 0x2E, 0xF2, 0xCA, 0x30, 0x1F,
56+
0x06, 0x03, 0x55, 0x1D, 0x23, 0x04, 0x18, 0x30, 0x16, 0x80, 0x14, 0xBC, 0xD4, 0xFD, 0xE8, 0x80,
57+
0x8A, 0x2D, 0xC9, 0x0B, 0x6D, 0x01, 0xA8, 0xC5, 0xB9, 0xB2, 0x47, 0x33, 0x7E, 0xBD, 0xDA, 0x30,
58+
0x0A, 0x06, 0x08, 0x2A, 0x86, 0x48, 0xCE, 0x3D, 0x04, 0x03, 0x02, 0x03, 0x47, 0x00, 0x30, 0x44,
59+
0x02, 0x20, 0x56, 0x73, 0x96, 0xE4, 0x9C, 0x0A, 0xA7, 0x4E, 0x61, 0x60, 0x12, 0xE3, 0x8A, 0x60,
60+
0xC3, 0xA8, 0x11, 0x09, 0x7D, 0x9C, 0x5D, 0xA4, 0xCD, 0x37, 0x89, 0xC3, 0x62, 0x96, 0x88, 0x7E,
61+
0x2A, 0x0C, 0x02, 0x20, 0x1E, 0x69, 0xB2, 0xAF, 0x0A, 0xD6, 0xC6, 0x7E, 0xE1, 0x2D, 0x5D, 0xBE,
62+
0x5A, 0x44, 0x5A, 0xD9, 0x1D, 0xF1, 0xA5, 0x98, 0x35, 0x8E, 0xD0, 0x69, 0xD9, 0x8B, 0xD7, 0xDB,
63+
0xB2, 0x99, 0xCC, 0x34
64+
};
65+
66+
const atcacert_cert_element_t g_tflxtls_cert_elements_4_device[] = {
67+
{
68+
.id = "SN03",
69+
.device_loc ={
70+
.zone = DEVZONE_CONFIG,
71+
.slot = 0,
72+
.is_genkey = 0,
73+
.offset = 0,
74+
.count = 4
75+
},
76+
.cert_loc ={
77+
.offset = 208,
78+
.count = 8
79+
},
80+
.transforms ={
81+
TF_BIN2HEX_UC,
82+
TF_NONE
83+
}
84+
},
85+
{
86+
.id = "SN48",
87+
.device_loc ={
88+
.zone = DEVZONE_CONFIG,
89+
.slot = 0,
90+
.is_genkey = 0,
91+
.offset = 8,
92+
.count = 5
93+
},
94+
.cert_loc ={
95+
.offset = 216,
96+
.count = 10
97+
},
98+
.transforms ={
99+
TF_BIN2HEX_UC,
100+
TF_NONE
101+
}
102+
}
103+
};
104+
105+
const atcacert_def_t g_tflxtls_cert_def_4_device = {
106+
.type = CERTTYPE_X509,
107+
.template_id = 3,
108+
.chain_id = 0,
109+
.private_key_slot = 0,
110+
.sn_source = SNSRC_PUB_KEY_HASH,
111+
.cert_sn_dev_loc = {
112+
.zone = DEVZONE_NONE,
113+
.slot = 0,
114+
.is_genkey = 0,
115+
.offset = 0,
116+
.count = 0
117+
},
118+
.issue_date_format = DATEFMT_RFC5280_UTC,
119+
.expire_date_format = DATEFMT_RFC5280_GEN,
120+
.tbs_cert_loc = {
121+
.offset = 4,
122+
.count = 411
123+
},
124+
.expire_years = 28,
125+
.public_key_dev_loc = {
126+
.zone = DEVZONE_DATA,
127+
.slot = 0,
128+
.is_genkey = 1,
129+
.offset = 0,
130+
.count = 64
131+
},
132+
.comp_cert_dev_loc = {
133+
.zone = DEVZONE_DATA,
134+
.slot = 10,
135+
.is_genkey = 0,
136+
.offset = 0,
137+
.count = 72
138+
},
139+
.std_cert_elements = {
140+
{ // STDCERT_PUBLIC_KEY
141+
.offset = 253,
142+
.count = 64
143+
},
144+
{ // STDCERT_SIGNATURE
145+
.offset = 427,
146+
.count = 64
147+
},
148+
{ // STDCERT_ISSUE_DATE
149+
.offset = 128,
150+
.count = 13
151+
},
152+
{ // STDCERT_EXPIRE_DATE
153+
.offset = 143,
154+
.count = 15
155+
},
156+
{ // STDCERT_SIGNER_ID
157+
.offset = 120,
158+
.count = 4
159+
},
160+
{ // STDCERT_CERT_SN
161+
.offset = 15,
162+
.count = 16
163+
},
164+
{ // STDCERT_AUTH_KEY_ID
165+
.offset = 395,
166+
.count = 20
167+
},
168+
{ // STDCERT_SUBJ_KEY_ID
169+
.offset = 362,
170+
.count = 20
171+
}
172+
},
173+
.cert_elements = g_tflxtls_cert_elements_4_device,
174+
.cert_elements_count = sizeof(g_tflxtls_cert_elements_4_device) / sizeof(g_tflxtls_cert_elements_4_device[0]),
175+
.cert_template = g_tflxtls_cert_template_4_device,
176+
.cert_template_size = sizeof(g_tflxtls_cert_template_4_device),
177+
.ca_cert_def = &g_tngtls_cert_def_1_signer
178+
};
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/**
2+
* \file
3+
* \brief TNG TLS device certificate definition
4+
*
5+
* \copyright (c) 2015-2020 Microchip Technology Inc. and its subsidiaries.
6+
*
7+
* \page License
8+
*
9+
* Subject to your compliance with these terms, you may use Microchip software
10+
* and any derivatives exclusively with Microchip products. It is your
11+
* responsibility to comply with third party license terms applicable to your
12+
* use of third party software (including open source software) that may
13+
* accompany Microchip software.
14+
*
15+
* THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER
16+
* EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY IMPLIED
17+
* WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A
18+
* PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT,
19+
* SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE
20+
* OF ANY KIND WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF
21+
* MICROCHIP HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE
22+
* FORESEEABLE. TO THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL
23+
* LIABILITY ON ALL CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED
24+
* THE AMOUNT OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR
25+
* THIS SOFTWARE.
26+
*/
27+
28+
#ifndef TFLXTLS_CERT_DEF_4_DEVICE_H
29+
#define TFLXTLS_CERT_DEF_4_DEVICE_H
30+
31+
#include "cryptoauthlib/lib/atcacert/atcacert_def.h"
32+
33+
#ifdef __cplusplus
34+
extern "C" {
35+
#endif
36+
37+
/** \ingroup tng_
38+
* @{
39+
*/
40+
extern const atcacert_def_t g_tflxtls_cert_def_4_device;
41+
/** @} */
42+
43+
#ifdef __cplusplus
44+
}
45+
#endif
46+
47+
#endif

0 commit comments

Comments
 (0)