首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何更改现有设备的散列规范和iter时间?

如何更改现有设备的散列规范和iter时间?
EN

Unix & Linux用户
提问于 2013-11-15 21:07:30
回答 1查看 15.9K关注 0票数 18

如何更改现有设备的散列规范和iter时间?

显然,如果我创建一个新设备,我可以传递这些选项,例如:

代码语言:javascript
复制
 sudo cryptsetup luksFormat --cipher aes-cbc-essiv:sha256 --key-size 256 --iter-time 2100 --hash sha512 /dev/loop0

但是,如果设备已经存在,我如何在不“破坏”设备的情况下将sha256更改为sha1或更改迭代时间。(显然,您必须重新键入密码,因为将生成一个新的哈希。)

EN

回答 1

Unix & Linux用户

发布于 2015-01-12 14:11:49

如果您只想更改散列,则不需要重新加密。你仍然需要建立一个新的卢克斯头部。相同的密码,相同的主键,相同的偏移量,不同的哈希。

你自己试试吧。首先,我们设置了一个具有标准设置和糟糕的iter计数的LUKS设备:

代码语言:javascript
复制
# truncate -s 8M /dev/shm/foobar
# cryptsetup --iter-time=42 luksFormat /dev/shm/foobar

WARNING!
========
This will overwrite data on /dev/shm/foobar irrevocably.

Are you sure? (Type uppercase yes): YES
Enter passphrase: 
Verify passphrase: 
# cryptsetup luksOpen /dev/shm/foobar foobar
Enter passphrase for /dev/shm/foobar: 
# shred -z /dev/mapper/foobar
# echo Hello World I am LUKS > /dev/mapper/foobar
# strings /dev/mapper/foobar
Hello World I am LUKS
# cryptsetup luksClose foobar

在这一点上,我们有一个LUKS设备与加密数据“你好世界我是陆克思”。特别是它看起来是这样的:

代码语言:javascript
复制
# cryptsetup luksDump /dev/shm/foobar
LUKS header information for /dev/shm/foobar

Version:        1
Cipher name:    aes
Cipher mode:    xts-plain64
Hash spec:      sha1
Payload offset: 4096
MK bits:        256
MK digest:      30 87 62 81 8e 8f a9 15 68 e0 82 c0 dc ee 19 54 9b f2 eb 5c 
MK salt:        c3 e0 28 53 67 10 13 d4 43 e3 7b d1 ce 62 6b e3 
                58 85 ee 67 71 76 b6 48 78 a8 34 71 58 71 21 f8 
MK iterations:  6175
UUID:           14a0a11d-0890-433e-bdcb-d2d1f5281bc2

Key Slot 0: ENABLED
    Iterations:             26033
    Salt:                   a1 7b 2b 5b 3d 8c 3c d1 3b 57 61 5a df 25 47 c8 
                            29 97 62 09 08 2b e1 b2 af 61 56 80 2f af a6 ae 
    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

正如您所看到的,糟糕的迭代计算,标准的sha1散列。

为了将其切换到高迭代次数和sha512散列,无需重新加密,我们需要使用相同的主密钥、相同的密码和相同的有效负载偏移量来创建一个新的LUKS报头。

获取主键:(警告:此示例将主密钥泄漏给一个世界可读的文件、进程列表以及shell的历史记录。为了安全起见,可以在RAM中/在Live /任何东西上这样做。

代码语言:javascript
复制
# cryptsetup --dump-master-key luksDump /dev/shm/foobar

WARNING!
========
Header dump with volume key is sensitive information
which allows access to encrypted partition without passphrase.
This dump should be always stored encrypted on safe place.

Are you sure? (Type uppercase yes): YES
Enter passphrase: 
LUKS header information for /dev/shm/foobar
Cipher name:    aes
Cipher mode:    xts-plain64
Payload offset: 4096
UUID:           14a0a11d-0890-433e-bdcb-d2d1f5281bc2
MK bits:        256
MK dump:    eb aa 57 2d 42 93 fe 90 00 b9 d2 e0 e0 7b 73 26 
            4b 64 1b 8b 8e 61 75 84 1b c3 d6 f7 3f 03 d2 14 

# printf '\xeb\xaa\x57\x2d\x42\x93\xfe\x90\x00\xb9\xd2\xe0\xe0\x7b\x73\x26\x4b\x64\x1b\x8b\x8e\x61\x75\x84\x1b\xc3\xd6\xf7\x3f\x03\xd2\x14' > /dev/shm/masterkey
# hexdump -C /dev/shm/masterkey
00000000  eb aa 57 2d 42 93 fe 90  00 b9 d2 e0 e0 7b 73 26  |..W-B........{s&|
00000010  4b 64 1b 8b 8e 61 75 84  1b c3 d6 f7 3f 03 d2 14  |Kd...au.....?...|
00000020

使用这个键创建新的LUKS头:(失败是可能的-首先备份旧的LUKS头!)

代码语言:javascript
复制
# cryptsetup --master-key-file=/dev/shm/masterkey --iter-time=5000 --hash=sha512 luksFormat /dev/shm/foobar

WARNING!
========
This will overwrite data on /dev/shm/foobar irrevocably.

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

看上去是这样的:

代码语言:javascript
复制
# cryptsetup luksDump /dev/shm/foobar
LUKS header information for /dev/shm/foobar

Version:        1
Cipher name:    aes
Cipher mode:    xts-plain64
Hash spec:      sha512
Payload offset: 4096
MK bits:        256
MK digest:      47 ab 7b c6 41 b0 7c d8 af 3c a0 a4 23 e6 72 87 9c 0f c6 a0 
MK salt:        32 49 a5 b5 cb 4d 8a d7 25 69 72 ae e5 b2 9e 9d 
                14 09 00 1d 01 f3 c9 99 da e1 6c fc 69 78 e4 64 
MK iterations:  393750
UUID:           fd554ae8-a862-4609-8327-c6dd65ee9a83

Key Slot 0: ENABLED
    Iterations:             1578295
    Salt:                   e5 75 1c 1f 63 1d c6 0b d9 27 1a b1 27 85 b9 c1 
                            89 e8 57 95 2a c8 a0 24 9c 29 c0 f2 27 d7 2f 9a 
    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

现在我们有了。相同的密码,偏移量如果它们不同,则必须与luksFormat一起指定它们.,新哈希和适当的迭代次数。

但内容还在吗?

代码语言:javascript
复制
# cryptsetup luksOpen /dev/shm/foobar foobar
Enter passphrase for /dev/shm/foobar: 
# strings /dev/mapper/foobar
Hello World I am LUKS

这就对了。

票数 15
EN
页面原文内容由Unix & Linux提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://unix.stackexchange.com/questions/101343

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档