Advertisement
1henno1

Sign VirtualBox Modules

Nov 13th, 2023 (edited)
321
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.07 KB | Source Code | 0 0
  1. #!/bin/bash
  2. # modified from https://gist.github.com/reillysiemens/ac6bea1e6c7684d62f544bd79b2182a4
  3.  
  4. readonly hash_algo='sha256'
  5. readonly key='/var/lib/shim-signed/mok/MOK.priv'
  6. readonly x509='/var/lib/shim-signed/mok/MOK.der'
  7.  
  8. readonly name="$(basename $0)"
  9. readonly esc='\033'
  10. readonly reset="${esc}[0m"
  11.  
  12. red() { local string="${1}"; echo -e "${esc}[0;31m${string}${reset}"; }
  13. green() { local string="${1}"; echo -e "${esc}[0;32m${string}${reset}"; }
  14. blue() { local string="${1}"; echo -e "${esc}[0;34m${string}${reset}"; }
  15. log() { local string="${1}"; echo -e "[$(blue $name)] ${string}"; }
  16.  
  17. [ -z "${KBUILD_SIGN_PIN}" ] && read -sp "Passphrase for ${key}: " KBUILD_SIGN_PIN && echo
  18. export KBUILD_SIGN_PIN
  19.  
  20. for module in $(dirname $(modinfo -n vboxdrv))/*.ko; do
  21.   log "Signing $(green ${module})..."
  22.   /usr/src/kernels/$(uname -r)/scripts/sign-file "${hash_algo}" "${key}" "${x509}" "${module}"
  23.   modprobe -v "$(basename ${module} .ko)" \
  24.           && log "Loaded $(green $(basename ${module} .ko))" \
  25.           || log "Unable to load $(red $(basename ${module} .ko))"
  26. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement