-
Notifications
You must be signed in to change notification settings - Fork 133
add: scripts for module signing #591
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| # Module Sining | ||
|
|
||
| In order to make the dkms modules work with secure boot they need to be singed. | ||
| This directory contains scripts that help you with that task. | ||
|
|
||
| ## Known Issues / Help Wanted | ||
|
|
||
| - doctor script does nothing | ||
| - only supports amd64 | ||
| - only tested on Debian | ||
|
|
||
| ## Run Doctor | ||
|
|
||
| The doctor script will check your environment and asks you to to install | ||
| additional packages if something is missing. | ||
|
|
||
| ## Cert Import | ||
|
|
||
| If you alread have a certificate with a key under your control imported into | ||
| the bios you can scipt this section. | ||
|
|
||
| bla bla | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Elaborate... :-D |
||
|
|
||
| ## Signing of VBOX modules | ||
|
|
||
| You need to either run the script in the directory that contains your | ||
| `MOK.der` and MOK.priv` or export the path in the `MOK_KEY_DIR` evironment | ||
| variable. | ||
|
|
||
| Execute the scipt `MOK_KEY_DIR=/path/to/your/key/dir ./sign-xbox-modules` as | ||
| root or via sudo to sign the modules. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| #!/usr/bin/env bash | ||
| MOK_CN_NAME={MOK_CA_NAME:-"$USER@$HOST"} | ||
|
|
||
| if [[ -e MOK.priv ]]; then | ||
| echo key already exists | ||
| exit 2 | ||
| fi | ||
|
|
||
| openssl req -new -x509 -newkey rsa:2048 -keyout MOK.priv -outform DER -out MOK.der -days 36500 -subj "/CN=$MOK_CN_NAME (SecureBoot Mok)/" && \ | ||
| chmod 600 MOK.priv |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| #!/usr/bin/env bash | ||
| mokutil --import MOK.der |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| #!/usr/bin/env bash | ||
| # LICENSE GPL-2.0 | ||
| # AUTHOR Jan Christoph Uhde - jan@uhde.io | ||
| set -uo pipefail | ||
|
|
||
| MOK_KEY_DIR="${MOK_KEY_DIR:-'.'}" | ||
|
|
||
| ferr() { echo "$*"; exit 1; } | ||
|
|
||
| hash_algo='sha256' | ||
| key="$MOK_KEY_DIR/MOK.priv" | ||
| x509="MOK_KEY_DIR/MOK.der" | ||
|
|
||
| # TODO - maybe this could be done better without exporting the key to the env | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could |
||
| # the key is only for a short time present in the process but it is still | ||
| # not optimal | ||
| test -v KBUILD_SIGN_PIN || read -p "passphrase for ${key}: " KBUILD_SIGN_PIN | ||
| export KBUILD_SIGN_PIN | ||
| echo | ||
|
|
||
| # The exact location of `sign-file` might vary depending on your platform. | ||
| # TODO - test with different distributions | ||
| for module_dir in /usr/lib/linux-kbuild*; do | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. At least Gentoo doesn't have this dir. But it has
|
||
| echo | ||
| echo "working on $module_dir" | ||
| sign_file="$module_dir/scripts/sign-file" | ||
| test -x $sign_file || ferr "can not execute $sign_file" | ||
|
|
||
| version=${module_dir#/usr/lib/linux-kbuild-} | ||
| # TODO - other platforms?! | ||
| module_dir="/lib/modules/$version-amd64/updates/dkms" | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's nothing like So I'd assume that The suffix is part of |
||
| echo "version: $version" | ||
| echo "module dir: $module_dir" | ||
|
|
||
| if ! [[ -d $module_dir ]] ; then | ||
| echo "no such directory: $module_dir" | ||
| continue | ||
| fi | ||
|
|
||
| echo | ||
| for module_path in "$module_dir"/hid-xpadneo* ; do | ||
| echo -n "module: $module_path ... " | ||
| if ! [[ -e "$module_path" ]] ; then | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why would this happen? The only incident would be that the for-loop expansion literally resolved to |
||
| echo "skipped" | ||
| continue | ||
| fi | ||
|
|
||
| case "$module_path" in | ||
| *xz) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're matching |
||
| unxz --keep "$module_path" || ferr "failed to unpack" | ||
| $sign_file "${hash_algo}" "${key}" "${x509}" "${module_path%%.xz}" || ferr "failed to sign" | ||
| rm "$module_path" | ||
| xz --check=crc32 --lzma2=dict=512KiB "${module_path%%.xz}" | ||
| ;; | ||
| *ko) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about other compression methods? xz is common, but modules may be compressed as gz as well (which was common some years ago). What about modules that have been previously signed? Is this idempotent? Also I don't like that it seemingly goes through all modules and touches files that may be part of distribution packaging. This can result in broken checksums. It uses Also, reviewing this, I found it confusing that the loop var is called |
||
| $sign_file "${hash_algo}" "${key}" "${x509}" "${module_path}" || ferr "failed to sign" | ||
| ;; | ||
| esac | ||
| echo "signed" | ||
| done | ||
| echo "$module_dir signed" | ||
| echo | ||
| done | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
... can skip this ...