@@ -160,6 +160,35 @@ function kernel_build() {
160
160
#
161
161
logmust fakeroot debian/rules printenv " ${debian_rules_args[@]} "
162
162
163
+ #
164
+ # Download SB keys and configure signing keys/certs before build
165
+ #
166
+ SB_KEYS_DIR=" /var/tmp/sbkeys"
167
+ logmust mkdir -p $SB_KEYS_DIR
168
+ logmust aws s3 cp --recursive s3://secure-boot-keys-prod/temp/db/ $SB_KEYS_DIR
169
+
170
+ FLAVOUR=$platform
171
+ OBJ=debian/build/build-$FLAVOUR
172
+ CERTS=$OBJ /certs
173
+
174
+ ensure the objdir + certs dir exist
175
+ mkdir -p " $CERTS "
176
+
177
+ # provide the key the packaging expects INSIDE the objdir
178
+ # (symlink or copy)
179
+ logmust ln -sf " ${SB_KEYS_DIR} /signing_key.pem" " $CERTS /signing_key.pem"
180
+ logmust chmod 600 " $CERTS /signing_key.pem"
181
+
182
+ # create the DER .x509 that sign-file needs from .crt)
183
+ logmust openssl x509 -in " ${SB_KEYS_DIR} /db.crt" -outform DER -out " $CERTS /signing_key.x509"
184
+ # sanity checks
185
+ logmust test -s " $CERTS /signing_key.pem" || { echo " missing signing_key.pem" ; exit 1; }
186
+ logmust test -s " $CERTS /signing_key.x509" || { echo " missing signing_key.x509" ; exit 1; }
187
+ logmust openssl pkey -in " $CERTS /signing_key.pem" -noout > /dev/null || { echo " key unreadable" ; exit 1; }
188
+
189
+ SBSIGN_KEY=" ${SBSIGN_KEY:- $SB_KEYS_DIR / db.key} "
190
+ SBSIGN_CERT=" ${SBSIGN_CERT:- $SB_KEYS_DIR / db.crt} "
191
+
163
192
#
164
193
# The default value of the tool argument for mk-build-deps
165
194
# is the following:
@@ -203,6 +232,33 @@ function kernel_build() {
203
232
# one of the .debs produced
204
233
#
205
234
logmust test -f " artifacts/linux-image-${kernel_version} _" * .deb
235
+
236
+ #
237
+ # After the build, unpackage linux-image package and sign vmlinuz
238
+ #
239
+ linux_deb=$( find artifacts -type f -name " linux-image-${kernel_version} *.deb" | head -n1)
240
+ temp_dir=$( mktemp -d -p " /var/tmp/" )
241
+ logmust fakeroot dpkg-deb -R $linux_deb " $temp_dir "
242
+
243
+ bz=" $temp_dir /boot/vmlinuz-${kernel_version} "
244
+ logmust sbsign --key $SBSIGN_KEY --cert $SBSIGN_CERT --output " $bz .signed" " $bz "
245
+ logmust mv " $bz .signed" " $bz "
246
+ logmust sbverify --list " $bz "
247
+
248
+ # Update md5sums
249
+ ( cd " $temp_dir "
250
+ : > DEBIAN/md5sums
251
+ # print paths relative to root of package
252
+ while IFS= read -r -d ' ' f; do
253
+ rel=" ${f# ./ } "
254
+ md5sum " $rel " >> DEBIAN/md5sums
255
+ done < <( find . -type f ! -path ' ./DEBIAN/*' -print0)
256
+ )
257
+
258
+ # Repack the .deb"
259
+ out_deb=" artifacts/linux-image.deb"
260
+ logmust fakeroot dpkg-deb -b " $temp_dir " " $out_deb "
261
+ logmust mv " $out_deb " " $linux_deb "
206
262
}
207
263
208
264
#
0 commit comments