Skip to content

Commit 8f72d94

Browse files
werwurmCopilot
andauthored
Add nat20 integration test suite for linux examples (#105)
Adds a C integration test binary (nat20_integration_test) that exercises the full DICE service stack via /dev/nat200. The test generates certificate chains across all supported key type (P-256, P-384) and format (X.509, COSE) permutations, verifies cryptographic signatures at each link, and confirms that parent_path-based issuance produces identical results to direct issuance after promote. Test structure: - Phase 1 (level 1): Generate CDI1, CDI2, ECA, ECA_EE certs and signatures using parent paths of varying depth from the UDS level. Verify all X.509 and COSE chains cryptographically. - Phase 2 (level 2): After one promote, regenerate CDI2/ECA/ECA_EE/sign with reduced parent path depth and assert byte-for-byte equality. - Phase 3 (level 3): After second promote, regenerate ECA/ECA_EE/sign with no parent path and assert equality. Also includes: - test_helpers.c: OpenSSL-based X.509 signature verification, public key extraction, COSE_Sign1 parsing and verification, CWT subject public key extraction, and compressed input computation. - nat20_qemu_init.sh: init wrapper for running tests in QEMU CI. - GitHub Action steps to build the rootfs and run the test suite in QEMU. - Buildroot package (nat20test) with OpenSSL dependency. --------- Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
1 parent 2dffb2b commit 8f72d94

14 files changed

Lines changed: 2239 additions & 17 deletions

File tree

.github/workflows/linux-kmod-build.yml

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ jobs:
4949
steps:
5050
- uses: actions/checkout@44c2b7a8a4ea60a981eaca3cf939b5f4305c123b #v4.1.5
5151

52-
- name: Install Buildroot dependencies
52+
- name: Install build and test dependencies
5353
run: |
5454
sudo apt-get update
5555
sudo apt-get install -y \
@@ -60,6 +60,7 @@ jobs:
6060
git \
6161
libncurses-dev \
6262
python3 \
63+
qemu-system-x86 \
6364
rsync \
6465
unzip \
6566
wget
@@ -152,3 +153,38 @@ jobs:
152153
find ${{ runner.temp }}/buildroot.build -name 'libnat20.a' | grep -q libnat20.a
153154
echo "libnat20.a built successfully:"
154155
find ${{ runner.temp }}/buildroot.build -name 'libnat20.a' -exec ls -la {} \;
156+
157+
- name: Build rootfs image
158+
env:
159+
NAT20LIB_OVERRIDE_SRCDIR: ${{ github.workspace }}
160+
NAT20DEVICE_OVERRIDE_SRCDIR: ${{ github.workspace }}
161+
NAT20CRYPTO_OVERRIDE_SRCDIR: ${{ github.workspace }}
162+
NAT20SW_OVERRIDE_SRCDIR: ${{ github.workspace }}
163+
LIBNAT20_OVERRIDE_SRCDIR: ${{ github.workspace }}
164+
NAT20TEST_OVERRIDE_SRCDIR: ${{ github.workspace }}
165+
run: make -C ${{ runner.temp }}/buildroot.build/buildroot -j $(( $(nproc) + 1 ))
166+
167+
- name: Run integration tests in QEMU
168+
timeout-minutes: 5
169+
run: |
170+
BUILDROOT_DIR="${{ runner.temp }}/buildroot.build/buildroot"
171+
KERNEL="${BUILDROOT_DIR}/output/images/bzImage"
172+
ROOTFS="${BUILDROOT_DIR}/output/images/rootfs.ext2"
173+
174+
qemu-system-x86_64 \
175+
-M pc \
176+
-kernel "${KERNEL}" \
177+
-drive file="${ROOTFS}",if=virtio,format=raw \
178+
-append "rootwait root=/dev/vda console=ttyS0 init=/usr/bin/nat20test_qemu_init.sh" \
179+
-nographic \
180+
-no-reboot \
181+
-net none \
182+
2>&1 | tee qemu_output.log
183+
184+
if grep -q "INTEGRATION_TESTS_PASSED" qemu_output.log; then
185+
echo "Integration tests passed."
186+
else
187+
echo "Integration tests failed. QEMU output:"
188+
cat qemu_output.log
189+
exit 1
190+
fi

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,3 @@ build/
4949
cmake_install.cmake
5050
compile_commands.json
5151
html/
52-
nat20test

examples/linux/br_external/Config.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,4 @@ source "$BR2_EXTERNAL_NAT20_PATH/package/nat20device/Config.in"
3838
source "$BR2_EXTERNAL_NAT20_PATH/package/nat20sw/Config.in"
3939
source "$BR2_EXTERNAL_NAT20_PATH/package/nat20lib/Config.in"
4040
source "$BR2_EXTERNAL_NAT20_PATH/package/libnat20/Config.in"
41+
source "$BR2_EXTERNAL_NAT20_PATH/package/nat20test/Config.in"

examples/linux/br_external/bootstrap.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ pushd ${LIBNAT20_BR_BUILD_DIR}
9999

100100
echo "LIBNAT20_BR_BUILD_DIR=${LIBNAT20_BR_BUILD_DIR}" | tee .env
101101
echo "LIBNAT20_ROOT=${LIBNAT20_ROOT}" | tee -a .env
102+
echo "LIBNAT20_PROJECT=${PROJECT}" | tee -a .env
102103

103104
cp ${LIBNAT20_ROOT}/examples/linux/br_external/utils/envsetup.sh ./
104105

@@ -109,7 +110,6 @@ git clone --depth 1 --branch "2025.08.1" https://gitlab.com/buildroot.org/buildr
109110
case "$PROJECT" in
110111
qemu)
111112
cp ${LIBNAT20_ROOT}/examples/linux/br_external/configs/qemu_br_defconfig buildroot/.config
112-
cp ${LIBNAT20_ROOT}/examples/linux/br_external/run-qemu.sh ./
113113
;;
114114
esac
115115

examples/linux/br_external/configs/qemu_br_defconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3981,3 +3981,4 @@ BR2_PACKAGE_NAT20DEVICE=y
39813981
BR2_PACKAGE_NAT20SW=y
39823982
BR2_PACKAGE_NAT20LIB=y
39833983
BR2_PACKAGE_LIBNAT20=y
3984+
BR2_PACKAGE_NAT20TEST=y
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Copyright 2026 Aurora Operations, Inc.
2+
#
3+
# SPDX-License-Identifier: Apache-2.0 OR GPL-2.0
4+
#
5+
# This work is dual licensed.
6+
# You may use it under Apache-2.0 or GPL-2.0 at your option.
7+
#
8+
# Licensed under the Apache License, Version 2.0 (the "License");
9+
# you may not use this file except in compliance with the License.
10+
# You may obtain a copy of the License at
11+
#
12+
# http://www.apache.org/licenses/LICENSE-2.0
13+
#
14+
# Unless required by applicable law or agreed to in writing, software
15+
# distributed under the License is distributed on an "AS IS" BASIS,
16+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
# See the License for the specific language governing permissions and
18+
# limitations under the License.
19+
#
20+
# OR
21+
#
22+
# This program is free software; you can redistribute it and/or
23+
# modify it under the terms of the GNU General Public License
24+
# as published by the Free Software Foundation; either version 2
25+
# of the License, or (at your option) any later version.
26+
#
27+
# This program is distributed in the hope that it will be useful,
28+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
29+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30+
# GNU General Public License for more details.
31+
#
32+
# You should have received a copy of the GNU General Public License
33+
# along with this program; if not, see
34+
# <https://www.gnu.org/licenses/>.
35+
36+
config BR2_PACKAGE_NAT20TEST
37+
bool "nat20test"
38+
depends on BR2_PACKAGE_LIBNAT20
39+
depends on BR2_PACKAGE_OPENSSL
40+
select BR2_PACKAGE_NAT20SW
41+
help
42+
Enable building the nat20test, an integration test for nat20device with nat20sw.
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Copyright 2026 Aurora Operations, Inc.
2+
#
3+
# SPDX-License-Identifier: Apache-2.0 OR GPL-2.0
4+
#
5+
# This work is dual licensed.
6+
# You may use it under Apache-2.0 or GPL-2.0 at your option.
7+
#
8+
# Licensed under the Apache License, Version 2.0 (the "License");
9+
# you may not use this file except in compliance with the License.
10+
# You may obtain a copy of the License at
11+
#
12+
# http://www.apache.org/licenses/LICENSE-2.0
13+
#
14+
# Unless required by applicable law or agreed to in writing, software
15+
# distributed under the License is distributed on an "AS IS" BASIS,
16+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
# See the License for the specific language governing permissions and
18+
# limitations under the License.
19+
#
20+
# OR
21+
#
22+
# This program is free software; you can redistribute it and/or
23+
# modify it under the terms of the GNU General Public License
24+
# as published by the Free Software Foundation; either version 2
25+
# of the License, or (at your option) any later version.
26+
#
27+
# This program is distributed in the hope that it will be useful,
28+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
29+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30+
# GNU General Public License for more details.
31+
#
32+
# You should have received a copy of the GNU General Public License
33+
# along with this program; if not, see
34+
# <https://www.gnu.org/licenses/>.
35+
36+
# In CI NAT20TEST_OVERRIDE_SRCDIR is set to the root of the repository,
37+
# so that the source under test is always the current branch.
38+
# Integrators who use this configuration should pin the version
39+
# to a specific commit or branch to avoid breakages when the main branch changes.
40+
NAT20TEST_VERSION = origin/main
41+
NAT20TEST_SITE = https://github.com/aurora-opensource/libnat20.git
42+
NAT20TEST_SITE_METHOD = git
43+
NAT20TEST_LICENSE = Apache-2.0 OR GPL-2.0
44+
NAT20TEST_LICENSE_FILES = LICENSE-Apache-2.0.txt LICENSE-GPL-2.0.txt
45+
46+
NAT20TEST_SUBDIR = examples/linux/nat20test
47+
48+
NAT20TEST_INSTALL_TARGET = YES
49+
NAT20TEST_DEPENDENCIES += libnat20 openssl
50+
51+
$(eval $(cmake-package))

examples/linux/br_external/utils/envsetup.sh

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ export NAT20CRYPTO_OVERRIDE_SRCDIR="$LIBNAT20_ROOT"
5050
export NAT20SW_OVERRIDE_SRCDIR="$LIBNAT20_ROOT"
5151
export NAT20DEVICE_OVERRIDE_SRCDIR="$LIBNAT20_ROOT"
5252
export NAT20LIB_OVERRIDE_SRCDIR="$LIBNAT20_ROOT"
53+
export NAT20TEST_OVERRIDE_SRCDIR="$LIBNAT20_ROOT"
5354
export LIBNAT20_OVERRIDE_SRCDIR="$LIBNAT20_ROOT"
5455

5556
function ensure_popd() {
@@ -77,16 +78,40 @@ function brrebuild() {
7778
echo " nat20device - Rebuild the nat20device module"
7879
echo " nat20sw - Rebuild the nat20sw module"
7980
echo " nat20lib - Rebuild the nat20lib library"
81+
echo " nat20test - Rebuild the nat20device integration test"
8082
popd
8183
return 1
8284
fi
8385

8486
case "$1" in
8587
all)
86-
ensure_popd make linux-rebuild nat20lib-rebuild nat20crypto-rebuild nat20device-rebuild nat20sw-rebuild libnat20-rebuild all
88+
ensure_popd make linux-rebuild nat20lib-rebuild nat20crypto-rebuild nat20device-rebuild nat20sw-rebuild libnat20-rebuild nat20test-rebuild all
8789
;;
8890
*)
8991
ensure_popd make $1-rebuild all
9092
;;
9193
esac
9294
}
95+
96+
function run-qemu() {
97+
if [ $LIBNAT20_PROJECT != "qemu" ]; then
98+
echo "Error: run-qemu is only supported for the qemu project."
99+
return 1
100+
fi
101+
102+
QEMU_BIN=qemu-system-x86_64
103+
104+
BUILDROOT_DIR="${LIBNAT20_BR_BUILD_DIR}/buildroot"
105+
KERNEL_IMAGE="${BUILDROOT_DIR}/output/images/bzImage"
106+
FS_IMAGE="${BUILDROOT_DIR}/output/images/rootfs.ext2"
107+
108+
if [ -n "$1" ]; then
109+
"${QEMU_BIN}" -M pc -kernel "${KERNEL_IMAGE}" -nographic -drive file="${FS_IMAGE}",if=virtio,format=raw -append "rootwait root=/dev/vda console=ttyS0 init=$1" -serial mon:stdio -net nic,model=virtio -net user
110+
else
111+
"${QEMU_BIN}" -M pc -kernel "${KERNEL_IMAGE}" -nographic -drive file="${FS_IMAGE}",if=virtio,format=raw -append "rootwait root=/dev/vda console=ttyS0" -serial mon:stdio -net nic,model=virtio -net user
112+
fi
113+
}
114+
115+
function run-nat20test-test() {
116+
run-qemu "/usr/bin/nat20test_qemu_init.sh"
117+
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# Copyright 2026 Aurora Operations, Inc.
2+
#
3+
# SPDX-License-Identifier: Apache-2.0 OR GPL-2.0
4+
#
5+
# This work is dual licensed.
6+
# You may use it under Apache-2.0 or GPL-2.0 at your option.
7+
#
8+
# Licensed under the Apache License, Version 2.0 (the "License");
9+
# you may not use this file except in compliance with the License.
10+
# You may obtain a copy of the License at
11+
#
12+
# http://www.apache.org/licenses/LICENSE-2.0
13+
#
14+
# Unless required by applicable law or agreed to in writing, software
15+
# distributed under the License is distributed on an "AS IS" BASIS,
16+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
# See the License for the specific language governing permissions and
18+
# limitations under the License.
19+
#
20+
# OR
21+
#
22+
# This program is free software; you can redistribute it and/or
23+
# modify it under the terms of the GNU General Public License
24+
# as published by the Free Software Foundation; either version 2
25+
# of the License, or (at your option) any later version.
26+
#
27+
# This program is distributed in the hope that it will be useful,
28+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
29+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30+
# GNU General Public License for more details.
31+
#
32+
# You should have received a copy of the GNU General Public License
33+
# along with this program; if not, see
34+
# <https://www.gnu.org/licenses/>.
35+
36+
cmake_minimum_required(VERSION 3.22)
37+
38+
project(NAT20TEST VERSION 0.0.1 LANGUAGES C)
39+
40+
# The C standard shall be C11.
41+
set(CMAKE_C_STANDARD 11)
42+
43+
# CMake shall generate a compile_commands.json file for
44+
# the benefit of clangd based IDE support.
45+
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
46+
47+
48+
###################################################################################################
49+
# Integration test binary — exercises the nat20 DICE service via /dev/nat200.
50+
add_executable(nat20_integration_test)
51+
52+
find_package(LibNat20 REQUIRED)
53+
find_package(OpenSSL REQUIRED)
54+
55+
target_sources(nat20_integration_test
56+
PRIVATE test/nat20_integration_test.c
57+
PRIVATE test/test_helpers.c
58+
)
59+
60+
target_include_directories(nat20_integration_test
61+
PRIVATE test
62+
)
63+
64+
target_link_libraries(nat20_integration_test
65+
PRIVATE LibNat20::nat20
66+
PRIVATE LibNat20::nat20_service
67+
PRIVATE LibNat20::nat20_crypto_nat20
68+
PRIVATE OpenSSL::Crypto
69+
)
70+
71+
target_compile_options(nat20_integration_test
72+
PRIVATE -pedantic
73+
PRIVATE -Wall
74+
PRIVATE -Wextra
75+
PRIVATE -Werror
76+
)
77+
78+
install(TARGETS nat20_integration_test RUNTIME DESTINATION bin)
79+
install(PROGRAMS nat20test.sh DESTINATION bin)
80+
install(PROGRAMS nat20test_qemu_init.sh DESTINATION bin)
81+
82+
###################################################################################################
Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/bash
1+
#!/bin/sh
22

33
# Copyright 2026 Aurora Operations, Inc.
44
#
@@ -35,18 +35,12 @@
3535
# along with this program; if not, see
3636
# <https://www.gnu.org/licenses/>.
3737

38-
QEMU_BIN=qemu-system-x86_64
38+
set -e
3939

40-
if [ ! -f ".env" ]; then
41-
echo ".env file not found. Please run bootstrap.sh first."
42-
exit 1
43-
fi
40+
SCRIPT_DIR="$(dirname "$0")"
4441

45-
source .env
42+
modprobe nat20sw
43+
mount -t securityfs none /sys/kernel/security
4644

47-
BUILDROOT_DIR="${LIBNAT20_BR_BUILD_DIR}/buildroot"
48-
KERNEL_IMAGE="${BUILDROOT_DIR}/output/images/bzImage"
49-
FS_IMAGE="${BUILDROOT_DIR}/output/images/rootfs.ext2"
50-
51-
52-
"${QEMU_BIN}" -M pc -kernel "${KERNEL_IMAGE}" -nographic -drive file="${FS_IMAGE}",if=virtio,format=raw -append "rootwait root=/dev/vda console=ttyS0" -serial mon:stdio -net nic,model=virtio -net user
45+
echo "Running integration test suite..."
46+
"${SCRIPT_DIR}/nat20_integration_test"

0 commit comments

Comments
 (0)