Trusted Platform Module

提供: ArchWiki
2022年2月10日 (木) 14:59時点におけるKusanaginoturugi (トーク | 投稿記録)による版 (はをがに変更)
ナビゲーションに移動 検索に移動

Trusted Platform Module (TPM) はセキュアな暗号プロセッサの国際規格です。暗号鍵をデバイスに統合することによりハードウェアを保護する専用のマイクロプロセッサとして設計されています。

実際に TPM を Secure Boot や Key Storage など様々なセキュリティアプリケーションで使うことができます。

当然ながら TPM が使えるのは TPM ハードウェアに対応しているデバイスだけです。あなたのハードウェアが TPM をサポートしているのに認識されない場合、BIOS の設定で TPM を有効にする必要があります。

バージョン

TPM の仕様には、大きく分けて 2 種類あります。1.2 と 2.0 があり、それぞれ異なるソフトウェアスタックを使用しています。

  • TPM 1.2 は IBM の "TrouSerS" TSS (TCG ソフトウェアスタック) を使用しており、trousersAUR (tcsd) と tpm-toolsAUR (ユーザースペース) としてパッケージ化されている。すべてのソフトウェアは、tcsd デーモンを介して TPM にアクセスする。
  • TPM 2.0 では、/dev/tpm0 を介した直接アクセス (一度に 1 クライアント)、tpm2-abrmd リソースマネージャデーモンを介したマネージドアクセス、または /dev/tpmrm0 を介したカーネルマネージドアクセスが可能です。ユーザースペースツールには Intel の tpm2-tools と IBM の ibm-tssAUR の2種類があります。

TPM 2.0 は UEFI ブートを必要とします。BIOS やレガシーブートシステムは TPM 1.2 しか使えません。

TPM チップの中には、ファームウェアのアップグレードによって 1.2 と 2.0 を切り替えられるものがあります(回数に限りがあります)。

Using TPM 1.2

ドライバー

TPM ドライバーは新しいカーネルならネイティブで含まれていますが、ロードする必要があります:

# modprobe tpm

さらに、使用しているチップセットにあわせて、以下のモジュールのどれかをロードしてください:

# modprobe tpm_{atmel,bios,infineon,nsc,tis,crb}

使用方法

TPM は tcsd によって管理します。Trusted Computing リソースを管理するユーザー空間のデーモンで、(TSS の仕様によれば) TPM デバイスドライバーの唯一の表玄関です。tcsd は AUR パッケージの trousersAUR に含まれています。IBM によって開発・リリースされており、/etc/tcsd.conf で設定することが可能です。

tcsd を起動して出力を監視するには、次を実行:

# tcsd -f

もしくは tcsd.service を起動・有効化してください。

tcsd を実行したら、tpm-toolsAUR もインストールすると良いでしょう。TPM を管理するためのコマンドラインツールが多数入っています。

他の便利なツール:

  • tpmmanager — tpm-tools の Qt フロントエンド。
https://sourceforge.net/projects/tpmmanager || tpmmanagerAUR
  • openssl_tpm_engine — TSS API と対話する OpenSSL エンジン。
https://sourceforge.net/projects/trousers || openssl_tpm_engineAUR[リンク切れ: アーカイブ: aur-mirror]
  • tpm_keyring2 — TPM ベースの eCryptfs 鍵を管理するキーマネージャ。
https://sourceforge.net/projects/trousers || tpm_keyring2AUR[リンク切れ: アーカイブ: aur-mirror]
  • opencryptoki — Linux の PKCS#11 実装。IBM の暗号ハードウェアを使用するためのドライバーやライブラリ、テスト用のソフトウェアトークンが含まれています。
https://sourceforge.net/projects/opencryptoki || opencryptokiAUR

基本

まずは基本的なバージョン情報を確認してください:

$ tpm_version

そしてセルフテストを実行:

$ tpm_selftest -l info
 TPM Test Results: 00000000 ...
 tpm_selftest succeeded

SSH 鍵のセキュア化

TPM を使って鍵を保護する方法は複数存在しますが、以下では simple-tpm-pk11-gitAUR を使用する簡単な方法を説明します。

まず、新しいディレクトリを作成して鍵を生成してください:

$ mkdir ~/.simple-tpm-pk11
$ stpm-keygen -o ~/.simple-tpm-pk11/my.key

鍵を設定:

~/.simple-tpm-pk11/config
key my.key

SSH を設定して適切な PKCS11 プロバイダを使用する:

~/.ssh/config
Host *
    PKCS11Provider /usr/lib/libsimple-tpm-pk11.so

これで PKCS11 プロバイダで鍵を生成することができます:

$ ssh-keygen -D /usr/lib/libsimple-tpm-pk11.so
ノート: 上記の方法では複数の鍵を生成・使用することはできません。

Using TPM 2.0

この記事またはセクションは加筆を必要としています。
理由: This section is a stub. You can help by expanding it with information on how to set up and use a TPM 2.0 device. (議論: トーク:Trusted Platform Module#)

Many informative resources to learn how to configure and make use of TPM 2.0 services in daily applications are available from the tpm2-software community.

Checking support

A TPM 2.0 chip has been a requirement for computers certified to run Windows 10 since 2016-07-28.[1] Linux has support for TPM 2.0 since version 3.20[2] and should not require any other steps to be enabled on a default Arch install.

Two ways to verify whether TPM 2.0 is setup without specific software:

  • checking the logs, e.g., by running journalctl -k --grep=tpm as root
  • read the value of /sys/class/tpm/tpm0/device/description[3] or /sys/class/tpm/tpm0/tpm_version_major

Data-at-rest encryption with LUKS

There are two methods for unlocking a LUKS volume using a TPM. An older method using clevis, and a newer method using systemd-cryptenroll. The newer method will be detailed first.

Using either method, an encrypted volume or volumes may be unlocked using keys stored in a TPM, either automatically at boot or manually at a later time. Using a TPM for this purpose ensures that your drives will not unlock unless certain conditions are met, such as your firmware not having been modified and Secure Boot not having been disabled (see #Accessing PCR registers).

警告: If you use this method on your root volume, this means that, as long as the previously mentioned certain conditions are met, your computer will unlock automatically at boot without needing to enter an encryption password.
  • This means that access to data is not protected in case the hardware gets stolen.
  • Be aware that this method makes you more vulnerable to cold boot attacks, because even if your computer has been powered off for a long time (ensuring the memory is completely cleared), an attacker could simply turn it on and wait for the TPM to load the key automatically. This may be a concern for high-value targets.

systemd-cryptenroll

Since version 248, systemd has had native support for enrolling LUKS keys in TPMs. This functionality is managed through the systemd-cryptenroll command. This method requires the following:

To begin, run the following command to list your installed TPMs:

$ systemd-cryptenroll --tpm2-device=list

A key may be enrolled in both the TPM and the LUKS volume using only one command. The following example binds the key to PCRs 0 and 7 (the system firmware and Secure Boot state):

# systemd-cryptenroll --tpm2-device=/path/to/tpm2_device --tpm2-pcrs=0,7 /dev/sdX

where /dev/sdX is the full path to the encrypted LUKS volume and /path/to/tpm2_device is the full path to the TPM as given in the output of the first command.

ヒント: If your computer has only one TPM installed, which is usually the case, you may instead specify --tpm2-device=auto to automatically select the only available TPM.

To test that the key works, run the following command while the LUKS volume is closed:

# /usr/lib/systemd/systemd-cryptsetup attach mapping_name /dev/sdX - tpm2-device=/path/to/tpm2_device

where mapping_name is your chosen name for the volume once opened. If the volume successfully unlocks, you are ready to add the required information to the crypttab so that systemd can automatically unlock the device at boot.

/etc/crypttab
# Example crypttab file. Fields are: name, underlying device, passphrase, cryptsetup options.

# Unlock /dev/sdX using the only available TPM, naming it myvolume
 myvolume	/dev/sdX	-	tpm2-device=auto
ノート: While you may specify the UUID of your LUKS volume in place of the pathname /etc/crypttab, the systemd-cryptenroll command itself currently only supports pathnames.

If the volume you wish to unlock contains your root filesystem, you must take the following additional steps:

  • Ensure you are using systemd and sd-encrypt in the HOOKS array of /etc/mkinitcpio.conf
  • Configure your initramfs to unlock the root volume with one of the following methods:
    • Specifying the root volume using the configuration outlined above in /etc/crypttab.initramfs (see tip at the top of Using sd-encrypt hook)
    • Setting rd.luks.options=XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX=tpm2-device=auto in addition to rd.luks.uuid or rd.luks.name in the kernel command line

To remove a key enrolled using this method, run:

# systemd-cryptenroll /dev/sdX --wipe-slot=slot_number

where slot_number is the numeric LUKS slot number in which your TPM key is stored.

Alternatively, run:

# systemd-cryptenroll /dev/sdX --wipe-slot=tpm2

to remove all TPM-associated keys from your LUKS volume.

See systemd-cryptenroll(1) and crypttab(5) for more information and examples.

Clevis

clevis allows binding a LUKS volume to a system by creating a key and encrypting it using the TPM, and sealing the key using PCR values which represent the system state at the time of the Clevis pin creation.

警告: Set a strong backup password in case the TPM unsealing fails, using:
# cryptsetup luksAddKey /dev/sdX

To bind a LUKS volume to the TPM, use:

# clevis luks bind -d /dev/sdX tpm2 '{}'

where '{}' contains the configuration. Even with no parameters, the drive cannot be decrypted from another computer (unless the attacker knows the backup password).

To seal the LUKS key against, for example, the UEFI settings and the Secure Boot policy, use:

'{"pcr_ids":"1,7"}'

If the UEFI or Secure Boot settings are modified, the TPM will compute different PCR values and decryption will fail. This gives protection against evil maid attacks.

For a list of parameters, see clevis-encrypt-tpm2(1) § CONFIG.

For a full explanation of the meanings of PCRs, see the TCG specification (§ 2.3.4).

To generate a new Clevis pin after changes in system configuration that result in different PCR values, for example updating the UEFI when PCR 0 is used, run

# cryptsetup luksDump /dev/sdX
Tokens:
  token slot: clevis
        Keyslot:  keyslot

to find the slot used for the Clevis pin, then

# clevis luks regen -d /dev/sdX -s keyslot

To remove the Clevis binding, run:

# clevis luks unbind -d /dev/sdX -s keyslot 
警告: Double check you have chosen the right slot, or you might lose access to your volume.

You can unlock a TPM-bound volume using:

# clevis luks unlock -d /dev/sdX

For automated decryption of volumes in /etc/crypttab, enable clevis-luks-askpass.path.

For automated decryption of the root volume, use Booster, Dracut or mkinitcpio-clevis-hook. Booster automatically decrypts LUKS volumes bound using Clevis out of the box. Dracut and mkinitcpio-clevis-hook needs the following extra packages:

followed by an initramfs regeneration:

Dracut:

# dracut -f

mkinitcpio-clevis-hook:

# mkinitcpio -P

Other good examples of TPM 2.0 usage

トラブルシューティング

tcsd.service が起動しない

パーミッションの問題が原因で tcsd.service サービスが起動できないのかもしれません [4]。以下のコマンドで解決できる可能性があります:

# chown tss:tss /dev/tpm*
# chown -R tss:tss /var/lib/tpm

参照