Repository navigation
feat(image): sign a UKI with your own key and upgrade anchor - #382
Merged
Merged
Conversation
Certificate now reads CRYPTOS_UPGRADE_ANCHOR (base64 DER, set by cryptos-switchroot from the anchor appended to the UKI's .initrd at sign time) before the build-time CertificateDER stamp. A sign-time anchor that does not parse is an error rather than a fallback, and it gets the same RSA check. Refs CryptOS-PKI/cryptos-appliance#41 Signed-off-by: Bugs5382 <12115015+Bugs5382@users.noreply.github.com>
cryptosctl image sign --image --key --cert [--out] appends a newc cpio holding upgrade-anchor.der to the UKI's .initrd, moves the sections after it without touching the stub's own sections, Authenticode-signs the result and writes the detached release signature as <out>.sig. The new internal/ukisign package checks its own output before anything is written: the anchor is in place, the Authenticode signature verifies over a fresh image hash, and the .sig passes imageupgrade.Verify. Refs CryptOS-PKI/cryptos-appliance#41 Signed-off-by: Bugs5382 <12115015+Bugs5382@users.noreply.github.com>
Refs CryptOS-PKI/cryptos-appliance#41 Signed-off-by: Bugs5382 <12115015+Bugs5382@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What and why
Release assets are built unsigned and carry no upgrade anchor, so a node installed from one serves the image upgrade calls as unavailable and can never take an in-place upgrade. I want to sign an asset after the fact and have the node trust my key for upgrades from then on.
internal/release:Certificate()now prefersCRYPTOS_UPGRADE_ANCHOR(base64 std of the cert DER, which cryptos-switchroot sets from the initramfs) over the build-timeCertificateDERldflag, thenErrNoCertificate. A sign-time anchor wins. A sign-time value that does not parse is an error, never a fallback, and it gets the same RSA check.internal/ukisign(new) andcryptosctl image sign --image <unsigned.uki> --key <key.pem> --cert <cert.pem> [--out <signed.uki>]:upgrade-anchor.der(0100444, root, mtime 0) to.initrd, at a 4-byte boundary;.initrdbyte for byte at the same RVA and file offset, grows.initrdin place, moves later sections to the next aligned RVA/offset, and updates SizeOfImage, SizeOfInitializedData and the CheckSum;<out>.sig, PKCS#1 v1.5 over SHA-256 of the final bytes;.linuxand one.initrd, and any layout where moving the later sections isn't safe (entry point, data directories or symbol table at or after.initrd, unknown trailing data).--out: the input without.unsigned, else.signed.uki.docs/image-sign.md, linked from the README.Refs CryptOS-PKI/cryptos-appliance#41
Verification
internal/release: tests for each precedence branch (sign-time wins, fallback to build stamp, neither, broken sign-time anchor, non-RSA sign-time anchor).internal/ukisign: a synthetic UKI (stub sections plus .osrel/.cmdline/.initrd/.linux/.sbat) is signed, and the tests check:.sigpassesimageupgrade.Verify;ukipcr.Predictstill accepts the output;cmd/cryptosctl: tests for the required flags, and that a non-UKI is refused and nothing is written.How this was verified
CI is the proof. I built and tested nothing locally for this change, and I did not run the doc's command blocks locally. The appliance suite will run
sbverify --certon a UKI signed by this command and boot it (cryptos-appliance#41).