Dm-crypt/ko

From Gentoo Wiki
Jump to:navigation Jump to:search
This page is a translated version of the page Dm-crypt and the translation is 46% complete.
Outdated translations are marked like this.
Resources

dm-crypt는 리눅스 커널 암호화 API 프레임워크와 장치 매퍼 하위 시스템을 활용한 디스크 암호화 시스템입니다. 관리자는 dm-crypt로 전체 디스크, 논리 볼륨 파티션, 단일 파일을 암호화할 수 있습니다.

dm-crypt 하위 시스템은 암호화 데이터 접근에 다중키를 허용하며, 키를 다루기도 하는(키 변경, 암호 추가 등)리눅스 통합 키 설정(LUKS) 구조를 지원합니다. dm-crypt에서 비 LUKS 설정도 지원하지만, 이 글에서는 유연성, 관리성, 커뮤니티 규모의 광범위한 지원을 위한 LUKS 기능에 중점을 두었습니다.

설정

dm-crypt를 활용할 수 있기 전 준비해야 할 두가지 사항이 있습니다:

  1. 커널 설정
  2. sys-fs/cryptsetup 꾸러미 설치

커널 설정

dm-crypt를 사용하려면 설정해야 할 몇가지 사항이 있습니다.

먼저 device mapper 기반 구조 지원과 crypt target을 커널에 포함해야합니다:

커널 device mapper와 crypt target 활성화
[*] Enable loadable module support
    Device Drivers --->
        [*] Multiple devices driver support (RAID and LVM) --->
            <*> Device mapper support
            <*> Crypt target support

다음, 관리자가 암호화 기능을 사용하려면 리눅스 커널에서 암호화 API 모음을 지원해야 합니다. "Cryptographic API" 섹션에서 찾아볼 수 있습니다:

커널 암호화 API 기능 활성화
[*] Cryptographic API --->
    <*> SHA224 and SHA256 digest algorithm
    <*> XTS support
    <*> AES cipher algorithms
    <*> AES cipher algorithms (x86_64)

마찬가지로 루트 파일 시스템을 암호화 했다면, 루트 파일 시스템을 마운트하기 전 루트 파일 시스템을 해독할 램 파일 시스템을 만들어야 합니다. 따라서, initramfs 지원도 필요합니다:

커널 initramfs 지원 활성화
General setup  --->
    [*] Initial RAM filesystem and RAM disk (initramfs/initrd) support

If using the tcrypt encryption option (TrueCrypt/tcplay/VeraCrypt compatibility mode), then the following items will also need to be added to the kernel. Otherwise, cryptsetup will return the following errors: "device-mapper: reload ioctl failed: Invalid argument" and "Kernel doesn't support TCRYPT compatible mapping".

커널 Enabling tcrypt (TrueCrypt/tcplay/VeraCrypt compatibility mode) support
Device Drivers --->
    [*] Block Devices ---> 
        <*> Loopback device support 
File systems ---> 
     <*> FUSE (Filesystem in Userspace) support 
[*] Cryptographic API ---> 
     <*> RIPEMD-160 digest algorithm 
     <*> SHA384 and SHA512 digest algorithms 
     <*> Whirlpool digest algorithms 
     <*> LRW support 
     <*> Serpent cipher algorithm 
     <*> Twofish cipher algorithm

Cryptsetup 설치

sys-fs/cryptsetup 꾸러미는 암호화 저장소를 열고 닫으며 이 저장소와 관련있는 암호문 또는 키를 관리하는 cryptsetup 명령을 제공합니다.

root #emerge --ask sys-fs/cryptsetup

암호화 저장소

Benchmark

cryptsetup provides a benchmarking tool which will help to decide which setup to choose. The output depends on kernel settings as well as USE flags and destination (HDD, SSD etc.).

root #cryptsetup benchmark
# Tests are approximate using memory only (no storage IO).
PBKDF2-sha1      3622024 iterations per second for 256-bit key
PBKDF2-sha256    7410431 iterations per second for 256-bit key
PBKDF2-sha512    3216490 iterations per second for 256-bit key
PBKDF2-ripemd160 1157368 iterations per second for 256-bit key
PBKDF2-whirlpool 1069975 iterations per second for 256-bit key
argon2i      14 iterations, 1048576 memory, 4 parallel threads (CPUs) for 256-bit key (requested 2000 ms time)
argon2id     15 iterations, 1048576 memory, 4 parallel threads (CPUs) for 256-bit key (requested 2000 ms time)
#     Algorithm |       Key |      Encryption |      Decryption
        aes-cbc        128b      1520.5 MiB/s      4400.1 MiB/s
    serpent-cbc        128b       159.6 MiB/s      1061.9 MiB/s
    twofish-cbc        128b       310.8 MiB/s       662.1 MiB/s
        aes-cbc        256b      1175.8 MiB/s      4025.0 MiB/s
    serpent-cbc        256b       160.0 MiB/s      1054.8 MiB/s
    twofish-cbc        256b       312.6 MiB/s       655.5 MiB/s
        aes-xts        256b      4081.0 MiB/s      4073.5 MiB/s
    serpent-xts        256b       953.7 MiB/s       946.3 MiB/s
    twofish-xts        256b       597.5 MiB/s       616.8 MiB/s
        aes-xts        512b      3733.8 MiB/s      3743.3 MiB/s
    serpent-xts        512b       970.9 MiB/s       964.5 MiB/s
    twofish-xts        512b       598.1 MiB/s       611.3 MiB/s

키 파일 또는 암호문

암호화 저장소를 시작하려면, 관리자가 암호화 키를 사용하는 방법을 결정해야합니다. cryptsetup 에서는 암호문 또는 키 파일을 사용하는 선택 방안이 있습니다. 키 파일을 사용하는 경우에는 어떤 파일이라도 상관 없지만 제대로 보호한 임의 데이터(키 파일로의 접근은 암호화 데이터에 접근을 의미하는 것으로 가정)가 담겨있는 파일을 사용하시는 것이 좋습니다.

키 파일을 만든다면 dd 명령을 사용할 수 있습니다:

root #dd if=/dev/urandom of=/etc/keys/enc.key bs=1 count=4096

다음 단락에서는 암호문, 키 파일 두 가지 경우에 대해 모든 명령 과정을 보여드리겠습니다. 물론 둘 중 한가지 방식만 필요합니다.

암호화 저장소 플랫폼 만들기

암호화 저장소 플랫폼(디스크, 파티션, 파일 등이 될 수 있음)을 만들려면 luksFormat 옵션과 함께 cryptsetup 명령을 사용하십시오.

예를 들어, 암호화 데이터가 담긴 /dev/vdb2 저장소 매체를 취하려면:

root #cryptsetup -s 512 luksFormat /dev/vdb2
This will overwrite data on /dev/vdb2 irrevocably.
  
Are you sure? (Type uppercase yes): YES
Enter LUKS passphrase: ...
Verify passphrase: ...

암호문 대신 키 파일을 사용하려면:

root #cryptsetup -s 512 luksFormat /dev/vdb2 /etc/keys/enc.key
This will overwrite data on /dev/vdb2 irrevocably.
  
Are you sure? (Type uppercase yes): YES

-s 512cryptsetup에게 실제 암호화 키를 사용할 키 길이를 알려줍니다(암호문 또는 키 파일과는 달리, 실제 암호화 키에 접근할 때 사용합니다).

참고
XTS splits the key into two halves, only one being used for the actual encryption. That means "aes-xts" with a 512-bit key actually uses 256 bits for the AES part.
중요
If the LUKS header gets damaged, your encrypted data will be lost forever, even if you have a backup of the GPG key and passphrase. Therefore, you may wish to consider backing up this header to a separate device, and storing it securely. See the LUKS FAQ for more details on how to do this.
root #cryptsetup luksHeaderBackup /dev/sdXn --header-backup-file /tmp/efiboot/luks-header.img
Be aware, that if you do keep a LUKS header backup in this fashion and subsequently revoke any of the keyslots, the old keys will still be usable to unlock the LUKS partition for those with an access to that header backup file.

Full disk encryption booting

To boot from a fully encrypted device (including encrypted /boot) using GRUB, encrypt using luks1, since luks2 isn't fully supported yet. Example command:

root #cryptsetup -c aes-xts-plain64 -s 512 -y luksFormat --type luks1 /dev/vdb2

암호화 저장소 열기

암호화 저장소(공개 해독 방식으로 실제 데이터에 접근할 수 있게 함)를 열려면, luksOpen 명령을 사용하십시오.

root #cryptsetup luksOpen /dev/vdb2 myname
Enter passphrase for /dev/vdb2: ...

키 파일을 사용한다면 명령은 다음과 같습니다:

root #cryptsetup luksOpen -d /etc/keys/enc.key /dev/vdb2 myname

명령 처리가 끝나면 새 /dev/mapper/myname 장치 파일을 사용할 수 있습니다. 이 장치 파일은 일반 저장소 위치와 같이 마운트할 수 있습니다:

If this is the first time this encrypted device is used, it needs to be formatted. The following example uses the Btrfs file system but of course any other file system will do:

root #mkfs.btrfs /dev/mapper/myname

Once the file system is formatted, or the formatting was already done in the past, then the device file can be mounted on the system:

root #mount /dev/mapper/myname /home

암호화 저장소 닫기

암호화 저장소(공개 해독 방식으로 실제 데이터에 더이상 접근할 수 없게 함)를 닫으려면, luksClose 명령을 사용하십시오:

root #cryptsetup luksClose myname

물론 해당 장치를 더 이상 사용하고 있지 않은지 확인하십시오.

LUKS 키 다루기

LUKS 는 실제 암호화 키에 접근할 때 사용합니다. (암호화) 파티션, 디스크, 파일의 헤더에 저장합니다.

슬롯 감청

luksDump 명령으로, 암호화 파티션, 디스크, 파일의 정보를 나타낼 수 있습니다. 이 정보에는 슬롯을 포함합니다:

root #cryptsetup luksDump /dev/vdb2
LUKS header information for /dev/vdb2
  
Version:        1
Cipher name:    aes
Cipher mode:    xts-plain64
Hash spec:      sha1
Payload offset: 4096
MK bits:        512
MK digest:      34 3b ec ac 10 af 19 e7 e2 d4 c8 90 eb a8 da 3c e4 4f 2e ce
MK salt:        ff 7c 7f 53 db 53 48 02 a4 32 dc e0 22 fc a3 51
                06 ba b3 48 b3 28 13 a8 7a 68 43 d6 46 79 14 fe
MK iterations:  59375
UUID:           2921a7c9-7ccb-4300-92f4-38160804e08c
  
Key Slot 0: ENABLED
        Iterations:             241053
        Salt:                   90 0f 0f db cf 66 ea a9 6c 7c 0c 0d b0 28 05 2f
                                8a 5c 14 54 98 62 1a 29 f3 08 25 0c ec c2 b1 68
        Key material offset:    8
        AF stripes:             4000
Key Slot 1: ENABLED
        Iterations:             273211
        Salt:                   01 4c 26 ed ff 18 75 31 b9 89 5d a6 e0 b5 f4 14
                                48 d0 23 47 a9 85 78 fb 76 c4 a9 d0 cd 63 fb d7
        Key material offset:    512
        AF stripes:             4000
Key Slot 2: DISABLED
Key Slot 3: DISABLED
Key Slot 4: DISABLED
Key Slot 5: DISABLED
Key Slot 6: DISABLED
Key Slot 7: DISABLED

위 예제에서, 두 슬롯을 사용했습니다. luksDump는 어떤 민감한 내용도 보여주지 않습니다. LUKS 헤더의 일부만 보여줍니다. luksDump를 호출한다고 해서 해독키를 보여주는건 아닙니다.

키 파일 또는 암호문 추가

암호화 저장소에 접근할 추가 키 파일 또는 암호문을 추가하려면, luksAccKey 옵션을 사용하십시오:

root #cryptsetup luksAddKey /dev/vdb2
Enter any passphrase: (Enter a valid, previously used passphrase to unlock the key)
Enter new passphrase for key slot: ... 
Verify passphrase: ...

키 파일로 키 잠금을 해제하려면(그래도 암호문에 추가한다면):

root #cryptsetup luksAddKey -d /etc/keys/enc.key /dev/vdb2
Enter new passphrase for key slot: ...
Verify passphrase: '''

키 파일(/etc/keys/backup.key를 말함)을 추가했다면:

root #cryptsetup luksAddKey /dev/vdb2 /etc/keys/backup.key

또는 메인키를 잠금 해제할 때 첫번째 키 파일을 사용한다면:

root #cryptsetup luksAddKey -d /etc/keys/enc.key /dev/vdb2 /etc/keys/backup.key

키 파일 또는 암호문 제거

luksRemoveKey 옵션으로 키 파일 또는 암호문을 제거할 수 있습니다(따라서 이들 요소를 더이상 저장소 해독 목적으로 사용할 수 없습니다):

root #cryptsetup luksRemoveKey /dev/vdb2
Enter LUKS passphrase to be deleted: ...

또는 키 파일을 제거하려면:

root #cryptsetup luksRemoveKey -d /etc/keys/backup.key /dev/vdb2

데이터를 접근하는데 있어 최소한 한가지 방식은 두어야합니다. 사용할 암호문 또는 키 파일을 제거하면 다시 복구할 수 없습니다.

슬롯 비우기

암호문 또는 키 파일을 알 수 없는 경우를 가정하면 슬롯을 비워둘 수 있습니다. 물론 어떤 슬롯에 암호문 또는 키 파일을 저장했는지 우선 알고 있어야 합니다.

이를 테면 슬롯 2 번을 비워보겠숩니다(슬롯 번호가 0번부터 시작하므로 세번째 슬롯입니다):

root #cryptsetup luksKillSlot /dev/vdb2 2

이 명령은 계속하기 전 유효한 암호문을 요구합니다. 대신 사용할 키 파일을 전달할 수 있습니다:

root #cryptsetup luksKillSlot -d /etc/keys/enc.key /dev/vdb2 2

Automate mounting encrypted file systems

Until now, the article focused on manual setup and mounting/unmounting of encrypted file systems. An init service dmcrypt exists which automates the decrypting and mounting of encrypted file systems.

Configuring dm-crypt

Edit the /etc/conf.d/dmcrypt file and add in entries for each file system. The supported entries are well documented in the file, the below example is just that - an example:

파일 /etc/conf.d/dmcryptAutomatically enabling two encrypted file systems
# Definition for /dev/mapper/home (for /home)
target=home
source=UUID="abcdef12-321a-a324-a88c-cac412befd98"
key=/etc/keys/home.key
# If trim is desired, it can be enabled like this.
# Keep in mind that trim is not enabled by default for a security reason.
options="--allow-discards"
 
# Definition for /dev/mapper/local (for /usr/local)
target=local
source=UUID="fedcba34-4823-b423-a94c-cadbefda2943"
key=/etc/keys/local.key
 
# Using an encrypted partition as key source.
target=other
source=UUID="ff24303e-49e1-4d13-b8ad-fc6b7e1d8174"
key=/keys/other.key                                # Relative to the root of the encrypted partition.
remdev=/dev/mapper/home                            # The recently decrypted partition.
 
# An empty line is important at the end of the file

Configuring fstab

The next step is to configure /etc/fstab to automatically mount the (decrypted) file systems when they become available. It is recommended to first obtain the UUID of the decrypted (mounted) file system:

root #blkid /dev/mapper/home
/dev/mapper/home: UUID="4321421a-4321-a6c9-de52-ba6421efab76" TYPE="ext4"

Then, update the /etc/fstab file accordingly:

파일 /etc/fstabAutomounting the decrypted file systems
UUID="4321421a-4321-a6c9-de52-ba6421efab76"   /home        ext4   defaults   0   0
UUID="bdef2432-3bd1-4ab4-523d-badcf234a342"   /usr/local   ext4   defaults   0   0

Add initscript to bootlevel

Don't forget to have the dmcrypt init service launched at boot:

root #rc-update add dmcrypt boot


Make decrypted device nodes visible

If you have decrypted/unlocked a device before the services were started for example your root disk in an with an initramfs then it's possible that the mapped device is not visible. In this case you can run the following to recreate it.

root #dmsetup mknodes

Mounting TrueCrypt/tcplay/VeraCrypt volumes

root #cryptsetup --type tcrypt open container-to-mount container-name

Replace container-to-mount with the device file under /dev or the path to the file you wish to open. Upon successful opening, the plaintext device will appear as /dev/mapper/container-name, which you can mount like any normal device.

If you are using key files, supply them using the --key-file option, to open a hidden volume, supply the --tcrypt-hidden option and for a partition or whole drive that is encrypted in system mode use the --tcrypt-system option.

When done, unmount the volume, and close the container using the following command:

root #cryptsetup close container-name

See also

External resources

  • The cryptsetup FAQ hosted on GitLab covers a wide range of frequently asked questions.