dm-crypt with Linux Unified Key Setup (LUKS) 를 이용한 Disk Encryption

 1. cryptsetup 의 단점
    - Without LUKS
        - password를 변경하기 위해서는 전제 disk를 re-encrypt해야 한다
        - 단지 하나의 key 만 할당할 수 있다.
        - mount를 하기 전까지 password가 틀린지 확인할 수 없다.

2. Encrypt Disk 생성 및 포멧
    - $ qemu-img create -f raw dm.img 3G 
    - $ sudo losetup /dev/loop0 dm.img
    - $ sudo cryptsetup luksFormat /dev/loop0 
    WARNING!
    ========
    This will overwrite data on /dev/loop0 irrevocably.

    Are you sure? (Type uppercase yes): YES
    Enter LUKS passphrase: testpwd
    Verify passphrase: testpwd

    - $ sudo cryptsetup luksOpen /dev/loop0 encrypt-fs
    Enter passphrase for /dev/loop0: testpwd
    - $ ls -al /dev/mapper/
    encrypt-fs -> ../dm-0
    - $ sudo mkfs.ext4 /dev/mapper/encrypt-fs

3. Encrypt Disk 제거
    - $ sudo cryptsetup luksClose encrypt-fs
    - $ sudo losetup -d /dev/loop0

4. Encrypt Disk Mount
    - $ sudo losetup /dev/loop0 dm.img
    - $ sudo cryptsetup luksOpen /dev/loop0 encrypt-fs 
    Enter passphrase : testpwd
    - $ mkdir mount
    - $ sudo mount /dev/mapper/encrypt-fs ./mount
    - $ ls a
    lost+found     
    
4. Key 추가
    - add  a  new  key file/passphrase. An existing passphrase or key file must be supplied.
    - $ sudo cryptsetup luksDump /dev/loop0 
    LUKS header information for /dev/loop0

    Version:           1
    Cipher name:       aes
    Cipher mode:       cbc-essiv:sha256
    Hash spec:         sha1
    Payload offset:    4096
    MK bits:           256
    MK digest:         b9 37 06 0a 01 e0 c3 79 1f d7 16 c9 e3 59 0a 6a a0 0d 82 45 
    MK salt:           f3 4c 70 e3 6f d4 02 55 2a b6 38 c5 ad 17 2d f9 
                       9f 4b d1 61 50 39 cd 3b 28 f2 38 6b 7d c9 4a 83 
    MK iterations:     63000
    UUID:              aeecbbb0-ce45-4ecc-b032-b7b0e0736988

    Key Slot 0: ENABLED
        Iterations:             252121
        Salt:                   ef c6 3c c6 15 0e 51 ba 97 9c 9b f5 ef a2 e3 3a 
                              1a 2b 0d ee 70 bc 64 2b b3 ba f1 48 48 9b b2 b5 
        Key material offset:    8
        AF stripes:                4000
    Key Slot 1: DISABLED
    Key Slot 2: DISABLED
    Key Slot 3: DISABLED
    Key Slot 4: DISABLED
    Key Slot 5: DISABLED
    Key Slot 6: DISABLED
    Key Slot 7: DISABLED
    - $  sudo cryptsetup luksAddKey /dev/loop0 
    Enter any passphrase: 
    Enter new passphrase for key slot: 
    Verify passphrase: 
    - $  sudo cryptsetup luksDump /dev/loop0 
    LUKS header information for /dev/loop0

    Version:           1
    Cipher name:       aes
    Cipher mode:       cbc-essiv:sha256
    Hash spec:         sha1
    Payload offset:    4096
    MK bits:           256
    MK digest:         b9 37 06 0a 01 e0 c3 79 1f d7 16 c9 e3 59 0a 6a a0 0d 82 45 
    MK salt:           f3 4c 70 e3 6f d4 02 55 2a b6 38 c5 ad 17 2d f9 
                       9f 4b d1 61 50 39 cd 3b 28 f2 38 6b 7d c9 4a 83 
    MK iterations:     63000
    UUID:              aeecbbb0-ce45-4ecc-b032-b7b0e0736988

    Key Slot 0: ENABLED
        Iterations:             252121
        Salt:                   ef c6 3c c6 15 0e 51 ba 97 9c 9b f5 ef a2 e3 3a 
                                  1a 2b 0d ee 70 bc 64 2b b3 ba f1 48 48 9b b2 b5 
        Key material offset:    8
        AF stripes:                4000
    Key Slot 1: ENABLED
        Iterations:             253053
        Salt:                   60 e8 07 5f 87 d5 e4 08 3c 1b e8 7a 48 e1 42 40 
                                  ba 8a e4 ba db 99 2f c4 0b 61 16 1b c0 ab c2 99 
        Key material offset:    264
        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
    
5. key 변경
    - change existing key file or passphras
    - $  sudo cryptsetup luksChangeKey  /dev/loop0 
    Enter LUKS passphrase to be changed: 
    Enter new LUKS passphrase: 
    Verify passphrase:

6. Encrypt Disk Unmount 및 제거
    - $ sudo umount ./mount
    - $ sudo cryptsetup luksClose encrypt-fs
    - $ sudo losetup -d /dev/loop0

댓글

이 블로그의 인기 게시물

SSH 연결 Delay 해결

[ELK] search guard를 이용한 보안 설정 (사용자 권한)

공공데이터(openapi) 사용법 (특정 정류소, 버스의 남은 좌석 확인 하기)