|
| 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