fedora.md

news/2025/3/17 16:23:45/文章来源:https://www.cnblogs.com/nsfoxer/p/18777082

fedora TPM自动解密磁盘

目录
  • fedora TPM自动解密磁盘
    • Motivation
    • Background
      • A summary of what is measured into which PCRs according to the spec
      • Some examples on what is measured into which PCR
    • Security implications
    • Prerequisites
    • Configure clevis
    • Automatically decrypt additional partitions
    • Unbind, rebind and edit
    • Troubleshooting
    • Resources


备注:

这是一篇关于如何在fedora系统上启用TPM,来自动解密硬盘加密的文章。我在fedora 41系统上成功实现,但需在每次内核更新后重新执行sudo clevis luks regen -d /dev/nvme0n1... -s 1该指令。

文章来源地址:https://fedoramagazine.org/automatically-decrypt-your-disk-using-tpm2/


This article demonstrates how to configure clevis and systemd-cryptenroll using a Trusted Platform Module 2 chip to automatically decrypt your LUKS-encrypted partitions at boot.

If you just want to get automatic decryption going you may skip directly to the Prerequisites section.

Motivation

Disk encryption protects your data (private keys and critical documents) through direct access of your hardware. Think of selling your notebook / smartphone or it being stolen by an opportunistic evil actor. Any data, even if “deleted”, is recoverable and hence may fall into the hands of an unknown third party.

Disk encryption does not protect your data from access on the running system. For example, disk encryption does not protect your data from access by malware running as your user or in kernel space. It’s already decrypted at that point.

Entering the passphrase to decrypt the disk at boot can become quite tedious. On modern systems a secure hardware chip called “TPM” (Trusted Platform Module) can store a secret and automatically decrypt your disk. This is an alternative factor, not a second factor. Keep that in mind. Done right, this is an alternative with a level of security similar to a passphrase.

Background

A TPM2 chip is a little hardware module inside your device which basically provides APIs for either WRITE-only or READ-only information. This way you might write a secret onto it, but you can never read it out later (but the TPM may use it later internally). Or you write info at one point that you only read out later. The TPM2 provides something called PCRs (Platform Configuration Registers). These registers take SHA1 or SHA256 hashes and contain measurements used to assert integrity of, for example, the UEFI configuration.

Enable or disable Secure Boot in the system’s UEFI. Among other things, Secure Boot computes hashes of every component in the boot chain (UEFI and its configuration, bootloader, etc.) and chains them together such that a change in one of those components changes the computed and stored hashes in all following PCRs. This way you can build up trust about the environment you are in. Having a measure of the trustworthiness of your environment is useful, for example, when decrypting your disk. The UEFI Secure Boot specification defines PCRs 0 – 7. Everything beyond that is free for the OS and applications to use.

A summary of what is measured into which PCRs according to the spec

  • PCR 0: the EFI Firmware info like its version
  • PCR 1: additional config and info related to the EFI Firmware
  • PCR 2: EFI drives from hardware components (like RAID controller)
  • PCR 3: additional config and info to drivers stored in 2
  • PCR 4: pre-OS diagnostics and the EFI OS Loader
  • PCR 5: config of the EFI OS Loader and GPT table
  • PCR 6: is reserved for host platform manufacturer variables and is not used by EFI
  • PCR 7: stores secure boot policy configuration

Some examples on what is measured into which PCR

  • Changes to the initramfs measure into PCRs 9 and 10. So if you regenerate the initramfs using dracut -f you have to rebind. This will happen on every update to the kernel.
  • Changes to the Grub configuration, like adding kernel arguments, kernels, etc. measure into PCRs 8, 9 and 10.
  • Storage devices measure into PCRs 8 and 10. However, Hubs and YubiKeys do not seem to measure in any PCR.
  • Additional operating systems measure into PCR 1. This occurs, for example, when attaching a USB stick before boot with a Fedora Linux live image.
  • Booting into a live image changes PCRs 1, 4, 5, 8, 9 and 10.

A tool called clevis generates a new decryption secret for the LUKS encrypted disk, stores it in the TPM2 chip and configures the TPM2 to only return the secret if the PCR state matches the one at configuration time. Clevis will attempt to retrieve the secret and automatically decrypt the disk at boot time only if the state is as expected.

Security implications

As you establish an alternative unlock method using only the on-board hardware of your platform, you have to trust your platform manufacturer to do their job right. This is a delicate topic. There is trust in a secure hardware and firmware design. Then there is trust that the UEFI, bootloader, kernel, initramfs, etc. are all unmodified. Combined you expect a trustworthy environment where it is OK to automatically decrypt the disk.

That being said you have to trust (or better, verify) that the manufacturer did not mess anything up in the overall platform design for this to be considered a fairly safe decryption alternative. There are a range of cases where things did not work out as planned. For example, when security researches showed that BitLocker on a Lenovo notebook would use unencrypted SPI communication with the TPM2 leaking the LUKS passphrase in plain text without even altering the system, or that BitLocker used the native encryption features of SSD drives that you can by-pass through factory reset.

These examples are all about BitLocker but it should make it clear that if the overall design is broken, then the secret is accessible and this alternative method less secure than a passphrase only present in your head (and somewhere safe like a password manager). On the other hand, keep in mind that in most cases elaborate research and attacks to access a drive’s data are not worth the effort for an opportunistic bad actor. Additionally, not having to enter a passphrase on every boot should help adoption of this technology as it is transparent but adds additional hurdles to unwanted access.

Prerequisites

First check that:

  • Secure Boot is enabled and working
  • A TPM2 chip is available
  • The clevis package is installed

Clevis is where the magic happens. It’s a tool you use in the running OS to bind the TPM2 as an alternative decryption method and use it inside the initramfs to read the decryption secret from the TPM2.

Check that secure boot is enabled. The output of dmesg should look like this:

$ dmesg | grep Secure
[    0.000000] secureboot: Secure boot enabled
[    0.000000] Kernel is locked down from EFI Secure Boot mode; see man kernel_lockdown.7
[    0.005537] secureboot: Secure boot enabled
[    1.582598] integrity: Loaded X.509 cert 'Fedora Secure Boot CA: fde32599c2d61db1bf5807335d7b20e4cd963b42'
[   35.382910] Bluetooth: hci0: Secure boot is enabled

Check dmesg for the presence of a TPM2 chip:

$ dmesg | grep TPM
[    0.005598] ACPI: TPM2 0x000000005D757000 00004C (v04 DELL   Dell Inc 00000002      01000013)

Install the clevis dependencies and regenerate your initramfs using dracut.

sudo dnf install clevis clevis-luks clevis-dracut clevis-udisks2 clevis-systemd
sudo dracut -fv --regenerate-all
sudo systemctl reboot

The reboot is important to get the correct PCR measurements based on the new initramfs image used for the next step.

Configure clevis

To bind the LUKS-encrypted partition with the TPM2 chip. Point clevis to your (root) LUKS partition and specify the PCRs it should use.

Enter your current LUKS passphrase when asked. The process uses this to generate a new independent secret that will tie your LUKS partition to the TPM2 for use as an alternative decryption method. So if it does not work you will still have the option to enter your decryption passphrase directly.

sudo clevis luks bind -d /dev/nvme... tpm2 '{"pcr_ids":"1,4,5,7,9"}'

As mentioned previously, PCRs 1, 4 and 5 change when booting into another system such as a live disk. PCR 7 tracks the current UEFI Secure Boot policy and PCR 9 changes if the initramfs loaded via EFI changes.

Note: If you just want to protect the LUKS passphrase from live images but don’t care about more “elaborate” attacks such as altering the unsigned initramfs on the unencrypted boot partition, then you might omit PCR 9 and save yourself the trouble of rebinding on updates.

Automatically decrypt additional partitions

In case of secondary encrypted partitions use /etc/crypttab.

Use systemd-cryptenroll to register the disk for systemd to unlock:

sudo systemd-cryptenroll /dev/nvme0n1... --tpm2-device=auto --tpm2-pcrs=1,4,5,7,9

Then reflect that config in your /etc/crypttab by appending the options tpm2-device=auto,tpm2-pcrs=1,4,5,7,9.

Unbind, rebind and edit

List all current bindings of a device:

$ sudo clevis luks list -d /dev/nvme0n1... tpm2
1: tpm2 '{"hash":"sha256","key":"ecc","pcr_bank":"sha256","pcr_ids":"0,1,2,3,4,5,7,9"}'

Unbind a device:

sudo clevis luks unbind -d /dev/nvme0n1... -s 1 tpm2

The -s parameter specifies the slot of the alternative secret for this disk stored in the TPM. It should be 1 if you always unbind before binding again.

Regenerate binding, in case the PCRs have changed:

sudo clevis luks regen -d /dev/nvme0n1... -s 1 tpm2

Edit the configuration of a device:

sudo clevis luks edit -d /dev/nvme0n1... -s 1 -c '{"pcr_ids":"0,1,2,3,4,5,7,9"}'

Troubleshooting

Disk decryption passphrase prompt shows at boot, but goes away after a while:

Add a sleep command to the systemd-ask-password-plymouth.service file using systemctl edit to avoid requests to the TPM before its kernel module is loaded:

[Service]
ExecStartPre=/bin/sleep 10

Add the following to the config file /etc/dracut.conf.d/systemd-ask-password-plymouth.conf:

install_items+=" /etc/systemd/system/systemd-ask-password-plymouth.service.d/override.conf "

Then regenerate dracut via sudo dracut -fv ‐‐regenerate-all.

Reboot and then regenerate the binding:

sudo systemctl reboot
...
sudo clevis luks regen -d /dev/nvme0n1... -s 1

Resources

  • Automatic LUKS volume unlocking using a TPM2 chip
  • Automatically decrypt with TPM2 on Silverblue (Discussion)
  • Right way to use the tpm for full disk encryption (Security StackExchange)
  • How does the TPM perform integrity measurements on a system (Security StackExchange)
  • Configuring SecureBoot + TPM2
  • Switch PCR banks on TPM2 devices
  • tpm2-luks project on Github
  • Understanding TPM PCRs, PCR banks and their relations
  • From a stolen laptop to inside the company network
  • TPM library specification
  • TCG EFI Platform specification

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/900428.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

[ SpringMVC ] SpringMVC如何通过是否有@RestController注解来判断返回ModelAndView还是Json

引言之前在面试的遇到面试官问我SpringMVC的执行流程,我那时候回答的是SpringMVC的DispatcherServlet的dodispatch方法找到ControllerMethod之后将返回值通过convert成Json返回响应体,事后想了一下回答的其实并不正确,因为SpringMVC之前学习的时候有使用ModelAndView返回视图,我…

从HR+AI到AI+HR,企业人力资源AI进程已过半

一、人力资源管理智能化应势而上,核心价值受企业管理层肯定 过往各项研究表明,AI 已经被广泛应用于企业经营的各个环节中。根据易路于2023 年发布的《AI 在企业人力资源中的应用白皮书1.0》(以下简称《白皮书1.0》),我们可以明确感受到:AI 已不同程度应用于招聘管理、员工…

multi-object tracking in the dark

创新点:构建LMOT数据集:开发了一种双摄像头系统,同步采集明暗视频帧,形成高度对齐的低光视频对,并提供高质量的多目标跟踪标注。该数据集包含大量城市户外场景视频,涵盖多种动态物体,为模型训练和评估提供了丰富的数据支持。 提出LTrack方法:引入自适应低通下采样模块(…

LGP11831_1 [UPTS 2025] 追忆 学习笔记

LGP11831_1 [UPTS 2025] 追忆 学习笔记 Luogu Link 前言 又幻想了……唉! 幻想自己场切这道题,最后标准分上升至 \(\text{598pts}\),翻掉了 \(\text{yyz}\),不至于一点脸不要。 本题解基本借鉴这篇题解。 题意简述 给定一个 \(n\) 点 \(m\) 边的简单有向图 \(G\),有 \(m\)…

sql 在两个数据表中,A表存在字段以逗号分隔存储B表的多id对象,进行关联查询

A 表:B表:关联查询 需求为,查询出A表的数据列表,需要将A表关联B表的数据id,概要通过B表的 name 进行输出显示 SELECT A.id,A.name,A.creator,A.created_at,GROUP_CONCAT(B.name SEPARATOR , ) AS B_names -- 将 c_name 合并为逗号分隔的字符串 FROM xf_service_type A LE…

算力市场何以拥有巨大潜力

算力市场未来确实具有巨大的潜力,这一判断基于多个方面的因素: 一、算力成为经济增长的主要驱动力 随着全球数字化转型的迅猛推进,算力已成为推动经济增长的关键引擎。各国纷纷加大在算力基础设施方面的投入,以期为经济发展注入新的活力。例如,欧盟委员会批准了一项名为“…

算法备案拟公示内容编写指南

除了自评估报告,算法备案复审中的拟公示内容也是难度颇大的一份材料,导致很多开发者的算法备案申请被驳回。今天我就提供一份简易模板供大家学习参考(请结合实际情况撰写,不要照抄,不要买模板,否则会判定真实性存疑或高度雷同,影响备案)。(各类文件套模板都会判定该真…

CH585 RF_Basic例程讲解含单向和双向发送

CH585_RF基础通讯例程见下图路径:1、RF初始化参数配置/******************************************************************************** @fn RFRole_Init** @brief RF应用层初始化** @param None.** @return None.*/ void RFRole_Init(void) {rfTaskID = TMOS_…

uniapp整合SQLite(Android)

一、勾选SQLite数据库选项 (1)HBuilder工具打开项目 (2)项目/manifest.json =>App模块配置 => 勾选SQLite(数据库)二、封装sqlite.ts 在项目根目录下创建sqlite/sqlite.ts// 数据库名称 const dbName = scan/*** 数据库地址* @type {String} 推荐以下划线为开头 _d…

No.68 Vue---vue3新特性

一、vue3新特性 1.1 六大亮点二、组合API(setup)2.1 ref或者reactive 1、创建项目 vue create vue-demo5 2、进入文件,启动服务。 3、 2.2 methods中定义的方法写在setup() 2.3setup()中使用props和context 在2.x中,组件的方法中可以通过this获取到当前组件的实例,并执…

2025年2月国产数据库大事记-墨天轮

​本文为墨天轮社区整理的2025年2月国产数据库大事件和重要产品发布消息,一起看看2月有哪些大事发生~本文为墨天轮社区整理的2025年2月国产数据库大事件和重要产品发布消息。 目录2025年2月国产数据库大事记 TOP10 2025年2月国产数据库大事记(时间线) 产品/版本发布 兼容认证…