|
1 | 1 | #!/usr/bin/env bash
|
2 | 2 | #
|
3 |
| -# Copyright 2018, 2020 Delphix |
| 3 | +# Copyright 2018, 2025 Delphix |
4 | 4 | #
|
5 | 5 | # Licensed under the Apache License, Version 2.0 (the "License");
|
6 | 6 | # you may not use this file except in compliance with the License.
|
|
23 | 23 | # be overriden.
|
24 | 24 | #
|
25 | 25 |
|
| 26 | +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
| 27 | +source "$SCRIPT_DIR/packages/common.sh" |
| 28 | + |
26 | 29 | function fetch() {
|
27 | 30 | logmust fetch_repo_from_git
|
28 | 31 | }
|
@@ -160,6 +163,44 @@ function kernel_build() {
|
160 | 163 | #
|
161 | 164 | logmust fakeroot debian/rules printenv "${debian_rules_args[@]}"
|
162 | 165 |
|
| 166 | + # |
| 167 | + # Configure signing keys/certs before build |
| 168 | + # |
| 169 | + # CONFIG_MODULE_SIG_KEY is set to /var/tmp/sbkeys/signing_key.pem in |
| 170 | + # resources/delphix_kernel_annotations |
| 171 | + # |
| 172 | + FLAVOUR=$platform |
| 173 | + OBJ=debian/build/build-$FLAVOUR |
| 174 | + CERTS=$OBJ/certs |
| 175 | + |
| 176 | + # ensure the objdir + certs dir exist |
| 177 | + mkdir -p "$CERTS" |
| 178 | + download_keys |
| 179 | + |
| 180 | + # provide the key the packaging expects INSIDE the objdir |
| 181 | + # (symlink or copy) |
| 182 | + logmust ln -sf "${SB_KEYS_DIR}/signing_key.pem" "$CERTS/signing_key.pem" |
| 183 | + logmust chmod 600 "$CERTS/signing_key.pem" |
| 184 | + |
| 185 | + # create the DER .x509 that sign-file needs from .crt) |
| 186 | + logmust openssl x509 -in "${SB_KEYS_DIR}/db.crt" -outform DER -out "$CERTS/signing_key.x509" |
| 187 | + |
| 188 | + # sanity checks |
| 189 | + logmust test -s "$CERTS/signing_key.pem" || { |
| 190 | + echo "missing signing_key.pem" |
| 191 | + exit 1 |
| 192 | + } |
| 193 | + logmust test -s "$CERTS/signing_key.x509" || { |
| 194 | + echo "missing signing_key.x509" |
| 195 | + exit 1 |
| 196 | + } |
| 197 | + logmust openssl pkey -in "$CERTS/signing_key.pem" -noout >/dev/null || { |
| 198 | + echo "key unreadable" |
| 199 | + exit 1 |
| 200 | + } |
| 201 | + SBSIGN_KEY="${SBSIGN_KEY:-$SB_KEYS_DIR/db.key}" |
| 202 | + SBSIGN_CERT="${SBSIGN_CERT:-$SB_KEYS_DIR/db.crt}" |
| 203 | + |
163 | 204 | #
|
164 | 205 | # The default value of the tool argument for mk-build-deps
|
165 | 206 | # is the following:
|
@@ -203,6 +244,23 @@ function kernel_build() {
|
203 | 244 | # one of the .debs produced
|
204 | 245 | #
|
205 | 246 | logmust test -f "artifacts/linux-image-${kernel_version}_"*.deb
|
| 247 | + |
| 248 | + # |
| 249 | + # After the build, unpackage linux-image package and sign vmlinuz |
| 250 | + # |
| 251 | + linux_deb=$(find artifacts -type f -name "linux-image-${kernel_version}*.deb" | head -n1) |
| 252 | + temp_dir=$(mktemp -d -p "/var/tmp/") |
| 253 | + logmust fakeroot dpkg-deb -R $linux_deb "$temp_dir" |
| 254 | + |
| 255 | + bz="$temp_dir/boot/vmlinuz-${kernel_version}" |
| 256 | + logmust sbsign --key $SBSIGN_KEY --cert $SBSIGN_CERT --output "$bz.signed" "$bz" |
| 257 | + logmust mv "$bz.signed" "$bz" |
| 258 | + logmust sbverify --list "$bz" |
| 259 | + |
| 260 | + # Repack the .deb" |
| 261 | + update_md5sums "$temp_dir" |
| 262 | + repack_deb $linux_deb $temp_dir |
| 263 | + delete_keys |
206 | 264 | }
|
207 | 265 |
|
208 | 266 | #
|
|
0 commit comments