如何从源代码构建垫片并注册密钥

如何从源代码构建垫片并注册密钥

如何从源代码构建垫片并注册密钥

我正在努力建立垫片从源头开始并将自己的密钥注册到 MOK 列表,但效果不佳。每当我添加密钥时,一切似乎都顺利进行,但当我检查已注册的密钥列表时,那里什么都没有。

采取的措施

依赖关系涵盖了整个帖子。

# Installing dependencies
sudo apt install git build-essential make gnu-efi libelf-dev efitools efibootmgr

获取垫片

# Getting shim
cd ~
mkdir git
cd git
git clone https://github.com/rhboot/shim.git

创建密钥

# Create key
sudo mkdir /testkeys
cd /testkeys
sudo openssl req -new -x509 -newkey rsa:2048 -subj "/CN=Test Local/" \
    -keyout test.key -out test.crt -days 3650 -nodes -sha256
# Convert to DER format
sudo openssl x509 -in test.crt -out test.cer -outform DER
# Change permissions
sudo chmod 400 test.key
sudo chmod 644 test.cer

建筑垫片

# Building shim
cd ~/git/shim
make VENDOR_CERT_FILE=/testkeys/test.cer LIBDIR=/usr/lib EFI_PATH=/usr/lib
sudo make EFIDIR=/boot/efi install-as-data

安装垫片

# Copying shim to EFI
sudo cp /usr/share/shim/15/x64/* /boot/efi/EFI/ubuntu/
# Registering shim (your drive and partition may be different)
efibootmgr -c -d /dev/nvme0n1 -p 1 -l \\EFI\\ubuntu\\shimx64.efi -L shim
# List boot entries
#efibootmgr
# Can be deleted with (id is just 0001, 0002, etc..)
#efibootmgr -Bb <id>

将钥匙添加到 MOK 列表

# Add key to MOK new list
mokutil --import /testkeys/test.cer
# Will be prompted for a password twice
# Now reboot
sudo reboot

在启动时,MokManager 出现,要求我注册密钥,是的,输入密码,一切似乎都很好,然后我按下重新启动并启动。

# List enrolled keys
mokutil --list-enrolled
#MokListRT is empty

如何???

我尝试过的事情

导入不同的密钥

我尝试添加一个与构建 shim 时使用的密钥不同的密钥。

# Create key
cd /testkeys
sudo openssl req -new -x509 -newkey rsa:2048 -subj "/CN=Random Local/" \
    -keyout random.key -out random.crt -days 3650 -nodes -sha256
# Convert to DER format
sudo openssl x509 -in random.crt -out random.cer -outform DER
sudo chmod 400 random.key
sudo chmod 644 random.cer

# Importing it
mokutil --import random.cer

# And reboot
sudo reboot

在启动时,MokManager 出现,要求我注册密钥,是的,输入密码,一切似乎都很好,然后我按下重新启动并启动。

# List enrolled keys
mokutil --list-enrolled
#MokListRT is empty

签名垫片

我尝试签名shimx64.efifbx64.efimmx64.efi使用构建 shim 时使用的密钥。

cd /testkeys
# Signing efi binaries
sudo sbsign --key test.key --cert test.crt --output /boot/efi/EFI/ubuntu/shimx64.efi /boot/efi/EFI/ubuntu/shimx64.efi
sudo sbsign --key test.key --cert test.crt --output /boot/efi/EFI/ubuntu/fbx64.efi /boot/efi/EFI/ubuntu/fbx64.efi
sudo sbsign --key test.key --cert test.crt --output /boot/efi/EFI/ubuntu/mmx64.efi /boot/efi/EFI/ubuntu/mmx64.efi

再次导入密钥

# Import key
mokutil --import random.cer
# And reboot
sudo reboot

同样的故事;在启动时,MokManager 出现,要求我注册密钥,是的,输入密码,一切似乎都很好,然后我按下重新启动并启动。

# List enrolled keys
mokutil --list-enrolled
#MokListRT is empty

我的环境

在 Dell XPS 13 上新安装了 Ubuntu 20.04.1 LTS 版本。我知道 Ubuntu 20.04.1 LTS 附带安装/配置的垫片。

任何帮助都将非常感谢,谢谢。

答案1

很可能您的 UEFI 未处于设置模式,如果您使用 KeyTool.efi 启动系统,这将显示在标题中。

我遇到过类似的问题,不得不删除我的 PK 才能使系统进入设置模式。

相关内容