Skip to content

Commit 89cc06d

Browse files
Merge remote-tracking branch 'main' into psa-storage-test-cases-never-supported-negative-framework
2 parents 8141968 + 40f125f commit 89cc06d

10 files changed

+206
-43
lines changed

data_files/.gitignore

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ cli-rsa.csr
22
server2-rsa.csr
33
test-ca.csr
44

5-
/data_files/mpi_write
6-
/data_files/hmac_drbg_seed
7-
/data_files/ctr_drbg_seed
8-
/data_files/entropy_seed
5+
mpi_write
6+
hmac_drbg_seed
7+
ctr_drbg_seed
8+
entropy_seed

scripts/all-core.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -938,7 +938,7 @@ run_component () {
938938
esac
939939
"${dd_cmd[@]}"
940940
941-
if [ -d tf-psa-crypto ]; then
941+
if in_mbedtls_repo && in_4_x_branch; then
942942
dd_cmd=(dd if=/dev/urandom of=./tf-psa-crypto/tests/seedfile bs=64 count=1)
943943
case $OSTYPE in
944944
linux*|freebsd*|openbsd*) dd_cmd+=(status=none)

scripts/check_files.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -371,10 +371,10 @@ class LicenseIssueTracker(LineIssueTracker):
371371
LICENSE_EXEMPTION_RE_LIST = []
372372

373373
# Exempt third-party drivers which may be under a different license
374-
if build_tree.is_mbedtls_3_6():
374+
if build_tree.looks_like_tf_psa_crypto_root(os.getcwd()):
375+
LICENSE_EXEMPTION_RE_LIST.append(r'drivers/(?=(everest)/.*)')
376+
elif build_tree.is_mbedtls_3_6():
375377
LICENSE_EXEMPTION_RE_LIST.append(r'3rdparty/(?!(p256-m)/.*)')
376-
else:
377-
LICENSE_EXEMPTION_RE_LIST.append(r'tf-psa-crypto/drivers/(?=(everest)/.*)')
378378

379379
LICENSE_EXEMPTION_RE_LIST += [
380380
# Documentation explaining the license may have accidental
@@ -479,7 +479,8 @@ def __init__(self, log_file):
479479
"""Instantiate the sanity checker.
480480
Check files under the current directory.
481481
Write a report of issues to log_file."""
482-
build_tree.check_repo_path()
482+
if not build_tree.looks_like_root(os.getcwd()):
483+
raise Exception("This script must be run from Mbed TLS or TF-PSA-Crypto root")
483484
self.logger = None
484485
self.setup_logger(log_file)
485486
self.issues_to_check = [

scripts/mbedtls_framework/build_tree.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@ def crypto_core_directory(root: Optional[str] = None, relative: Optional[bool] =
4444
return "core"
4545
return os.path.join(root, "core")
4646
elif looks_like_mbedtls_root(root):
47-
if os.path.isdir(os.path.join(root, 'tf-psa-crypto')):
48-
path = "tf-psa-crypto/core"
49-
else:
47+
if is_mbedtls_3_6():
5048
path = "library"
49+
else:
50+
path = "tf-psa-crypto/core"
5151
if relative:
5252
return path
5353
return os.path.join(root, path)

scripts/mbedtls_framework/code_wrapper/psa_wrapper.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def rel_path(self, filename: str, path_list: List[str] = ['include', 'psa']) ->
106106
# Temporary, while Mbed TLS does not just rely on the TF-PSA-Crypto
107107
# build system to build its crypto library. When it does, the first
108108
# case can just be removed.
109-
if os.path.isdir(os.path.join(self.mbedtls_root, 'tf-psa-crypto')):
109+
if not build_tree.is_mbedtls_3_6():
110110
path_list = ['tf-psa-crypto' ] + path_list
111111
return os.path.join(self.mbedtls_root, *path_list, filename)
112112

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
"""Install all the required Python packages, with the minimum Python version.
2+
"""
3+
4+
# Copyright The Mbed TLS Contributors
5+
# SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
6+
7+
import argparse
8+
import os
9+
import re
10+
import subprocess
11+
import sys
12+
import tempfile
13+
import typing
14+
15+
from typing import List, Optional
16+
17+
import framework_scripts_path # pylint: disable=unused-import
18+
from mbedtls_framework import typing_util
19+
20+
def pylint_doesn_t_notice_that_certain_types_are_used_in_annotations(
21+
_list: List[typing.Any],
22+
) -> None:
23+
pass
24+
25+
26+
class Requirements:
27+
"""Collect and massage Python requirements."""
28+
29+
def __init__(self) -> None:
30+
self.requirements = [] #type: List[str]
31+
32+
def adjust_requirement(self, req: str) -> str:
33+
"""Adjust a requirement to the minimum specified version."""
34+
# allow inheritance #pylint: disable=no-self-use
35+
# If a requirement specifies a minimum version, impose that version.
36+
split_req = req.split(';', 1)
37+
split_req[0] = re.sub(r'>=|~=', r'==', split_req[0])
38+
return ';'.join(split_req)
39+
40+
def add_file(self, filename: str) -> None:
41+
"""Add requirements from the specified file.
42+
43+
This method supports a subset of pip's requirement file syntax:
44+
* One requirement specifier per line, which is passed to
45+
`adjust_requirement`.
46+
* Comments (``#`` at the beginning of the line or after whitespace).
47+
* ``-r FILENAME`` to include another file.
48+
"""
49+
for line in open(filename):
50+
line = line.strip()
51+
line = re.sub(r'(\A|\s+)#.*', r'', line)
52+
if not line:
53+
continue
54+
m = re.match(r'-r\s+', line)
55+
if m:
56+
nested_file = os.path.join(os.path.dirname(filename),
57+
line[m.end(0):])
58+
self.add_file(nested_file)
59+
continue
60+
self.requirements.append(self.adjust_requirement(line))
61+
62+
def write(self, out: typing_util.Writable) -> None:
63+
"""List the gathered requirements."""
64+
for req in self.requirements:
65+
out.write(req + '\n')
66+
67+
def install(
68+
self,
69+
pip_general_options: Optional[List[str]] = None,
70+
pip_install_options: Optional[List[str]] = None,
71+
) -> None:
72+
"""Call pip to install the requirements."""
73+
if pip_general_options is None:
74+
pip_general_options = []
75+
if pip_install_options is None:
76+
pip_install_options = []
77+
with tempfile.TemporaryDirectory() as temp_dir:
78+
# This is more complicated than it needs to be for the sake
79+
# of Windows. Use a temporary file rather than the command line
80+
# to avoid quoting issues. Use a temporary directory rather
81+
# than NamedTemporaryFile because with a NamedTemporaryFile on
82+
# Windows, the subprocess can't open the file because this process
83+
# has an exclusive lock on it.
84+
req_file_name = os.path.join(temp_dir, 'requirements.txt')
85+
with open(req_file_name, 'w') as req_file:
86+
self.write(req_file)
87+
subprocess.check_call([sys.executable, '-m', 'pip'] +
88+
pip_general_options +
89+
['install'] + pip_install_options +
90+
['-r', req_file_name])
91+
92+
def main(default_requirement_file: str) -> None:
93+
"""Command line entry point."""
94+
parser = argparse.ArgumentParser(description=__doc__)
95+
parser.add_argument('--no-act', '-n',
96+
action='store_true',
97+
help="Don't act, just print what will be done")
98+
parser.add_argument('--pip-install-option',
99+
action='append', dest='pip_install_options',
100+
help="Pass this option to pip install")
101+
parser.add_argument('--pip-option',
102+
action='append', dest='pip_general_options',
103+
help="Pass this general option to pip")
104+
parser.add_argument('--user',
105+
action='append_const', dest='pip_install_options',
106+
const='--user',
107+
help="Install to the Python user install directory"
108+
" (short for --pip-install-option --user)")
109+
parser.add_argument('files', nargs='*', metavar='FILE',
110+
help="Requirement files"
111+
" (default: {})" \
112+
.format(default_requirement_file))
113+
options = parser.parse_args()
114+
if not options.files:
115+
options.files = [default_requirement_file]
116+
reqs = Requirements()
117+
for filename in options.files:
118+
reqs.add_file(filename)
119+
reqs.write(sys.stdout)
120+
if not options.no_act:
121+
reqs.install(pip_general_options=options.pip_general_options,
122+
pip_install_options=options.pip_install_options)

scripts/mbedtls_framework/psa_information.py

+12-12
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
# SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
66
#
77

8-
import os
98
import re
109
from collections import OrderedDict
1110
from typing import List, Optional
1211

12+
from . import build_tree
1313
from . import macro_collector
1414

1515

@@ -36,17 +36,17 @@ def remove_unwanted_macros(
3636
def read_psa_interface(self) -> macro_collector.PSAMacroEnumerator:
3737
"""Return the list of known key types, algorithms, etc."""
3838
constructors = macro_collector.InputsForTest()
39-
# Temporary, while Mbed TLS does not just rely on the TF-PSA-Crypto
40-
# build system to build its crypto library. When it does, the first
41-
# case can just be removed.
42-
if os.path.isdir('tf-psa-crypto'):
43-
header_file_names = ['tf-psa-crypto/include/psa/crypto_values.h',
44-
'tf-psa-crypto/include/psa/crypto_extra.h']
45-
test_suites = ['tf-psa-crypto/tests/suites/test_suite_psa_crypto_metadata.data']
46-
else:
47-
header_file_names = ['include/psa/crypto_values.h',
48-
'include/psa/crypto_extra.h']
49-
test_suites = ['tests/suites/test_suite_psa_crypto_metadata.data']
39+
40+
if build_tree.looks_like_root('.'):
41+
if build_tree.looks_like_mbedtls_root('.') and \
42+
(not build_tree.is_mbedtls_3_6()):
43+
header_file_names = ['tf-psa-crypto/include/psa/crypto_values.h',
44+
'tf-psa-crypto/include/psa/crypto_extra.h']
45+
test_suites = ['tf-psa-crypto/tests/suites/test_suite_psa_crypto_metadata.data']
46+
else:
47+
header_file_names = ['include/psa/crypto_values.h',
48+
'include/psa/crypto_extra.h']
49+
test_suites = ['tests/suites/test_suite_psa_crypto_metadata.data']
5050

5151
for header_file_name in header_file_names:
5252
constructors.parse_header(header_file_name)

scripts/mbedtls_framework/psa_storage.py

+9-14
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
# SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
1111
#
1212

13-
import os
1413
import re
1514
import struct
1615
from typing import Dict, List, Optional, Set, Union
@@ -45,21 +44,17 @@ def update_cache(self) -> None:
4544
# Temporary, while Mbed TLS does not just rely on the TF-PSA-Crypto
4645
# build system to build its crypto library. When it does, the first
4746
# case can just be removed.
48-
if os.path.isdir('tf-psa-crypto'):
49-
includes = ['include', 'tf-psa-crypto/include',
50-
'tf-psa-crypto/drivers/builtin/include',
51-
'tf-psa-crypto/drivers/everest/include']
52-
else:
47+
48+
if build_tree.looks_like_root('.'):
5349
includes = ['include']
50+
if build_tree.looks_like_tf_psa_crypto_root('.'):
51+
includes.append('drivers/builtin/include')
52+
includes.append('drivers/everest/include')
53+
elif not build_tree.is_mbedtls_3_6():
54+
includes.append('tf-psa-crypto/include')
55+
includes.append('tf-psa-crypto/drivers/builtin/include')
56+
includes.append('tf-psa-crypto/drivers/everest/include')
5457

55-
if build_tree.looks_like_tf_psa_crypto_root('.'):
56-
includes.append('drivers/builtin/include')
57-
includes.append('drivers/everest/include')
58-
# Temporary, while TF-PSA-Crypto build system in Mbed TLS still
59-
# reference some files in Mbed TLS include directory. When it does
60-
# not anymore, this can be removed.
61-
if build_tree.looks_like_mbedtls_root('..'):
62-
includes.append('../include')
6358
values = c_build_helper.get_c_expression_values(
6459
'unsigned long', '%lu',
6560
expressions,

scripts/mbedtls_framework/psa_test_case.py

+9-4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import re
1010
from typing import FrozenSet, List, Optional, Set
1111

12+
from . import build_tree
1213
from . import psa_information
1314
from . import test_case
1415

@@ -36,10 +37,14 @@ def find_dependencies_not_implemented(dependencies: List[str]) -> List[str]:
3637
# Temporary, while Mbed TLS does not just rely on the TF-PSA-Crypto
3738
# build system to build its crypto library. When it does, the first
3839
# case can just be removed.
39-
if os.path.isdir('tf-psa-crypto'):
40-
include_dir = 'tf-psa-crypto/include'
41-
else:
42-
include_dir = 'include'
40+
41+
if build_tree.looks_like_root('.'):
42+
if build_tree.looks_like_mbedtls_root('.') and \
43+
(not build_tree.is_mbedtls_3_6()):
44+
include_dir = 'tf-psa-crypto/include'
45+
else:
46+
include_dir = 'include'
47+
4348
acc = set() #type: Set[str]
4449
for filename in [
4550
os.path.join(include_dir, 'psa/crypto_config.h'),

scripts/pkgconfig.sh

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/bin/sh
2+
#
3+
# Copyright The Mbed TLS Contributors
4+
# SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
5+
#
6+
# Purpose
7+
#
8+
# Test pkgconfig files.
9+
#
10+
# For each of the build pkg-config files, .pc files, check that
11+
# they validate and do some basic sanity testing on the output,
12+
# i.e. that the strings are non-empty.
13+
#
14+
# NOTE: This requires the built pc files to be on the pkg-config
15+
# search path, this can be controlled with env variable
16+
# PKG_CONFIG_PATH. See man(1) pkg-config for details.
17+
#
18+
19+
set -e -u
20+
21+
if [ $# -le 0 ]
22+
then
23+
echo " [!] No package names specified" >&2
24+
echo "Usage: $0 <package name 1> <package name 2> ..." >&2
25+
exit 1
26+
fi
27+
28+
for pc in "$@"; do
29+
printf "testing package config file: ${pc} ... "
30+
pkg-config --validate "${pc}"
31+
version="$(pkg-config --modversion "${pc}")"
32+
test -n "$version"
33+
cflags="$(pkg-config --cflags "${pc}")"
34+
test -n "$cflags"
35+
libs="$(pkg-config --libs "${pc}")"
36+
test -n "$libs"
37+
printf "passed\n"
38+
done
39+
40+
exit 0

0 commit comments

Comments
 (0)