Skip to content

Commit 0612f25

Browse files
committed
Add nat20cli command line tool for nat20device.
This commandline tool provides a primitive interface to communicate with a nat20 device.
1 parent 42b2c9e commit 0612f25

11 files changed

Lines changed: 1390 additions & 2 deletions

File tree

.github/license-check/license-config.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"**/Kbuild",
1111
"examples/linux/br_external/external.desc",
1212
"examples/linux/**/Makefile",
13+
"examples/linux/nat20cli/openssl_dice.cnf",
1314
".clang-format",
1415
".gitignore"
1516
],

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

Lines changed: 17 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,18 @@ 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 nat20cli userspace cli tool
158+
env:
159+
LIBNAT20_OVERRIDE_SRCDIR: ${{ github.workspace }}
160+
NAT20CLI_OVERRIDE_SRCDIR: ${{ github.workspace }}
161+
run: |
162+
cd ${{ runner.temp }}/buildroot.build/buildroot
163+
make nat20cli-dirclean
164+
make nat20cli -j $(( $(nproc) + 1 ))
165+
166+
- name: Verify nat20cli was produced
167+
run: |
168+
find ${{ runner.temp }}/buildroot.build -name 'nat20cli' | grep -q nat20cli
169+
echo "nat20cli built successfully:"
170+
find ${{ runner.temp }}/buildroot.build -name 'nat20cli' -exec ls -la {} \;

examples/linux/br_external/Config.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
# along with this program; if not, see
3434
# <https://www.gnu.org/licenses/>.
3535

36+
source "$BR2_EXTERNAL_NAT20_PATH/package/nat20cli/Config.in"
3637
source "$BR2_EXTERNAL_NAT20_PATH/package/nat20crypto/Config.in"
3738
source "$BR2_EXTERNAL_NAT20_PATH/package/nat20device/Config.in"
3839
source "$BR2_EXTERNAL_NAT20_PATH/package/nat20sw/Config.in"

examples/linux/br_external/configs/qemu_br_defconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3976,6 +3976,7 @@ BR2_TARGET_UBOOT_CUSTOM_PATCH_DIR=""
39763976
#
39773977
# Provides NAT20 related packages.
39783978
#
3979+
BR2_PACKAGE_NAT20CLI=y
39793980
BR2_PACKAGE_NAT20CRYPTO=y
39803981
BR2_PACKAGE_NAT20DEVICE=y
39813982
BR2_PACKAGE_NAT20SW=y
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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_NAT20CLI
37+
bool "nat20cli"
38+
depends on BR2_PACKAGE_LIBNAT20
39+
help
40+
Enable building the nat20cli tool.
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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+
NAT20CLI_VERSION = origin/main
37+
NAT20CLI_SITE = https://github.com/aurora-opensource/libnat20.git
38+
NAT20CLI_SITE_METHOD = git
39+
NAT20CLI_LICENSE = Apache-2.0 OR GPL-2.0
40+
NAT20CLI_LICENSE_FILES = LICENSE-Apache-2.0.txt LICENSE-GPL-2.0.txt
41+
42+
NAT20CLI_SUBDIR = examples/linux/nat20cli
43+
44+
NAT20CLI_INSTALL_TARGET = YES
45+
NAT20CLI_DEPENDENCIES += libnat20
46+
47+
$(eval $(cmake-package))

examples/linux/br_external/utils/envsetup.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ fi
4646

4747
source .env
4848

49+
export NAT20CLI_OVERRIDE_SRCDIR="$LIBNAT20_ROOT"
4950
export NAT20CRYPTO_OVERRIDE_SRCDIR="$LIBNAT20_ROOT"
5051
export NAT20SW_OVERRIDE_SRCDIR="$LIBNAT20_ROOT"
5152
export NAT20DEVICE_OVERRIDE_SRCDIR="$LIBNAT20_ROOT"
@@ -72,6 +73,7 @@ function brrebuild() {
7273
echo "Available targets:"
7374
echo " all - Rebuild all components"
7475
echo " linux - Rebuild the linux kernel"
76+
echo " nat20cli - Rebuild the Dice CLI"
7577
echo " nat20crypto - Rebuild the nat20crypto module"
7678
echo " libnat20 - Rebuild the libnat20 library"
7779
echo " nat20device - Rebuild the nat20device module"
@@ -83,7 +85,7 @@ function brrebuild() {
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 nat20cli-rebuild all
8789
;;
8890
*)
8991
ensure_popd make $1-rebuild all
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(NAT20CLI 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 benfit of clangd based IDE support.
45+
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
46+
47+
###################################################################################################
48+
# The following section defines all the groups of source files.
49+
# All files must be specified explicitly; no globbing or other generation is allowed.
50+
51+
set(NAT20CLI_SOURCES
52+
# Add the core library source files here.
53+
src/main.c
54+
)
55+
56+
###################################################################################################
57+
58+
###################################################################################################
59+
# The nat20_service library is also part of the product of this project.
60+
# It will always be compiled.
61+
add_executable(nat20cli)
62+
63+
find_package(LibNat20 REQUIRED)
64+
65+
target_sources(nat20cli
66+
PRIVATE ${NAT20CLI_SOURCES}
67+
)
68+
69+
target_link_libraries(nat20cli PRIVATE LibNat20::nat20 LibNat20::nat20_service LibNat20::nat20_crypto_nat20)
70+
71+
target_compile_options(nat20cli
72+
PRIVATE -pedantic
73+
PRIVATE -Wall
74+
PRIVATE -Wextra
75+
PRIVATE -Werror
76+
)
77+
78+
install(TARGETS nat20cli RUNTIME DESTINATION bin)
79+
install(PROGRAMS nat20clitest.sh DESTINATION bin)
80+
install(FILES openssl_dice.cnf DESTINATION bin)
81+
82+
###################################################################################################
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#!/bin/sh
2+
3+
# Copyright 2026 Aurora Operations, Inc.
4+
#
5+
# SPDX-License-Identifier: Apache-2.0 OR GPL-2.0
6+
#
7+
# This work is dual licensed.
8+
# You may use it under Apache-2.0 or GPL-2.0 at your option.
9+
#
10+
# Licensed under the Apache License, Version 2.0 (the "License");
11+
# you may not use this file except in compliance with the License.
12+
# You may obtain a copy of the License at
13+
#
14+
# http://www.apache.org/licenses/LICENSE-2.0
15+
#
16+
# Unless required by applicable law or agreed to in writing, software
17+
# distributed under the License is distributed on an "AS IS" BASIS,
18+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19+
# See the License for the specific language governing permissions and
20+
# limitations under the License.
21+
#
22+
# OR
23+
#
24+
# This program is free software; you can redistribute it and/or
25+
# modify it under the terms of the GNU General Public License
26+
# as published by the Free Software Foundation; either version 2
27+
# of the License, or (at your option) any later version.
28+
#
29+
# This program is distributed in the hope that it will be useful,
30+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
31+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32+
# GNU General Public License for more details.
33+
#
34+
# You should have received a copy of the GNU General Public License
35+
# along with this program; if not, see
36+
# <https://www.gnu.org/licenses/>.
37+
38+
set -e
39+
40+
SCRIPT_DIR="$(dirname "$0")"
41+
export OPENSSL_CONF="${SCRIPT_DIR}/openssl_dice.cnf"
42+
43+
modprobe nat20sw
44+
mount -t securityfs none /sys/kernel/security
45+
46+
nat20cli cdi-cert --key-type p256 --parent-key-type p256 --output cdi_0.der --certificate-format x509 --code-desc 795375622d322e332e343a33386334353963666164666132623839353333363939353465313266373534386433613161633937336338383830303563336236646232333436636263386631 --code 228d8f76c811276e991012cf5f46090377fc72c95a6ef9e1ccd4eebec8997be5b57f0fb2c7f4804af212711e7b49533f8bc00ddee9480f76155b3da1101604b9 --conf-desc 45787472616f7264696e617279206e6f726d616c20636f6e66696775726174696f6e --conf 671e957aff5565a55961dcaef7634f1a665d8f286e7bd99593532741417f22981b57bdc39241c9685f7377e3622067c261c3ce974e6db5f18d121adad2d76185 --auth-desc 41206365727469666963617465 --auth 50808e4ab921ecf31ca5f662b6d8b85b98ec4d3f64175c8b5d70c1f0e2fef048f87b3178907e1f2d652bd8588fa84f4c374347cc34b97dae13a5b981790b38cb --mode normal --hidden 2f299d2cc916e5219a6bcbc14c7135fa25e9a71018c2bafe8c0658d4041de6c87aa444aedcc68e7d7674b81b5838be1b74bf19d4d6fb05fb0db9ee7e297afc09
47+
nat20cli cdi-cert --key-type p256 --parent-key-type p256 --output cdi_0.cose --certificate-format cose --code-desc 795375622d322e332e343a33386334353963666164666132623839353333363939353465313266373534386433613161633937336338383830303563336236646232333436636263386631 --code 228d8f76c811276e991012cf5f46090377fc72c95a6ef9e1ccd4eebec8997be5b57f0fb2c7f4804af212711e7b49533f8bc00ddee9480f76155b3da1101604b9 --conf-desc 45787472616f7264696e617279206e6f726d616c20636f6e66696775726174696f6e --conf 671e957aff5565a55961dcaef7634f1a665d8f286e7bd99593532741417f22981b57bdc39241c9685f7377e3622067c261c3ce974e6db5f18d121adad2d76185 --auth-desc 41206365727469666963617465 --auth 50808e4ab921ecf31ca5f662b6d8b85b98ec4d3f64175c8b5d70c1f0e2fef048f87b3178907e1f2d652bd8588fa84f4c374347cc34b97dae13a5b981790b38cb --mode normal --hidden 2f299d2cc916e5219a6bcbc14c7135fa25e9a71018c2bafe8c0658d4041de6c87aa444aedcc68e7d7674b81b5838be1b74bf19d4d6fb05fb0db9ee7e297afc09
48+
nat20cli promote -i 790fd72ee1352017d822773bc8f5c1ac6e4bf310dfac72fbff622368c01372bc78324f0c06cbc37964e32b18588560a386357e4517ffe93052c67fe6213c38bc
49+
nat20cli cdi-cert --key-type p256 --parent-key-type p256 --output cdi_1.der --certificate-format x509 --code-desc 795375622d322e332e343a33386334353963666164666132623839353333363939353465313266373534386433613161633937336338383830303563336236646232333436636263386631 --code 228d8f76c811276e991012cf5f46090377fc72c95a6ef9e1ccd4eebec8997be5b57f0fb2c7f4804af212711e7b49533f8bc00ddee9480f76155b3da1101604b9 --conf-desc 45787472616f7264696e617279206e6f726d616c20636f6e66696775726174696f6e --conf 671e957aff5565a55961dcaef7634f1a665d8f286e7bd99593532741417f22981b57bdc39241c9685f7377e3622067c261c3ce974e6db5f18d121adad2d76185 --auth-desc 41206365727469666963617465 --auth 50808e4ab921ecf31ca5f662b6d8b85b98ec4d3f64175c8b5d70c1f0e2fef048f87b3178907e1f2d652bd8588fa84f4c374347cc34b97dae13a5b981790b38cb --mode normal --hidden 2f299d2cc916e5219a6bcbc14c7135fa25e9a71018c2bafe8c0658d4041de6c87aa444aedcc68e7d7674b81b5838be1b74bf19d4d6fb05fb0db9ee7e297afc09
50+
nat20cli cdi-cert --key-type p256 --parent-key-type p256 --output cdi_1.cose --certificate-format cose --code-desc 795375622d322e332e343a33386334353963666164666132623839353333363939353465313266373534386433613161633937336338383830303563336236646232333436636263386631 --code 228d8f76c811276e991012cf5f46090377fc72c95a6ef9e1ccd4eebec8997be5b57f0fb2c7f4804af212711e7b49533f8bc00ddee9480f76155b3da1101604b9 --conf-desc 45787472616f7264696e617279206e6f726d616c20636f6e66696775726174696f6e --conf 671e957aff5565a55961dcaef7634f1a665d8f286e7bd99593532741417f22981b57bdc39241c9685f7377e3622067c261c3ce974e6db5f18d121adad2d76185 --auth-desc 41206365727469666963617465 --auth 50808e4ab921ecf31ca5f662b6d8b85b98ec4d3f64175c8b5d70c1f0e2fef048f87b3178907e1f2d652bd8588fa84f4c374347cc34b97dae13a5b981790b38cb --mode normal --hidden 2f299d2cc916e5219a6bcbc14c7135fa25e9a71018c2bafe8c0658d4041de6c87aa444aedcc68e7d7674b81b5838be1b74bf19d4d6fb05fb0db9ee7e297afc09
51+
52+
openssl x509 -inform der -outform pem -in cdi_0.der -out cdi_0.pem
53+
openssl x509 -inform der -outform pem -in cdi_1.der -out cdi_1.pem
54+
55+
# The dice chain is formatted as variable length CBOR array
56+
# with each element being a tagged certificate.
57+
# Here, it is assumed the the chain contains only the semi hardcoded UDS certificate
58+
# from the nat20sw example, which is the only certificate in the chain.
59+
# arr (#6.80150 (bytes(DER encoded cert)))
60+
# tail -c+10 strips off the first 9 bytes:
61+
# The variable lenght array header (1 byte 0x9f)
62+
# The certificate tag (5 bytes)
63+
# The bytes header (3 bytes)
64+
# The head -c-1 strips off the last byte, which is the CBOR "break" byte (0xff) for the variable length array.
65+
# The resulting uds_cert.der file is the DER encoded UDS certificate, which can be parsed with standard tools.
66+
tail -c+10 /sys/kernel/security/nat200/dice_chain | head -c-1 > uds_cert.der
67+
68+
openssl x509 -inform der -in uds_cert.der -outform pem -out uds_cert_p256.pem
69+
70+
cat uds_cert_p256.pem cdi_0.pem > chain.pem
71+
72+
openssl x509 -inform pem -in uds_cert_p256.pem -noout -text
73+
openssl x509 -inform pem -in cdi_0.pem -noout -text
74+
openssl x509 -inform pem -in cdi_1.pem -noout -text
75+
76+
# Verify the certificate chain. The UDS certificate is self-signed, so it is the trust anchor for the chain.
77+
# The -ignore_critical flag is needed to ignore the critical extension in the UDS certificate,
78+
# which is not understood by OpenSSL but is required by the DICE specification. This check
79+
# only verifies the signatures and the certificate format, not the critical extension semantics.
80+
openssl verify -ignore_critical -CAfile chain.pem cdi_1.pem
81+
82+
echo "OpenSSL chain verification passed."

0 commit comments

Comments
 (0)