EFI secure boot

一、EFI
   secure boot 是EFI BIOS中的一个子标签,同时EFI BIOS提供证书管理功能,系统可以同时拥有多个证书供用户选择,EFI只能执行经过正确签名的固件
   EFI 证书种类比较多:PK,KEK,db,dbx 和 MOK
   *一般PC的EFI(例如我的dell)都植入了Microsoft Windows UEFI Driver Publisher's cer
   *据了解,但没有找到确切依据,这些证书存在flash芯片里头了,得看EFI的代码了
   *被EFI执行的固件支持多个签名(不是多层),只要有一个签名正确就能执行
   *EFI固件需要放在esp分区当中,用于被efi-bios启动,esp分区是efi架构的特性之一

    替换原始efi key步骤:
    1、按照下载的脚本依次生成PK KEK DB
    2、使用efi自带的界面工具依次导入新的证书
    3、使用sbsign or pesign 等工具对EFI固件(如shim)进行签名
    4、在efi中新增一个启动项指向签名固件
    5、验证,原来的启动项不能执行了,但是新增加的启动项可以正常启动

二、shim
   centos等开源linux系统中 secure boot 特色组件,EFI会校验shim,shim用于校验grub2和kernel,这么做一是为了避开开源软件相关协议,不公开私钥,则不能对GPL组件进行签名,二是由于grub等bootloader有点大,不适合作为安全控制模块。
   *非secureboot模式下是没有这个组件的,efi直接启动grub2
   *shim组件类似手机sec.img,提供Mokmanager、mokutil工具用于证书管理,这些证书用于校验grub2和kernel,shim需要使用efi中的证书对应的私钥进行签名,而grub2和kernel的 签名则可以自己随意定制,然后将证书使用shim相关工具导入NVRAM即可
   *在centos中跳过shim,直接让efi执行grub2也是没有问题的,grub2需要使用efi中的证书对应的私钥进行签名
   *shim功能很灵活,不仅支持key的校验,还支持hash的校验,更有对tpm的支持

三、grub2 kernel
   shim模式下grub2中用户选择kernel后,grub2回调shim组件校验kernel,grub2、kernel使用相同的私钥进行签名
   无shim模式下grub2 与kernel 都需要使用efi证书对应的私钥进行签名,由efi进行grub2与kernel的校验

四、luks
   centos提供分区加密机制,使用device mapper内核模块作为技术支撑

五、可信问题
   *initrd以及initrd加载的模块都是不可信的,这部分都没有经过签名
   *systemtap、kexec、kdump 等都是没有签名的

   *第三方KO模块没有签名,不知内核是否有相应机制控制(模块需要使用mok签名,shim会验证)


   附:efi key生成脚本

#!/bin/bash
# Copyright (c) 2015 by Roderick W. Smith
# Licensed under the terms of the GPL v3

echo -n "Enter a Common Name to embed in the keys: "
read NAME

openssl req -new -x509 -newkey rsa:2048 -subj "/CN=$NAME PK/" -keyout PK.key \
        -out PK.crt -days 3650 -nodes -sha256
openssl req -new -x509 -newkey rsa:2048 -subj "/CN=$NAME KEK/" -keyout KEK.key \
        -out KEK.crt -days 3650 -nodes -sha256
openssl req -new -x509 -newkey rsa:2048 -subj "/CN=$NAME DB/" -keyout DB.key \
        -out DB.crt -days 3650 -nodes -sha256
openssl x509 -in PK.crt -out PK.cer -outform DER
openssl x509 -in KEK.crt -out KEK.cer -outform DER
openssl x509 -in DB.crt -out DB.cer -outform DER

GUID=`python -c 'import uuid; print(str(uuid.uuid1()))'`
echo $GUID > myGUID.txt

cert-to-efi-sig-list -g $GUID PK.crt PK.esl
cert-to-efi-sig-list -g $GUID KEK.crt KEK.esl
cert-to-efi-sig-list -g $GUID DB.crt DB.esl
rm -f noPK.esl
touch noPK.esl

sign-efi-sig-list -t "$(date --date='1 second' +'%Y-%m-%d %H:%M:%S')" \
                  -k PK.key -c PK.crt PK PK.esl PK.auth
sign-efi-sig-list -t "$(date --date='1 second' +'%Y-%m-%d %H:%M:%S')" \
                  -k PK.key -c PK.crt PK noPK.esl noPK.auth
sign-efi-sig-list -t "$(date --date='1 second' +'%Y-%m-%d %H:%M:%S')" \
                  -k PK.key -c PK.crt KEK KEK.esl KEK.auth
sign-efi-sig-list -t "$(date --date='1 second' +'%Y-%m-%d %H:%M:%S')" \
                  -k KEK.key -c KEK.crt db DB.esl DB.auth

chmod 0600 *.key

echo ""
echo ""
echo "For use with KeyTool, copy the *.auth and *.esl files to a FAT USB"
echo "flash drive or to your EFI System Partition (ESP)."
echo "For use with most UEFIs' built-in key managers, copy the *.cer files."
echo ""


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值