-
Notifications
You must be signed in to change notification settings - Fork 128
Add scripts that sign the module for Secure Boot #563
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
Draft
flodavid
wants to merge
5
commits into
atar-axis:master
Choose a base branch
from
flodavid:signing-module-scripts
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ac9e1da
xpadneo, installer: Add scripts that sign the module for Secure Boot
flodavid 2d516d3
fixup! xpadneo, installer: Add scripts that sign the module for Secur…
flodavid 39be136
fixup! fixup! xpadneo, installer: Add scripts that sign the module fo…
flodavid 6ef9bf6
fixup! fixup! fixup! xpadneo, installer: Add scripts that sign the mo…
flodavid 8c68f33
fixup! xpadneo, installer: Add scripts that sign the module for Secur…
flodavid File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| #!/usr/bin/env bash | ||
| #set -x | ||
| set -e | ||
|
|
||
| # https://docs.fedoraproject.org/en-US/fedora/rawhide/system-administrators-guide/kernel-module-driver-configuration/Working_with_Kernel_Modules/#sect-signing-kernel-modules-for-secure-boot | ||
|
|
||
| source "$(dirname "$0")/../lib/mok.sh" | ||
|
|
||
| if [ "$EUID" -ne 0 ] | ||
| then error "Please run as root" | ||
| fi | ||
|
|
||
| DKMS_MOK_DIR="${DKMS_MOK_DIR:-/var/lib/shim-signed/mok}" | ||
|
|
||
| command -v openssl > /dev/null 2>&1 || warn "missing openssl, you will not be able to create a new MOK key" | ||
| command -v mokutil > /dev/null 2>&1 || warn "missing mokutil, you will not be able to sign the module" | ||
| [ -d /var/lib/shim-signed ] || error "missing shim-signed, unable to enrol MOK" | ||
|
|
||
| function install_xpadneo () { | ||
| info "start install_xpadneo" | ||
|
|
||
| # Uninstall previous version | ||
| rmmod hid-xpadneo > /dev/null 2>&1 || true | ||
|
|
||
| make modules | ||
| make modules_install | ||
|
|
||
| if [[ -z "$skip_signing" ]]; then | ||
| info "Now Manually signing" | ||
| signing_ko "$DKMS_MOK_DIR" | ||
| fi | ||
|
|
||
| depmod -a | ||
| modprobe hid-xpadneo | ||
| modinfo hid-xpadneo | ||
|
|
||
| if [ -d /sys/module/hid_xpadneo ] | ||
| then | ||
| info "hid_xpadneo loaded!" | ||
| # suggest to load uhid to support Bluetooth LE (for firmware 5.x) | ||
| if [ ! -d /sys/devices/virtual/misc/uhid ] | ||
| then info "you may need to run 'sudo modprobe uhid' to support firmware 5.x" | ||
| fi | ||
| else warn "failed to load hid_xpadneo" | ||
| fi | ||
|
|
||
| info "finished install_xpadneo" | ||
| } | ||
|
|
||
| if [ "$#" -ne "0" ] | ||
| then | ||
| signing_help | ||
| exit 0 | ||
| else | ||
| if mokutil --sb-state | grep -q "SecureBoot enabled"; then | ||
| if ! [ -d /sys/module/hid_xpadneo ] | ||
| then | ||
| info "Secure boot is enabled and you have to setup signing" | ||
| if check_keys "$DKMS_MOK_DIR" | ||
| then | ||
| cert_setup "$DKMS_MOK_DIR" | ||
| install_xpadneo | ||
| fi | ||
| else | ||
| info "hid_xpadneo is loaded" | ||
| fi | ||
| else | ||
| warn "no need to sign module!" | ||
| export skip_signing=1 | ||
| if ! [ -d /sys/module/hid_xpadneo ] | ||
| then install_xpadneo | ||
| fi | ||
| fi | ||
| fi |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,7 @@ MODULE_AUTHOR("Florian Dollinger <[email protected]>"); | |
| MODULE_AUTHOR("Kai Krakow <[email protected]>"); | ||
| MODULE_DESCRIPTION("Linux kernel driver for Xbox ONE S+ gamepads (BT), incl. FF"); | ||
| MODULE_VERSION(XPADNEO_VERSION); | ||
| MODULE_SOFTDEP("bluetooth pre: uhid"); | ||
|
|
||
| static u8 param_trigger_rumble_mode = 0; | ||
| module_param_named(trigger_rumble_mode, param_trigger_rumble_mode, byte, 0644); | ||
|
|
||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| #!/bin/bash | ||
| # set -x | ||
|
|
||
| if [ ${EUID} -ne 0 ]; then | ||
| echo >&2 "ERROR: You most probably need superuser privileges to use this script, please run me via sudo!" | ||
| exit 3 | ||
| fi | ||
|
|
||
| if [ -f "/usr/src/kernels/$(uname -r)/scripts" ] | ||
| then | ||
| kernel_src_dir="/usr/src/kernels/$(uname -r)" | ||
| else | ||
| kernel_src_dir="/usr/src/linux-headers-$(uname -r)" | ||
| fi | ||
|
|
||
| function info { echo -e "\e[32m[info] $*\e[39m"; } | ||
| function warn { echo -e "\e[33m[warn] $*\e[39m"; } | ||
| function error { echo -e "\e[31m[error] $*\e[39m"; exit 1; } | ||
|
|
||
| function signing_help () { | ||
| echo " | ||
| just run the script, reboot (you will have to type a pass you set) and run again! | ||
| " | ||
| } | ||
|
|
||
| function check_keys () { | ||
| if [ -f "$1/MOK.priv" ] | ||
| then | ||
| if mokutil --test-key "$1/MOK.der" | grep -q "already enrolled" | ||
| then | ||
| info "The Key is already trusted" | ||
| return 0 | ||
| else | ||
| warn "The key exist but is not trusted yet, re-enroling it because it does not hurt. You missing a reboot?" | ||
| fi | ||
| else | ||
| info "No Private key found. Generating one" | ||
| update-secureboot-policy --new-key | ||
| fi | ||
| update-secureboot-policy --enroll-key | ||
| return 1 | ||
| } | ||
|
|
||
| function cert_setup () { | ||
| if [ ! -f "$kernel_src_dir/certs/signing_key.pem" ] | ||
| then if [ ! -f "$1/MOK.pem" ] | ||
| then | ||
| info "Still no certificate associated to MOK found. Generating one" | ||
| generate_certificate "$1" | ||
| else | ||
| info "Existing signing certificate, installing it..." | ||
| install_certificate "$1" | ||
| fi | ||
| else info "Signing certificate already exists" | ||
| fi | ||
| info "finished cert_setup" | ||
| } | ||
|
|
||
| function generate_certificate () { | ||
| openssl x509 -inform der -in "$1/MOK.der" -out "$1/MOK.pem" | ||
|
|
||
| mkdir -p "$kernel_src_dir/certs/" | ||
| cp "$1/MOK.pem" "$kernel_src_dir/certs/signing_key.pem" | ||
| chmod 444 "$kernel_src_dir/certs/signing_key.pem"$ | ||
| info "finished generate_certificate" | ||
|
|
||
| install_certificate "$1" | ||
| } | ||
|
|
||
| function install_certificate () { | ||
| # openssl_509_pass="${1:-$(openssl rand -hex 6)}" | ||
| # # echo "$openssl_509_pass" > "$1/.openssl_pass" | ||
| # # chmod 600 "$1/.openssl_pass" | ||
| # echo "The password for the x509 cert is: $openssl_509_pass" | ||
| # export KBUILD_SIGN_PIN="$(cat "$1/.openssl_pass" 2> /dev/null || echo "" )" | ||
|
|
||
| cp "$1/MOK.pem" "$kernel_src_dir/certs/signing_key.pem" | ||
| chmod 444 "$kernel_src_dir/certs/signing_key.pem" | ||
|
|
||
| info "finished install_certificate" | ||
| } | ||
|
|
||
| function signing_ko () { | ||
| module_ko_file=$(modinfo hid-xpadneo | awk '/^filename:/ { print $2 }') | ||
| if [ -z "$module_ko_file" ] | ||
| then error "Can not locate the folder used for hid-xpadneo.ko to sign it. Find the module and try to set the var 'ko_folder'" | ||
| fi | ||
| ko_path=${module_ko_file:-ko_folder/hid-xpadneo.ko%.ko*} | ||
|
|
||
| sign_file_dir="${sign_file_dir:-$kernel_src_dir/scripts}" | ||
| if "${sign_file_dir}/sign-file" sha256 "$1/MOK.priv" "$1/MOK.der" "${ko_path}" | ||
| then info "${ko_path}/hid-xpadneo.ko" | ||
| fi | ||
|
|
||
| info "finished signing_ko" | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| #!/usr/bin/env bash | ||
| #set -x | ||
| set -e | ||
|
|
||
| # https://docs.fedoraproject.org/en-US/fedora/rawhide/system-administrators-guide/kernel-module-driver-configuration/Working_with_Kernel_Modules/#sect-signing-kernel-modules-for-secure-boot | ||
|
|
||
| source "$(dirname "$0")/lib/mok.sh" | ||
|
|
||
| dkms_mok_dir="${dkms_mok_dir:-/var/lib/shim-signed/mok}" | ||
|
|
||
| command -v openssl > /dev/null 2>&1 || warn "missing openssl, you will not be able to create a new MOK key" | ||
| command -v mokutil > /dev/null 2>&1 || warn "missing mokutil, you will not be able to sign the module" | ||
| [ -d /var/lib/shim-signed ] || error "missing shim-signed, unable to enrol MOK" | ||
|
|
||
| function install_xpadneo () { | ||
| info "start install_xpadneo" | ||
|
|
||
| # Uninstall previous version | ||
| source "$(dirname "$0")/uninstall.sh" | ||
|
|
||
| # Try to load uhid module if not found, to support firmware 5.x | ||
| if [ ! -d /sys/devices/virtual/misc/uhid ] | ||
| then modprobe uhid | ||
| fi | ||
| source "$(dirname "$0")/install.sh" | ||
|
|
||
| module_ko_file=$(modinfo hid-xpadneo | awk '/^filename:/ { print $2 }') | ||
| if [ -z "$module_ko_file" ] | ||
| then error "Module compilation or installation failed" | ||
| fi | ||
|
|
||
| depmod -a | ||
|
|
||
| if modprobe hid-xpadneo | ||
| then | ||
| modinfo hid-xpadneo | ||
| info "finished install_xpadneo" | ||
|
|
||
| if [ -d /sys/module/hid_xpadneo ] | ||
| then info "hid_xpadneo loaded!" | ||
| else warn "failed to load hid_xpadneo (check for errors by running 'sudo dmesg')" | ||
| fi | ||
| else warn "failed to load hid_xpadneo" | ||
| fi | ||
| } | ||
|
|
||
| if [ "$#" -ne "0" ] | ||
| then | ||
| signing_help | ||
| exit 0 | ||
| else | ||
| if mokutil --sb-state | grep -q "SecureBoot enabled" | ||
| then warn "no need to sign module!" | ||
| fi | ||
|
|
||
| if ! [ -d /sys/module/hid_xpadneo ] | ||
| then | ||
| info "Secure boot is enabled and you have to setup signing" | ||
| if check_keys "$dkms_mok_dir" | ||
| then install_xpadneo | ||
| fi | ||
| else info "hid_xpadneo is already loaded" | ||
| fi | ||
| fi |
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.
Uh oh!
There was an error while loading. Please reload this page.