硬盘加密#

(Nitrokey Pro 2 - Linux)

VeraCrypt (以前的TrueCrypt)#

`VeraCrypt <https://www.veracrypt.fr/en/Home.html>`__是一款适用于Windows、macOS和GNU+Linux的免费开源磁盘加密软件。它是TrueCrypt的继承者,因此被推荐使用,尽管以下说明也应适用于TrueCrypt。

按照这些步骤来使用`Nitrokey Storage 2 <https://shop.nitrokey.com/shop/product/nitrokey-storage-2-56>`__或`Nitrokey Pro 2 <https://shop.nitrokey.com/shop/product/nk-pro-2-nitrokey-pro-2-3>`__。

  1. 安装最新版本的`OpenSC <https://github.com/OpenSC/OpenSC/wiki>`__,或者下载`PKCS#11库 <https://smartcard-auth.de/download-en.html>`__。

  2. 在VeraCrypt的Settings>Preferences>Security Token(位置取决于系统,例如:/usr/lib/opensc)中选择库。

  3. 通过Tools>Keyfile Generator生成一个64字节的密钥文件。

  4. 现在你应该能够通过Tools>Manage Security Token Keyfiles导入生成的密钥文件。你应该选择第一个插槽([0] User PIN)。然后,该密钥文件将作为 “私人数据对象1”(PrivDO1)存储在Nitrokey上。

  5. 在这之后,你应该安全地擦除你电脑上的原始密钥文件!

  6. 现在你可以用Nitrokey使用VeraCrypt:创建一个容器,选择设备上的密钥文件作为密码的替代。

警告

安全方面的考虑

请注意,VeraCrypt并没有利用Nitrokey(以及一般的智能卡)提供的全部安全性。相反,它在Nitrokey上存储了一个密钥文件,理论上,在用户输入PIN后,该文件可能被计算机病毒窃取。

注意:`Aloaha Crypt <https://www.aloaha.com/aloaha-crypt-disk/>`__是基于TrueCrypt/VeraCrypt但没有描述的安全限制。

在GNU+Linux上用LUKS/dm-crypt进行硬盘加密#

这里有`出色的说明<https://blog.kumina.nl/2010/07/two-factor-luks-using-ubuntu/>`__如何在GNU+Linux下使用Nitrokey用LUKS/dm-crypt来加密你的硬盘。其他说明

Purism创建了一个`简单的脚本<https://docs.puri.sm/PureBoot/LibremKeyLUKS.html>`__来添加Nitrokey/LibremKey作为解锁LUKS分区的方法(还没有经过Nitrokey测试)。

`这个项目<https://github.com/artosan/nitroluks/>`__旨在通过Nitrokey Pro或基于Password Safe的Storage(尚未被Nitrokey测试)来简化LUKS的使用。关于如何在Gentoo上使用它的描述可以在`这里<https://amedeos.github.io/gentoo/nitrokey/2019/01/21/gentoo-nitrokey-luks.html>`__找到。

对于Arch Linux,见`initramfs-scencrypt <https://github.com/fuhry/initramfs-scencrypt>`__。

在GNU+Linux上用EncFS进行存储加密#

小技巧

先决条件

请确保你`安装了设备驱动程序,改变了默认的PIN码,并使用GnuPG <https://www.nitrokey.com/start>`__生成或导入密钥。

EncFS <https://github.com/vgough/encfs>`__是一个易于使用的加密文件系统,它是基于`FUSE。你可以按照这些步骤,用很长的密码和Nitrokey Pro 2来使用它。

初始化#

  1. 创建一个具有随机数据的密钥文件。

$ dd bs=64 count=1 if=/dev/urandom of=keyfile
  1. 加密密钥文件,并使用你的Nitrokey的用户ID。

$ gpg --encrypt keyfile
  1. 移除明文的密钥文件。

$ rm keyfile # you may want to use 'wipe' or 'shred' to securely delete the keyfile
  1. 创建挂载点。

$ mkdir ~/.cryptdir ~/cryptdir
  1. 创建实际的加密文件夹

$ gpg -d keyfile.gpg | encfs -S ~/.cryptdir ~/cryptdir
# There may appears an error message about missing permission of fusermount
# This message can be ignored
  1. 解除对新文件系统的挂载。

$ fusermount -u ~/cryptdir

使用方法#

  1. 挂载加密的文件系统,并输入Nitrokey的PIN码。

$ gpg -d keyfile.gpg | encfs -S ~/.cryptdir ~/cryptdir
  1. 使用完毕后,解除对文件系统的挂载。

$ fusermount -u ~/cryptdir

在GNU+Linux上使用ECryptFS进行存储加密#

`eCryptfs <https://www.ecryptfs.org/>`__是GNU+Linux的一个基于文件的透明加密文件系统,可以通过一个PKCS#11驱动与Nitrokey一起使用。

见`这些<http://tkxuyen.com/blog/?p=293>`__说明。

  1. 将证书和密钥导入到Nitrokey。

# Warning: This will delete existing keys on your Nitrokey!
$ pkcs15-init --delete-objects privkey,pubkey --id 3 --store-private-key user@example.com.p12 --format pkcs12 --auth-id 3 --verify-pin
  1. 创建文件~/.ecryptfsrc.pkcs11。

$ editor ~/.ecryptfsrc.pkcs11
  1. 输入这个内容。

$ pkcs11-log-level=5 pkcs11-provider1,name=name,library=/usr/lib/opensc-pkcs11.so,cert-private=true
$ openvpn --show-pkcs11-ids path to opensc-pkcs11 module
Certificate
    DN: /description=Iv4IQpLO02Mnix9i/CN=user@example.com/emailAddress=user@example.com
    Serial: 066E04
    Serialized id: ZeitControl/PKCS\x2315\x20emulated/000500000c7f/OpenPGP\x20card\x20\x28User\x20PIN\x29/03
  1. 复制序列化的ID,供以后使用。

$ ecryptfs-manager
# This will show list option. Choose option "Add public key to keyring"
# Choose pkcs11-helper
# Enter the serialized ID of step 3 to PKCS#11 ID.

或者,尝试`ESOSI <https://sourceforge.net/projects/esosi/>`__或使用OpenSC和OpenVPN遵循这些步骤。

指南的来源:https://www.nitrokey.com/documentation/applications#a:hard-disk-encryption