@@ -74,22 +74,27 @@ machine="$(uname -m)"
7474if [ " ${machine} " = " x86_64" ]; then
7575 root_guid=4f68bce3-e8cd-4db1-96e7-fbcaf984b709
7676 verity_guid=2c7357ed-ebd2-46d9-aec1-23d437ec2bf5
77+ signature_guid=41092b05-9fc8-4523-994f-2def0408b176
7778 architecture=" x86-64"
7879elif [ " ${machine} " = " i386" ] || [ " ${machine} " = " i686" ] || [ " ${machine} " = " x86" ]; then
7980 root_guid=44479540-f297-41b2-9af7-d131d5f0458a
8081 verity_guid=d13c5d3b-b5d1-422a-b29f-9454fdc89d76
82+ signature_guid=5996fc05-109c-48de-808b-23fa0830b676
8183 architecture=" x86"
8284elif [ " ${machine} " = " aarch64" ] || [ " ${machine} " = " aarch64_be" ] || [ " ${machine} " = " armv8b" ] || [ " ${machine} " = " armv8l" ]; then
8385 root_guid=b921b045-1df0-41c3-af44-4c6f280d3fae
8486 verity_guid=df3300ce-d69f-4c92-978c-9bfb0f38d820
87+ signature_guid=6db69de6-29f4-4758-a7a5-962190f00ce3
8588 architecture=" arm64"
8689elif [ " ${machine} " = " arm" ]; then
8790 root_guid=69dad710-2ce4-4e3c-b16c-21a1d49abed3
8891 verity_guid=7386cdf2-203c-47a9-a498-f2ecce45a2d6
92+ signature_guid=42b0455f-eb11-491d-98d3-56145ba9d037
8993 architecture=" arm"
9094elif [ " ${machine} " = " ia64" ]; then
9195 root_guid=993d8d3d-f80e-4225-855a-9daf8ed7ea97
9296 verity_guid=86ed10d5-b607-45bb-8957-d350f23d0571
97+ signature_guid=e98b36ee-32ba-4882-9b12-0ce14655f46a
9398 architecture=" ia64"
9499elif [ " ${machine} " = " ppc64le" ]; then
95100 # There's no support of PPC in the discoverable partitions specification yet, so skip the rest for now
102107# du rounds up to block size, which is more helpful for partitioning
103108root_size=" $( du -k " ${image} .raw" | cut -f1) "
104109verity_size=" $( du -k " ${image} .verity" | cut -f1) "
110+ signature_size=4
105111# 4MB seems to be the minimum size blkid will accept, below that probing fails
106- dd if=/dev/zero of=" ${image} .gpt" bs=512 count=$(( 8192 + root_size* 2 + verity_size* 2 ))
112+ dd if=/dev/zero of=" ${image} .gpt" bs=512 count=$(( 8192 + root_size* 2 + verity_size* 2 + signature_size * 2 ))
107113# sfdisk seems unhappy if the size overflows into the next unit, eg: 1580KiB will be interpreted as 1MiB
108114# so do some basic rounding up if the minimal image is more than 1 MB
109115if [ " ${root_size} " -ge 1024 ]; then
@@ -112,18 +118,51 @@ else
112118 root_size=" ${root_size} KiB"
113119fi
114120verity_size=" $(( verity_size * 2 )) KiB"
121+ signature_size=" $(( signature_size * 2 )) KiB"
122+
123+ # Unfortunately OpenSSL insists on reading some config file, hence provide one with mostly placeholder contents
124+ cat >> " ${image} .openssl.cnf" << EOF
125+ [ req ]
126+ prompt = no
127+ distinguished_name = req_distinguished_name
128+
129+ [ req_distinguished_name ]
130+ C = DE
131+ ST = Test State
132+ L = Test Locality
133+ O = Org Name
134+ OU = Org Unit Name
135+ CN = Common Name
136+ emailAddress = test@email.com
137+ EOF
138+
139+ # Create key pair
140+ openssl req -config " ${image} .openssl.cnf" -new -x509 -newkey rsa:1024 -keyout " ${image} .key" -out " ${image} .crt" -days 365 -nodes
141+ # Sign Verity root hash with it
142+ openssl smime -sign -nocerts -noattr -binary -in " ${image} .roothash" -inkey " ${image} .key" -signer " ${image} .crt" -outform der -out " ${image} .roothash.p7s"
143+ # Generate signature partition JSON data
144+ echo ' {"rootHash":"' " ${roothash} " ' ","signature":"' " $( base64 -w 0 < " ${image} .roothash.p7s" ) " ' "}' > " ${image} .verity-sig"
145+ # Pad it
146+ truncate -s " ${signature_size} " " ${image} .verity-sig"
147+ # Register certificate in the (userspace) verity key ring
148+ mkdir -p /run/verity.d
149+ ln -s " ${image} .crt" /run/verity.d/ok.crt
150+
115151# Construct a UUID from hash
116152# input: 11111111222233334444555566667777
117153# output: 11111111-2222-3333-4444-555566667777
118154uuid=" $( head -c 32 " ${image} .roothash" | sed -r ' s/(.{8})(.{4})(.{4})(.{4})(.+)/\1-\2-\3-\4-\5/' ) "
119155echo -e " label: gpt\nsize=${root_size} , type=${root_guid} , uuid=${uuid} " | sfdisk " ${image} .gpt"
120156uuid=" $( tail -c 32 " ${image} .roothash" | sed -r ' s/(.{8})(.{4})(.{4})(.{4})(.+)/\1-\2-\3-\4-\5/' ) "
121157echo -e " size=${verity_size} , type=${verity_guid} , uuid=${uuid} " | sfdisk " ${image} .gpt" --append
158+ echo -e " size=${signature_size} , type=${signature_guid} " | sfdisk " ${image} .gpt" --append
122159sfdisk --part-label " ${image} .gpt" 1 " Root Partition"
123160sfdisk --part-label " ${image} .gpt" 2 " Verity Partition"
161+ sfdisk --part-label " ${image} .gpt" 3 " Signature Partition"
124162loop=" $( losetup --show -P -f " ${image} .gpt" ) "
125163dd if=" ${image} .raw" of=" ${loop} p1"
126164dd if=" ${image} .verity" of=" ${loop} p2"
165+ dd if=" ${image} .verity-sig" of=" ${loop} p3"
127166losetup -d " ${loop} "
128167
129168# Derive partition UUIDs from root hash, in UUID syntax
0 commit comments