diff options
author | Changqing Li <changqing.li@windriver.com> | 2025-04-15 18:56:07 +0800 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2025-04-20 10:11:18 +0100 |
commit | 640a8b226d4046634b3288c1c22b203d72012fc7 (patch) | |
tree | 1fd1ee03ef4698cdc65067703c8c4e99dc8966ff | |
parent | d7cb9c2dafad53b7c795c72668604791ffd869ab (diff) | |
download | poky-640a8b226d4046634b3288c1c22b203d72012fc7.tar.gz |
buildtools-tarball: Make buildtools respects host CA certificates
To adapt user network enviroment, buildtools should first try to use
the user configured envs like SSL_CERT_FILE/CURL_CA_BUNDLE/..., if these
envs is not set, then use the auto-detected ca file and ca path, and
finally use the CA certificates in buildtools.
nativesdk-openssl set OPENSSLDIR as "/not/builtin", need set SSL_CERT_FILE/SSL_CERT_DIR to work
nativesdk-curl don't set default ca file, need
SSL_CERT_FILE/SSL_CERT_DIR or CURL_CA_BUNDLE/CURL_CA_PATH to work
nativesdk-git actually use libcurl, and GIT_SSL_CAPATH/GIT_SSL_CAINFO
also works
nativesdk-python3-requests will use cacert.pem under python module certifi by
default, need to set REQUESTS_CA_BUNDLE
(From OE-Core rev: 96f247b65a6deda36ec7fe6fe140bbf86777007f)
Signed-off-by: Changqing Li <changqing.li@windriver.com>
Signed-off-by: Mathieu Dubois-Briand <mathieu.dubois-briand@bootlin.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
5 files changed, 88 insertions, 15 deletions
diff --git a/meta/recipes-connectivity/openssl/files/environment.d-openssl.sh b/meta/recipes-connectivity/openssl/files/environment.d-openssl.sh index 79b9bc77ec..71d378734c 100644 --- a/meta/recipes-connectivity/openssl/files/environment.d-openssl.sh +++ b/meta/recipes-connectivity/openssl/files/environment.d-openssl.sh | |||
@@ -1,9 +1,24 @@ | |||
1 | export OPENSSL_CONF="$OECORE_NATIVE_SYSROOT/usr/lib/ssl-3/openssl.cnf" | 1 | export OPENSSL_CONF="$OECORE_NATIVE_SYSROOT/usr/lib/ssl-3/openssl.cnf" |
2 | if [ -e "${OECORE_NATIVE_SYSROOT}/etc/ssl/certs/ca-certificates.crt" ];then | ||
3 | export SSL_CERT_DIR="$OECORE_NATIVE_SYSROOT/usr/lib/ssl-3/certs" | ||
4 | export SSL_CERT_FILE="$OECORE_NATIVE_SYSROOT/usr/lib/ssl-3/certs/ca-certificates.crt" | ||
5 | export BB_ENV_PASSTHROUGH_ADDITIONS="${BB_ENV_PASSTHROUGH_ADDITIONS:-} SSL_CERT_DIR SSL_CERT_FILE" | ||
6 | fi | ||
7 | export OPENSSL_MODULES="$OECORE_NATIVE_SYSROOT/usr/lib/ossl-modules/" | 2 | export OPENSSL_MODULES="$OECORE_NATIVE_SYSROOT/usr/lib/ossl-modules/" |
8 | export OPENSSL_ENGINES="$OECORE_NATIVE_SYSROOT/usr/lib/engines-3" | 3 | export OPENSSL_ENGINES="$OECORE_NATIVE_SYSROOT/usr/lib/engines-3" |
9 | export BB_ENV_PASSTHROUGH_ADDITIONS="${BB_ENV_PASSTHROUGH_ADDITIONS:-} OPENSSL_CONF OPENSSL_MODULES OPENSSL_ENGINES" | 4 | export BB_ENV_PASSTHROUGH_ADDITIONS="${BB_ENV_PASSTHROUGH_ADDITIONS:-} OPENSSL_CONF OPENSSL_MODULES OPENSSL_ENGINES" |
5 | |||
6 | # Respect host env SSL_CERT_FILE/SSL_CERT_DIR first, then auto-detected host cert, then cert in buildtools | ||
7 | # CAFILE/CAPATH is auto-deteced when source buildtools | ||
8 | if [ -z "$SSL_CERT_FILE" ]; then | ||
9 | if [ -n "$CAFILE" ];then | ||
10 | export SSL_CERT_FILE="$CAFILE" | ||
11 | elif [ -e "${OECORE_NATIVE_SYSROOT}/etc/ssl/certs/ca-certificates.crt" ];then | ||
12 | export SSL_CERT_FILE="$OECORE_NATIVE_SYSROOT/usr/lib/ssl-3/certs/ca-certificates.crt" | ||
13 | fi | ||
14 | fi | ||
15 | |||
16 | if [ -z "$SSL_CERT_DIR" ]; then | ||
17 | if [ -n "$CAPATH" ];then | ||
18 | export SSL_CERT_DIR="$CAPATH" | ||
19 | elif [ -e "${OECORE_NATIVE_SYSROOT}/etc/ssl/certs/ca-certificates.crt" ];then | ||
20 | export SSL_CERT_DIR="$OECORE_NATIVE_SYSROOT/usr/lib/ssl-3/certs" | ||
21 | fi | ||
22 | fi | ||
23 | |||
24 | export BB_ENV_PASSTHROUGH_ADDITIONS="${BB_ENV_PASSTHROUGH_ADDITIONS:-} SSL_CERT_DIR SSL_CERT_FILE" | ||
diff --git a/meta/recipes-core/meta/buildtools-tarball.bb b/meta/recipes-core/meta/buildtools-tarball.bb index 414c266663..8e78169e23 100644 --- a/meta/recipes-core/meta/buildtools-tarball.bb +++ b/meta/recipes-core/meta/buildtools-tarball.bb | |||
@@ -80,14 +80,35 @@ create_sdk_files:append () { | |||
80 | toolchain_create_sdk_version ${SDK_OUTPUT}/${SDKPATH}/version-${SDK_SYS} | 80 | toolchain_create_sdk_version ${SDK_OUTPUT}/${SDKPATH}/version-${SDK_SYS} |
81 | 81 | ||
82 | cat >> $script <<EOF | 82 | cat >> $script <<EOF |
83 | # Detect host ca file/path, export for envfile to use | ||
84 | # /etc/ssl/certs/ca-certificates.crt Debian systems | ||
85 | # /etc/pki/tls/certs/ca-bundle.crt Fedora systems | ||
86 | # /etc/ssl/ca-bundle.pem Suse systems | ||
87 | export CAFILE | ||
88 | export CAPATH | ||
89 | for a in /etc/ssl/certs/ca-certificates.crt \ | ||
90 | /etc/pki/tls/certs/ca-bundle.crt \ | ||
91 | /etc/ssl/ca-bundle.pem ; do | ||
92 | if test -f "\$a"; then | ||
93 | CAFILE="\$a" | ||
94 | break | ||
95 | fi | ||
96 | done | ||
97 | |||
98 | a="/etc/ssl/certs" | ||
99 | if test -d "\$a" && ls "\$a"/[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f].0 >/dev/null 2>/dev/null; then | ||
100 | CAPATH="\$a" | ||
101 | fi | ||
102 | |||
83 | if [ -d "\$OECORE_NATIVE_SYSROOT/environment-setup.d" ]; then | 103 | if [ -d "\$OECORE_NATIVE_SYSROOT/environment-setup.d" ]; then |
84 | for envfile in \$OECORE_NATIVE_SYSROOT/environment-setup.d/*.sh; do | 104 | for envfile in \$OECORE_NATIVE_SYSROOT/environment-setup.d/*.sh; do |
85 | . \$envfile | 105 | . \$envfile |
86 | done | 106 | done |
87 | fi | 107 | fi |
108 | |||
88 | # We have to unset this else it can confuse oe-selftest and other tools | 109 | # We have to unset this else it can confuse oe-selftest and other tools |
89 | # which may also use the overlapping namespace. | 110 | # which may also use the overlapping namespace. |
90 | unset OECORE_NATIVE_SYSROOT | 111 | unset OECORE_NATIVE_SYSROOT CAFILE CAPATH |
91 | EOF | 112 | EOF |
92 | 113 | ||
93 | if [ "${SDKMACHINE}" = "i686" ]; then | 114 | if [ "${SDKMACHINE}" = "i686" ]; then |
diff --git a/meta/recipes-devtools/git/git/environment.d-git.sh b/meta/recipes-devtools/git/git/environment.d-git.sh index f8e3221510..9c7b5a9251 100644 --- a/meta/recipes-devtools/git/git/environment.d-git.sh +++ b/meta/recipes-devtools/git/git/environment.d-git.sh | |||
@@ -1,4 +1,19 @@ | |||
1 | if [ -e "${OECORE_NATIVE_SYSROOT}/etc/ssl/certs/ca-certificates.crt" ];then | 1 | # Respect host env GIT_SSL_CAINFO/GIT_SSL_CAPATH first, then auto-detected host cert, then cert in buildtools |
2 | export GIT_SSL_CAINFO="${OECORE_NATIVE_SYSROOT}/etc/ssl/certs/ca-certificates.crt" | 2 | # CAFILE/CAPATH is auto-deteced when source buildtools |
3 | export BB_ENV_PASSTHROUGH_ADDITIONS="${BB_ENV_PASSTHROUGH_ADDITIONS:-} GIT_SSL_CAINFO" | 3 | if [ -z "$GIT_SSL_CAINFO" ]; then |
4 | if [ -n "$CAFILE" ];then | ||
5 | export GIT_SSL_CAINFO="$CAFILE" | ||
6 | elif [ -e "${OECORE_NATIVE_SYSROOT}/etc/ssl/certs/ca-certificates.crt" ];then | ||
7 | export GIT_SSL_CAINFO="${OECORE_NATIVE_SYSROOT}/etc/ssl/certs/ca-certificates.crt" | ||
8 | fi | ||
4 | fi | 9 | fi |
10 | |||
11 | if [ -z "$GIT_SSL_CAPATH" ]; then | ||
12 | if [ -n "$CAPATH" ];then | ||
13 | export GIT_SSL_CAPATH="$CAPATH" | ||
14 | elif [ -e "${OECORE_NATIVE_SYSROOT}/etc/ssl/certs/ca-certificates.crt" ];then | ||
15 | export GIT_SSL_CAPATH="${OECORE_NATIVE_SYSROOT}/etc/ssl/certs" | ||
16 | fi | ||
17 | fi | ||
18 | |||
19 | export BB_ENV_PASSTHROUGH_ADDITIONS="${BB_ENV_PASSTHROUGH_ADDITIONS:-} GIT_SSL_CAINFO GIT_SSL_CAPATH" | ||
diff --git a/meta/recipes-devtools/python/python3-requests/environment.d-python3-requests.sh b/meta/recipes-devtools/python/python3-requests/environment.d-python3-requests.sh index c7faec127d..492177a9c3 100644 --- a/meta/recipes-devtools/python/python3-requests/environment.d-python3-requests.sh +++ b/meta/recipes-devtools/python/python3-requests/environment.d-python3-requests.sh | |||
@@ -1,4 +1,11 @@ | |||
1 | if [ -e "${OECORE_NATIVE_SYSROOT}/etc/ssl/certs/ca-certificates.crt" ];then | 1 | # Respect host env REQUESTS_CA_BUNDLE first, then auto-detected host cert, then cert in buildtools |
2 | export REQUESTS_CA_BUNDLE="${OECORE_NATIVE_SYSROOT}/etc/ssl/certs/ca-certificates.crt" | 2 | # CAFILE/CAPATH is auto-deteced when source buildtools |
3 | export BB_ENV_PASSTHROUGH_ADDITIONS="${BB_ENV_PASSTHROUGH_ADDITIONS:-} REQUESTS_CA_BUNDLE" | 3 | if [ -z "$REQUESTS_CA_BUNDLE" ]; then |
4 | if [ -n "$CAFILE" ];then | ||
5 | export REQUESTS_CA_BUNDLE="$CAFILE" | ||
6 | elif [ -e "${OECORE_NATIVE_SYSROOT}/etc/ssl/certs/ca-certificates.crt" ];then | ||
7 | export REQUESTS_CA_BUNDLE="${OECORE_NATIVE_SYSROOT}/etc/ssl/certs/ca-certificates.crt" | ||
8 | fi | ||
4 | fi | 9 | fi |
10 | |||
11 | export BB_ENV_PASSTHROUGH_ADDITIONS="${BB_ENV_PASSTHROUGH_ADDITIONS:-} REQUESTS_CA_BUNDLE" | ||
diff --git a/meta/recipes-support/curl/curl/environment.d-curl.sh b/meta/recipes-support/curl/curl/environment.d-curl.sh index 0ab83a267d..7c2971b3da 100644 --- a/meta/recipes-support/curl/curl/environment.d-curl.sh +++ b/meta/recipes-support/curl/curl/environment.d-curl.sh | |||
@@ -1,4 +1,19 @@ | |||
1 | if [ -e "${OECORE_NATIVE_SYSROOT}/etc/ssl/certs/ca-certificates.crt" ];then | 1 | # Respect host env CURL_CA_BUNDLE/CURL_CA_PATH first, then auto-detected host cert, then cert in buildtools |
2 | export CURL_CA_BUNDLE="${OECORE_NATIVE_SYSROOT}/etc/ssl/certs/ca-certificates.crt" | 2 | # CAFILE/CAPATH is auto-deteced when source buildtools |
3 | export BB_ENV_PASSTHROUGH_ADDITIONS="${BB_ENV_PASSTHROUGH_ADDITIONS:-} CURL_CA_BUNDLE" | 3 | if [ -z "$CURL_CA_PATH" ]; then |
4 | if [ -n "$CAFILE" ];then | ||
5 | export CURL_CA_BUNDLE="$CAFILE" | ||
6 | elif [ -e "${OECORE_NATIVE_SYSROOT}/etc/ssl/certs/ca-certificates.crt" ];then | ||
7 | export CURL_CA_BUNDLE="${OECORE_NATIVE_SYSROOT}/etc/ssl/certs/ca-certificates.crt" | ||
8 | fi | ||
4 | fi | 9 | fi |
10 | |||
11 | if [ -z "$CURL_CA_PATH" ]; then | ||
12 | if [ -n "$CAPATH" ];then | ||
13 | export CURL_CA_PATH="$CAPATH" | ||
14 | elif [ -e "${OECORE_NATIVE_SYSROOT}/etc/ssl/certs/ca-certificates.crt" ];then | ||
15 | export CURL_CA_PATH="${OECORE_NATIVE_SYSROOT}/etc/ssl/certs" | ||
16 | fi | ||
17 | fi | ||
18 | |||
19 | export BB_ENV_PASSTHROUGH_ADDITIONS="${BB_ENV_PASSTHROUGH_ADDITIONS:-} CURL_CA_BUNDLE CURL_CA_PATH" | ||