4444 needs_posix_server : false
4545 posix_server_nvminit : false
4646 needs_nvm_image : true
47+ # The "secondary root fallback" entries below provision NVM with a
48+ # mismatched root CA at the primary slot (id 1) and the real root at
49+ # the secondary slot (id 2). This forces wolfBoot to take the
50+ # WOLFHSM_SECONDARY_ROOT_CA_NVM_ID fallback path during cert chain
51+ # verification and ensures the sunny-day update still succeeds.
52+ - name : " wolfHSM client cert chain verify ECC, secondary root fallback"
53+ file : " config/examples/sim-wolfHSM-client-certchain-ecc.config"
54+ needs_posix_server : true
55+ posix_server_nvminit : true
56+ needs_nvm_image : false
57+ secondary_root_fallback : true
58+ cert_algo : ecc256
59+ - name : " wolfHSM client cert chain verify RSA4096, secondary root fallback"
60+ file : " config/examples/sim-wolfHSM-client-certchain-rsa4096.config"
61+ needs_posix_server : true
62+ posix_server_nvminit : true
63+ needs_nvm_image : false
64+ secondary_root_fallback : true
65+ cert_algo : rsa4096
66+ - name : " wolfHSM server cert chain verify ECC, secondary root fallback"
67+ file : " config/examples/sim-wolfHSM-server-certchain-ecc.config"
68+ needs_posix_server : false
69+ posix_server_nvminit : false
70+ needs_nvm_image : true
71+ secondary_root_fallback : true
72+ cert_algo : ecc256
73+ - name : " wolfHSM server cert chain verify RSA4096, secondary root fallback"
74+ file : " config/examples/sim-wolfHSM-server-certchain-rsa4096.config"
75+ needs_posix_server : false
76+ posix_server_nvminit : false
77+ needs_nvm_image : true
78+ secondary_root_fallback : true
79+ cert_algo : rsa4096
4780
4881 fail-fast : false
4982
@@ -74,7 +107,25 @@ jobs:
74107
75108 - name : Build wolfboot.elf
76109 run : |
77- make clean && make test-sim-internal-flash-with-update
110+ make clean
111+ if [ "${{ matrix.config.secondary_root_fallback }}" = "true" ]; then
112+ make test-sim-internal-flash-with-update WOLFHSM_SECONDARY_ROOT_CA_NVM_ID=2
113+ else
114+ make test-sim-internal-flash-with-update
115+ fi
116+
117+ # Generate an unrelated "wrong" root CA to provision at the primary NVM
118+ # slot. This forces verification against the primary root to fail so the
119+ # WOLFHSM_SECONDARY_ROOT_CA_NVM_ID fallback path is exercised.
120+ - name : Generate wrong root CA for secondary root fallback test
121+ if : matrix.config.secondary_root_fallback
122+ run : |
123+ rm -rf test-dummy-ca-wrong
124+ tools/scripts/sim-gen-dummy-chain.sh --algo ${{ matrix.config.cert_algo }} --outdir test-dummy-ca-wrong
125+ if cmp -s test-dummy-ca/root-cert.der test-dummy-ca-wrong/root-cert.der; then
126+ echo "Wrong root cert is identical to the real root; secondary fallback would not be exercised" >&2
127+ exit 1
128+ fi
78129
79130 - name : Build example POSIX TCP server
80131 if : matrix.config.needs_posix_server
@@ -87,7 +138,13 @@ jobs:
87138 cd lib/wolfHSM/examples/posix/wh_posix_server
88139 if [ "${{ matrix.config.posix_server_nvminit }}" = "true" ]; then
89140 tmpfile=$(mktemp)
90- echo "obj 1 0xFFFF 0x0000 \"cert CA\" ../../../../../test-dummy-ca/root-cert.der" >> $tmpfile
141+ if [ "${{ matrix.config.secondary_root_fallback }}" = "true" ]; then
142+ # Mismatched root at primary slot (id 1) and real root at secondary slot (id 2)
143+ echo "obj 1 0xFFFF 0x0000 \"cert CA wrong\" ../../../../../test-dummy-ca-wrong/root-cert.der" >> $tmpfile
144+ echo "obj 2 0xFFFF 0x0000 \"cert CA right\" ../../../../../test-dummy-ca/root-cert.der" >> $tmpfile
145+ else
146+ echo "obj 1 0xFFFF 0x0000 \"cert CA\" ../../../../../test-dummy-ca/root-cert.der" >> $tmpfile
147+ fi
91148 ./Build/wh_posix_server.elf --type tcp --nvminit $tmpfile &
92149 else
93150 # --flags=0x100 sets the WH_NVM_FLAGS_USAGE_VERIFY flag
@@ -103,7 +160,13 @@ jobs:
103160 run : |
104161 make -C lib/wolfHSM/tools/whnvmtool
105162 tmpfile=$(mktemp)
106- echo "obj 1 0xFFFF 0x0000 \"cert CA\" test-dummy-ca/root-cert.der" >> $tmpfile
163+ if [ "${{ matrix.config.secondary_root_fallback }}" = "true" ]; then
164+ # Mismatched root at primary slot (id 1) and real root at secondary slot (id 2)
165+ echo "obj 1 0xFFFF 0x0000 \"cert CA wrong\" test-dummy-ca-wrong/root-cert.der" >> $tmpfile
166+ echo "obj 2 0xFFFF 0x0000 \"cert CA right\" test-dummy-ca/root-cert.der" >> $tmpfile
167+ else
168+ echo "obj 1 0xFFFF 0x0000 \"cert CA\" test-dummy-ca/root-cert.der" >> $tmpfile
169+ fi
107170 ./lib/wolfHSM/tools/whnvmtool/whnvmtool --image=wolfBoot_wolfHSM_NVM.bin --size=16348 --invert-erased-byte $tmpfile
108171
109172 # Run the sunny day update test against the server
0 commit comments