mirror of
https://gitlab.com/cryptsetup/cryptsetup.git
synced 2025-12-06 08:20:07 +01:00
Compare commits
568 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0f8e7f317f | ||
|
|
c5b0a4dd32 | ||
|
|
5c5551d1d3 | ||
|
|
aa324567a8 | ||
|
|
0ee752c42d | ||
|
|
4746717b75 | ||
|
|
3ad942e338 | ||
|
|
b5190da581 | ||
|
|
5fa8e84ef0 | ||
|
|
63adb3b0cf | ||
|
|
20774374a9 | ||
|
|
d169020001 | ||
|
|
76766f11c0 | ||
|
|
5d6d65ce86 | ||
|
|
24ab0871e7 | ||
|
|
11e325a112 | ||
|
|
6ea32db1fa | ||
|
|
49c8a8b9ef | ||
|
|
a480c388b8 | ||
|
|
5406064f55 | ||
|
|
9b66d0d039 | ||
|
|
adff844c46 | ||
|
|
f702246d78 | ||
|
|
8606342b53 | ||
|
|
ccb0f7c0b2 | ||
|
|
72384b43bd | ||
|
|
5ef3de8945 | ||
|
|
ad913cf437 | ||
|
|
7820f07e85 | ||
|
|
01bda280ee | ||
|
|
b40f31fb8c | ||
|
|
066d651210 | ||
|
|
b00946d449 | ||
|
|
6a14f52e5d | ||
|
|
3c68e3f5b1 | ||
|
|
ec1ef8f19d | ||
|
|
6a64c2e932 | ||
|
|
835c603b13 | ||
|
|
a718b90ac6 | ||
|
|
089edb74b4 | ||
|
|
8c60cf8645 | ||
|
|
f364990b9b | ||
|
|
3b826d0fa3 | ||
|
|
cab332c367 | ||
|
|
9ee74f59d7 | ||
|
|
46afee6299 | ||
|
|
90bba399ab | ||
|
|
c403f73ad0 | ||
|
|
470b99a647 | ||
|
|
a68968af8f | ||
|
|
ee9c7855ca | ||
|
|
1a156458f2 | ||
|
|
796b901912 | ||
|
|
508284cd28 | ||
|
|
5d1972bb97 | ||
|
|
7c76d17a9c | ||
|
|
8ff663a761 | ||
|
|
d3ad9fe25f | ||
|
|
cc374ee10d | ||
|
|
06f132066b | ||
|
|
82816cb52f | ||
|
|
426cab3aeb | ||
|
|
152ed1fb44 | ||
|
|
c6ff9f8bd7 | ||
|
|
c104bccc3f | ||
|
|
4654e6f578 | ||
|
|
2cf38465c4 | ||
|
|
3428296186 | ||
|
|
877afd2281 | ||
|
|
2f320f3148 | ||
|
|
a0277d3ff6 | ||
|
|
531ebba50b | ||
|
|
d8bac63e5c | ||
|
|
b408b8238c | ||
|
|
2e80962501 | ||
|
|
43827ba380 | ||
|
|
cd374664d4 | ||
|
|
3694f9c099 | ||
|
|
06249b8e99 | ||
|
|
bf915e82f4 | ||
|
|
bfe0c7fc5f | ||
|
|
0eb8493156 | ||
|
|
9736f533bb | ||
|
|
cc6df5fa39 | ||
|
|
62896c20ff | ||
|
|
ea5fb82a48 | ||
|
|
25c29b80b5 | ||
|
|
f8caa82186 | ||
|
|
c35b896209 | ||
|
|
5a36a1f3a2 | ||
|
|
afb7cd6d01 | ||
|
|
c9af248c38 | ||
|
|
95eb986206 | ||
|
|
b4670ce7f0 | ||
|
|
6633fa626a | ||
|
|
df7a995fa2 | ||
|
|
ca2e93b69d | ||
|
|
3589f9578a | ||
|
|
07d23c2ee8 | ||
|
|
eadbcac115 | ||
|
|
3dc7dff2b2 | ||
|
|
35793c24f0 | ||
|
|
ff958d376e | ||
|
|
6545523df3 | ||
|
|
3e52aa820c | ||
|
|
73cd60b1cc | ||
|
|
c7b0f8fcda | ||
|
|
057af1e20a | ||
|
|
aea841eeb0 | ||
|
|
5b9e98f941 | ||
|
|
c645045adb | ||
|
|
224555aaf9 | ||
|
|
d9fc45de04 | ||
|
|
db77541790 | ||
|
|
e884fe93bd | ||
|
|
c2507f02cf | ||
|
|
fc6982f577 | ||
|
|
06fff68255 | ||
|
|
8f752a2bd7 | ||
|
|
07e687106a | ||
|
|
9125df1398 | ||
|
|
52cc01c977 | ||
|
|
b8d2218720 | ||
|
|
05a4d3fe0a | ||
|
|
df5e54545e | ||
|
|
f79ef935a7 | ||
|
|
cd3cb945ab | ||
|
|
f1d624b6c8 | ||
|
|
3f268c3052 | ||
|
|
0ec7027d83 | ||
|
|
0ae5240f55 | ||
|
|
51f5f71ee0 | ||
|
|
5784692218 | ||
|
|
f82d3ee51a | ||
|
|
d02c809bc7 | ||
|
|
b7a07efdcf | ||
|
|
a8bb07ae9f | ||
|
|
897e798fc0 | ||
|
|
2d0b19b359 | ||
|
|
702f9b1cf4 | ||
|
|
1d20a60e4a | ||
|
|
71422b411e | ||
|
|
f446dbb896 | ||
|
|
975425d0eb | ||
|
|
c020fafd66 | ||
|
|
2954b46d43 | ||
|
|
4cdd826282 | ||
|
|
413b484774 | ||
|
|
351d7fefca | ||
|
|
a7872ab856 | ||
|
|
c1613285e7 | ||
|
|
8805eb2b45 | ||
|
|
a3f919bd25 | ||
|
|
4f6f7404df | ||
|
|
5776c52bcf | ||
|
|
db44e9de22 | ||
|
|
c40be6cc7a | ||
|
|
b047b8ae20 | ||
|
|
e9434dc9e3 | ||
|
|
c6149c9cd8 | ||
|
|
8f2b23cd94 | ||
|
|
8d449aa9a6 | ||
|
|
e6089dd9c9 | ||
|
|
bc488fd4f1 | ||
|
|
ec3a9746a9 | ||
|
|
530bcfd4fa | ||
|
|
bd4f374b47 | ||
|
|
0a7c13207d | ||
|
|
c5fc3fe84a | ||
|
|
8d0e90b90a | ||
|
|
1aeb0a1f6e | ||
|
|
ce80f7c5b1 | ||
|
|
25cd2b2fb7 | ||
|
|
78797ae078 | ||
|
|
96d83455ca | ||
|
|
36805b3cfe | ||
|
|
5d0a11a21b | ||
|
|
d4cd675f33 | ||
|
|
c3328a123c | ||
|
|
2cc320f180 | ||
|
|
6f26d7a77f | ||
|
|
9d559bba8f | ||
|
|
cb9cb7154d | ||
|
|
da15a67c96 | ||
|
|
69efb9177d | ||
|
|
f9ce835e58 | ||
|
|
3dd6e222c8 | ||
|
|
04b8c4ff32 | ||
|
|
9b2adfede9 | ||
|
|
520aea9de0 | ||
|
|
9f233a68f3 | ||
|
|
476cd2f764 | ||
|
|
ca87b74333 | ||
|
|
25a943ad01 | ||
|
|
f22a6613eb | ||
|
|
8914ae468b | ||
|
|
3e712b2dcd | ||
|
|
17e0e9fd27 | ||
|
|
e7f67f8928 | ||
|
|
4b049fe848 | ||
|
|
fea4074e8f | ||
|
|
9209d7e3b5 | ||
|
|
ca2e1fc956 | ||
|
|
1592f1e274 | ||
|
|
74027ca922 | ||
|
|
1910960364 | ||
|
|
2708021e6f | ||
|
|
8e8ecd50de | ||
|
|
3ebf7fa3bd | ||
|
|
68130ef2f5 | ||
|
|
a77acb21c9 | ||
|
|
6e6e9f169e | ||
|
|
6a8bade7e6 | ||
|
|
3367b78958 | ||
|
|
28603e4de7 | ||
|
|
d8cf203d46 | ||
|
|
9faa602f6c | ||
|
|
c9b727e9ea | ||
|
|
1534dc6c61 | ||
|
|
dd6d6cfa1c | ||
|
|
8e564bbb5c | ||
|
|
284a49443e | ||
|
|
61abbc6e5d | ||
|
|
1fe2d3d92b | ||
|
|
b0da623c8a | ||
|
|
ff1502edd0 | ||
|
|
2d9c0b507d | ||
|
|
20320dfd0e | ||
|
|
6483fb027a | ||
|
|
030d50f6ba | ||
|
|
dc8bbbf352 | ||
|
|
c72030d25a | ||
|
|
4309294c2a | ||
|
|
f5dd3c8e32 | ||
|
|
6dd347ddb4 | ||
|
|
e15e09025d | ||
|
|
caf71248df | ||
|
|
7b327509b4 | ||
|
|
83138b7803 | ||
|
|
cea7a1489a | ||
|
|
f6e2fbb366 | ||
|
|
2e4a3a9888 | ||
|
|
639ffa36a5 | ||
|
|
05f9297141 | ||
|
|
28baeca882 | ||
|
|
b1558ec973 | ||
|
|
4862c38ca9 | ||
|
|
bec7394722 | ||
|
|
42479bd1df | ||
|
|
01f896711e | ||
|
|
ed2117c724 | ||
|
|
bc7511762f | ||
|
|
03cc8a9ce4 | ||
|
|
a4d7c46d80 | ||
|
|
7d912c7d3e | ||
|
|
65b43d5d12 | ||
|
|
36fd8d6b3c | ||
|
|
f28e159ff2 | ||
|
|
633ffbf8b7 | ||
|
|
4359973586 | ||
|
|
0dfeb304cc | ||
|
|
12cc7ea745 | ||
|
|
1ff2b85252 | ||
|
|
76301cef4c | ||
|
|
4471452105 | ||
|
|
d703301fe8 | ||
|
|
85f7ee59f8 | ||
|
|
fe71fd469a | ||
|
|
f05c9833ee | ||
|
|
11e7e267f7 | ||
|
|
0738ba2451 | ||
|
|
12ff94c02f | ||
|
|
da2f6e9d93 | ||
|
|
49b246193b | ||
|
|
1862a991d8 | ||
|
|
89839cb1cf | ||
|
|
07bb8b3023 | ||
|
|
56d55a4585 | ||
|
|
3cd158b983 | ||
|
|
d1ffca3189 | ||
|
|
e21e3b298a | ||
|
|
f47f6b7fb4 | ||
|
|
1e7521c056 | ||
|
|
bb6d522198 | ||
|
|
c0b2f99b04 | ||
|
|
89b3105493 | ||
|
|
37cc06444d | ||
|
|
2d10545e70 | ||
|
|
04b781d613 | ||
|
|
5a252c9166 | ||
|
|
373d4c9848 | ||
|
|
fa84d60586 | ||
|
|
7dc4a336bd | ||
|
|
362d523fa6 | ||
|
|
586b0a39d8 | ||
|
|
6df3488654 | ||
|
|
10e4d8fbac | ||
|
|
81c44b5eee | ||
|
|
aa9eef28c4 | ||
|
|
0a2c6fccc3 | ||
|
|
88a95c7f03 | ||
|
|
90c1873134 | ||
|
|
d1d9dd8e20 | ||
|
|
39dc77d825 | ||
|
|
24d349f491 | ||
|
|
0eff642d2f | ||
|
|
b7c1f1e13d | ||
|
|
c27123cf61 | ||
|
|
0edfeb19f1 | ||
|
|
f069c256a6 | ||
|
|
670d08b406 | ||
|
|
0c29321407 | ||
|
|
b4643cb5be | ||
|
|
3c886ccff8 | ||
|
|
eddc3b0381 | ||
|
|
83cc90be5d | ||
|
|
ba92a5e865 | ||
|
|
8a12f6dc2c | ||
|
|
9fad8a8c92 | ||
|
|
57eab17262 | ||
|
|
fc5f9cc46d | ||
|
|
38e631d174 | ||
|
|
3283135f16 | ||
|
|
bd491b4479 | ||
|
|
6dbfe52c35 | ||
|
|
9da23371d5 | ||
|
|
29c5deb4f1 | ||
|
|
9bc45ae15f | ||
|
|
08abc0eb77 | ||
|
|
fea3a76c38 | ||
|
|
3a7f03bae6 | ||
|
|
652081426b | ||
|
|
406d2d8b0a | ||
|
|
7a1df1c323 | ||
|
|
5a44d14d97 | ||
|
|
b444d1ecd7 | ||
|
|
0456670328 | ||
|
|
eff4da95a1 | ||
|
|
ad7d16a1b4 | ||
|
|
f5abfde1fa | ||
|
|
02d13d7257 | ||
|
|
941b82a8be | ||
|
|
482fcd0602 | ||
|
|
14c7148edd | ||
|
|
a00722e80c | ||
|
|
42f4dcef88 | ||
|
|
37188482fe | ||
|
|
eb3228233a | ||
|
|
8dec7eac05 | ||
|
|
e9c2aaccb5 | ||
|
|
112c0ff08b | ||
|
|
e431cbdfa7 | ||
|
|
6514d1bc2e | ||
|
|
53d3ca0062 | ||
|
|
3062a9ba91 | ||
|
|
dcc2b252dd | ||
|
|
66b3aa9582 | ||
|
|
32a141d548 | ||
|
|
69e7d64c49 | ||
|
|
7d5025a865 | ||
|
|
c65cd4eb74 | ||
|
|
8ff3b0cd63 | ||
|
|
cc2d29dbf4 | ||
|
|
6ed739d9ca | ||
|
|
5d07b0730c | ||
|
|
fe05e47656 | ||
|
|
8399bd8309 | ||
|
|
a730d56e66 | ||
|
|
6599ae1f2f | ||
|
|
0b5426da12 | ||
|
|
be9c3cd979 | ||
|
|
02106c3292 | ||
|
|
e078650435 | ||
|
|
7d6b4d9936 | ||
|
|
ab087f7342 | ||
|
|
962735cf7a | ||
|
|
4ce7766e14 | ||
|
|
cdc70991f7 | ||
|
|
a1fe799afd | ||
|
|
157f72f611 | ||
|
|
c97080cee7 | ||
|
|
5b623d2314 | ||
|
|
26f87c284b | ||
|
|
8cddcb76b2 | ||
|
|
6199fed6bb | ||
|
|
96da06430b | ||
|
|
752c9a5279 | ||
|
|
46ee71edcd | ||
|
|
bcfb7731ab | ||
|
|
57d0f19bda | ||
|
|
4cf663a661 | ||
|
|
0b9893c640 | ||
|
|
ba4c028f5f | ||
|
|
52f5cb8ced | ||
|
|
f3ec1e2254 | ||
|
|
d5729bdf01 | ||
|
|
3c54d8a239 | ||
|
|
f647333f49 | ||
|
|
fcddbf5c03 | ||
|
|
1bce69cfde | ||
|
|
32d4f243e6 | ||
|
|
8e6b8cd6e6 | ||
|
|
6a6c4d0887 | ||
|
|
737ecd9d42 | ||
|
|
191d8a0716 | ||
|
|
cfcc908cae | ||
|
|
cf2e099087 | ||
|
|
d6cc88cabb | ||
|
|
42692418c2 | ||
|
|
a985c12659 | ||
|
|
5ebf128023 | ||
|
|
911b16bab8 | ||
|
|
693f61c47f | ||
|
|
3a8c866393 | ||
|
|
0851c2cfb0 | ||
|
|
958eaf4b24 | ||
|
|
07f9248448 | ||
|
|
c2371f95c6 | ||
|
|
379322f0b8 | ||
|
|
b30b17d1eb | ||
|
|
ef3beeb390 | ||
|
|
48e0b20e62 | ||
|
|
018680046c | ||
|
|
aebe14a6e9 | ||
|
|
c4b7bf8635 | ||
|
|
3973f6a57c | ||
|
|
5906ca25f7 | ||
|
|
2ce8573f04 | ||
|
|
f6706ce124 | ||
|
|
31ebf3dc2c | ||
|
|
cb183de1da | ||
|
|
c867f2e8a0 | ||
|
|
c9ff83bfa3 | ||
|
|
05c997da1f | ||
|
|
f677bdc12f | ||
|
|
2178461c89 | ||
|
|
d438151f25 | ||
|
|
7d475266b6 | ||
|
|
367cb7a761 | ||
|
|
4604f00218 | ||
|
|
8eff9151ac | ||
|
|
50797c7948 | ||
|
|
c34a3e2c5b | ||
|
|
35211cdc8f | ||
|
|
4a8a1f2dde | ||
|
|
f2ab443cca | ||
|
|
abc15094c6 | ||
|
|
f390695767 | ||
|
|
f092bcdfdb | ||
|
|
1633f030e8 | ||
|
|
4451df15b4 | ||
|
|
f50062517e | ||
|
|
967e3de552 | ||
|
|
d95472e757 | ||
|
|
3e0e5bac2a | ||
|
|
08cb76bbfd | ||
|
|
281dd51f5a | ||
|
|
1c7c815108 | ||
|
|
d177af8842 | ||
|
|
544129d240 | ||
|
|
9f79678723 | ||
|
|
a491b938ba | ||
|
|
588c8cf5b3 | ||
|
|
876ca59234 | ||
|
|
f5910d83c4 | ||
|
|
e43a22abcf | ||
|
|
2a7aa8992b | ||
|
|
e36597e2c6 | ||
|
|
6403de2109 | ||
|
|
9b49e47b13 | ||
|
|
8540be5b82 | ||
|
|
ae6d6261a1 | ||
|
|
ce4fcd2009 | ||
|
|
76620881f4 | ||
|
|
f99efd6166 | ||
|
|
74e94e7bdd | ||
|
|
72cd628357 | ||
|
|
45367e4a34 | ||
|
|
7d76831250 | ||
|
|
d2ff3fc2ee | ||
|
|
537b8454a4 | ||
|
|
a7c71b90b1 | ||
|
|
e0be3deb3a | ||
|
|
5490476d84 | ||
|
|
90865eb887 | ||
|
|
157f71d78e | ||
|
|
176fee54e4 | ||
|
|
61f4363ed7 | ||
|
|
86cc67e081 | ||
|
|
dcc9888350 | ||
|
|
6af6a424b4 | ||
|
|
e1ceb63023 | ||
|
|
4eb7193a27 | ||
|
|
e6ff3b37a4 | ||
|
|
c3e095969f | ||
|
|
2e345a1059 | ||
|
|
e759ebe0bd | ||
|
|
533b874590 | ||
|
|
780ebb4680 | ||
|
|
02a579af59 | ||
|
|
9bcf1c4b8d | ||
|
|
dec9b4f7c7 | ||
|
|
4701842829 | ||
|
|
488b4bdbe8 | ||
|
|
c8d886b422 | ||
|
|
a83bbd2e92 | ||
|
|
c3a47cb72f | ||
|
|
0971e55d4d | ||
|
|
6f45c7a8ac | ||
|
|
c567d852a5 | ||
|
|
0b38128e21 | ||
|
|
b9daa8b2ee | ||
|
|
878c7173c3 | ||
|
|
f69b980dcf | ||
|
|
33378792ca | ||
|
|
c7a2b4d5e3 | ||
|
|
4a077fc2c9 | ||
|
|
f309ec21d7 | ||
|
|
e261cf7481 | ||
|
|
fa8390b23e | ||
|
|
af89858d47 | ||
|
|
e6a3569743 | ||
|
|
604abec333 | ||
|
|
790666ffb0 | ||
|
|
c9f6ccff9f | ||
|
|
02b3f42500 | ||
|
|
e10724accb | ||
|
|
5b68dec43a | ||
|
|
9d13da0050 | ||
|
|
1e94425279 | ||
|
|
fc48f9bc08 | ||
|
|
2eb25910a1 | ||
|
|
1dab341b33 | ||
|
|
1f7ed87e6c | ||
|
|
c59ea422cc | ||
|
|
0bcb71f742 | ||
|
|
7e38a3386e | ||
|
|
c25b5ef215 | ||
|
|
72fb507de2 | ||
|
|
45c4c95b98 | ||
|
|
e8861d1043 | ||
|
|
c48fcb743b | ||
|
|
d5d732ddf4 | ||
|
|
f83bd5cdf6 | ||
|
|
76c87c628f | ||
|
|
fa125a354d | ||
|
|
f184b54796 | ||
|
|
75925fb2f7 | ||
|
|
b780228ade | ||
|
|
91c012eff0 | ||
|
|
05d45c6948 | ||
|
|
a2c13fbc48 | ||
|
|
16c7aab99b | ||
|
|
0cf5e309a0 | ||
|
|
b5fbd682f2 | ||
|
|
90e04b0046 | ||
|
|
329f6562c2 | ||
|
|
852bad1ef4 | ||
|
|
aa44a61ab2 | ||
|
|
3e237cb490 | ||
|
|
7b206fb13d | ||
|
|
8f7e898341 | ||
|
|
7499d9f245 | ||
|
|
ba6e6f051a | ||
|
|
d4f4dfb54f | ||
|
|
3e7dedaf99 | ||
|
|
f18cd7ae81 | ||
|
|
0ae4fcf8eb |
28
.github/workflows/cibuild-setup-ubuntu.sh
vendored
Executable file
28
.github/workflows/cibuild-setup-ubuntu.sh
vendored
Executable file
@@ -0,0 +1,28 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -ex
|
||||
|
||||
PACKAGES=(
|
||||
git make autoconf automake autopoint pkg-config libtool libtool-bin
|
||||
gettext libssl-dev libdevmapper-dev libpopt-dev uuid-dev libsepol1-dev
|
||||
libjson-c-dev libssh-dev libblkid-dev tar libargon2-0-dev libpwquality-dev
|
||||
sharutils dmsetup jq xxd expect keyutils netcat passwd openssh-client sshpass
|
||||
)
|
||||
|
||||
COMPILER="${COMPILER:?}"
|
||||
COMPILER_VERSION="${COMPILER_VERSION:?}"
|
||||
RELEASE="$(lsb_release -cs)"
|
||||
|
||||
bash -c "echo 'deb-src http://archive.ubuntu.com/ubuntu/ $RELEASE main restricted universe multiverse' >>/etc/apt/sources.list"
|
||||
|
||||
# Latest gcc stack deb packages provided by
|
||||
# https://launchpad.net/~ubuntu-toolchain-r/+archive/ubuntu/test
|
||||
add-apt-repository -y ppa:ubuntu-toolchain-r/test
|
||||
PACKAGES+=(gcc-$COMPILER_VERSION)
|
||||
|
||||
# scsi_debug, gost crypto
|
||||
PACKAGES+=(dkms linux-headers-$(uname -r) linux-modules-extra-$(uname -r) gost-crypto-dkms)
|
||||
|
||||
apt-get -y update --fix-missing
|
||||
apt-get -y install "${PACKAGES[@]}"
|
||||
apt-get -y build-dep cryptsetup
|
||||
38
.github/workflows/cibuild.sh
vendored
Executable file
38
.github/workflows/cibuild.sh
vendored
Executable file
@@ -0,0 +1,38 @@
|
||||
#!/bin/bash
|
||||
|
||||
PHASES=(${@:-CONFIGURE MAKE CHECK})
|
||||
COMPILER="${COMPILER:?}"
|
||||
COMPILER_VERSION="${COMPILER_VERSION}"
|
||||
CFLAGS=(-O1 -g)
|
||||
CXXFLAGS=(-O1 -g)
|
||||
|
||||
CC="gcc${COMPILER_VERSION:+-$COMPILER_VERSION}"
|
||||
CXX="g++${COMPILER_VERSION:+-$COMPILER_VERSION}"
|
||||
|
||||
set -ex
|
||||
|
||||
for phase in "${PHASES[@]}"; do
|
||||
case $phase in
|
||||
CONFIGURE)
|
||||
opts=(
|
||||
--enable-libargon2
|
||||
)
|
||||
|
||||
sudo -E git clean -xdf
|
||||
|
||||
./autogen.sh
|
||||
CC="$CC" CXX="$CXX" CFLAGS="${CFLAGS[@]}" CXXFLAGS="${CXXFLAGS[@]}" ./configure "${opts[@]}"
|
||||
;;
|
||||
MAKE)
|
||||
make -j
|
||||
make -j -C tests check-programs
|
||||
;;
|
||||
CHECK)
|
||||
make check
|
||||
;;
|
||||
|
||||
*)
|
||||
echo >&2 "Unknown phase '$phase'"
|
||||
exit 1
|
||||
esac
|
||||
done
|
||||
29
.github/workflows/cibuild.yml
vendored
Normal file
29
.github/workflows/cibuild.yml
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
name: Build test
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- 'master'
|
||||
- 'wip-luks2'
|
||||
- 'v2.3.x'
|
||||
paths-ignore:
|
||||
- 'docs/**'
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
if: github.repository == 'mbroz/cryptsetup'
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
env:
|
||||
- { COMPILER: "gcc", COMPILER_VERSION: "11", RUN_SSH_PLUGIN_TEST: "1" }
|
||||
env: ${{ matrix.env }}
|
||||
steps:
|
||||
- name: Repository checkout
|
||||
uses: actions/checkout@v1
|
||||
- name: Ubuntu setup
|
||||
run: sudo -E .github/workflows/cibuild-setup-ubuntu.sh
|
||||
- name: Configure & Make
|
||||
run: .github/workflows/cibuild.sh CONFIGURE MAKE
|
||||
- name: Check
|
||||
run: sudo -E .github/workflows/cibuild.sh CHECK
|
||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -25,6 +25,7 @@ config.sub
|
||||
configure
|
||||
cryptsetup
|
||||
cryptsetup-reencrypt
|
||||
cryptsetup-ssh
|
||||
depcomp
|
||||
install-sh
|
||||
integritysetup
|
||||
|
||||
46
.gitlab-ci.yml
Normal file
46
.gitlab-ci.yml
Normal file
@@ -0,0 +1,46 @@
|
||||
default:
|
||||
before_script:
|
||||
- sudo apt-get -y update --fix-missing
|
||||
- >
|
||||
sudo apt-get -y install -y -qq git gcc make
|
||||
autoconf automake autopoint pkg-config libtool libtool-bin gettext
|
||||
libssl-dev libdevmapper-dev libpopt-dev uuid-dev libsepol1-dev
|
||||
libjson-c-dev libssh-dev libblkid-dev tar libargon2-0-dev
|
||||
libpwquality-dev sharutils dmsetup jq xxd expect keyutils
|
||||
netcat passwd openssh-client sshpass
|
||||
- sudo apt-get -y build-dep cryptsetup
|
||||
- sudo -E git clean -xdf
|
||||
- ./autogen.sh
|
||||
- ./configure --enable-libargon2
|
||||
|
||||
stages:
|
||||
- test
|
||||
|
||||
# Merge request: Build and run only non-root tests
|
||||
test-mergerq-job:
|
||||
stage: test
|
||||
interruptible: true
|
||||
rules:
|
||||
- if: $CI_PROJECT_PATH != "cryptsetup/cryptsetup"
|
||||
when: never
|
||||
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
|
||||
script:
|
||||
- make -j
|
||||
- make -j -C tests check-programs
|
||||
- make check
|
||||
|
||||
# For main branch commit, run all tests as root
|
||||
test-main-commit-job:
|
||||
stage: test
|
||||
interruptible: true
|
||||
variables:
|
||||
RUN_SSH_PLUGIN_TEST: "1"
|
||||
rules:
|
||||
- if: $CI_PROJECT_PATH != "cryptsetup/cryptsetup"
|
||||
when: never
|
||||
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
|
||||
script:
|
||||
- make -j
|
||||
- make -j -C tests check-programs
|
||||
- sudo -E make check
|
||||
- sudo -E make clean
|
||||
15
.gitlab/issue_templates/Bug.md
Normal file
15
.gitlab/issue_templates/Bug.md
Normal file
@@ -0,0 +1,15 @@
|
||||
### Issue description
|
||||
<!-- Please, shortly describe the issue here. -->
|
||||
|
||||
### Steps for reproducing the issue
|
||||
<!-- How it can be reproduced? Include all important steps. -->
|
||||
|
||||
### Additional info
|
||||
<!-- Please mention what distribution you are using. -->
|
||||
|
||||
### Debug log
|
||||
<!-- Paste a debug log of the failing command (add --debug option) between the markers below (to keep raw debug format).-->
|
||||
```
|
||||
Output with --debug option:
|
||||
|
||||
```
|
||||
5
.gitlab/issue_templates/Documentation.md
Normal file
5
.gitlab/issue_templates/Documentation.md
Normal file
@@ -0,0 +1,5 @@
|
||||
### Documentation issue
|
||||
<!-- Please, shortly describe the issue in documentation here. -->
|
||||
|
||||
### Additional info
|
||||
<!-- Please mention what cryptsetup version you are using. -->
|
||||
5
.gitlab/issue_templates/Feature.md
Normal file
5
.gitlab/issue_templates/Feature.md
Normal file
@@ -0,0 +1,5 @@
|
||||
### New feature description
|
||||
<!-- Please, shortly describe the requested feature here. -->
|
||||
|
||||
### Additional info
|
||||
<!-- Please mention what distribution and cryptsetup version you are using. -->
|
||||
@@ -1,160 +0,0 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# .travis-functions.sh:
|
||||
# - helper functions to be sourced from .travis.yml
|
||||
# - designed to respect travis' environment but testing locally is possible
|
||||
# - modified copy from util-linux project
|
||||
#
|
||||
|
||||
if [ ! -f "configure.ac" ]; then
|
||||
echo ".travis-functions.sh must be sourced from source dir" >&2
|
||||
return 1 || exit 1
|
||||
fi
|
||||
|
||||
## some config settings
|
||||
# travis docs say we get 1.5 CPUs
|
||||
MAKE="make -j2"
|
||||
DUMP_CONFIG_LOG="short"
|
||||
export TS_OPT_parsable="yes"
|
||||
|
||||
function configure_travis
|
||||
{
|
||||
./configure "$@"
|
||||
err=$?
|
||||
if [ "$DUMP_CONFIG_LOG" = "short" ]; then
|
||||
grep -B1 -A10000 "^## Output variables" config.log | grep -v "_FALSE="
|
||||
elif [ "$DUMP_CONFIG_LOG" = "full" ]; then
|
||||
cat config.log
|
||||
fi
|
||||
return $err
|
||||
}
|
||||
|
||||
function check_nonroot
|
||||
{
|
||||
local cfg_opts="$1"
|
||||
|
||||
[ -z "$cfg_opts" ] && return
|
||||
|
||||
configure_travis \
|
||||
--enable-cryptsetup-reencrypt \
|
||||
--enable-internal-sse-argon2 \
|
||||
"$cfg_opts" \
|
||||
|| return
|
||||
|
||||
$MAKE || return
|
||||
|
||||
make check
|
||||
}
|
||||
|
||||
function check_root
|
||||
{
|
||||
local cfg_opts="$1"
|
||||
|
||||
[ -z "$cfg_opts" ] && return
|
||||
|
||||
configure_travis \
|
||||
--enable-cryptsetup-reencrypt \
|
||||
--enable-internal-sse-argon2 \
|
||||
"$cfg_opts" \
|
||||
|| return
|
||||
|
||||
$MAKE || return
|
||||
|
||||
# FIXME: we should use -E option here
|
||||
sudo make check
|
||||
}
|
||||
|
||||
function check_nonroot_compile_only
|
||||
{
|
||||
local cfg_opts="$1"
|
||||
|
||||
[ -z "$cfg_opts" ] && return
|
||||
|
||||
configure_travis \
|
||||
--enable-cryptsetup-reencrypt \
|
||||
--enable-internal-sse-argon2 \
|
||||
"$cfg_opts" \
|
||||
|| return
|
||||
|
||||
$MAKE
|
||||
}
|
||||
|
||||
function travis_install_script
|
||||
{
|
||||
# install some packages from Ubuntu's default sources
|
||||
sudo apt-get -qq update
|
||||
sudo apt-get install -qq >/dev/null \
|
||||
sharutils \
|
||||
libgcrypt20-dev \
|
||||
libssl-dev \
|
||||
libdevmapper-dev \
|
||||
libpopt-dev \
|
||||
uuid-dev \
|
||||
libsepol1-dev \
|
||||
libtool \
|
||||
dmsetup \
|
||||
autoconf \
|
||||
automake \
|
||||
pkg-config \
|
||||
autopoint \
|
||||
gettext \
|
||||
expect \
|
||||
keyutils \
|
||||
libjson-c-dev \
|
||||
libblkid-dev \
|
||||
|| return
|
||||
}
|
||||
|
||||
function travis_before_script
|
||||
{
|
||||
set -o xtrace
|
||||
|
||||
./autogen.sh
|
||||
ret=$?
|
||||
|
||||
set +o xtrace
|
||||
return $ret
|
||||
}
|
||||
|
||||
function travis_script
|
||||
{
|
||||
local ret
|
||||
set -o xtrace
|
||||
|
||||
case "$MAKE_CHECK" in
|
||||
gcrypt)
|
||||
check_nonroot "--with-crypto_backend=gcrypt" && \
|
||||
check_root "--with-crypto_backend=gcrypt"
|
||||
;;
|
||||
gcrypt_compile)
|
||||
check_nonroot_compile_only "--with-crypto_backend=gcrypt"
|
||||
;;
|
||||
openssl)
|
||||
check_nonroot "--with-crypto_backend=openssl" && \
|
||||
check_root "--with-crypto_backend=openssl"
|
||||
;;
|
||||
openssl_compile)
|
||||
check_nonroot_compile_only "--with-crypto_backend=openssl"
|
||||
;;
|
||||
kernel)
|
||||
check_nonroot "--with-crypto_backend=kernel" && \
|
||||
check_root "--with-crypto_backend=kernel"
|
||||
;;
|
||||
kernel_compile)
|
||||
check_nonroot_compile_only "--with-crypto_backend=kernel"
|
||||
;;
|
||||
*)
|
||||
echo "error, check environment (travis.yml)" >&2
|
||||
false
|
||||
;;
|
||||
esac
|
||||
|
||||
ret=$?
|
||||
set +o xtrace
|
||||
return $ret
|
||||
}
|
||||
|
||||
function travis_after_script
|
||||
{
|
||||
return 0
|
||||
}
|
||||
39
.travis.yml
39
.travis.yml
@@ -1,39 +0,0 @@
|
||||
language: c
|
||||
|
||||
sudo: required
|
||||
dist: bionic
|
||||
|
||||
compiler:
|
||||
- gcc
|
||||
|
||||
env:
|
||||
- MAKE_CHECK="gcrypt"
|
||||
- MAKE_CHECK="openssl"
|
||||
- MAKE_CHECK="kernel"
|
||||
|
||||
branches:
|
||||
only:
|
||||
- master
|
||||
- wip-luks2
|
||||
|
||||
before_install:
|
||||
- uname -a
|
||||
- $CC --version
|
||||
- which $CC
|
||||
# workaround clang not system wide, fail on sudo make install
|
||||
- export CC=`which $CC`
|
||||
# workaround travis-ci issue #5301
|
||||
- unset PYTHON_CFLAGS
|
||||
|
||||
install:
|
||||
- source ./.travis-functions.sh
|
||||
- travis_install_script
|
||||
|
||||
before_script:
|
||||
- travis_before_script
|
||||
|
||||
script:
|
||||
- travis_script
|
||||
|
||||
after_script:
|
||||
- travis_after_script
|
||||
@@ -1,6 +0,0 @@
|
||||
Since version 1.6 this file is no longer maintained.
|
||||
|
||||
See docs/*ReleaseNotes for release changes documentation.
|
||||
|
||||
See version control history for full commit messages.
|
||||
https://gitlab.com/cryptsetup/cryptsetup/commits/master
|
||||
229
INSTALL
229
INSTALL
@@ -1,229 +0,0 @@
|
||||
Copyright 1994, 1995, 1996, 1999, 2000, 2001, 2002 Free Software
|
||||
Foundation, Inc.
|
||||
|
||||
This file is free documentation; the Free Software Foundation gives
|
||||
unlimited permission to copy, distribute and modify it.
|
||||
|
||||
Basic Installation
|
||||
==================
|
||||
|
||||
These are generic installation instructions.
|
||||
|
||||
The `configure' shell script attempts to guess correct values for
|
||||
various system-dependent variables used during compilation. It uses
|
||||
those values to create a `Makefile' in each directory of the package.
|
||||
It may also create one or more `.h' files containing system-dependent
|
||||
definitions. Finally, it creates a shell script `config.status' that
|
||||
you can run in the future to recreate the current configuration, and a
|
||||
file `config.log' containing compiler output (useful mainly for
|
||||
debugging `configure').
|
||||
|
||||
It can also use an optional file (typically called `config.cache'
|
||||
and enabled with `--cache-file=config.cache' or simply `-C') that saves
|
||||
the results of its tests to speed up reconfiguring. (Caching is
|
||||
disabled by default to prevent problems with accidental use of stale
|
||||
cache files.)
|
||||
|
||||
If you need to do unusual things to compile the package, please try
|
||||
to figure out how `configure' could check whether to do them, and mail
|
||||
diffs or instructions to the address given in the `README' so they can
|
||||
be considered for the next release. If you are using the cache, and at
|
||||
some point `config.cache' contains results you don't want to keep, you
|
||||
may remove or edit it.
|
||||
|
||||
The file `configure.ac' (or `configure.in') is used to create
|
||||
`configure' by a program called `autoconf'. You only need
|
||||
`configure.ac' if you want to change it or regenerate `configure' using
|
||||
a newer version of `autoconf'.
|
||||
|
||||
The simplest way to compile this package is:
|
||||
|
||||
1. `cd' to the directory containing the package's source code and type
|
||||
`./configure' to configure the package for your system. If you're
|
||||
using `csh' on an old version of System V, you might need to type
|
||||
`sh ./configure' instead to prevent `csh' from trying to execute
|
||||
`configure' itself.
|
||||
|
||||
Running `configure' takes a while. While running, it prints some
|
||||
messages telling which features it is checking for.
|
||||
|
||||
2. Type `make' to compile the package.
|
||||
|
||||
3. Optionally, type `make check' to run any self-tests that come with
|
||||
the package.
|
||||
|
||||
4. Type `make install' to install the programs and any data files and
|
||||
documentation.
|
||||
|
||||
5. You can remove the program binaries and object files from the
|
||||
source code directory by typing `make clean'. To also remove the
|
||||
files that `configure' created (so you can compile the package for
|
||||
a different kind of computer), type `make distclean'. There is
|
||||
also a `make maintainer-clean' target, but that is intended mainly
|
||||
for the package's developers. If you use it, you may have to get
|
||||
all sorts of other programs in order to regenerate files that came
|
||||
with the distribution.
|
||||
|
||||
Compilers and Options
|
||||
=====================
|
||||
|
||||
Some systems require unusual options for compilation or linking that
|
||||
the `configure' script does not know about. Run `./configure --help'
|
||||
for details on some of the pertinent environment variables.
|
||||
|
||||
You can give `configure' initial values for configuration parameters
|
||||
by setting variables in the command line or in the environment. Here
|
||||
is an example:
|
||||
|
||||
./configure CC=c89 CFLAGS=-O2 LIBS=-lposix
|
||||
|
||||
*Note Defining Variables::, for more details.
|
||||
|
||||
Compiling For Multiple Architectures
|
||||
====================================
|
||||
|
||||
You can compile the package for more than one kind of computer at the
|
||||
same time, by placing the object files for each architecture in their
|
||||
own directory. To do this, you must use a version of `make' that
|
||||
supports the `VPATH' variable, such as GNU `make'. `cd' to the
|
||||
directory where you want the object files and executables to go and run
|
||||
the `configure' script. `configure' automatically checks for the
|
||||
source code in the directory that `configure' is in and in `..'.
|
||||
|
||||
If you have to use a `make' that does not support the `VPATH'
|
||||
variable, you have to compile the package for one architecture at a
|
||||
time in the source code directory. After you have installed the
|
||||
package for one architecture, use `make distclean' before reconfiguring
|
||||
for another architecture.
|
||||
|
||||
Installation Names
|
||||
==================
|
||||
|
||||
By default, `make install' will install the package's files in
|
||||
`/usr/local/bin', `/usr/local/man', etc. You can specify an
|
||||
installation prefix other than `/usr/local' by giving `configure' the
|
||||
option `--prefix=PATH'.
|
||||
|
||||
You can specify separate installation prefixes for
|
||||
architecture-specific files and architecture-independent files. If you
|
||||
give `configure' the option `--exec-prefix=PATH', the package will use
|
||||
PATH as the prefix for installing programs and libraries.
|
||||
Documentation and other data files will still use the regular prefix.
|
||||
|
||||
In addition, if you use an unusual directory layout you can give
|
||||
options like `--bindir=PATH' to specify different values for particular
|
||||
kinds of files. Run `configure --help' for a list of the directories
|
||||
you can set and what kinds of files go in them.
|
||||
|
||||
If the package supports it, you can cause programs to be installed
|
||||
with an extra prefix or suffix on their names by giving `configure' the
|
||||
option `--program-prefix=PREFIX' or `--program-suffix=SUFFIX'.
|
||||
|
||||
Optional Features
|
||||
=================
|
||||
|
||||
Some packages pay attention to `--enable-FEATURE' options to
|
||||
`configure', where FEATURE indicates an optional part of the package.
|
||||
They may also pay attention to `--with-PACKAGE' options, where PACKAGE
|
||||
is something like `gnu-as' or `x' (for the X Window System). The
|
||||
`README' should mention any `--enable-' and `--with-' options that the
|
||||
package recognizes.
|
||||
|
||||
For packages that use the X Window System, `configure' can usually
|
||||
find the X include and library files automatically, but if it doesn't,
|
||||
you can use the `configure' options `--x-includes=DIR' and
|
||||
`--x-libraries=DIR' to specify their locations.
|
||||
|
||||
Specifying the System Type
|
||||
==========================
|
||||
|
||||
There may be some features `configure' cannot figure out
|
||||
automatically, but needs to determine by the type of machine the package
|
||||
will run on. Usually, assuming the package is built to be run on the
|
||||
_same_ architectures, `configure' can figure that out, but if it prints
|
||||
a message saying it cannot guess the machine type, give it the
|
||||
`--build=TYPE' option. TYPE can either be a short name for the system
|
||||
type, such as `sun4', or a canonical name which has the form:
|
||||
|
||||
CPU-COMPANY-SYSTEM
|
||||
|
||||
where SYSTEM can have one of these forms:
|
||||
|
||||
OS KERNEL-OS
|
||||
|
||||
See the file `config.sub' for the possible values of each field. If
|
||||
`config.sub' isn't included in this package, then this package doesn't
|
||||
need to know the machine type.
|
||||
|
||||
If you are _building_ compiler tools for cross-compiling, you should
|
||||
use the `--target=TYPE' option to select the type of system they will
|
||||
produce code for.
|
||||
|
||||
If you want to _use_ a cross compiler, that generates code for a
|
||||
platform different from the build platform, you should specify the
|
||||
"host" platform (i.e., that on which the generated programs will
|
||||
eventually be run) with `--host=TYPE'.
|
||||
|
||||
Sharing Defaults
|
||||
================
|
||||
|
||||
If you want to set default values for `configure' scripts to share,
|
||||
you can create a site shell script called `config.site' that gives
|
||||
default values for variables like `CC', `cache_file', and `prefix'.
|
||||
`configure' looks for `PREFIX/share/config.site' if it exists, then
|
||||
`PREFIX/etc/config.site' if it exists. Or, you can set the
|
||||
`CONFIG_SITE' environment variable to the location of the site script.
|
||||
A warning: not all `configure' scripts look for a site script.
|
||||
|
||||
Defining Variables
|
||||
==================
|
||||
|
||||
Variables not defined in a site shell script can be set in the
|
||||
environment passed to `configure'. However, some packages may run
|
||||
configure again during the build, and the customized values of these
|
||||
variables may be lost. In order to avoid this problem, you should set
|
||||
them in the `configure' command line, using `VAR=value'. For example:
|
||||
|
||||
./configure CC=/usr/local2/bin/gcc
|
||||
|
||||
will cause the specified gcc to be used as the C compiler (unless it is
|
||||
overridden in the site shell script).
|
||||
|
||||
`configure' Invocation
|
||||
======================
|
||||
|
||||
`configure' recognizes the following options to control how it
|
||||
operates.
|
||||
|
||||
`--help'
|
||||
`-h'
|
||||
Print a summary of the options to `configure', and exit.
|
||||
|
||||
`--version'
|
||||
`-V'
|
||||
Print the version of Autoconf used to generate the `configure'
|
||||
script, and exit.
|
||||
|
||||
`--cache-file=FILE'
|
||||
Enable the cache: use and save the results of the tests in FILE,
|
||||
traditionally `config.cache'. FILE defaults to `/dev/null' to
|
||||
disable caching.
|
||||
|
||||
`--config-cache'
|
||||
`-C'
|
||||
Alias for `--cache-file=config.cache'.
|
||||
|
||||
`--quiet'
|
||||
`--silent'
|
||||
`-q'
|
||||
Do not print messages saying which checks are being made. To
|
||||
suppress all normal output, redirect it to `/dev/null' (any error
|
||||
messages will still be shown).
|
||||
|
||||
`--srcdir=DIR'
|
||||
Look for the package's source code in directory DIR. Usually
|
||||
`configure' can determine that directory automatically.
|
||||
|
||||
`configure' also accepts some other, not widely useful, options. Run
|
||||
`configure --help' for more details.
|
||||
|
||||
18
Makefile.am
18
Makefile.am
@@ -1,4 +1,4 @@
|
||||
EXTRA_DIST = COPYING.LGPL FAQ docs misc
|
||||
EXTRA_DIST = README.md COPYING.LGPL FAQ docs misc autogen.sh
|
||||
SUBDIRS = po tests
|
||||
CLEANFILES =
|
||||
DISTCLEAN_TARGETS =
|
||||
@@ -11,7 +11,8 @@ AM_CPPFLAGS = \
|
||||
-DLIBDIR=\""$(libdir)"\" \
|
||||
-DPREFIX=\""$(prefix)"\" \
|
||||
-DSYSCONFDIR=\""$(sysconfdir)"\" \
|
||||
-DVERSION=\""$(VERSION)"\"
|
||||
-DVERSION=\""$(VERSION)"\" \
|
||||
-DEXTERNAL_LUKS2_TOKENS_PATH=\"${EXTERNAL_LUKS2_TOKENS_PATH}\"
|
||||
AM_CFLAGS = -Wall
|
||||
AM_LDFLAGS =
|
||||
|
||||
@@ -19,10 +20,13 @@ LDADD = $(LTLIBINTL) -lm
|
||||
|
||||
tmpfilesddir = @DEFAULT_TMPFILESDIR@
|
||||
|
||||
include_HEADERS =
|
||||
lib_LTLIBRARIES =
|
||||
noinst_LTLIBRARIES =
|
||||
sbin_PROGRAMS =
|
||||
man8_MANS =
|
||||
tmpfilesd_DATA =
|
||||
pkgconfig_DATA =
|
||||
|
||||
include man/Makemodule.am
|
||||
|
||||
@@ -35,12 +39,14 @@ include lib/crypto_backend/Makemodule.am
|
||||
include lib/Makemodule.am
|
||||
|
||||
include src/Makemodule.am
|
||||
include tokens/Makemodule.am
|
||||
|
||||
ACLOCAL_AMFLAGS = -I m4
|
||||
|
||||
DISTCHECK_CONFIGURE_FLAGS = \
|
||||
--with-tmpfilesdir=$$dc_install_base/usr/lib/tmpfiles.d \
|
||||
--enable-internal-argon2 --enable-internal-sse-argon2
|
||||
--enable-internal-argon2 --enable-internal-sse-argon2 \
|
||||
--enable-external-tokens --enable-ssh-token
|
||||
|
||||
distclean-local:
|
||||
-find . -name \*~ -o -name \*.orig -o -name \*.rej | xargs rm -f
|
||||
@@ -48,3 +54,9 @@ distclean-local:
|
||||
|
||||
clean-local:
|
||||
-rm -rf docs/doxygen_api_docs libargon2.la
|
||||
|
||||
install-data-local:
|
||||
$(MKDIR_P) -m 0755 $(DESTDIR)/${EXTERNAL_LUKS2_TOKENS_PATH}
|
||||
|
||||
uninstall-local:
|
||||
rmdir $(DESTDIR)/${EXTERNAL_LUKS2_TOKENS_PATH} 2>/dev/null || :
|
||||
|
||||
31
README
31
README
@@ -1,31 +0,0 @@
|
||||
|
||||
cryptsetup
|
||||
|
||||
setup cryptographic volumes for dm-crypt (including LUKS extension)
|
||||
|
||||
WEB PAGE:
|
||||
|
||||
https://gitlab.com/cryptsetup/cryptsetup/
|
||||
|
||||
FAQ:
|
||||
|
||||
https://gitlab.com/cryptsetup/cryptsetup/wikis/FrequentlyAskedQuestions
|
||||
|
||||
MAILING LIST:
|
||||
|
||||
E-MAIL: dm-crypt@saout.de
|
||||
URL: http://www.saout.de/mailman/listinfo/dm-crypt
|
||||
|
||||
DOWNLOAD:
|
||||
|
||||
https://www.kernel.org/pub/linux/utils/cryptsetup/
|
||||
|
||||
SOURCE CODE:
|
||||
|
||||
URL: https://gitlab.com/cryptsetup/cryptsetup/tree/master
|
||||
Checkout: git clone https://gitlab.com/cryptsetup/cryptsetup.git
|
||||
|
||||
NLS (PO TRANSLATIONS):
|
||||
|
||||
PO files are maintained by:
|
||||
http://translationproject.org/domain/cryptsetup.html
|
||||
48
README.md
48
README.md
@@ -6,11 +6,11 @@ What the ...?
|
||||
on the [DMCrypt](https://gitlab.com/cryptsetup/cryptsetup/wikis/DMCrypt) kernel module.
|
||||
|
||||
These include **plain** **dm-crypt** volumes, **LUKS** volumes, **loop-AES**,
|
||||
**TrueCrypt** (including **VeraCrypt** extension) and BitLocker formats.
|
||||
**TrueCrypt** (including **VeraCrypt** extension) and **BitLocker** formats.
|
||||
|
||||
The project also includes a **veritysetup** utility used to conveniently setup
|
||||
[DMVerity](https://gitlab.com/cryptsetup/cryptsetup/wikis/DMVerity) block integrity checking kernel module
|
||||
and, since version 2.0, **integritysetup** to setup
|
||||
and **integritysetup** to setup
|
||||
[DMIntegrity](https://gitlab.com/cryptsetup/cryptsetup/wikis/DMIntegrity) block integrity kernel module.
|
||||
|
||||
|
||||
@@ -44,25 +44,16 @@ Download
|
||||
--------
|
||||
All release tarballs and release notes are hosted on [kernel.org](https://www.kernel.org/pub/linux/utils/cryptsetup/).
|
||||
|
||||
**The latest testing cryptsetup version is 2.3.0-rc0**
|
||||
* [cryptsetup-2.3.0-rc0.tar.xz](https://www.kernel.org/pub/linux/utils/cryptsetup/v2.3/cryptsetup-2.3.0-rc0.tar.xz)
|
||||
* Signature [cryptsetup-2.3.0-rc0.tar.sign](https://www.kernel.org/pub/linux/utils/cryptsetup/v2.3/cryptsetup-2.3.0-rc0.tar.sign)
|
||||
**The latest stable cryptsetup version is 2.4.0**
|
||||
* [cryptsetup-2.4.0.tar.xz](https://www.kernel.org/pub/linux/utils/cryptsetup/v2.4/cryptsetup-2.4.0.tar.xz)
|
||||
* Signature [cryptsetup-2.4.0.tar.sign](https://www.kernel.org/pub/linux/utils/cryptsetup/v2.4/cryptsetup-2.4.0.tar.sign)
|
||||
_(You need to decompress file first to check signature.)_
|
||||
* [Cryptsetup 2.3.0-rc0 Release Notes](https://www.kernel.org/pub/linux/utils/cryptsetup/v2.3/v2.3.0-rc0-ReleaseNotes).
|
||||
|
||||
**The latest stable cryptsetup version is 2.2.2**
|
||||
* [cryptsetup-2.2.2.tar.xz](https://www.kernel.org/pub/linux/utils/cryptsetup/v2.2/cryptsetup-2.2.2.tar.xz)
|
||||
* Signature [cryptsetup-2.2.2.tar.sign](https://www.kernel.org/pub/linux/utils/cryptsetup/v2.2/cryptsetup-2.2.2.tar.sign)
|
||||
_(You need to decompress file first to check signature.)_
|
||||
* [Cryptsetup 2.2.2 Release Notes](https://www.kernel.org/pub/linux/utils/cryptsetup/v2.2/v2.2.2-ReleaseNotes).
|
||||
* [Cryptsetup 2.4.0 Release Notes](https://www.kernel.org/pub/linux/utils/cryptsetup/v2.4/v2.4.0-ReleaseNotes).
|
||||
|
||||
Previous versions
|
||||
* [Version 2.2.1](https://www.kernel.org/pub/linux/utils/cryptsetup/v2.2/cryptsetup-2.2.1.tar.xz) -
|
||||
[Signature](https://www.kernel.org/pub/linux/utils/cryptsetup/v2.2/cryptsetup-2.2.1.tar.sign) -
|
||||
[Release Notes](https://www.kernel.org/pub/linux/utils/cryptsetup/v2.2/v2.2.0-ReleaseNotes).
|
||||
* [Version 2.0.6](https://www.kernel.org/pub/linux/utils/cryptsetup/v2.0/cryptsetup-2.0.6.tar.xz) -
|
||||
[Signature](https://www.kernel.org/pub/linux/utils/cryptsetup/v2.0/cryptsetup-2.0.6.tar.sign) -
|
||||
[Release Notes](https://www.kernel.org/pub/linux/utils/cryptsetup/v2.0/v2.0.6-ReleaseNotes).
|
||||
* [Version 2.3.6](https://www.kernel.org/pub/linux/utils/cryptsetup/v2.3/cryptsetup-2.3.6.tar.xz) -
|
||||
[Signature](https://www.kernel.org/pub/linux/utils/cryptsetup/v2.3/cryptsetup-2.3.6.tar.sign) -
|
||||
[Release Notes](https://www.kernel.org/pub/linux/utils/cryptsetup/v2.3/v2.3.6-ReleaseNotes).
|
||||
* [Version 1.7.5](https://www.kernel.org/pub/linux/utils/cryptsetup/v1.7/cryptsetup-1.7.5.tar.xz) -
|
||||
[Signature](https://www.kernel.org/pub/linux/utils/cryptsetup/v1.7/cryptsetup-1.7.5.tar.sign) -
|
||||
[Release Notes](https://www.kernel.org/pub/linux/utils/cryptsetup/v1.7/v1.7.5-ReleaseNotes).
|
||||
@@ -76,14 +67,27 @@ For libcryptsetup documentation see [libcryptsetup API](https://mbroz.fedorapeop
|
||||
|
||||
The libcryptsetup API/ABI changes are tracked in [compatibility report](https://abi-laboratory.pro/tracker/timeline/cryptsetup/).
|
||||
|
||||
NLS PO files are maintained by [TranslationProject](http://translationproject.org/domain/cryptsetup.html).
|
||||
NLS PO files are maintained by [TranslationProject](https://translationproject.org/domain/cryptsetup.html).
|
||||
|
||||
Required packages
|
||||
-----------------
|
||||
All distributions provide cryptsetup as distro package. If you need to compile cryptsetup youfself, some packages are required for compilation. Please always prefer distro specific build tools to manually configuring cryptsetup.
|
||||
Fo available compile options, check ``configure --help`` for more info. If you are using a git snapshot, you need to generate configure script with ``autogen.sh`` script.
|
||||
|
||||
Here is the list of packages needed for the compilation of project for particular distributions:
|
||||
* For Fedora: `git gcc make autoconf automake gettext-devel pkgconfig openssl-devel popt-devel device-mapper-devel libuuid-devel json-c-devel libblkid-devel findutils libtool libssh-devel tar`. Optionally `libargon2-devel libpwquality-devel`. To run internal testsuite you also need `sharutils device-mapper jq vim-common expect keyutils netcat shadow-utils openssh-clients openssh sshpass`.
|
||||
|
||||
* For Debian and Ubuntu: `git gcc make autoconf automake autopoint pkg-config libtool gettext libssl-dev libdevmapper-dev libpopt-dev uuid-dev libsepol1-dev libjson-c-dev libssh-dev libblkid-dev tar`. Optionally `libargon2-0-dev libpwquality-dev`. To run internal testsuite you also need `sharutils dmsetup jq xxd expect keyutils netcat passwd openssh-client sshpass`
|
||||
|
||||
Note that the list could change as distributions evolve.
|
||||
|
||||
Help!
|
||||
-----
|
||||
Please always read [FAQ](https://gitlab.com/cryptsetup/cryptsetup/wikis/FrequentlyAskedQuestions) first.
|
||||
Please read the [FAQ](https://gitlab.com/cryptsetup/cryptsetup/wikis/FrequentlyAskedQuestions) and search the manuals (man page, man-page) before posting questions in the mailing list. You will be able to ask better questions and better understand the answers. The FAQ is online and in the source code. The man pages are in source and should be available after installation using standard man commands. e.g. man cryptsetup
|
||||
|
||||
For cryptsetup and LUKS related questions, please use the dm-crypt mailing list, [dm-crypt@saout.de](mailto:dm-crypt@saout.de).
|
||||
|
||||
If you want to subscribe just send an empty mail to [dm-crypt-subscribe@saout.de](mailto:dm-crypt-subscribe@saout.de).
|
||||
|
||||
You can also browse [list archive](http://www.saout.de/pipermail/dm-crypt/) or read it through
|
||||
[web interface](https://marc.info/?l=dm-crypt).
|
||||
You can also browse [list archive](https://www.saout.de/pipermail/dm-crypt/) or read and search it through
|
||||
[web interface on lore.kernel.org](https://lore.kernel.org/dm-crypt/) or alternatively on [marc.info](https://marc.info/?l=dm-crypt).
|
||||
|
||||
1
TODO
1
TODO
@@ -1 +0,0 @@
|
||||
Please see issues tracked at https://gitlab.com/cryptsetup/cryptsetup/issues.
|
||||
31
autogen.sh
31
autogen.sh
@@ -9,25 +9,31 @@ DIE=0
|
||||
(autopoint --version) < /dev/null > /dev/null 2>&1 || {
|
||||
echo
|
||||
echo "**Error**: You must have autopoint installed."
|
||||
echo "Download the appropriate package for your distribution,"
|
||||
echo "or see http://www.gnu.org/software/gettext"
|
||||
echo "Download the appropriate package for your distribution."
|
||||
DIE=1
|
||||
}
|
||||
|
||||
|
||||
(msgfmt --version) < /dev/null > /dev/null 2>&1 || {
|
||||
echo
|
||||
echo "**Warning**: You should have gettext installed."
|
||||
echo "Download the appropriate package for your distribution."
|
||||
echo "To disable translation, you can also use --disable-nls"
|
||||
echo "configure option."
|
||||
}
|
||||
|
||||
(autoconf --version) < /dev/null > /dev/null 2>&1 || {
|
||||
echo
|
||||
echo "**Error**: You must have autoconf installed to."
|
||||
echo "Download the appropriate package for your distribution,"
|
||||
echo "or get the source tarball at ftp://ftp.gnu.org/pub/gnu/"
|
||||
echo "**Error**: You must have autoconf installed."
|
||||
echo "Download the appropriate package for your distribution."
|
||||
DIE=1
|
||||
}
|
||||
|
||||
(grep "^AM_PROG_LIBTOOL" $srcdir/configure.ac >/dev/null) && {
|
||||
(libtool --version) < /dev/null > /dev/null 2>&1 || {
|
||||
(grep "^LT_INIT" $srcdir/configure.ac >/dev/null) && {
|
||||
(libtoolize --version) < /dev/null > /dev/null 2>&1 || {
|
||||
echo
|
||||
echo "**Error**: You must have libtool installed."
|
||||
echo "Get ftp://ftp.gnu.org/pub/gnu/"
|
||||
echo "(or a newer version if it is available)"
|
||||
echo "**Error**: You must have libtoolize installed."
|
||||
echo "Download the appropriate package for your distribution."
|
||||
DIE=1
|
||||
}
|
||||
}
|
||||
@@ -35,8 +41,7 @@ DIE=0
|
||||
(automake --version) < /dev/null > /dev/null 2>&1 || {
|
||||
echo
|
||||
echo "**Error**: You must have automake installed."
|
||||
echo "Get ftp://ftp.gnu.org/pub/gnu/"
|
||||
echo "(or a newer version if it is available)"
|
||||
echo "Download the appropriate package for your distribution."
|
||||
DIE=1
|
||||
NO_AUTOMAKE=yes
|
||||
}
|
||||
@@ -47,8 +52,6 @@ test -n "$NO_AUTOMAKE" || (aclocal --version) < /dev/null > /dev/null 2>&1 || {
|
||||
echo
|
||||
echo "**Error**: Missing aclocal. The version of automake"
|
||||
echo "installed doesn't appear recent enough."
|
||||
echo "Get ftp://ftp.gnu.org/pub/gnu/"
|
||||
echo "(or a newer version if it is available)"
|
||||
DIE=1
|
||||
}
|
||||
|
||||
|
||||
66
configure.ac
66
configure.ac
@@ -1,9 +1,9 @@
|
||||
AC_PREREQ([2.67])
|
||||
AC_INIT([cryptsetup],[2.3.0])
|
||||
AC_INIT([cryptsetup],[2.4.0])
|
||||
|
||||
dnl library version from <major>.<minor>.<release>[-<suffix>]
|
||||
LIBCRYPTSETUP_VERSION=$(echo $PACKAGE_VERSION | cut -f1 -d-)
|
||||
LIBCRYPTSETUP_VERSION_INFO=18:0:6
|
||||
LIBCRYPTSETUP_VERSION_INFO=19:0:7
|
||||
|
||||
AM_SILENT_RULES([yes])
|
||||
AC_CONFIG_SRCDIR(src/cryptsetup.c)
|
||||
@@ -16,7 +16,7 @@ AC_CONFIG_HEADERS([config.h:config.h.in])
|
||||
|
||||
# For old automake use this
|
||||
#AM_INIT_AUTOMAKE(dist-xz subdir-objects)
|
||||
AM_INIT_AUTOMAKE([dist-xz 1.12 serial-tests subdir-objects])
|
||||
AM_INIT_AUTOMAKE([dist-xz 1.12 serial-tests subdir-objects foreign])
|
||||
|
||||
if test "x$prefix" = "xNONE"; then
|
||||
sysconfdir=/etc
|
||||
@@ -30,9 +30,11 @@ AM_PROG_CC_C_O
|
||||
AC_PROG_CPP
|
||||
AC_PROG_INSTALL
|
||||
AC_PROG_MAKE_SET
|
||||
AC_PROG_MKDIR_P
|
||||
AC_ENABLE_STATIC(no)
|
||||
LT_INIT
|
||||
PKG_PROG_PKG_CONFIG
|
||||
AM_ICONV
|
||||
|
||||
dnl ==========================================================================
|
||||
dnl define PKG_CHECK_VAR for old pkg-config <= 0.28
|
||||
@@ -59,6 +61,12 @@ AC_HEADER_DIRENT
|
||||
AC_HEADER_STDC
|
||||
AC_CHECK_HEADERS(fcntl.h malloc.h inttypes.h sys/ioctl.h sys/mman.h \
|
||||
sys/sysmacros.h sys/statvfs.h ctype.h unistd.h locale.h byteswap.h endian.h stdint.h)
|
||||
AC_CHECK_DECLS([O_CLOEXEC],,[AC_DEFINE([O_CLOEXEC],[0], [Defined to 0 if not provided])],
|
||||
[[
|
||||
#ifdef HAVE_FCNTL_H
|
||||
# include <fcntl.h>
|
||||
#endif
|
||||
]])
|
||||
|
||||
AC_CHECK_HEADERS(uuid/uuid.h,,[AC_MSG_ERROR([You need the uuid library.])])
|
||||
AC_CHECK_HEADER(libdevmapper.h,,[AC_MSG_ERROR([You need the device-mapper library.])])
|
||||
@@ -108,6 +116,25 @@ AC_FUNC_FSEEKO
|
||||
AC_PROG_GCC_TRADITIONAL
|
||||
AC_FUNC_STRERROR_R
|
||||
|
||||
dnl ==========================================================================
|
||||
dnl LUKS2 external tokens
|
||||
|
||||
AC_ARG_ENABLE([external-tokens],
|
||||
AS_HELP_STRING([--disable-external-tokens], [disable external LUKS2 tokens]),
|
||||
[], [enable_external_tokens=yes])
|
||||
if test "x$enable_external_tokens" = "xyes"; then
|
||||
AC_DEFINE(USE_EXTERNAL_TOKENS, 1, [Use external tokens])
|
||||
fi
|
||||
|
||||
AC_ARG_ENABLE([ssh-token],
|
||||
AS_HELP_STRING([--disable-ssh-token], [disable LUKS2 ssh-token]),
|
||||
[], [enable_ssh_token=yes])
|
||||
AM_CONDITIONAL(SSHPLUGIN_TOKEN, test "x$enable_ssh_token" = "xyes")
|
||||
|
||||
if test "x$enable_ssh_token" = "xyes" -a "x$enable_external_tokens" = "xno"; then
|
||||
AC_MSG_ERROR([Requested LUKS2 ssh-token build, but external tokens are disabled.])
|
||||
fi
|
||||
|
||||
dnl ==========================================================================
|
||||
|
||||
AM_GNU_GETTEXT([external],[need-ngettext])
|
||||
@@ -169,7 +196,15 @@ AC_DEFINE_UNQUOTED([PASSWDQC_CONFIG_FILE], ["$use_passwdqc_config"], [passwdqc l
|
||||
if test "x$enable_passwdqc" = "xyes"; then
|
||||
AC_DEFINE(ENABLE_PASSWDQC, 1, [Enable password quality checking using passwdqc library])
|
||||
|
||||
PASSWDQC_LIBS="-lpasswdqc"
|
||||
saved_LIBS="$LIBS"
|
||||
AC_SEARCH_LIBS([passwdqc_check], [passwdqc])
|
||||
case "$ac_cv_search_passwdqc_check" in
|
||||
no) AC_MSG_ERROR([failed to find passwdqc_check]) ;;
|
||||
-l*) PASSWDQC_LIBS="$ac_cv_search_passwdqc_check" ;;
|
||||
*) PASSWDQC_LIBS= ;;
|
||||
esac
|
||||
AC_CHECK_FUNCS([passwdqc_params_free])
|
||||
LIBS="$saved_LIBS"
|
||||
fi
|
||||
|
||||
if test "x$enable_pwquality$enable_passwdqc" = "xyesyes"; then
|
||||
@@ -348,6 +383,7 @@ AC_CHECK_DECLS([dm_task_retry_remove], [], [], [#include <libdevmapper.h>])
|
||||
AC_CHECK_DECLS([dm_task_deferred_remove], [], [], [#include <libdevmapper.h>])
|
||||
AC_CHECK_DECLS([dm_device_has_mounted_fs], [], [], [#include <libdevmapper.h>])
|
||||
AC_CHECK_DECLS([dm_device_has_holders], [], [], [#include <libdevmapper.h>])
|
||||
AC_CHECK_DECLS([dm_device_get_name], [], [], [#include <libdevmapper.h>])
|
||||
AC_CHECK_DECLS([DM_DEVICE_GET_TARGET_VERSION], [], [], [#include <libdevmapper.h>])
|
||||
AC_CHECK_DECLS([DM_UDEV_DISABLE_DISK_RULES_FLAG], [have_cookie=yes], [have_cookie=no], [#include <libdevmapper.h>])
|
||||
if test "x$enable_udev" = xyes; then
|
||||
@@ -364,6 +400,12 @@ PKG_CHECK_MODULES([JSON_C], [json-c])
|
||||
AC_CHECK_DECLS([json_object_object_add_ex], [], [], [#include <json-c/json.h>])
|
||||
AC_CHECK_DECLS([json_object_deep_copy], [], [], [#include <json-c/json.h>])
|
||||
|
||||
dnl Check for libssh for SSH plugin
|
||||
if test "x$enable_ssh_token" = "xyes"; then
|
||||
PKG_CHECK_MODULES([LIBSSH], [libssh])
|
||||
AC_CHECK_DECLS([ssh_session_is_known_server], [], [], [#include <libssh/libssh.h>])
|
||||
fi
|
||||
|
||||
dnl Crypto backend configuration.
|
||||
AC_ARG_WITH([crypto_backend],
|
||||
AS_HELP_STRING([--with-crypto_backend=BACKEND], [crypto backend (gcrypt/openssl/nss/kernel/nettle) [openssl]]),
|
||||
@@ -520,6 +562,8 @@ AC_SUBST([JSON_C_LIBS])
|
||||
AC_SUBST([LIBARGON2_LIBS])
|
||||
AC_SUBST([BLKID_LIBS])
|
||||
|
||||
AC_SUBST([LIBSSH_LIBS])
|
||||
|
||||
AC_SUBST([LIBCRYPTSETUP_VERSION])
|
||||
AC_SUBST([LIBCRYPTSETUP_VERSION_INFO])
|
||||
|
||||
@@ -575,7 +619,7 @@ if test "x$enable_luks_adjust_xts_keysize" = "xyes"; then
|
||||
AC_DEFINE(ENABLE_LUKS_ADJUST_XTS_KEYSIZE, 1, [XTS mode - double default LUKS keysize if needed])
|
||||
fi
|
||||
|
||||
CS_STR_WITH([luks2-pbkdf], [Default PBKDF algorithm (pbkdf2 or argon2i/argon2id) for LUKS2], [argon2i])
|
||||
CS_STR_WITH([luks2-pbkdf], [Default PBKDF algorithm (pbkdf2 or argon2i/argon2id) for LUKS2], [argon2id])
|
||||
CS_NUM_WITH([luks1-iter-time], [PBKDF2 iteration time for LUKS1 (in ms)], [2000])
|
||||
CS_NUM_WITH([luks2-iter-time], [Argon2 PBKDF iteration time for LUKS2 (in ms)], [2000])
|
||||
CS_NUM_WITH([luks2-memory-kb], [Argon2 PBKDF memory cost for LUKS2 (in kB)], [1048576])
|
||||
@@ -588,7 +632,8 @@ CS_STR_WITH([loopaes-cipher], [cipher for loop-AES mode], [aes])
|
||||
CS_NUM_WITH([loopaes-keybits],[key length in bits for loop-AES mode], [256])
|
||||
|
||||
CS_NUM_WITH([keyfile-size-maxkb],[maximum keyfile size (in KiB)], [8192])
|
||||
CS_NUM_WITH([passphrase-size-max],[maximum keyfile size (in characters)], [512])
|
||||
CS_NUM_WITH([integrity-keyfile-size-maxkb],[maximum integritysetup keyfile size (in KiB)], [4])
|
||||
CS_NUM_WITH([passphrase-size-max],[maximum passphrase size (in characters)], [512])
|
||||
|
||||
CS_STR_WITH([verity-hash], [hash function for verity mode], [sha256])
|
||||
CS_NUM_WITH([verity-data-block], [data block size for verity mode], [4096])
|
||||
@@ -616,6 +661,15 @@ test -z "$with_luks2_lock_dir_perms" && with_luks2_lock_dir_perms=0700
|
||||
DEFAULT_LUKS2_LOCK_DIR_PERMS=$with_luks2_lock_dir_perms
|
||||
AC_SUBST(DEFAULT_LUKS2_LOCK_DIR_PERMS)
|
||||
|
||||
CS_STR_WITH([luks2-external-tokens-path], [path to directory with LUKSv2 external token handlers (plugins)], [LIBDIR/cryptsetup])
|
||||
if test -n "$with_luks2_external_tokens_path"; then
|
||||
CS_ABSPATH([${with_luks2_external_tokens_path}],[with-luks2-external-tokens-path])
|
||||
EXTERNAL_LUKS2_TOKENS_PATH=$with_luks2_external_tokens_path
|
||||
else
|
||||
EXTERNAL_LUKS2_TOKENS_PATH="\${libdir}/cryptsetup"
|
||||
fi
|
||||
AC_SUBST(EXTERNAL_LUKS2_TOKENS_PATH)
|
||||
|
||||
dnl Override default LUKS format version (for cryptsetup or cryptsetup-reencrypt format actions only).
|
||||
AC_ARG_WITH([default_luks_format],
|
||||
AS_HELP_STRING([--with-default-luks-format=FORMAT], [default LUKS format version (LUKS1/LUKS2) [LUKS2]]),
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* libcryptsetup API log example
|
||||
*
|
||||
* Copyright (C) 2011-2020 Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2011-2021 Red Hat, Inc. All rights reserved.
|
||||
*
|
||||
* This file is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* libcryptsetup API - using LUKS device example
|
||||
*
|
||||
* Copyright (C) 2011-2020 Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2011-2021 Red Hat, Inc. All rights reserved.
|
||||
*
|
||||
* This file is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
|
||||
45
docs/v2.3.1-ReleaseNotes
Normal file
45
docs/v2.3.1-ReleaseNotes
Normal file
@@ -0,0 +1,45 @@
|
||||
Cryptsetup 2.3.1 Release Notes
|
||||
==============================
|
||||
Stable bug-fix release.
|
||||
|
||||
All users of cryptsetup 2.x should upgrade to this version.
|
||||
|
||||
Changes since version 2.3.0
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
* Support VeraCrypt 128 bytes passwords.
|
||||
VeraCrypt now allows passwords of maximal length 128 bytes
|
||||
(compared to legacy TrueCrypt where it was limited by 64 bytes).
|
||||
|
||||
* Strip extra newline from BitLocker recovery keys
|
||||
There might be a trailing newline added by the text editor when
|
||||
the recovery passphrase was passed using the --key-file option.
|
||||
|
||||
* Detect separate libiconv library.
|
||||
It should fix compilation issues on distributions with iconv
|
||||
implemented in a separate library.
|
||||
|
||||
* Various fixes and workarounds to build on old Linux distributions.
|
||||
|
||||
* Split lines with hexadecimal digest printing for large key-sizes.
|
||||
|
||||
* Do not wipe the device with no integrity profile.
|
||||
With --integrity none we performed useless full device wipe.
|
||||
|
||||
* Workaround for dm-integrity kernel table bug.
|
||||
Some kernels show an invalid dm-integrity mapping table
|
||||
if superblock contains the "recalculate" bit. This causes
|
||||
integritysetup to not recognize the dm-integrity device.
|
||||
Integritysetup now specifies kernel options such a way that
|
||||
even on unpatched kernels mapping table is correct.
|
||||
|
||||
* Print error message if LUKS1 keyslot cannot be processed.
|
||||
If the crypto backend is missing support for hash algorithms
|
||||
used in PBKDF2, the error message was not visible.
|
||||
|
||||
* Properly align LUKS2 keyslots area on conversion.
|
||||
If the LUKS1 payload offset (data offset) is not aligned
|
||||
to 4 KiB boundary, new LUKS2 keyslots area in now aligned properly.
|
||||
|
||||
* Validate LUKS2 earlier on conversion to not corrupt the device
|
||||
if binary keyslots areas metadata are not correct.
|
||||
42
docs/v2.3.2-ReleaseNotes
Normal file
42
docs/v2.3.2-ReleaseNotes
Normal file
@@ -0,0 +1,42 @@
|
||||
Cryptsetup 2.3.2 Release Notes
|
||||
==============================
|
||||
Stable bug-fix release.
|
||||
|
||||
All users of cryptsetup 2.x should upgrade to this version.
|
||||
|
||||
Changes since version 2.3.1
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
* Support compilation with json-c library version 0.14.
|
||||
|
||||
* Update FAQ document for some LUKS2 specific information.
|
||||
|
||||
* Add option to dump content of LUKS2 unbound keyslot:
|
||||
cryptsetup luksDump --unbound -S <slot> <device>
|
||||
or optionally with --master-key-file option.
|
||||
|
||||
The slot number --key-slot (-S) option is mandatory here.
|
||||
|
||||
An unbound keyslot store a key is that is not assigned to data
|
||||
area on disk (LUKS2 allows to store arbitrary keys).
|
||||
|
||||
* Rephrase some error messages and remove redundant end-of-lines.
|
||||
|
||||
* Add support for discards (TRIM) for standalone dm-integrity devices.
|
||||
Linux kernel 5.7 adds support for optional discard/TRIM operation
|
||||
over dm-integrity devices.
|
||||
|
||||
It is now supported through --allow-discards integritysetup option.
|
||||
Note you need to add this flag in all activation calls.
|
||||
|
||||
Note that this option cannot be used for LUKS2 authenticated encryption
|
||||
(that uses dm-integrity for storing additional per-sector metadata).
|
||||
|
||||
* Fix cryptsetup-reencrypt to work on devices that do not allow
|
||||
direct-io device access.
|
||||
|
||||
* Fix a crash in the BitLocker-compatible code error path.
|
||||
|
||||
* Fix Veracrypt compatible support for longer (>64 bytes) passphrases.
|
||||
It allows some older images to be correctly opened again.
|
||||
The issue was introduced in version 2.3.1.
|
||||
42
docs/v2.3.3-ReleaseNotes
Normal file
42
docs/v2.3.3-ReleaseNotes
Normal file
@@ -0,0 +1,42 @@
|
||||
Cryptsetup 2.3.3 Release Notes
|
||||
==============================
|
||||
Stable bug-fix release.
|
||||
|
||||
All users of cryptsetup 2.x should upgrade to this version.
|
||||
|
||||
Changes since version 2.3.2
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
* Fix BitLocker compatible device access that uses native 4kB sectors.
|
||||
|
||||
Devices formatted with storage that natively support 4096-bytes
|
||||
sectors can also use this sector size for encryption units.
|
||||
|
||||
* Support large IV count (--iv-large-sectors) cryptsetup option
|
||||
for plain device mapping.
|
||||
|
||||
The large IV count is supported in dm-crypt together with larger
|
||||
sector encryption. It counts the Initialization Vector (IV) in
|
||||
a larger sector size instead of 512-bytes sectors.
|
||||
|
||||
This option does not have any performance or security impact,
|
||||
but it can be used for accessing incompatible existing disk images
|
||||
from other systems.
|
||||
|
||||
Only open action with plain device type and sector size > 512 bytes
|
||||
are supported.
|
||||
|
||||
* Fix a memory leak in BitLocker compatible handling.
|
||||
|
||||
* Allow EBOIV (Initialization Vector algorithm) use.
|
||||
|
||||
The EBOIV initialization vector is intended to be used internally
|
||||
with BitLocker devices (for CBC mode). It can now be used also
|
||||
outside of the BitLocker compatible code.
|
||||
|
||||
* Require both keyslot cipher and key size options.
|
||||
|
||||
If these LUKS2 keyslot parameters were not specified together,
|
||||
cryptsetup silently failed.
|
||||
|
||||
* Update to man pages and FAQ.
|
||||
112
docs/v2.3.4-ReleaseNotes
Normal file
112
docs/v2.3.4-ReleaseNotes
Normal file
@@ -0,0 +1,112 @@
|
||||
Cryptsetup 2.3.4 Release Notes
|
||||
==============================
|
||||
Stable bug-fix release with a security fix (32-bit only).
|
||||
|
||||
All users of cryptsetup 2.2.x and later should upgrade to this version.
|
||||
|
||||
Changes since version 2.3.3
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
* Fix a possible out-of-bounds memory write while validating LUKS2 data
|
||||
segments metadata (CVE-2020-14382).
|
||||
|
||||
This problem can be triggered only on 32-bit builds (64-bit systems
|
||||
are not affected).
|
||||
|
||||
LUKS2 format validation code contains a bug in segments validation code
|
||||
where the code does not check for possible overflow on memory allocation.
|
||||
|
||||
Due to the bug, the libcryptsetup can be tricked to expect such allocation
|
||||
was successful. Later it may read data from image crafted by an attacker and
|
||||
actually write such data beyond allocated memory.
|
||||
|
||||
The bug was introduced in cryptsetup 2.2.0. All later releases until 2.3.4
|
||||
are affected.
|
||||
|
||||
If you only backport the fix for this CVE, these master branch git commits
|
||||
should be backported:
|
||||
52f5cb8cedf22fb3e14c744814ec8af7614146c7
|
||||
46ee71edcd13e1dad50815ad65c28779aa6f7503
|
||||
752c9a52798f11d3b765b673ebaa3058eb25316e
|
||||
|
||||
Thanks to Tobias Stoeckmann for discovering this issue.
|
||||
|
||||
* Ignore reported optimal IO size if not aligned to minimal page size.
|
||||
|
||||
Some USB enclosures report bogus block device topology (see lsblk -t) that
|
||||
prevents LUKS2 format with 4k sector size (reported values are not correctly
|
||||
aligned). The code now ignores such values and uses the default alignment.
|
||||
|
||||
* Added support for new no_read/write_wrokqueue dm-crypt options (kernel 5.9).
|
||||
|
||||
These performance options, introduced in kernel 5.9, configure dm-crypt
|
||||
to bypass read or write workqueues and run encryption synchronously.
|
||||
|
||||
Use --perf-no_read_workqueue or --perf-no_write_workqueue cryptsetup arguments
|
||||
to use these dm-crypt flags.
|
||||
|
||||
These options are available only for low-level dm-crypt performance tuning,
|
||||
use only if you need a change to default dm-crypt behavior.
|
||||
|
||||
For LUKS2, these flags can be persistently stored in metadata with
|
||||
the --persistent option.
|
||||
|
||||
* Added support panic_on_corruption option for dm-verity devices (kernel 5.9).
|
||||
|
||||
Veritysetup now supports --panic-on-corruption argument that configures
|
||||
the dm-verity device to panics kernel if a corruption is detected.
|
||||
|
||||
This option is intended for specific configurations, do not use it in
|
||||
standard configurations.
|
||||
|
||||
* Support --master-key-file option for online LUKS2 reencryption
|
||||
|
||||
This can be used for reencryption of devices that uses protected key AES cipher
|
||||
on some mainframes crypto accelerators.
|
||||
|
||||
* Always return EEXIST error code if a device already exists.
|
||||
|
||||
Some libcryptsetup functions (activate_by*) now return EEXIST error code,
|
||||
so the caller can distinguish that call fails because some parallel process
|
||||
already activated the device.
|
||||
Previously all fails returned EINVAL (invalid value).
|
||||
|
||||
* Fix a problem in integritysetup if a hash algorithm has dash in the name.
|
||||
|
||||
If users want to use blake2b/blake2s, the kernel algorithm name includes
|
||||
a dash (like "blake2s-256").
|
||||
Theses algorithms can now be used for integritysetup devices.
|
||||
|
||||
* Fix crypto backend to properly handle ECB mode.
|
||||
|
||||
Even though it should never be used, it should still work for testing :)
|
||||
This fixes a bug introduced in cryptsetup version 2.3.2.
|
||||
|
||||
* TrueCrypt/VeraCrypt compatible mode now supports the activation of devices
|
||||
with a larger sector.
|
||||
|
||||
TrueCrypt/VeraCrypt always uses 512-byte sector for encryption, but for devices
|
||||
with a larger native sector, it stores this value in the header.
|
||||
|
||||
This patch allows activation of such devices, basically ignoring
|
||||
the mentioned sector size.
|
||||
|
||||
* LUKS2: Do not create excessively large headers.
|
||||
|
||||
When creating a LUKS2 header with a specified --offset larger than
|
||||
the LUKS2 header size, do not create a larger file than needed.
|
||||
|
||||
* Fix unspecified sector size for BitLocker compatible mode.
|
||||
|
||||
Some BitLocker devices can contain zeroed sector size in the header.
|
||||
In this case, the 512-byte sector should be used.
|
||||
The bug was introduced in version 2.3.3.
|
||||
|
||||
* Fix reading key data size in metadata for BitLocker compatible mode.
|
||||
|
||||
Such devices with an unexpected entry in metadata can now be activated.
|
||||
|
||||
Thanks to all users reporting these problems, BitLocker metadata documentation
|
||||
is not publicly available, and we depend only on these reports.
|
||||
|
||||
* Fix typos in documentation.
|
||||
181
docs/v2.3.5-ReleaseNotes
Normal file
181
docs/v2.3.5-ReleaseNotes
Normal file
@@ -0,0 +1,181 @@
|
||||
Cryptsetup 2.3.5 Release Notes
|
||||
==============================
|
||||
Stable bug-fix release with minor extensions.
|
||||
|
||||
All users of cryptsetup 2.x and later should upgrade to this version.
|
||||
|
||||
Changes since version 2.3.4
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
* Fix partial reads of passphrase from an interactive terminal.
|
||||
Some stable kernels (5.3.11) started to return buffer from a terminal
|
||||
in parts of maximal size 64 bytes.
|
||||
This breaks the reading of passphrases longer than 64 characters
|
||||
entered through an interactive terminal. The change is already fixed
|
||||
in later kernel releases, but tools now support such partial read from
|
||||
terminal properly.
|
||||
|
||||
* Fix maximal length of password entered through a terminal.
|
||||
Now the maximal interactive passphrase length is exactly
|
||||
512 characters (not 511).
|
||||
|
||||
* integritysetup: support new dm-integrity HMAC recalculation options.
|
||||
|
||||
In older kernels (since version 4.19), an attacker can force
|
||||
an automatic recalculation of integrity tags by modifying
|
||||
the dm-integrity superblock.
|
||||
This is a problem with a keyed algorithms (HMAC), where it expects
|
||||
nobody can trigger such recalculation without the key.
|
||||
(Automatic recalculation will start after the next activation.)
|
||||
|
||||
Note that dm-integrity in standalone mode was *not* supposed
|
||||
to provide cryptographic data integrity protection.
|
||||
Despite that, we try to keep the system secure if keyed algorithms
|
||||
are used.
|
||||
Thank Daniel Glöckner for the original report of this problem.
|
||||
|
||||
Authenticated encryption that provides data integrity protection (in
|
||||
combination with dm-crypt and LUKS2) is not affected by this problem.
|
||||
|
||||
The fix in the kernel for this problem contains two parts.
|
||||
|
||||
Firstly, the dm-integrity kernel module disables integrity
|
||||
recalculation if keyed algorithms (HMAC) are used.
|
||||
This change is included in long-term stable kernels.
|
||||
|
||||
Secondly, since the kernel version 5.11, dm-integrity introduces
|
||||
modified protection where a journal-integrity algorithm guards
|
||||
superblock; also, journal sections are protected. An attacker cannot
|
||||
copy sectors from one journal section to another, and the superblock
|
||||
also contains salt to prevent header replacement from another device.
|
||||
|
||||
If you want to protect data with HMAC, you should always also use HMAC
|
||||
for --journal-integrity. Keys can be independent.
|
||||
If HMAC is used for data but not for the journal, the recalculation
|
||||
option is disabled.
|
||||
|
||||
If you need to use (insecure) backward compatibility implementation,
|
||||
two new integritysetup options are introduced:
|
||||
- Use --integrity-legacy-recalc (instead of --integrity-recalc)
|
||||
to allow recalculation on legacy devices.
|
||||
- Use --integrity-legacy-hmac in format action to force old insecure
|
||||
HMAC format.
|
||||
|
||||
Libcryptsetup API also introduces flags
|
||||
CRYPT_COMPAT_LEGACY_INTEGRITY_HMAC and
|
||||
CRYPT_COMPAT_LEGACY_INTEGRITY_RECALC
|
||||
to set these through crypt_set_compatibility() call.
|
||||
|
||||
* integritysetup: display of recalculating sector in dump command.
|
||||
|
||||
* veritysetup: fix verity FEC if stored in the same image with hashes.
|
||||
|
||||
Optional FEC (Forward Error Correction) data should cover the whole
|
||||
data area, hashes (Merkle tree), and optionally additional metadata
|
||||
(located after hash area).
|
||||
|
||||
Unfortunately, if FEC data is stored in the same file as hash,
|
||||
the calculation wrongly used the whole file size, thus overlaps with
|
||||
the FEC area itself. This produced unusable and too large FEC data.
|
||||
There is no problem if the FEC image is a separate image.
|
||||
|
||||
The problem is now fixed, introducing FEC blocks calculation as:
|
||||
- If the hash device is in a separate image, metadata covers the
|
||||
whole rest of the image after the hash area. (Unchanged behavior.)
|
||||
- If hash and FEC device is in the image, metadata ends on the FEC
|
||||
area offset.
|
||||
|
||||
Note: there is also a fix for FEC in the dm-verity kernel (on the way
|
||||
to stable kernels) that fixes error correction with larger RS roots.
|
||||
|
||||
* veritysetup: run FEC repair check even if root hash fails.
|
||||
|
||||
Note: The userspace FEC verify command reports are only informational
|
||||
for now. Code does not check verity hash after FEC recovery in
|
||||
userspace. The Reed-Solomon decoder can then report the possibility
|
||||
that it fixed data even if parity is too damaged.
|
||||
This will be fixed in the next major release.
|
||||
|
||||
* veritysetup: do not process hash image if hash area is empty.
|
||||
|
||||
Sometimes the device is so small that there is only a root hash
|
||||
needed, and the hash area is not used.
|
||||
Also, the size of the hash image is not increased for hash block
|
||||
alignment in this case.
|
||||
|
||||
* veritysetup: store verity hash algorithm in superblock in lowercase.
|
||||
|
||||
Otherwise, the kernel could refuse the activation of the device.
|
||||
|
||||
* bitlk: fix a crash if the device disappears during BitLocker scan.
|
||||
|
||||
* bitlk: show a better error when trying to open an NTFS device.
|
||||
|
||||
Both BitLocker version 1 and NTFS have the same signature.
|
||||
If a user opens an NTFS device without BitLocker, it now correctly
|
||||
informs that it is not a BITLK device.
|
||||
|
||||
* bitlk: add support for startup key protected VMKs.
|
||||
|
||||
The startup key can be provided in --key-file option for open command.
|
||||
|
||||
* Fix LUKS1 repair code (regression since version 1.7.x).
|
||||
|
||||
We cannot trust possibly broken keyslots metadata in repair, so the
|
||||
code recalculates them instead.
|
||||
This makes the repair code working again when the master boot record
|
||||
signature overwrites the LUKS header.
|
||||
|
||||
* Fix luksKeyChange for LUKS2 with assigned tokens.
|
||||
|
||||
The token references are now correctly assigned to the new keyslot
|
||||
number.
|
||||
|
||||
* Fix cryptsetup resize using LUKS2 tokens.
|
||||
|
||||
Code needlessly asked for passphrase even though volume key was
|
||||
already unlocked via LUKS2 token.
|
||||
|
||||
* Print a visible error if device resize is not supported.
|
||||
|
||||
* Add error message when suspending wrong non-LUKS device.
|
||||
|
||||
* Fix default XTS mode key size in reencryption.
|
||||
|
||||
The same luksFormat logic (double key size because XTS uses two keys)
|
||||
is applied in the reencryption code.
|
||||
|
||||
* Rephrase missing locking directory warning and move it to debug level.
|
||||
|
||||
The system should later provide a safe transition to tempdir
|
||||
configuration, so creating locking directory inside libcryptsetup
|
||||
call is safe.
|
||||
|
||||
* Many fixes for the use of cipher_null (empty debug cipher).
|
||||
|
||||
Support for this empty cipher was intended as a debug feature and for
|
||||
measuring performance overhead. Unfortunately, many systems started to
|
||||
use it as an "empty shell" for LUKS (to enable encryption later).
|
||||
|
||||
This use is very dangerous and it creates a false sense of security.
|
||||
|
||||
Anyway, to not break such systems, we try to support these
|
||||
configurations.
|
||||
Using cipher_null in any production system is strongly discouraged!
|
||||
|
||||
Fixes include:
|
||||
- allow LUKS resume for a device with cipher_null.
|
||||
- do not upload key in keyring when data cipher is null.
|
||||
- switch to default cipher when reencrypting cipher_null device.
|
||||
- replace possible bogus cipher_null keyslots before reencryption.
|
||||
- fix broken detection of null cipher in LUKS2.
|
||||
cipher_null is no longer possible to be used in keyslot encryption
|
||||
in LUKS2, it can be used only for data for debugging purposes.
|
||||
|
||||
* Fixes for libpasswdqc 2.0.x (optional passphrase quality check).
|
||||
|
||||
* Fixes for problems discovered by various tools for code analysis.
|
||||
|
||||
Fixes include a rework of libpopt command line option string leaks.
|
||||
|
||||
* Various fixes to man pages.
|
||||
56
docs/v2.3.6-ReleaseNotes
Normal file
56
docs/v2.3.6-ReleaseNotes
Normal file
@@ -0,0 +1,56 @@
|
||||
Cryptsetup 2.3.6 Release Notes
|
||||
==============================
|
||||
Stable bug-fix release with minor extensions.
|
||||
|
||||
All users of cryptsetup 2.x and later should upgrade to this version.
|
||||
|
||||
Changes since version 2.3.5
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
* integritysetup: Fix possible dm-integrity mapping table truncation.
|
||||
|
||||
While integritysetup in standalone mode (no encryption) was not
|
||||
designed to provide keyed (and cryptographically strong) data
|
||||
integrity protection, some options can use such algorithms (HMAC).
|
||||
|
||||
If a key is used, it is directly sent to the kernel dm-integrity as
|
||||
a mapping table option (no key derivation is performed).
|
||||
For HMAC, such a key could be quite long (up to 4096 bytes in
|
||||
integritysetup CLI).
|
||||
|
||||
Unfortunately, due to fixed buffers and not correctly checking string
|
||||
truncation, some parameter combinations could cause truncation
|
||||
of the dm-integrity mapping table.
|
||||
In most cases, the table was rejected by the kernel.
|
||||
The worst possible case was key truncation for HMAC options
|
||||
(internal_hash and journal_mac dm-integrity table options).
|
||||
|
||||
This release fixes possible truncation and also adds more sanity
|
||||
checks to reject truncated options.
|
||||
Also, integritysetup now mentions maximal allowed key size
|
||||
in --help output.
|
||||
|
||||
For old standalone dm-integrity devices where the key length was
|
||||
truncated, you have to modify (shorten) --integrity-key-size
|
||||
resp. --journal-integrity-key-size option now.
|
||||
|
||||
This bug is _not_ present for dm-crypt/LUKS, LUKS2 (including
|
||||
integrity protection), or dm-verity devices; it affects only
|
||||
standalone dm-integrity with HMAC integrity protection.
|
||||
|
||||
* cryptsetup: Backup header can be used to activate TCRYPT device.
|
||||
Use --header option to specify the header.
|
||||
|
||||
* cryptsetup: Avoid LUKS2 decryption without detached header.
|
||||
This feature will be added later and is currently not supported.
|
||||
|
||||
* Additional fixes and workarounds for common warnings produced
|
||||
by some static analysis tools (like gcc-11 analyzer) and additional
|
||||
code hardening.
|
||||
|
||||
* Fix standalone libintl detection for compiled tests.
|
||||
|
||||
* Add Blake2b and Blake2s hash support for crypto backends.
|
||||
Kernel and gcrypt crypto backend support all variants.
|
||||
OpenSSL supports only Blake2b-512 and Blake2s-256.
|
||||
Crypto backend supports kernel notation e.g. "blake2b-512".
|
||||
302
docs/v2.4.0-ReleaseNotes
Normal file
302
docs/v2.4.0-ReleaseNotes
Normal file
@@ -0,0 +1,302 @@
|
||||
Cryptsetup 2.4.0 Release Notes
|
||||
==============================
|
||||
Stable release candidate with new features and bug fixes.
|
||||
|
||||
This version introduces support for external libraries
|
||||
(plugins) for handling LUKS2 token objects.
|
||||
|
||||
Changes since version 2.3.6
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
* External LUKS token plugins
|
||||
|
||||
A LUKS2 token is an object that can describe how to get a passphrase
|
||||
to unlock a particular keyslot. The generic metadata format is part
|
||||
of the LUKS2 specification.
|
||||
|
||||
Cryptsetup 2.4 adds the possibility to implement token handlers
|
||||
in external libraries (possibly provided by other projects).
|
||||
|
||||
A token library allows cryptsetup to understand metadata and provide
|
||||
basic operations. Currently external tokens may be used to unlock
|
||||
keyslots for following CLI actions: open (luksOpen),
|
||||
refresh (open --refresh), resize and dump (prints token specific
|
||||
content).
|
||||
|
||||
LUKS2 devices cannot be resumed (luksResume action) via tokens yet.
|
||||
Support for resume and other actions will be added later.
|
||||
|
||||
The library now provides an interface that automatically tries to load
|
||||
an external library for a token object in LUKS2 metadata.
|
||||
|
||||
Token libraries should be installed in the cryptsetup subdirectory
|
||||
(usually /lib*/cryptsetup). This path is configurable through
|
||||
--with-luks2-external-tokens-path configure option.
|
||||
|
||||
The external plugin loading can be compiled entirely out if
|
||||
--disable-external-tokens configure option is used. The external token
|
||||
interface can also be disabled runtime on the command line by
|
||||
--disable-external-tokens cryptsetup switch or by calling
|
||||
crypt_token_external_disable() API function.
|
||||
|
||||
The name of the loaded token library is determined from the JSON LUKS
|
||||
metadata token object type. For example, "ssh" token will load library
|
||||
"libcryptsetup-token-ssh.so".
|
||||
|
||||
External projects can use this interface to handle specific hardware
|
||||
without introducing additional dependencies to libcryptsetup core.
|
||||
|
||||
As of cryptsetup 2.4.0 release systemd project already merged upstream
|
||||
native cryptsetup token handler for its systemd-tpm2 LUKS2 token
|
||||
released originally in systemd-v248. The token can be created using
|
||||
systemd-cryptenroll utility and devices may be manipulated either by
|
||||
systemd-cryptsetup cli or by cryptsetup for actions listed above.
|
||||
|
||||
Other tokens like systemd-fido2 and systemd-pkcs11 are currently
|
||||
in-review.
|
||||
|
||||
* Experimental SSH token
|
||||
|
||||
As a demonstration of the external LUKS2 token interface, a new SSH
|
||||
token handler and cryptsetup-ssh utility is now provided and compiled
|
||||
by default.
|
||||
|
||||
Crypsetup SSH token allows using remote keyfile through SSH protocol
|
||||
(it will authenticate through SSH certificates).
|
||||
|
||||
You can disable the build of this token library with
|
||||
--disable-ssh-token configure option.
|
||||
|
||||
To configure the token metadata, you need cryptsetup-ssh utility.
|
||||
|
||||
Activation of the device is then performed by the cryptsetup utility.
|
||||
|
||||
Example (how to activate LUKS2 through remote keyfile):
|
||||
|
||||
- configure existing LUKS2 device with keyslot activated by a keyfile
|
||||
# cryptsetup luksAddKey <device> keyfile --key-slot 2
|
||||
|
||||
- store that keyfile on a remote system accessible through SSH
|
||||
|
||||
- configure SSH to use certificate for authentication
|
||||
|
||||
- add a LUKS2 token with cryptsetup-ssh utility:
|
||||
# cryptsetup-ssh add <device>1 --key-slot 2 \
|
||||
--ssh-server test-vm \
|
||||
--ssh-user test \
|
||||
--ssh-path /home/test/keyfile \
|
||||
--ssh-keypath /home/test/.ssh/test_rsa_key
|
||||
|
||||
- you should see token metadata now with "cryptsetup luksDump ..."
|
||||
...
|
||||
Tokens:
|
||||
0: ssh
|
||||
ssh_server: test-vm
|
||||
ssh_user: test
|
||||
ssh_path: /home/test/keyfile
|
||||
ssh_key_path: /home/test/.ssh/test_rsa_key
|
||||
Keyslot: 2
|
||||
|
||||
|
||||
- activation now should be automatic
|
||||
# cryptsetup open <device> test --verbose
|
||||
SSH token initiating ssh session.
|
||||
Key slot 2 unlocked.
|
||||
Command successful.
|
||||
|
||||
- to remove a token, you can use "cryptsetup token remove" command
|
||||
(no plugin library required)
|
||||
|
||||
Please note SSH token is just demonstration of plugin interface API,
|
||||
it is an EXPERIMENTAL feature.
|
||||
|
||||
* Add cryptsetup --token-type parameter.
|
||||
|
||||
It restricts token type to the parameter value in case no specific
|
||||
token-id is selected.
|
||||
|
||||
* Support for token based activation with PIN.
|
||||
|
||||
If specific token requires PIN to unlock keyslot passphrase and
|
||||
--token-only parameter was used cryptsetup asks for additional
|
||||
token PIN.
|
||||
|
||||
* Respect keyslot priority with token-based activation.
|
||||
|
||||
* Default LUKS2 PBKDF is now Argon2id
|
||||
|
||||
Cryptsetup LUKS2 was using Argon2 while there were two versions,
|
||||
data-independent (Argon2i) suitable for the KDF use case and
|
||||
Argon2d (data-dependent). Later Argon2id was introduced as a new
|
||||
mandatory algorithm.
|
||||
|
||||
We switched the password-based key derivation algorithms
|
||||
following the latest version of Argon2 RFC draft
|
||||
(https://datatracker.ietf.org/doc/draft-irtf-cfrg-argon2/) to Argon2id
|
||||
(from Argon2i) as it is the mandatory and primary version
|
||||
of the Argon2 algorithm.
|
||||
|
||||
There is no need to modify older containers; the main reason is that
|
||||
RFC makes Argon2id the primary variant, while Argon2i subvariant is
|
||||
only optional.
|
||||
Argon2id provides better protection to side-channel attacks while
|
||||
still providing protection to time-memory tradeoffs.
|
||||
|
||||
We will switch to OpenSSL implementation once it is available.
|
||||
With a crystal ball as a reference, it could happen early in
|
||||
OpenSSL 3.1 release.
|
||||
Watch https://github.com/openssl/openssl/issues/4091.
|
||||
|
||||
* Increase minimal memory cost for Argon2 benchmark to 64MiB.
|
||||
|
||||
This patch increases the benchmarking value to 64 MiB (as minimal
|
||||
suggested values in Argon2 RFC). For compatibility reasons, we still
|
||||
allow older limits if set by a parameter.
|
||||
|
||||
NOTE: Argon2 RFC draft defines suggested parameters for disk
|
||||
encryption, but the LUKS2 approach is slightly different. We need to
|
||||
provide platform-independent values. The values in the draft expect
|
||||
64bit systems (suggesting using 6 GiB of RAM). In comparison, we need
|
||||
to provide compatibility with all 32bit systems, so allocating more
|
||||
than 4GiB memory is not an option for LUKS2.
|
||||
|
||||
The maximal limit in LUKS2 stays for 4 GiB, and by default LUKS2 PBKDF
|
||||
benchmarking sets maximum to 1 GIB, preferring an increase of CPU cost
|
||||
while running benchmark
|
||||
|
||||
* Autodetect optimal encryption sector size on LUKS2 format.
|
||||
|
||||
While the support for larger encryption sectors is supported
|
||||
for several releases, it required an additional parameter.
|
||||
|
||||
Code now uses automatic detection of 4096-bytes native sector devices
|
||||
and automatically enables 4096-bytes encryption size for LUKS2.
|
||||
|
||||
If no setor size option is used, sector size is detected
|
||||
automatically by cryptsetup. For libcryptsetup API, autodetection
|
||||
happens once you specify sector_size to 0.
|
||||
|
||||
NOTE: crypt_format() function runs autodetection ONLY if you
|
||||
recompile your application to the new API symbol version.
|
||||
For backward compatibility, older applications ignore this parameter.
|
||||
|
||||
* Use VeraCrypt option by default and add --disable-veracrypt option.
|
||||
|
||||
While TrueCrypt is no longer developed and supported since 2014,
|
||||
VeraCrypt devices (a successor of TrueCrypt) are much more used today.
|
||||
|
||||
Default is now to support VeraCrypt format (in addition to TrueCrypt),
|
||||
making the --veracrypt option obsolete (ignored as it is the default).
|
||||
|
||||
If you need to disable VeraCrypt support, use the new option
|
||||
--disable-veracrypt.
|
||||
|
||||
This option increases the time to recognize wrong passwords because
|
||||
some VeraCrypt modes use a high PBKDF2 iteration count, and the code
|
||||
must try all variants. This could be limited by using --hash and
|
||||
--cipher options mentioned below.
|
||||
|
||||
* Support --hash and --cipher to limit opening time for TCRYPT type
|
||||
|
||||
If a user knows which particular PBKDF2 hash or cipher is used for
|
||||
TrueCrypt/VeraCrypt container, TCRYPT format now supports --hash and
|
||||
--cipher option.
|
||||
|
||||
Note the value means substring (all cipher chains containing
|
||||
the cipher substring are tried).
|
||||
|
||||
For example, you can use
|
||||
# cryptsetup tcryptDump --hash sha512 <container>
|
||||
|
||||
Note: to speed up the scan, the hash option (used for PBKDF)2 matters.
|
||||
Cipher variants are scanned very quickly.
|
||||
|
||||
Use with care.
|
||||
It can reveal some sensitive attributes of the container!
|
||||
|
||||
* Fixed default OpenSSL crypt backend support for OpenSSL3.
|
||||
|
||||
For OpenSSL version 3, we need to load legacy provider for older hash
|
||||
and ciphers. For example, RIPEMD160 and Whirlpool hash algorithms are
|
||||
no longer available by default.
|
||||
|
||||
NOTE: the plain format still uses RIPEMD160 for password hashing by
|
||||
default. Changing the default would cause incompatibilities for many
|
||||
old systems. Nevertheless, such a change will be needed very soon.
|
||||
|
||||
* integritysetup: add integrity-recalculate-reset flag.
|
||||
|
||||
The new dm-integrity option in kernel 5.13 can restart recalculation
|
||||
from the beginning of the device.
|
||||
It can be used to change the integrity checksum function.
|
||||
|
||||
New integritysetup --integrity-recalculate-reset option is added to
|
||||
integritysetup, and CRYPT_ACTIVATE_RECALCULATE_RESET flag to API.
|
||||
|
||||
* cryptsetup: retains keyslot number in luksChangeKey for LUKS2.
|
||||
|
||||
In LUKS1, any change in keyslot means keyslot number change.
|
||||
|
||||
In LUKS2, we can retain the keyslot number.
|
||||
Now luksKeyChange and crypt_keyslot_change_by_passphrase() API
|
||||
retains keyslot number for LUKS2 by default.
|
||||
|
||||
* Fix cryptsetup resize using LUKS2 tokens.
|
||||
|
||||
Fix a bug where cryptsetup needlessly asked for a passphrase even
|
||||
though the volume key was already unlocked via LUKS2 token.
|
||||
|
||||
* Add close --deferred and --cancel-deferred options.
|
||||
|
||||
All command-line utilities now understand deferred options for the
|
||||
close command. Deferred close means that the device is removed
|
||||
automagically after the last user closed the device.
|
||||
Cancel deferred means to cancel this operation (so the device remains
|
||||
active even if there a no longer active users).
|
||||
|
||||
CRYPT_DEACTIVATE_DEFERRED and CRYPT_DEACTIVATE_DEFERRED_CANCEL flags
|
||||
are now available for API.
|
||||
|
||||
* Rewritten command-line option parsing to avoid libpopt arguments
|
||||
memory leaks.
|
||||
|
||||
Note: some distributions use patched lipopt that still leaks memory
|
||||
inside internal code (see Debian bug 941814).
|
||||
|
||||
* Add --test-args option.
|
||||
|
||||
New --test-args option can be used for syntax checking for valid
|
||||
command-line arguments with no actions performed.
|
||||
Note that it cannot detect unknown algorithm names and similar where
|
||||
we need call API functions.
|
||||
|
||||
* veritysetup: add --root-hash-file option
|
||||
Allow passing the root hash via a file, rather than verbatim on
|
||||
the command line, for the open, verify, and format actions.
|
||||
|
||||
* libcryptsetup C API extensions (see libcryptsetup.h for details)
|
||||
|
||||
- crypt_logf - a printf like log function
|
||||
- crypt_dump_json - dump LUKS2 metadata in JSON format
|
||||
- crypt_header_is_detached - check if context use detached header
|
||||
- crypt_token_max - get maximal tokens number
|
||||
- crypt_token_external_path - get path for plugins (or NULL)
|
||||
- crypt_token_external_disable - disable runtime support for plugins
|
||||
- crypt_activate_by_token_pin - activate by token with additional PIN
|
||||
- crypt_reencrypt_run - fixed API for deprecated crypt_reencrypt
|
||||
|
||||
The token plugin library interface cosists from these versioned
|
||||
exported symbols (for details see header file and SSH token example):
|
||||
cryptsetup_token_open
|
||||
cryptsetup_token_open_pin
|
||||
cryptsetup_token_buffer_free
|
||||
cryptsetup_token_validate
|
||||
cryptsetup_token_dump
|
||||
cryptsetup_token_version
|
||||
|
||||
Since version 2.4 libcryptsetup uses exact symbol versioning
|
||||
Newly introduced functions have CRYPTSETUP_2.4 namespace (the old
|
||||
symbol always used CRYPTSETUP_2.0).
|
||||
There is no change in soname (the library is backward compatible).
|
||||
|
||||
* Many fixes and additions to documentation and man pages.
|
||||
@@ -1,11 +1,11 @@
|
||||
pkgconfigdir = $(libdir)/pkgconfig
|
||||
pkgconfig_DATA = lib/libcryptsetup.pc
|
||||
pkgconfig_DATA += lib/libcryptsetup.pc
|
||||
|
||||
lib_LTLIBRARIES = libcryptsetup.la
|
||||
lib_LTLIBRARIES += libcryptsetup.la
|
||||
|
||||
noinst_LTLIBRARIES += libutils_io.la
|
||||
|
||||
include_HEADERS = lib/libcryptsetup.h
|
||||
include_HEADERS += lib/libcryptsetup.h
|
||||
|
||||
EXTRA_DIST += lib/libcryptsetup.pc.in lib/libcryptsetup.sym
|
||||
|
||||
@@ -15,15 +15,7 @@ libutils_io_la_SOURCES = \
|
||||
lib/utils_io.c \
|
||||
lib/utils_io.h
|
||||
|
||||
libcryptsetup_la_CPPFLAGS = $(AM_CPPFLAGS) \
|
||||
-I $(top_srcdir)/lib/crypto_backend \
|
||||
-I $(top_srcdir)/lib/luks1 \
|
||||
-I $(top_srcdir)/lib/luks2 \
|
||||
-I $(top_srcdir)/lib/loopaes \
|
||||
-I $(top_srcdir)/lib/verity \
|
||||
-I $(top_srcdir)/lib/tcrypt \
|
||||
-I $(top_srcdir)/lib/integrity \
|
||||
-I $(top_srcdir)/lib/bitlk
|
||||
libcryptsetup_la_CPPFLAGS = $(AM_CPPFLAGS)
|
||||
|
||||
libcryptsetup_la_DEPENDENCIES = libutils_io.la libcrypto_backend.la lib/libcryptsetup.sym
|
||||
|
||||
@@ -40,6 +32,7 @@ libcryptsetup_la_LIBADD = \
|
||||
@LIBARGON2_LIBS@ \
|
||||
@JSON_C_LIBS@ \
|
||||
@BLKID_LIBS@ \
|
||||
$(LTLIBICONV) \
|
||||
libcrypto_backend.la \
|
||||
libutils_io.la
|
||||
|
||||
@@ -49,6 +42,8 @@ libcryptsetup_la_SOURCES = \
|
||||
lib/bitops.h \
|
||||
lib/nls.h \
|
||||
lib/libcryptsetup.h \
|
||||
lib/libcryptsetup_macros.h \
|
||||
lib/libcryptsetup_symver.h \
|
||||
lib/utils.c \
|
||||
lib/utils_benchmark.c \
|
||||
lib/utils_crypt.c \
|
||||
@@ -76,7 +71,7 @@ libcryptsetup_la_SOURCES = \
|
||||
lib/base64.h \
|
||||
lib/base64.c \
|
||||
lib/integrity/integrity.h \
|
||||
lib/integrity/integrity.c \
|
||||
lib/integrity/integrity.c \
|
||||
lib/loopaes/loopaes.h \
|
||||
lib/loopaes/loopaes.c \
|
||||
lib/tcrypt/tcrypt.h \
|
||||
@@ -92,7 +87,7 @@ libcryptsetup_la_SOURCES = \
|
||||
lib/verity/verity.h \
|
||||
lib/verity/rs_encode_char.c \
|
||||
lib/verity/rs_decode_char.c \
|
||||
lib/verity/rs.h \
|
||||
lib/verity/rs.h \
|
||||
lib/luks2/luks2_disk_metadata.c \
|
||||
lib/luks2/luks2_json_format.c \
|
||||
lib/luks2/luks2_json_metadata.c \
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
* BITLK (BitLocker-compatible) volume handling
|
||||
*
|
||||
* Copyright (C) 2019-2020 Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2019-2020 Milan Broz
|
||||
* Copyright (C) 2019-2020 Vojtech Trefny
|
||||
* Copyright (C) 2019-2021 Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2019-2021 Milan Broz
|
||||
* Copyright (C) 2019-2021 Vojtech Trefny
|
||||
*
|
||||
* This file is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
@@ -22,7 +22,6 @@
|
||||
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <fcntl.h>
|
||||
#include <uuid/uuid.h>
|
||||
#include <time.h>
|
||||
#include <iconv.h>
|
||||
@@ -55,6 +54,9 @@
|
||||
#define BITLK_RECOVERY_PARTS 8
|
||||
#define BITLK_RECOVERY_PART_LEN 6
|
||||
|
||||
#define BITLK_BEK_FILE_HEADER_LEN 48
|
||||
#define BITLK_STARTUP_KEY_HEADER_LEN 24
|
||||
|
||||
#define BITLK_KDF_HASH "sha256"
|
||||
#define BITLK_KDF_ITERATION_COUNT 0x100000
|
||||
|
||||
@@ -112,6 +114,7 @@ struct segment {
|
||||
struct bitlk_signature {
|
||||
uint8_t boot_code[3];
|
||||
uint8_t signature[8];
|
||||
uint16_t sector_size;
|
||||
} __attribute__ ((packed));
|
||||
|
||||
struct bitlk_superblock {
|
||||
@@ -162,6 +165,18 @@ struct bitlk_kdf_data {
|
||||
uint64_t count;
|
||||
};
|
||||
|
||||
struct bitlk_bek_header {
|
||||
uint32_t metadata_size;
|
||||
uint32_t metadata_version;
|
||||
uint32_t metadata_header_size;
|
||||
uint32_t metada_size_copy;
|
||||
struct bitlk_guid guid;
|
||||
uint32_t next_nonce;
|
||||
uint16_t encryption;
|
||||
uint16_t unknown;
|
||||
uint64_t creation_time;
|
||||
} __attribute__ ((packed));
|
||||
|
||||
static BITLKVMKProtection get_vmk_protection(uint16_t protection)
|
||||
{
|
||||
switch (protection) {
|
||||
@@ -291,7 +306,7 @@ static int passphrase_to_utf16(struct crypt_device *cd, char *input, size_t inle
|
||||
*out = outbuf;
|
||||
} else {
|
||||
*out = NULL;
|
||||
free(outbuf);
|
||||
crypt_safe_free(outbuf);
|
||||
log_dbg(cd, "Failed to convert passphrase: %s", strerror(errno));
|
||||
r = -errno;
|
||||
}
|
||||
@@ -311,7 +326,9 @@ static int parse_vmk_entry(struct crypt_device *cd, uint8_t *data, int start, in
|
||||
bool supported = false;
|
||||
|
||||
/* only passphrase or recovery passphrase vmks are supported (can be used to activate) */
|
||||
supported = (*vmk)->protection == BITLK_PROTECTION_PASSPHRASE || (*vmk)->protection == BITLK_PROTECTION_RECOVERY_PASSPHRASE;
|
||||
supported = (*vmk)->protection == BITLK_PROTECTION_PASSPHRASE ||
|
||||
(*vmk)->protection == BITLK_PROTECTION_RECOVERY_PASSPHRASE ||
|
||||
(*vmk)->protection == BITLK_PROTECTION_STARTUP_KEY;
|
||||
|
||||
while (end - start > 2) {
|
||||
/* size of this entry */
|
||||
@@ -394,6 +411,9 @@ static int parse_vmk_entry(struct crypt_device *cd, uint8_t *data, int start, in
|
||||
(*vmk)->name = string;
|
||||
string = NULL;
|
||||
}
|
||||
/* no idea what this is, lets hope it's not important */
|
||||
} else if (key_entry_value == BITLK_ENTRY_VALUE_USE_KEY && (*vmk)->protection == BITLK_PROTECTION_STARTUP_KEY) {
|
||||
;
|
||||
} else {
|
||||
if (supported) {
|
||||
log_err(cd, _("Unexpected metadata entry value '%u' found when parsing supported Volume Master Key."), key_entry_value);
|
||||
@@ -415,6 +435,7 @@ void BITLK_bitlk_fvek_free(struct bitlk_fvek *fvek)
|
||||
return;
|
||||
|
||||
crypt_free_volume_key(fvek->vk);
|
||||
free(fvek);
|
||||
}
|
||||
|
||||
void BITLK_bitlk_vmk_free(struct bitlk_vmk *vmk)
|
||||
@@ -435,6 +456,9 @@ void BITLK_bitlk_vmk_free(struct bitlk_vmk *vmk)
|
||||
|
||||
void BITLK_bitlk_metadata_free(struct bitlk_metadata *metadata)
|
||||
{
|
||||
if (!metadata)
|
||||
return;
|
||||
|
||||
free(metadata->guid);
|
||||
if (metadata->description)
|
||||
free(metadata->description);
|
||||
@@ -480,6 +504,18 @@ int BITLK_read_sb(struct crypt_device *cd, struct bitlk_metadata *params)
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (memcmp(sig.signature, BITLK_SIGNATURE, sizeof(sig.signature)) == 0) {
|
||||
params->togo = false;
|
||||
fve_offset = BITLK_HEADER_METADATA_OFFSET;
|
||||
} else if (memcmp(sig.signature, BITLK_SIGNATURE_TOGO, sizeof(sig.signature)) == 0) {
|
||||
params->togo = true;
|
||||
fve_offset = BITLK_HEADER_METADATA_OFFSET_TOGO;
|
||||
} else {
|
||||
log_err(cd, _("Invalid or unknown signature for BITLK device."));
|
||||
r = -EINVAL;
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (memcmp(sig.boot_code, BITLK_BOOTCODE_V1, sizeof(sig.boot_code)) == 0) {
|
||||
log_err(cd, _("BITLK version 1 is currently not supported."));
|
||||
r = -ENOTSUP;
|
||||
@@ -492,14 +528,14 @@ int BITLK_read_sb(struct crypt_device *cd, struct bitlk_metadata *params)
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (memcmp(sig.signature, BITLK_SIGNATURE, sizeof(sig.signature)) == 0) {
|
||||
params->togo = false;
|
||||
fve_offset = BITLK_HEADER_METADATA_OFFSET;
|
||||
} else if (memcmp(sig.signature, BITLK_SIGNATURE_TOGO, sizeof(sig.signature)) == 0) {
|
||||
params->togo = true;
|
||||
fve_offset = BITLK_HEADER_METADATA_OFFSET_TOGO;
|
||||
} else {
|
||||
log_err(cd, _("Invalid or unknown signature for BITLK device."));
|
||||
params->sector_size = le16_to_cpu(sig.sector_size);
|
||||
if (params->sector_size == 0) {
|
||||
log_dbg(cd, "Got sector size 0, assuming 512.");
|
||||
params->sector_size = SECTOR_SIZE;
|
||||
}
|
||||
|
||||
if (!(params->sector_size == 512 || params->sector_size == 4096)) {
|
||||
log_err(cd, _("Unsupported sector size %" PRIu16 "."), params->sector_size);
|
||||
r = -EINVAL;
|
||||
goto out;
|
||||
}
|
||||
@@ -551,12 +587,12 @@ int BITLK_read_sb(struct crypt_device *cd, struct bitlk_metadata *params)
|
||||
switch (le16_to_cpu(fve.encryption)) {
|
||||
/* AES-CBC with Elephant difuser */
|
||||
case 0x8000:
|
||||
params->key_size = 128;
|
||||
params->key_size = 256;
|
||||
params->cipher = "aes";
|
||||
params->cipher_mode = "cbc-elephant";
|
||||
break;
|
||||
case 0x8001:
|
||||
params->key_size = 256;
|
||||
params->key_size = 512;
|
||||
params->cipher = "aes";
|
||||
params->cipher_mode = "cbc-elephant";
|
||||
break;
|
||||
@@ -573,12 +609,12 @@ int BITLK_read_sb(struct crypt_device *cd, struct bitlk_metadata *params)
|
||||
break;
|
||||
/* AES-XTS */
|
||||
case 0x8004:
|
||||
params->key_size = 128;
|
||||
params->key_size = 256;
|
||||
params->cipher = "aes";
|
||||
params->cipher_mode = "xts-plain64";
|
||||
break;
|
||||
case 0x8005:
|
||||
params->key_size = 256;
|
||||
params->key_size = 512;
|
||||
params->cipher = "aes";
|
||||
params->cipher_mode = "xts-plain64";
|
||||
break;
|
||||
@@ -615,7 +651,7 @@ int BITLK_read_sb(struct crypt_device *cd, struct bitlk_metadata *params)
|
||||
|
||||
if (read_lseek_blockwise(devfd, device_block_size(cd, device),
|
||||
device_alignment(device), fve_entries, fve_metadata_size - BITLK_FVE_METADATA_HEADER_LEN,
|
||||
params->metadata_offset[0] + BITLK_FVE_METADATA_HEADERS_LEN) != fve_metadata_size - BITLK_FVE_METADATA_HEADER_LEN) {
|
||||
params->metadata_offset[0] + BITLK_FVE_METADATA_HEADERS_LEN) != (ssize_t)(fve_metadata_size - BITLK_FVE_METADATA_HEADER_LEN)) {
|
||||
log_err(cd, _("Failed to read BITLK metadata entries from %s."), device_path(device));
|
||||
r = -EINVAL;
|
||||
goto out;
|
||||
@@ -641,6 +677,10 @@ int BITLK_read_sb(struct crypt_device *cd, struct bitlk_metadata *params)
|
||||
sizeof(entry_vmk));
|
||||
|
||||
vmk = malloc(sizeof(struct bitlk_vmk));
|
||||
if (!vmk) {
|
||||
r = -ENOMEM;
|
||||
goto out;
|
||||
}
|
||||
memset(vmk, 0, sizeof(struct bitlk_vmk));
|
||||
|
||||
guid_to_string(&entry_vmk.guid, guid_buf);
|
||||
@@ -669,6 +709,10 @@ int BITLK_read_sb(struct crypt_device *cd, struct bitlk_metadata *params)
|
||||
/* FVEK */
|
||||
} else if (entry_type == BITLK_ENTRY_TYPE_FVEK) {
|
||||
params->fvek = malloc(sizeof(struct bitlk_fvek));
|
||||
if (!params->fvek) {
|
||||
r = -ENOMEM;
|
||||
goto out;
|
||||
}
|
||||
memcpy(params->fvek->nonce,
|
||||
fve_entries + start + BITLK_ENTRY_HEADER_LEN,
|
||||
sizeof(params->fvek->nonce));
|
||||
@@ -722,6 +766,7 @@ int BITLK_dump(struct crypt_device *cd, struct device *device, struct bitlk_meta
|
||||
log_std(cd, "Info for BITLK%s device %s.\n", params->togo ? " To Go" : "", device_path(device));
|
||||
log_std(cd, "Version: \t%u\n", params->metadata_version);
|
||||
log_std(cd, "GUID: \t%s\n", params->guid);
|
||||
log_std(cd, "Sector size: \t%u [bytes]\n", params->sector_size);
|
||||
log_std(cd, "Created: \t%s", ctime((time_t *)&(params->creation_time)));
|
||||
log_std(cd, "Description: \t%s\n", params->description);
|
||||
log_std(cd, "Cipher name: \t%s\n", params->cipher);
|
||||
@@ -789,8 +834,14 @@ static int get_recovery_key(struct crypt_device *cd,
|
||||
- 8 groups of 6 divided by '-'
|
||||
- each part is a number dividable by 11
|
||||
*/
|
||||
if (passwordLen != BITLK_RECOVERY_KEY_LEN)
|
||||
return 0;
|
||||
if (passwordLen != BITLK_RECOVERY_KEY_LEN) {
|
||||
if (passwordLen == BITLK_RECOVERY_KEY_LEN + 1 && password[passwordLen - 1] == '\n') {
|
||||
/* looks like a recovery key with an extra newline, possibly from a key file */
|
||||
passwordLen--;
|
||||
log_dbg(cd, "Possible extra EOL stripped from the recovery key.");
|
||||
} else
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (i = BITLK_RECOVERY_PART_LEN; i < passwordLen; i += BITLK_RECOVERY_PART_LEN + 1) {
|
||||
if (password[i] != '-')
|
||||
@@ -818,6 +869,120 @@ static int get_recovery_key(struct crypt_device *cd,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int parse_external_key_entry(struct crypt_device *cd, const char *data, int start, int end, struct volume_key **vk)
|
||||
{
|
||||
uint16_t key_entry_size = 0;
|
||||
uint16_t key_entry_type = 0;
|
||||
uint16_t key_entry_value = 0;
|
||||
size_t key_size = 0;
|
||||
const char *key = NULL;
|
||||
|
||||
while (end - start > 2) {
|
||||
/* size of this entry */
|
||||
memcpy(&key_entry_size, data + start, sizeof(key_entry_size));
|
||||
key_entry_size = le16_to_cpu(key_entry_size);
|
||||
if (key_entry_size == 0)
|
||||
break;
|
||||
|
||||
/* type and value of this entry */
|
||||
memcpy(&key_entry_type, data + start + sizeof(key_entry_size), sizeof(key_entry_type));
|
||||
memcpy(&key_entry_value,
|
||||
data + start + sizeof(key_entry_size) + sizeof(key_entry_type),
|
||||
sizeof(key_entry_value));
|
||||
key_entry_type = le16_to_cpu(key_entry_type);
|
||||
key_entry_value = le16_to_cpu(key_entry_value);
|
||||
|
||||
/* only properties should be in this entry */
|
||||
if (key_entry_type != BITLK_ENTRY_TYPE_PROPERTY) {
|
||||
log_err(cd, _("Unexpected metadata entry type '%u' found when parsing external key."), key_entry_type);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (key_entry_value == BITLK_ENTRY_VALUE_KEY) {
|
||||
key_size = key_entry_size - (BITLK_ENTRY_HEADER_LEN + 4);
|
||||
key = (const char *) data + start + BITLK_ENTRY_HEADER_LEN + 4;
|
||||
*vk = crypt_alloc_volume_key(key_size, key);
|
||||
if (*vk == NULL)
|
||||
return -ENOMEM;
|
||||
return 0;
|
||||
/* optional "ExternalKey" string, we can safely ignore it */
|
||||
} else if (key_entry_value == BITLK_ENTRY_VALUE_STRING)
|
||||
;
|
||||
else {
|
||||
log_err(cd, _("Unexpected metadata entry value '%u' found when parsing external key."), key_entry_value);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
start += key_entry_size;
|
||||
}
|
||||
|
||||
/* if we got here we failed to parse the metadata */
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
/* check if given passphrase can be a startup key (has right format) and convert it */
|
||||
static int get_startup_key(struct crypt_device *cd,
|
||||
const char *password,
|
||||
size_t passwordLen,
|
||||
const struct bitlk_vmk *vmk,
|
||||
struct volume_key **su_key)
|
||||
{
|
||||
struct bitlk_bek_header bek_header = {0};
|
||||
char guid_buf[UUID_STR_LEN] = {0};
|
||||
|
||||
uint16_t key_entry_size = 0;
|
||||
uint16_t key_entry_type = 0;
|
||||
uint16_t key_entry_value = 0;
|
||||
|
||||
if (passwordLen < BITLK_BEK_FILE_HEADER_LEN)
|
||||
return -EPERM;
|
||||
|
||||
memcpy(&bek_header, password, BITLK_BEK_FILE_HEADER_LEN);
|
||||
|
||||
/* metadata should contain GUID of the VMK this startup key is used for */
|
||||
guid_to_string(&bek_header.guid, guid_buf);
|
||||
if (strcmp(guid_buf, vmk->guid) == 0)
|
||||
log_dbg(cd, "Found matching startup key for VMK %s", vmk->guid);
|
||||
else
|
||||
return -EPERM;
|
||||
|
||||
if (bek_header.metadata_version != 1) {
|
||||
log_err(cd, "Unsupported BEK metadata version %" PRIu32 "", bek_header.metadata_version);
|
||||
return -ENOTSUP;
|
||||
}
|
||||
|
||||
if (bek_header.metadata_size != passwordLen) {
|
||||
log_err(cd, "Unexpected BEK metadata size %" PRIu32 " does not match BEK file length", bek_header.metadata_size);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
/* we are expecting exactly one metadata entry starting immediately after the header */
|
||||
memcpy(&key_entry_size, password + BITLK_BEK_FILE_HEADER_LEN, sizeof(key_entry_size));
|
||||
key_entry_size = le16_to_cpu(key_entry_size);
|
||||
if (key_entry_size < BITLK_ENTRY_HEADER_LEN) {
|
||||
log_dbg(cd, "Unexpected metadata entry size %" PRIu16 " when parsing BEK file", key_entry_size);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
/* type and value of this entry */
|
||||
memcpy(&key_entry_type, password + BITLK_BEK_FILE_HEADER_LEN + sizeof(key_entry_size), sizeof(key_entry_type));
|
||||
memcpy(&key_entry_value,
|
||||
password + BITLK_BEK_FILE_HEADER_LEN + sizeof(key_entry_size) + sizeof(key_entry_type),
|
||||
sizeof(key_entry_value));
|
||||
key_entry_type = le16_to_cpu(key_entry_type);
|
||||
key_entry_value = le16_to_cpu(key_entry_value);
|
||||
|
||||
if (key_entry_type == BITLK_ENTRY_TYPE_STARTUP_KEY && key_entry_value == BITLK_ENTRY_VALUE_EXTERNAL_KEY) {
|
||||
return parse_external_key_entry(cd, password,
|
||||
BITLK_BEK_FILE_HEADER_LEN + BITLK_ENTRY_HEADER_LEN + BITLK_STARTUP_KEY_HEADER_LEN,
|
||||
passwordLen, su_key);
|
||||
} else {
|
||||
log_err(cd, _("Unexpected metadata entry found when parsing startup key."));
|
||||
log_dbg(cd, "Entry type: %u, entry value: %u", key_entry_type, key_entry_value);
|
||||
return -EINVAL;
|
||||
}
|
||||
}
|
||||
|
||||
static int bitlk_kdf(struct crypt_device *cd,
|
||||
const char *password,
|
||||
size_t passwordLen,
|
||||
@@ -893,7 +1058,7 @@ static int decrypt_key(struct crypt_device *cd,
|
||||
{
|
||||
char *outbuf;
|
||||
int r;
|
||||
uint32_t key_size = 0;
|
||||
uint16_t key_size = 0;
|
||||
|
||||
outbuf = crypt_safe_alloc(enc_key->keylength);
|
||||
if (!outbuf)
|
||||
@@ -908,16 +1073,18 @@ static int decrypt_key(struct crypt_device *cd,
|
||||
}
|
||||
|
||||
/* key_data has it's size as part of the metadata */
|
||||
memcpy(&key_size, outbuf, 4);
|
||||
key_size = le32_to_cpu(key_size);
|
||||
memcpy(&key_size, outbuf, 2);
|
||||
key_size = le16_to_cpu(key_size);
|
||||
if (enc_key->keylength != key_size) {
|
||||
log_err(cd, _("Wrong key size."));
|
||||
log_err(cd, _("Unexpected key data size."));
|
||||
log_dbg(cd, "Expected key data size: %zu, got %" PRIu16 "", enc_key->keylength, key_size);
|
||||
|
||||
r = -EINVAL;
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (is_fvek && strcmp(crypt_get_cipher_mode(cd), "cbc-elephant") == 0 &&
|
||||
crypt_get_volume_key_size(cd) == 16) {
|
||||
crypt_get_volume_key_size(cd) == 32) {
|
||||
/* 128bit AES-CBC with Elephant -- key size is 256 bit (2 keys) but key data is 512 bits,
|
||||
data: 16B CBC key, 16B empty, 16B elephant key, 16B empty */
|
||||
memcpy(outbuf + 16 + BITLK_OPEN_KEY_METADATA_LEN,
|
||||
@@ -934,56 +1101,34 @@ out:
|
||||
return r;
|
||||
}
|
||||
|
||||
int BITLK_activate(struct crypt_device *cd,
|
||||
const char *name,
|
||||
const char *password,
|
||||
size_t passwordLen,
|
||||
const struct bitlk_metadata *params,
|
||||
uint32_t flags)
|
||||
int BITLK_get_volume_key(struct crypt_device *cd,
|
||||
const char *password,
|
||||
size_t passwordLen,
|
||||
const struct bitlk_metadata *params,
|
||||
struct volume_key **open_fvek_key)
|
||||
{
|
||||
int r = 0;
|
||||
int i = 0;
|
||||
int j = 0;
|
||||
int min = 0;
|
||||
int num_segments = 0;
|
||||
struct crypt_dm_active_device dmd = {
|
||||
.flags = flags,
|
||||
};
|
||||
struct dm_target *next_segment = NULL;
|
||||
struct volume_key *open_vmk_key = NULL;
|
||||
struct volume_key *open_fvek_key = NULL;
|
||||
struct volume_key *vmk_dec_key = NULL;
|
||||
struct volume_key *recovery_key = NULL;
|
||||
const struct bitlk_vmk *next_vmk = NULL;
|
||||
struct segment segments[MAX_BITLK_SEGMENTS] = {};
|
||||
struct segment temp;
|
||||
uint64_t next_start = 0;
|
||||
uint64_t next_end = 0;
|
||||
uint64_t last_segment = 0;
|
||||
uint32_t dmt_flags;
|
||||
|
||||
if (!params->state) {
|
||||
log_err(cd, _("This BITLK device is in an unsupported state and cannot be activated."));
|
||||
r = -ENOTSUP;
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (params->type != BITLK_ENCRYPTION_TYPE_NORMAL) {
|
||||
log_err(cd, _("BITLK devices with type '%s' cannot be activated."), get_bitlk_type_string(params->type));
|
||||
r = -ENOTSUP;
|
||||
goto out;
|
||||
}
|
||||
|
||||
next_vmk = params->vmks;
|
||||
while (next_vmk) {
|
||||
if (next_vmk->protection == BITLK_PROTECTION_PASSPHRASE) {
|
||||
r = bitlk_kdf(cd, password, passwordLen, false, next_vmk->salt, &vmk_dec_key);
|
||||
if (r)
|
||||
return r;
|
||||
if (r) {
|
||||
/* something wrong happened, but we still want to check other key slots */
|
||||
next_vmk = next_vmk->next;
|
||||
continue;
|
||||
}
|
||||
} else if (next_vmk->protection == BITLK_PROTECTION_RECOVERY_PASSPHRASE) {
|
||||
r = get_recovery_key(cd, password, passwordLen, &recovery_key);
|
||||
if (r)
|
||||
return r;
|
||||
if (r) {
|
||||
/* something wrong happened, but we still want to check other key slots */
|
||||
next_vmk = next_vmk->next;
|
||||
continue;
|
||||
}
|
||||
if (recovery_key == NULL) {
|
||||
/* r = 0 but no key -> given passphrase is not a recovery passphrase */
|
||||
r = -EPERM;
|
||||
@@ -996,8 +1141,15 @@ int BITLK_activate(struct crypt_device *cd,
|
||||
crypt_free_volume_key(recovery_key);
|
||||
if (r)
|
||||
return r;
|
||||
} else if (next_vmk->protection == BITLK_PROTECTION_STARTUP_KEY) {
|
||||
r = get_startup_key(cd, password, passwordLen, next_vmk, &vmk_dec_key);
|
||||
if (r) {
|
||||
next_vmk = next_vmk->next;
|
||||
continue;
|
||||
}
|
||||
log_dbg(cd, "Trying to use external key found in provided password.");
|
||||
} else {
|
||||
/* only passphrase and recovery passphrase VMKs supported right now */
|
||||
/* only passphrase, recovery passphrase and startup key VMKs supported right now */
|
||||
log_dbg(cd, "Skipping %s", get_vmk_protection_string(next_vmk->protection));
|
||||
next_vmk = next_vmk->next;
|
||||
if (r == 0)
|
||||
@@ -1020,7 +1172,7 @@ int BITLK_activate(struct crypt_device *cd,
|
||||
}
|
||||
crypt_free_volume_key(vmk_dec_key);
|
||||
|
||||
r = decrypt_key(cd, &open_fvek_key, params->fvek->vk, open_vmk_key,
|
||||
r = decrypt_key(cd, open_fvek_key, params->fvek->vk, open_vmk_key,
|
||||
params->fvek->mac_tag, BITLK_VMK_MAC_TAG_SIZE,
|
||||
params->fvek->nonce, BITLK_NONCE_SIZE, true);
|
||||
if (r < 0) {
|
||||
@@ -1041,28 +1193,66 @@ int BITLK_activate(struct crypt_device *cd,
|
||||
return r;
|
||||
}
|
||||
|
||||
/* Password verify only */
|
||||
if (!name) {
|
||||
crypt_free_volume_key(open_fvek_key);
|
||||
return r;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int _activate_check(struct crypt_device *cd,
|
||||
const struct bitlk_metadata *params)
|
||||
{
|
||||
const struct bitlk_vmk *next_vmk = NULL;
|
||||
|
||||
if (!params->state) {
|
||||
log_err(cd, _("This BITLK device is in an unsupported state and cannot be activated."));
|
||||
return -ENOTSUP;
|
||||
}
|
||||
|
||||
if (params->type != BITLK_ENCRYPTION_TYPE_NORMAL) {
|
||||
log_err(cd, _("BITLK devices with type '%s' cannot be activated."), get_bitlk_type_string(params->type));
|
||||
return -ENOTSUP;
|
||||
}
|
||||
|
||||
next_vmk = params->vmks;
|
||||
while (next_vmk) {
|
||||
if (next_vmk->protection == BITLK_PROTECTION_CLEAR_KEY) {
|
||||
crypt_free_volume_key(open_fvek_key);
|
||||
log_err(cd, _("Activation of partially decrypted BITLK device is not supported."));
|
||||
return -ENOTSUP;
|
||||
}
|
||||
next_vmk = next_vmk->next;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int _activate(struct crypt_device *cd,
|
||||
const char *name,
|
||||
struct volume_key *open_fvek_key,
|
||||
const struct bitlk_metadata *params,
|
||||
uint32_t flags)
|
||||
{
|
||||
int r = 0;
|
||||
int i = 0;
|
||||
int j = 0;
|
||||
int min = 0;
|
||||
int num_segments = 0;
|
||||
struct crypt_dm_active_device dmd = {
|
||||
.flags = flags,
|
||||
};
|
||||
struct dm_target *next_segment = NULL;
|
||||
struct segment segments[MAX_BITLK_SEGMENTS] = {};
|
||||
struct segment temp;
|
||||
uint64_t next_start = 0;
|
||||
uint64_t next_end = 0;
|
||||
uint64_t last_segment = 0;
|
||||
uint32_t dmt_flags;
|
||||
|
||||
r = _activate_check(cd, params);
|
||||
if (r)
|
||||
return r;
|
||||
|
||||
r = device_block_adjust(cd, crypt_data_device(cd), DEV_EXCL,
|
||||
0, &dmd.size, &dmd.flags);
|
||||
if (r) {
|
||||
crypt_free_volume_key(open_fvek_key);
|
||||
if (r)
|
||||
return r;
|
||||
}
|
||||
|
||||
/* there will be always 4 dm-zero segments: 3x metadata, 1x FS header */
|
||||
for (i = 0; i < 3; i++) {
|
||||
@@ -1150,6 +1340,9 @@ int BITLK_activate(struct crypt_device *cd,
|
||||
}
|
||||
}
|
||||
|
||||
if (params->sector_size != SECTOR_SIZE)
|
||||
dmd.flags |= CRYPT_ACTIVATE_IV_LARGE_SECTORS;
|
||||
|
||||
r = dm_targets_allocate(&dmd.segment, num_segments);
|
||||
if (r)
|
||||
goto out;
|
||||
@@ -1170,7 +1363,7 @@ int BITLK_activate(struct crypt_device *cd,
|
||||
segments[i].iv_offset,
|
||||
segments[i].iv_offset,
|
||||
NULL, 0,
|
||||
SECTOR_SIZE);
|
||||
params->sector_size);
|
||||
if (r)
|
||||
goto out;
|
||||
|
||||
@@ -1194,6 +1387,57 @@ int BITLK_activate(struct crypt_device *cd,
|
||||
}
|
||||
out:
|
||||
dm_targets_free(cd, &dmd);
|
||||
return r;
|
||||
}
|
||||
|
||||
int BITLK_activate_by_passphrase(struct crypt_device *cd,
|
||||
const char *name,
|
||||
const char *password,
|
||||
size_t passwordLen,
|
||||
const struct bitlk_metadata *params,
|
||||
uint32_t flags)
|
||||
{
|
||||
int r = 0;
|
||||
struct volume_key *open_fvek_key = NULL;
|
||||
|
||||
r = _activate_check(cd, params);
|
||||
if (r)
|
||||
return r;
|
||||
|
||||
r = BITLK_get_volume_key(cd, password, passwordLen, params, &open_fvek_key);
|
||||
if (r < 0)
|
||||
goto out;
|
||||
|
||||
/* Password verify only */
|
||||
if (!name)
|
||||
goto out;
|
||||
|
||||
r = _activate(cd, name, open_fvek_key, params, flags);
|
||||
out:
|
||||
crypt_free_volume_key(open_fvek_key);
|
||||
return r;
|
||||
}
|
||||
|
||||
int BITLK_activate_by_volume_key(struct crypt_device *cd,
|
||||
const char *name,
|
||||
const char *volume_key,
|
||||
size_t volume_key_size,
|
||||
const struct bitlk_metadata *params,
|
||||
uint32_t flags)
|
||||
{
|
||||
int r = 0;
|
||||
struct volume_key *open_fvek_key = NULL;
|
||||
|
||||
r = _activate_check(cd, params);
|
||||
if (r)
|
||||
return r;
|
||||
|
||||
open_fvek_key = crypt_alloc_volume_key(volume_key_size, volume_key);
|
||||
if (!open_fvek_key)
|
||||
return -ENOMEM;
|
||||
|
||||
r = _activate(cd, name, open_fvek_key, params, flags);
|
||||
|
||||
crypt_free_volume_key(open_fvek_key);
|
||||
return r;
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
* BITLK (BitLocker-compatible) header definition
|
||||
*
|
||||
* Copyright (C) 2019-2020 Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2019-2020 Milan Broz
|
||||
* Copyright (C) 2019-2020 Vojtech Trefny
|
||||
* Copyright (C) 2019-2021 Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2019-2021 Milan Broz
|
||||
* Copyright (C) 2019-2021 Vojtech Trefny
|
||||
*
|
||||
* This file is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
@@ -29,6 +29,7 @@
|
||||
|
||||
struct crypt_device;
|
||||
struct device;
|
||||
struct volume_key;
|
||||
|
||||
#define BITLK_NONCE_SIZE 12
|
||||
#define BITLK_SALT_SIZE 16
|
||||
@@ -95,6 +96,7 @@ struct bitlk_fvek {
|
||||
};
|
||||
|
||||
struct bitlk_metadata {
|
||||
uint16_t sector_size;
|
||||
bool togo;
|
||||
bool state;
|
||||
BITLKEncryptionType type;
|
||||
@@ -116,12 +118,25 @@ int BITLK_read_sb(struct crypt_device *cd, struct bitlk_metadata *params);
|
||||
|
||||
int BITLK_dump(struct crypt_device *cd, struct device *device, struct bitlk_metadata *params);
|
||||
|
||||
int BITLK_activate(struct crypt_device *cd,
|
||||
const char *name,
|
||||
const char *password,
|
||||
size_t passwordLen,
|
||||
const struct bitlk_metadata *params,
|
||||
uint32_t flags);
|
||||
int BITLK_get_volume_key(struct crypt_device *cd,
|
||||
const char *password,
|
||||
size_t passwordLen,
|
||||
const struct bitlk_metadata *params,
|
||||
struct volume_key **open_fvek_key);
|
||||
|
||||
int BITLK_activate_by_passphrase(struct crypt_device *cd,
|
||||
const char *name,
|
||||
const char *password,
|
||||
size_t passwordLen,
|
||||
const struct bitlk_metadata *params,
|
||||
uint32_t flags);
|
||||
|
||||
int BITLK_activate_by_volume_key(struct crypt_device *cd,
|
||||
const char *name,
|
||||
const char *volume_key,
|
||||
size_t volume_key_size,
|
||||
const struct bitlk_metadata *params,
|
||||
uint32_t flags);
|
||||
|
||||
void BITLK_bitlk_fvek_free(struct bitlk_fvek *fvek);
|
||||
void BITLK_bitlk_vmk_free(struct bitlk_vmk *vmk);
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
* cryptsetup plain device helper functions
|
||||
*
|
||||
* Copyright (C) 2004 Jana Saout <jana@saout.de>
|
||||
* Copyright (C) 2010-2020 Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2010-2020 Milan Broz
|
||||
* Copyright (C) 2010-2021 Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2010-2021 Milan Broz
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
|
||||
@@ -8,8 +8,8 @@
|
||||
* License/Waiver or the Apache Public License 2.0, at your option. The terms of
|
||||
* these licenses can be found at:
|
||||
*
|
||||
* - CC0 1.0 Universal : http://creativecommons.org/publicdomain/zero/1.0
|
||||
* - Apache 2.0 : http://www.apache.org/licenses/LICENSE-2.0
|
||||
* - CC0 1.0 Universal : https://creativecommons.org/publicdomain/zero/1.0
|
||||
* - Apache 2.0 : https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* You should have received a copy of both of these licenses along with this
|
||||
* software. If not, they may be obtained at the above URLs.
|
||||
@@ -450,6 +450,8 @@ const char *argon2_error_message(int error_code) {
|
||||
|
||||
size_t argon2_encodedlen(uint32_t t_cost, uint32_t m_cost, uint32_t parallelism,
|
||||
uint32_t saltlen, uint32_t hashlen, argon2_type type) {
|
||||
if (!argon2_type2string(type, 0))
|
||||
return 0;
|
||||
return strlen("$$v=$m=,t=,p=$$") + strlen(argon2_type2string(type, 0)) +
|
||||
numlen(t_cost) + numlen(m_cost) + numlen(parallelism) +
|
||||
b64len(saltlen) + b64len(hashlen) + numlen(ARGON2_VERSION_NUMBER) + 1;
|
||||
|
||||
@@ -8,8 +8,8 @@
|
||||
* License/Waiver or the Apache Public License 2.0, at your option. The terms of
|
||||
* these licenses can be found at:
|
||||
*
|
||||
* - CC0 1.0 Universal : http://creativecommons.org/publicdomain/zero/1.0
|
||||
* - Apache 2.0 : http://www.apache.org/licenses/LICENSE-2.0
|
||||
* - CC0 1.0 Universal : https://creativecommons.org/publicdomain/zero/1.0
|
||||
* - Apache 2.0 : https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* You should have received a copy of both of these licenses along with this
|
||||
* software. If not, they may be obtained at the above URLs.
|
||||
|
||||
@@ -8,8 +8,8 @@
|
||||
* License/Waiver or the Apache Public License 2.0, at your option. The terms of
|
||||
* these licenses can be found at:
|
||||
*
|
||||
* - CC0 1.0 Universal : http://creativecommons.org/publicdomain/zero/1.0
|
||||
* - Apache 2.0 : http://www.apache.org/licenses/LICENSE-2.0
|
||||
* - CC0 1.0 Universal : https://creativecommons.org/publicdomain/zero/1.0
|
||||
* - Apache 2.0 : https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* You should have received a copy of both of these licenses along with this
|
||||
* software. If not, they may be obtained at the above URLs.
|
||||
|
||||
@@ -8,8 +8,8 @@
|
||||
* License/Waiver or the Apache Public License 2.0, at your option. The terms of
|
||||
* these licenses can be found at:
|
||||
*
|
||||
* - CC0 1.0 Universal : http://creativecommons.org/publicdomain/zero/1.0
|
||||
* - Apache 2.0 : http://www.apache.org/licenses/LICENSE-2.0
|
||||
* - CC0 1.0 Universal : https://creativecommons.org/publicdomain/zero/1.0
|
||||
* - Apache 2.0 : https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* You should have received a copy of both of these licenses along with this
|
||||
* software. If not, they may be obtained at the above URLs.
|
||||
|
||||
@@ -8,8 +8,8 @@
|
||||
* License/Waiver or the Apache Public License 2.0, at your option. The terms of
|
||||
* these licenses can be found at:
|
||||
*
|
||||
* - CC0 1.0 Universal : http://creativecommons.org/publicdomain/zero/1.0
|
||||
* - Apache 2.0 : http://www.apache.org/licenses/LICENSE-2.0
|
||||
* - CC0 1.0 Universal : https://creativecommons.org/publicdomain/zero/1.0
|
||||
* - Apache 2.0 : https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* You should have received a copy of both of these licenses along with this
|
||||
* software. If not, they may be obtained at the above URLs.
|
||||
|
||||
@@ -8,8 +8,8 @@
|
||||
* License/Waiver or the Apache Public License 2.0, at your option. The terms of
|
||||
* these licenses can be found at:
|
||||
*
|
||||
* - CC0 1.0 Universal : http://creativecommons.org/publicdomain/zero/1.0
|
||||
* - Apache 2.0 : http://www.apache.org/licenses/LICENSE-2.0
|
||||
* - CC0 1.0 Universal : https://creativecommons.org/publicdomain/zero/1.0
|
||||
* - Apache 2.0 : https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* You should have received a copy of both of these licenses along with this
|
||||
* software. If not, they may be obtained at the above URLs.
|
||||
|
||||
@@ -8,8 +8,8 @@
|
||||
* License/Waiver or the Apache Public License 2.0, at your option. The terms of
|
||||
* these licenses can be found at:
|
||||
*
|
||||
* - CC0 1.0 Universal : http://creativecommons.org/publicdomain/zero/1.0
|
||||
* - Apache 2.0 : http://www.apache.org/licenses/LICENSE-2.0
|
||||
* - CC0 1.0 Universal : https://creativecommons.org/publicdomain/zero/1.0
|
||||
* - Apache 2.0 : https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* You should have received a copy of both of these licenses along with this
|
||||
* software. If not, they may be obtained at the above URLs.
|
||||
|
||||
@@ -8,8 +8,8 @@
|
||||
* License/Waiver or the Apache Public License 2.0, at your option. The terms of
|
||||
* these licenses can be found at:
|
||||
*
|
||||
* - CC0 1.0 Universal : http://creativecommons.org/publicdomain/zero/1.0
|
||||
* - Apache 2.0 : http://www.apache.org/licenses/LICENSE-2.0
|
||||
* - CC0 1.0 Universal : https://creativecommons.org/publicdomain/zero/1.0
|
||||
* - Apache 2.0 : https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* You should have received a copy of both of these licenses along with this
|
||||
* software. If not, they may be obtained at the above URLs.
|
||||
|
||||
@@ -8,8 +8,8 @@
|
||||
* License/Waiver or the Apache Public License 2.0, at your option. The terms of
|
||||
* these licenses can be found at:
|
||||
*
|
||||
* - CC0 1.0 Universal : http://creativecommons.org/publicdomain/zero/1.0
|
||||
* - Apache 2.0 : http://www.apache.org/licenses/LICENSE-2.0
|
||||
* - CC0 1.0 Universal : https://creativecommons.org/publicdomain/zero/1.0
|
||||
* - Apache 2.0 : https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* You should have received a copy of both of these licenses along with this
|
||||
* software. If not, they may be obtained at the above URLs.
|
||||
|
||||
@@ -8,8 +8,8 @@
|
||||
* License/Waiver or the Apache Public License 2.0, at your option. The terms of
|
||||
* these licenses can be found at:
|
||||
*
|
||||
* - CC0 1.0 Universal : http://creativecommons.org/publicdomain/zero/1.0
|
||||
* - Apache 2.0 : http://www.apache.org/licenses/LICENSE-2.0
|
||||
* - CC0 1.0 Universal : https://creativecommons.org/publicdomain/zero/1.0
|
||||
* - Apache 2.0 : https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* You should have received a copy of both of these licenses along with this
|
||||
* software. If not, they may be obtained at the above URLs.
|
||||
|
||||
@@ -8,8 +8,8 @@
|
||||
* License/Waiver or the Apache Public License 2.0, at your option. The terms of
|
||||
* these licenses can be found at:
|
||||
*
|
||||
* - CC0 1.0 Universal : http://creativecommons.org/publicdomain/zero/1.0
|
||||
* - Apache 2.0 : http://www.apache.org/licenses/LICENSE-2.0
|
||||
* - CC0 1.0 Universal : https://creativecommons.org/publicdomain/zero/1.0
|
||||
* - Apache 2.0 : https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* You should have received a copy of both of these licenses along with this
|
||||
* software. If not, they may be obtained at the above URLs.
|
||||
|
||||
@@ -8,8 +8,8 @@
|
||||
* License/Waiver or the Apache Public License 2.0, at your option. The terms of
|
||||
* these licenses can be found at:
|
||||
*
|
||||
* - CC0 1.0 Universal : http://creativecommons.org/publicdomain/zero/1.0
|
||||
* - Apache 2.0 : http://www.apache.org/licenses/LICENSE-2.0
|
||||
* - CC0 1.0 Universal : https://creativecommons.org/publicdomain/zero/1.0
|
||||
* - Apache 2.0 : https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* You should have received a copy of both of these licenses along with this
|
||||
* software. If not, they may be obtained at the above URLs.
|
||||
|
||||
@@ -8,8 +8,8 @@
|
||||
* License/Waiver or the Apache Public License 2.0, at your option. The terms of
|
||||
* these licenses can be found at:
|
||||
*
|
||||
* - CC0 1.0 Universal : http://creativecommons.org/publicdomain/zero/1.0
|
||||
* - Apache 2.0 : http://www.apache.org/licenses/LICENSE-2.0
|
||||
* - CC0 1.0 Universal : https://creativecommons.org/publicdomain/zero/1.0
|
||||
* - Apache 2.0 : https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* You should have received a copy of both of these licenses along with this
|
||||
* software. If not, they may be obtained at the above URLs.
|
||||
|
||||
@@ -8,8 +8,8 @@
|
||||
* License/Waiver or the Apache Public License 2.0, at your option. The terms of
|
||||
* these licenses can be found at:
|
||||
*
|
||||
* - CC0 1.0 Universal : http://creativecommons.org/publicdomain/zero/1.0
|
||||
* - Apache 2.0 : http://www.apache.org/licenses/LICENSE-2.0
|
||||
* - CC0 1.0 Universal : https://creativecommons.org/publicdomain/zero/1.0
|
||||
* - Apache 2.0 : https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* You should have received a copy of both of these licenses along with this
|
||||
* software. If not, they may be obtained at the above URLs.
|
||||
|
||||
@@ -8,8 +8,8 @@
|
||||
* License/Waiver or the Apache Public License 2.0, at your option. The terms of
|
||||
* these licenses can be found at:
|
||||
*
|
||||
* - CC0 1.0 Universal : http://creativecommons.org/publicdomain/zero/1.0
|
||||
* - Apache 2.0 : http://www.apache.org/licenses/LICENSE-2.0
|
||||
* - CC0 1.0 Universal : https://creativecommons.org/publicdomain/zero/1.0
|
||||
* - Apache 2.0 : https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* You should have received a copy of both of these licenses along with this
|
||||
* software. If not, they may be obtained at the above URLs.
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/*
|
||||
* Argon2 PBKDF2 library wrapper
|
||||
*
|
||||
* Copyright (C) 2016-2020 Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2016-2020 Milan Broz
|
||||
* Copyright (C) 2016-2021 Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2016-2021 Milan Broz
|
||||
*
|
||||
* This file is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/*
|
||||
* Cipher performance check
|
||||
*
|
||||
* Copyright (C) 2018-2020 Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2018-2020 Milan Broz
|
||||
* Copyright (C) 2018-2021 Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2018-2021 Milan Broz
|
||||
*
|
||||
* This file is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
@@ -23,6 +23,10 @@
|
||||
#include <time.h>
|
||||
#include "crypto_backend_internal.h"
|
||||
|
||||
#ifndef CLOCK_MONOTONIC_RAW
|
||||
#define CLOCK_MONOTONIC_RAW CLOCK_MONOTONIC
|
||||
#endif
|
||||
|
||||
/*
|
||||
* This is not simulating storage, so using disk block causes extreme overhead.
|
||||
* Let's use some fixed block size where results are more reliable...
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/*
|
||||
* Linux kernel cipher generic utilities
|
||||
*
|
||||
* Copyright (C) 2018-2020 Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2018-2020 Milan Broz
|
||||
* Copyright (C) 2018-2021 Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2018-2021 Milan Broz
|
||||
*
|
||||
* This file is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
@@ -31,7 +31,6 @@ struct cipher_alg {
|
||||
bool wrapped_key;
|
||||
};
|
||||
|
||||
/* FIXME: Getting block size should be dynamic from cipher backend. */
|
||||
static const struct cipher_alg cipher_algs[] = {
|
||||
{ "cipher_null", NULL, 16, false },
|
||||
{ "aes", NULL, 16, false },
|
||||
@@ -51,6 +50,7 @@ static const struct cipher_alg cipher_algs[] = {
|
||||
{ "paes", NULL, 16, true }, /* protected AES, s390 wrapped key scheme */
|
||||
{ "xchacha12,aes", "adiantum", 32, false },
|
||||
{ "xchacha20,aes", "adiantum", 32, false },
|
||||
{ "sm4", NULL, 16, false },
|
||||
{ NULL, NULL, 0, false }
|
||||
};
|
||||
|
||||
@@ -72,7 +72,13 @@ int crypt_cipher_ivsize(const char *name, const char *mode)
|
||||
{
|
||||
const struct cipher_alg *ca = _get_alg(name, mode);
|
||||
|
||||
return ca ? ca->blocksize : -EINVAL;
|
||||
if (!ca)
|
||||
return -EINVAL;
|
||||
|
||||
if (mode && !strcasecmp(mode, "ecb"))
|
||||
return 0;
|
||||
|
||||
return ca->blocksize;
|
||||
}
|
||||
|
||||
int crypt_cipher_wrapped_key(const char *name, const char *mode)
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/*
|
||||
* crypto backend implementation
|
||||
*
|
||||
* Copyright (C) 2010-2020 Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2010-2020 Milan Broz
|
||||
* Copyright (C) 2010-2021 Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2010-2021 Milan Broz
|
||||
*
|
||||
* This file is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
@@ -26,13 +26,12 @@
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
|
||||
struct crypt_device;
|
||||
struct crypt_hash;
|
||||
struct crypt_hmac;
|
||||
struct crypt_cipher;
|
||||
struct crypt_storage;
|
||||
|
||||
int crypt_backend_init(struct crypt_device *ctx);
|
||||
int crypt_backend_init(void);
|
||||
void crypt_backend_destroy(void);
|
||||
|
||||
#define CRYPT_BACKEND_KERNEL (1 << 0) /* Crypto uses kernel part, for benchmark */
|
||||
@@ -63,7 +62,7 @@ int crypt_backend_rng(char *buffer, size_t length, int quality, int fips);
|
||||
/* PBKDF*/
|
||||
struct crypt_pbkdf_limits {
|
||||
uint32_t min_iterations, max_iterations;
|
||||
uint32_t min_memory, max_memory;
|
||||
uint32_t min_memory, max_memory, min_bench_memory;
|
||||
uint32_t min_parallel, max_parallel;
|
||||
};
|
||||
|
||||
@@ -110,7 +109,7 @@ int crypt_cipher_check_kernel(const char *name, const char *mode,
|
||||
/* Storage encryption wrappers */
|
||||
int crypt_storage_init(struct crypt_storage **ctx, size_t sector_size,
|
||||
const char *cipher, const char *cipher_mode,
|
||||
const void *key, size_t key_length);
|
||||
const void *key, size_t key_length, bool large_iv);
|
||||
void crypt_storage_destroy(struct crypt_storage *ctx);
|
||||
int crypt_storage_decrypt(struct crypt_storage *ctx, uint64_t iv_offset,
|
||||
uint64_t length, char *buffer);
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/*
|
||||
* crypto backend implementation
|
||||
*
|
||||
* Copyright (C) 2010-2020 Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2010-2020 Milan Broz
|
||||
* Copyright (C) 2010-2021 Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2010-2021 Milan Broz
|
||||
*
|
||||
* This file is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
@@ -23,7 +23,6 @@
|
||||
|
||||
#include "crypto_backend.h"
|
||||
|
||||
#if USE_INTERNAL_PBKDF2
|
||||
/* internal PBKDF2 implementation */
|
||||
int pkcs5_pbkdf2(const char *hash,
|
||||
const char *P, size_t Plen,
|
||||
@@ -31,7 +30,6 @@ int pkcs5_pbkdf2(const char *hash,
|
||||
unsigned int c,
|
||||
unsigned int dkLen, char *DK,
|
||||
unsigned int hash_block_size);
|
||||
#endif
|
||||
|
||||
/* Argon2 implementation wrapper */
|
||||
int argon2(const char *type, const char *password, size_t password_length,
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/*
|
||||
* Linux kernel userspace API crypto backend implementation (skcipher)
|
||||
*
|
||||
* Copyright (C) 2012-2020 Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2012-2020 Milan Broz
|
||||
* Copyright (C) 2012-2021 Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2012-2021 Milan Broz
|
||||
*
|
||||
* This file is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
@@ -96,11 +96,14 @@ int crypt_cipher_init_kernel(struct crypt_cipher_kernel *ctx, const char *name,
|
||||
.salg_family = AF_ALG,
|
||||
.salg_type = "skcipher",
|
||||
};
|
||||
int r;
|
||||
|
||||
if (!strcmp(name, "cipher_null"))
|
||||
key_length = 0;
|
||||
|
||||
snprintf((char *)sa.salg_name, sizeof(sa.salg_name), "%s(%s)", mode, name);
|
||||
r = snprintf((char *)sa.salg_name, sizeof(sa.salg_name), "%s(%s)", mode, name);
|
||||
if (r < 0 || (size_t)r >= sizeof(sa.salg_name))
|
||||
return -EINVAL;
|
||||
|
||||
return _crypt_cipher_init(ctx, key, key_length, 0, &sa);
|
||||
}
|
||||
@@ -152,6 +155,9 @@ static int _crypt_cipher_crypt(struct crypt_cipher_kernel *ctx,
|
||||
/* Set IV */
|
||||
if (iv) {
|
||||
header = CMSG_NXTHDR(&msg, header);
|
||||
if (!header)
|
||||
return -EINVAL;
|
||||
|
||||
header->cmsg_level = SOL_ALG;
|
||||
header->cmsg_type = ALG_SET_IV;
|
||||
header->cmsg_len = iv_msg_size;
|
||||
@@ -161,15 +167,14 @@ static int _crypt_cipher_crypt(struct crypt_cipher_kernel *ctx,
|
||||
}
|
||||
|
||||
len = sendmsg(ctx->opfd, &msg, 0);
|
||||
if (len != (ssize_t)(in_length)) {
|
||||
if (len != (ssize_t)(in_length))
|
||||
r = -EIO;
|
||||
goto bad;
|
||||
else {
|
||||
len = read(ctx->opfd, out, out_length);
|
||||
if (len != (ssize_t)out_length)
|
||||
r = -EIO;
|
||||
}
|
||||
|
||||
len = read(ctx->opfd, out, out_length);
|
||||
if (len != (ssize_t)out_length)
|
||||
r = -EIO;
|
||||
bad:
|
||||
crypt_backend_memzero(buffer, sizeof(buffer));
|
||||
return r;
|
||||
}
|
||||
@@ -227,7 +232,10 @@ int crypt_cipher_check_kernel(const char *name, const char *mode,
|
||||
}
|
||||
|
||||
salg_type = aead ? "aead" : "skcipher";
|
||||
snprintf((char *)sa.salg_type, sizeof(sa.salg_type), "%s", salg_type);
|
||||
r = snprintf((char *)sa.salg_type, sizeof(sa.salg_type), "%s", salg_type);
|
||||
if (r < 0 || (size_t)r >= sizeof(sa.salg_name))
|
||||
return -EINVAL;
|
||||
|
||||
memset(tmp_salg_name, 0, sizeof(tmp_salg_name));
|
||||
|
||||
/* FIXME: this is duplicating a part of devmapper backend */
|
||||
@@ -240,7 +248,7 @@ int crypt_cipher_check_kernel(const char *name, const char *mode,
|
||||
else
|
||||
r = snprintf(tmp_salg_name, sizeof(tmp_salg_name), "%s(%s)", real_mode, name);
|
||||
|
||||
if (r <= 0 || r > (int)(sizeof(sa.salg_name) - 1))
|
||||
if (r < 0 || (size_t)r >= sizeof(tmp_salg_name))
|
||||
return -EINVAL;
|
||||
|
||||
memcpy(sa.salg_name, tmp_salg_name, sizeof(sa.salg_name));
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/*
|
||||
* GCRYPT crypto backend implementation
|
||||
*
|
||||
* Copyright (C) 2010-2020 Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2010-2020 Milan Broz
|
||||
* Copyright (C) 2010-2021 Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2010-2021 Milan Broz
|
||||
*
|
||||
* This file is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
@@ -51,9 +51,14 @@ struct crypt_cipher {
|
||||
} u;
|
||||
};
|
||||
|
||||
struct hash_alg {
|
||||
const char *name;
|
||||
const char *gcrypt_name;
|
||||
};
|
||||
|
||||
/*
|
||||
* Test for wrong Whirlpool variant,
|
||||
* Ref: http://lists.gnupg.org/pipermail/gcrypt-devel/2014-January/002889.html
|
||||
* Ref: https://lists.gnupg.org/pipermail/gcrypt-devel/2014-January/002889.html
|
||||
*/
|
||||
static void crypt_hash_test_whirlpool_bug(void)
|
||||
{
|
||||
@@ -89,8 +94,10 @@ static void crypt_hash_test_whirlpool_bug(void)
|
||||
crypto_backend_whirlpool_bug = 1;
|
||||
}
|
||||
|
||||
int crypt_backend_init(struct crypt_device *ctx)
|
||||
int crypt_backend_init(void)
|
||||
{
|
||||
int r;
|
||||
|
||||
if (crypto_backend_initialised)
|
||||
return 0;
|
||||
|
||||
@@ -99,7 +106,7 @@ int crypt_backend_init(struct crypt_device *ctx)
|
||||
return -ENOSYS;
|
||||
}
|
||||
|
||||
/* FIXME: If gcrypt compiled to support POSIX 1003.1e capabilities,
|
||||
/* If gcrypt compiled to support POSIX 1003.1e capabilities,
|
||||
* it drops all privileges during secure memory initialisation.
|
||||
* For now, the only workaround is to disable secure memory in gcrypt.
|
||||
* cryptsetup always need at least cap_sys_admin privilege for dm-ioctl
|
||||
@@ -120,11 +127,12 @@ int crypt_backend_init(struct crypt_device *ctx)
|
||||
crypto_backend_initialised = 1;
|
||||
crypt_hash_test_whirlpool_bug();
|
||||
|
||||
snprintf(version, 64, "gcrypt %s%s%s",
|
||||
r = snprintf(version, sizeof(version), "gcrypt %s%s%s",
|
||||
gcry_check_version(NULL),
|
||||
crypto_backend_secmem ? "" : ", secmem disabled",
|
||||
crypto_backend_whirlpool_bug > 0 ? ", flawed whirlpool" : ""
|
||||
);
|
||||
crypto_backend_whirlpool_bug > 0 ? ", flawed whirlpool" : "");
|
||||
if (r < 0 || (size_t)r >= sizeof(version))
|
||||
return -EINVAL;
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -150,10 +158,24 @@ uint32_t crypt_backend_flags(void)
|
||||
static const char *crypt_hash_compat_name(const char *name, unsigned int *flags)
|
||||
{
|
||||
const char *hash_name = name;
|
||||
int i;
|
||||
static struct hash_alg hash_algs[] = {
|
||||
{ "blake2b-160", "blake2b_160" },
|
||||
{ "blake2b-256", "blake2b_256" },
|
||||
{ "blake2b-384", "blake2b_384" },
|
||||
{ "blake2b-512", "blake2b_512" },
|
||||
{ "blake2s-128", "blake2s_128" },
|
||||
{ "blake2s-160", "blake2s_160" },
|
||||
{ "blake2s-224", "blake2s_224" },
|
||||
{ "blake2s-256", "blake2s_256" },
|
||||
{ NULL, NULL, }};
|
||||
|
||||
if (!name)
|
||||
return NULL;
|
||||
|
||||
/* "whirlpool_gcryptbug" is out shortcut to flawed whirlpool
|
||||
* in libgcrypt < 1.6.0 */
|
||||
if (name && !strcasecmp(name, "whirlpool_gcryptbug")) {
|
||||
if (!strcasecmp(name, "whirlpool_gcryptbug")) {
|
||||
#if GCRYPT_VERSION_NUMBER >= 0x010601
|
||||
if (flags)
|
||||
*flags |= GCRY_MD_FLAG_BUGEMU1;
|
||||
@@ -161,6 +183,15 @@ static const char *crypt_hash_compat_name(const char *name, unsigned int *flags)
|
||||
hash_name = "whirlpool";
|
||||
}
|
||||
|
||||
i = 0;
|
||||
while (hash_algs[i].name) {
|
||||
if (!strcasecmp(name, hash_algs[i].name)) {
|
||||
hash_name = hash_algs[i].gcrypt_name;
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
return hash_name;
|
||||
}
|
||||
|
||||
@@ -316,7 +347,7 @@ void crypt_hmac_destroy(struct crypt_hmac *ctx)
|
||||
}
|
||||
|
||||
/* RNG */
|
||||
int crypt_backend_rng(char *buffer, size_t length, int quality, int fips)
|
||||
int crypt_backend_rng(char *buffer, size_t length, int quality, int fips __attribute__((unused)))
|
||||
{
|
||||
switch(quality) {
|
||||
case CRYPT_RND_NORMAL:
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/*
|
||||
* Linux kernel userspace API crypto backend implementation
|
||||
*
|
||||
* Copyright (C) 2010-2020 Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2010-2020 Milan Broz
|
||||
* Copyright (C) 2010-2021 Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2010-2021 Milan Broz
|
||||
*
|
||||
* This file is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
@@ -29,7 +29,6 @@
|
||||
#include <linux/if_alg.h>
|
||||
#include "crypto_backend_internal.h"
|
||||
|
||||
/* FIXME: remove later */
|
||||
#ifndef AF_ALG
|
||||
#define AF_ALG 38
|
||||
#endif
|
||||
@@ -62,6 +61,14 @@ static struct hash_alg hash_algs[] = {
|
||||
{ "stribog256","streebog256", 32, 64 },
|
||||
{ "stribog512","streebog512", 64, 64 },
|
||||
{ "sm3", "sm3", 32, 64 },
|
||||
{ "blake2b-160","blake2b-160",20, 128 },
|
||||
{ "blake2b-256","blake2b-256",32, 128 },
|
||||
{ "blake2b-384","blake2b-384",48, 128 },
|
||||
{ "blake2b-512","blake2b-512",64, 128 },
|
||||
{ "blake2s-128","blake2s-128",16, 64 },
|
||||
{ "blake2s-160","blake2s-160",20, 64 },
|
||||
{ "blake2s-224","blake2s-224",28, 64 },
|
||||
{ "blake2s-256","blake2s-256",32, 64 },
|
||||
{ NULL, NULL, 0, 0 }
|
||||
};
|
||||
|
||||
@@ -110,7 +117,7 @@ static int crypt_kernel_socket_init(struct sockaddr_alg *sa, int *tfmfd, int *op
|
||||
return 0;
|
||||
}
|
||||
|
||||
int crypt_backend_init(struct crypt_device *ctx)
|
||||
int crypt_backend_init(void)
|
||||
{
|
||||
struct utsname uts;
|
||||
struct sockaddr_alg sa = {
|
||||
@@ -118,7 +125,7 @@ int crypt_backend_init(struct crypt_device *ctx)
|
||||
.salg_type = "hash",
|
||||
.salg_name = "sha256",
|
||||
};
|
||||
int tfmfd = -1, opfd = -1;
|
||||
int r, tfmfd = -1, opfd = -1;
|
||||
|
||||
if (crypto_backend_initialised)
|
||||
return 0;
|
||||
@@ -126,15 +133,17 @@ int crypt_backend_init(struct crypt_device *ctx)
|
||||
if (uname(&uts) == -1 || strcmp(uts.sysname, "Linux"))
|
||||
return -EINVAL;
|
||||
|
||||
r = snprintf(version, sizeof(version), "%s %s kernel cryptoAPI",
|
||||
uts.sysname, uts.release);
|
||||
if (r < 0 || (size_t)r >= sizeof(version))
|
||||
return -EINVAL;
|
||||
|
||||
if (crypt_kernel_socket_init(&sa, &tfmfd, &opfd, NULL, 0) < 0)
|
||||
return -EINVAL;
|
||||
|
||||
close(tfmfd);
|
||||
close(opfd);
|
||||
|
||||
snprintf(version, sizeof(version), "%s %s kernel cryptoAPI",
|
||||
uts.sysname, uts.release);
|
||||
|
||||
crypto_backend_initialised = 1;
|
||||
return 0;
|
||||
}
|
||||
@@ -255,6 +264,7 @@ int crypt_hmac_init(struct crypt_hmac **ctx, const char *name,
|
||||
.salg_family = AF_ALG,
|
||||
.salg_type = "hash",
|
||||
};
|
||||
int r;
|
||||
|
||||
h = malloc(sizeof(*h));
|
||||
if (!h)
|
||||
@@ -267,8 +277,12 @@ int crypt_hmac_init(struct crypt_hmac **ctx, const char *name,
|
||||
}
|
||||
h->hash_len = ha->length;
|
||||
|
||||
snprintf((char *)sa.salg_name, sizeof(sa.salg_name),
|
||||
r = snprintf((char *)sa.salg_name, sizeof(sa.salg_name),
|
||||
"hmac(%s)", ha->kernel_name);
|
||||
if (r < 0 || (size_t)r >= sizeof(sa.salg_name)) {
|
||||
free(h);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (crypt_kernel_socket_init(&sa, &h->tfmfd, &h->opfd, key, key_length) < 0) {
|
||||
free(h);
|
||||
@@ -315,7 +329,8 @@ void crypt_hmac_destroy(struct crypt_hmac *ctx)
|
||||
}
|
||||
|
||||
/* RNG - N/A */
|
||||
int crypt_backend_rng(char *buffer, size_t length, int quality, int fips)
|
||||
int crypt_backend_rng(char *buffer __attribute__((unused)), size_t length __attribute__((unused)),
|
||||
int quality __attribute__((unused)), int fips __attribute__((unused)))
|
||||
{
|
||||
return -EINVAL;
|
||||
}
|
||||
@@ -388,7 +403,7 @@ int crypt_cipher_decrypt(struct crypt_cipher *ctx,
|
||||
return crypt_cipher_decrypt_kernel(&ctx->ck, in, out, length, iv, iv_length);
|
||||
}
|
||||
|
||||
bool crypt_cipher_kernel_only(struct crypt_cipher *ctx)
|
||||
bool crypt_cipher_kernel_only(struct crypt_cipher *ctx __attribute__((unused)))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/*
|
||||
* Nettle crypto backend implementation
|
||||
*
|
||||
* Copyright (C) 2011-2020 Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2011-2020 Milan Broz
|
||||
* Copyright (C) 2011-2021 Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2011-2021 Milan Broz
|
||||
*
|
||||
* This file is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
@@ -213,7 +213,7 @@ static struct hash_alg *_get_alg(const char *name)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int crypt_backend_init(struct crypt_device *ctx)
|
||||
int crypt_backend_init(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@@ -301,12 +301,16 @@ int crypt_hmac_init(struct crypt_hmac **ctx, const char *name,
|
||||
|
||||
|
||||
h->hash = _get_alg(name);
|
||||
if (!h->hash)
|
||||
goto bad;
|
||||
if (!h->hash) {
|
||||
free(h);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
h->key = malloc(key_length);
|
||||
if (!h->key)
|
||||
goto bad;
|
||||
if (!h->key) {
|
||||
free(h);
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
memcpy(h->key, key, key_length);
|
||||
h->key_length = key_length;
|
||||
@@ -316,9 +320,6 @@ int crypt_hmac_init(struct crypt_hmac **ctx, const char *name,
|
||||
|
||||
*ctx = h;
|
||||
return 0;
|
||||
bad:
|
||||
free(h);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
static void crypt_hmac_restart(struct crypt_hmac *ctx)
|
||||
@@ -351,7 +352,10 @@ void crypt_hmac_destroy(struct crypt_hmac *ctx)
|
||||
}
|
||||
|
||||
/* RNG - N/A */
|
||||
int crypt_backend_rng(char *buffer, size_t length, int quality, int fips)
|
||||
int crypt_backend_rng(char *buffer __attribute__((unused)),
|
||||
size_t length __attribute__((unused)),
|
||||
int quality __attribute__((unused)),
|
||||
int fips __attribute__((unused)))
|
||||
{
|
||||
return -EINVAL;
|
||||
}
|
||||
@@ -429,7 +433,7 @@ int crypt_cipher_decrypt(struct crypt_cipher *ctx,
|
||||
return crypt_cipher_decrypt_kernel(&ctx->ck, in, out, length, iv, iv_length);
|
||||
}
|
||||
|
||||
bool crypt_cipher_kernel_only(struct crypt_cipher *ctx)
|
||||
bool crypt_cipher_kernel_only(struct crypt_cipher *ctx __attribute__((unused)))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/*
|
||||
* NSS crypto backend implementation
|
||||
*
|
||||
* Copyright (C) 2010-2020 Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2010-2020 Milan Broz
|
||||
* Copyright (C) 2010-2021 Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2010-2021 Milan Broz
|
||||
*
|
||||
* This file is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
@@ -75,8 +75,10 @@ static struct hash_alg *_get_alg(const char *name)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int crypt_backend_init(struct crypt_device *ctx)
|
||||
int crypt_backend_init(void)
|
||||
{
|
||||
int r;
|
||||
|
||||
if (crypto_backend_initialised)
|
||||
return 0;
|
||||
|
||||
@@ -84,10 +86,13 @@ int crypt_backend_init(struct crypt_device *ctx)
|
||||
return -EINVAL;
|
||||
|
||||
#if HAVE_DECL_NSS_GETVERSION
|
||||
snprintf(version, 64, "NSS %s", NSS_GetVersion());
|
||||
r = snprintf(version, sizeof(version), "NSS %s", NSS_GetVersion());
|
||||
#else
|
||||
snprintf(version, 64, "NSS");
|
||||
r = snprintf(version, sizeof(version), "NSS");
|
||||
#endif
|
||||
if (r < 0 || (size_t)r >= sizeof(version))
|
||||
return -EINVAL;
|
||||
|
||||
crypto_backend_initialised = 1;
|
||||
return 0;
|
||||
}
|
||||
@@ -220,28 +225,28 @@ int crypt_hmac_init(struct crypt_hmac **ctx, const char *name,
|
||||
|
||||
h->hash = _get_alg(name);
|
||||
if (!h->hash)
|
||||
goto bad;
|
||||
goto err;
|
||||
|
||||
h->slot = PK11_GetInternalKeySlot();
|
||||
if (!h->slot)
|
||||
goto bad;
|
||||
goto err;
|
||||
|
||||
h->key = PK11_ImportSymKey(h->slot, h->hash->ck_type, PK11_OriginUnwrap,
|
||||
CKA_SIGN, &keyItem, NULL);
|
||||
if (!h->key)
|
||||
goto bad;
|
||||
goto err;
|
||||
|
||||
h->md = PK11_CreateContextBySymKey(h->hash->ck_type, CKA_SIGN, h->key,
|
||||
&noParams);
|
||||
if (!h->md)
|
||||
goto bad;
|
||||
goto err;
|
||||
|
||||
if (PK11_DigestBegin(h->md) != SECSuccess)
|
||||
goto bad;
|
||||
goto err;
|
||||
|
||||
*ctx = h;
|
||||
return 0;
|
||||
bad:
|
||||
err:
|
||||
crypt_hmac_destroy(h);
|
||||
return -EINVAL;
|
||||
}
|
||||
@@ -298,7 +303,7 @@ void crypt_hmac_destroy(struct crypt_hmac *ctx)
|
||||
}
|
||||
|
||||
/* RNG */
|
||||
int crypt_backend_rng(char *buffer, size_t length, int quality, int fips)
|
||||
int crypt_backend_rng(char *buffer, size_t length, int quality __attribute__((unused)), int fips)
|
||||
{
|
||||
if (fips)
|
||||
return -EINVAL;
|
||||
@@ -377,7 +382,7 @@ int crypt_cipher_decrypt(struct crypt_cipher *ctx,
|
||||
return crypt_cipher_decrypt_kernel(&ctx->ck, in, out, length, iv, iv_length);
|
||||
}
|
||||
|
||||
bool crypt_cipher_kernel_only(struct crypt_cipher *ctx)
|
||||
bool crypt_cipher_kernel_only(struct crypt_cipher *ctx __attribute__((unused)))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/*
|
||||
* OPENSSL crypto backend implementation
|
||||
*
|
||||
* Copyright (C) 2010-2020 Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2010-2020 Milan Broz
|
||||
* Copyright (C) 2010-2021 Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2010-2021 Milan Broz
|
||||
*
|
||||
* This file is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
@@ -28,12 +28,22 @@
|
||||
* for all of the code used other than OpenSSL.
|
||||
*/
|
||||
|
||||
/*
|
||||
* HMAC will be later rewritten to a new API from OpenSSL 3
|
||||
*/
|
||||
#define OPENSSL_SUPPRESS_DEPRECATED
|
||||
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <openssl/evp.h>
|
||||
#include <openssl/hmac.h>
|
||||
#include <openssl/rand.h>
|
||||
#include "crypto_backend_internal.h"
|
||||
#if OPENSSL_VERSION_MAJOR >= 3
|
||||
#include <openssl/provider.h>
|
||||
static OSSL_PROVIDER *ossl_legacy = NULL;
|
||||
static OSSL_PROVIDER *ossl_default = NULL;
|
||||
#endif
|
||||
|
||||
#define CONST_CAST(x) (x)(uintptr_t)
|
||||
|
||||
@@ -63,6 +73,11 @@ struct crypt_cipher {
|
||||
} u;
|
||||
};
|
||||
|
||||
struct hash_alg {
|
||||
const char *name;
|
||||
const char *openssl_name;
|
||||
};
|
||||
|
||||
/*
|
||||
* Compatible wrappers for OpenSSL < 1.1.0 and LibreSSL < 2.7.0
|
||||
*/
|
||||
@@ -74,6 +89,10 @@ static void openssl_backend_init(void)
|
||||
OpenSSL_add_all_algorithms();
|
||||
}
|
||||
|
||||
static void openssl_backend_exit(void)
|
||||
{
|
||||
}
|
||||
|
||||
static const char *openssl_backend_version(void)
|
||||
{
|
||||
return SSLeay_version(SSLEAY_VERSION);
|
||||
@@ -113,6 +132,30 @@ static void HMAC_CTX_free(HMAC_CTX *md)
|
||||
#else
|
||||
static void openssl_backend_init(void)
|
||||
{
|
||||
/*
|
||||
* OpenSSL >= 3.0.0 provides some algorithms in legacy provider
|
||||
*/
|
||||
#if OPENSSL_VERSION_MAJOR >= 3
|
||||
OPENSSL_init_crypto(OPENSSL_INIT_NO_ATEXIT, NULL);
|
||||
ossl_legacy = OSSL_PROVIDER_try_load(NULL, "legacy", 0);
|
||||
ossl_default = OSSL_PROVIDER_try_load(NULL, "default", 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void openssl_backend_exit(void)
|
||||
{
|
||||
#if OPENSSL_VERSION_MAJOR >= 3
|
||||
/*
|
||||
* If Destructor was already called, we must not call it again
|
||||
*/
|
||||
if (OPENSSL_init_crypto(0, NULL) != 0) {
|
||||
OSSL_PROVIDER_unload(ossl_legacy);
|
||||
OSSL_PROVIDER_unload(ossl_default);
|
||||
OPENSSL_cleanup();
|
||||
}
|
||||
ossl_legacy = NULL;
|
||||
ossl_default = NULL;
|
||||
#endif
|
||||
}
|
||||
|
||||
static const char *openssl_backend_version(void)
|
||||
@@ -121,7 +164,7 @@ static const char *openssl_backend_version(void)
|
||||
}
|
||||
#endif
|
||||
|
||||
int crypt_backend_init(struct crypt_device *ctx)
|
||||
int crypt_backend_init(void)
|
||||
{
|
||||
if (crypto_backend_initialised)
|
||||
return 0;
|
||||
@@ -135,6 +178,7 @@ int crypt_backend_init(struct crypt_device *ctx)
|
||||
void crypt_backend_destroy(void)
|
||||
{
|
||||
crypto_backend_initialised = 0;
|
||||
openssl_backend_exit();
|
||||
}
|
||||
|
||||
uint32_t crypt_backend_flags(void)
|
||||
@@ -147,11 +191,36 @@ const char *crypt_backend_version(void)
|
||||
return openssl_backend_version();
|
||||
}
|
||||
|
||||
static const char *crypt_hash_compat_name(const char *name)
|
||||
{
|
||||
const char *hash_name = name;
|
||||
int i;
|
||||
static struct hash_alg hash_algs[] = {
|
||||
{ "blake2b-512", "blake2b512" },
|
||||
{ "blake2s-256", "blake2s256" },
|
||||
{ NULL, NULL, }};
|
||||
|
||||
if (!name)
|
||||
return NULL;
|
||||
|
||||
i = 0;
|
||||
while (hash_algs[i].name) {
|
||||
if (!strcasecmp(name, hash_algs[i].name)) {
|
||||
hash_name = hash_algs[i].openssl_name;
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
return hash_name;
|
||||
}
|
||||
|
||||
/* HASH */
|
||||
int crypt_hash_size(const char *name)
|
||||
{
|
||||
const EVP_MD *hash_id = EVP_get_digestbyname(name);
|
||||
const EVP_MD *hash_id;
|
||||
|
||||
hash_id = EVP_get_digestbyname(crypt_hash_compat_name(name));
|
||||
if (!hash_id)
|
||||
return -EINVAL;
|
||||
|
||||
@@ -172,7 +241,7 @@ int crypt_hash_init(struct crypt_hash **ctx, const char *name)
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
h->hash_id = EVP_get_digestbyname(name);
|
||||
h->hash_id = EVP_get_digestbyname(crypt_hash_compat_name(name));
|
||||
if (!h->hash_id) {
|
||||
EVP_MD_CTX_free(h->md);
|
||||
free(h);
|
||||
@@ -257,7 +326,7 @@ int crypt_hmac_init(struct crypt_hmac **ctx, const char *name,
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
h->hash_id = EVP_get_digestbyname(name);
|
||||
h->hash_id = EVP_get_digestbyname(crypt_hash_compat_name(name));
|
||||
if (!h->hash_id) {
|
||||
HMAC_CTX_free(h->md);
|
||||
free(h);
|
||||
@@ -311,7 +380,8 @@ void crypt_hmac_destroy(struct crypt_hmac *ctx)
|
||||
}
|
||||
|
||||
/* RNG */
|
||||
int crypt_backend_rng(char *buffer, size_t length, int quality, int fips)
|
||||
int crypt_backend_rng(char *buffer, size_t length,
|
||||
int quality __attribute__((unused)), int fips __attribute__((unused)))
|
||||
{
|
||||
if (RAND_bytes((unsigned char *)buffer, length) != 1)
|
||||
return -EINVAL;
|
||||
@@ -333,7 +403,7 @@ int crypt_pbkdf(const char *kdf, const char *hash,
|
||||
return -EINVAL;
|
||||
|
||||
if (!strcmp(kdf, "pbkdf2")) {
|
||||
hash_id = EVP_get_digestbyname(hash);
|
||||
hash_id = EVP_get_digestbyname(crypt_hash_compat_name(hash));
|
||||
if (!hash_id)
|
||||
return -EINVAL;
|
||||
|
||||
@@ -372,7 +442,7 @@ static int _cipher_init(EVP_CIPHER_CTX **hd_enc, EVP_CIPHER_CTX **hd_dec, const
|
||||
key_bits /= 2;
|
||||
|
||||
r = snprintf(cipher_name, sizeof(cipher_name), "%s-%d-%s", name, key_bits, mode);
|
||||
if (r < 0 || r >= (int)sizeof(cipher_name))
|
||||
if (r < 0 || (size_t)r >= sizeof(cipher_name))
|
||||
return -EINVAL;
|
||||
|
||||
type = EVP_get_cipherbyname(cipher_name);
|
||||
@@ -508,7 +578,7 @@ bool crypt_cipher_kernel_only(struct crypt_cipher *ctx)
|
||||
return ctx->use_kernel;
|
||||
}
|
||||
|
||||
int crypt_bitlk_decrypt_key(const void *key, size_t key_length,
|
||||
int crypt_bitlk_decrypt_key(const void *key, size_t key_length __attribute__((unused)),
|
||||
const char *in, char *out, size_t length,
|
||||
const char *iv, size_t iv_length,
|
||||
const char *tag, size_t tag_length)
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* Generic wrapper for storage encryption modes and Initial Vectors
|
||||
* (reimplementation of some functions from Linux dm-crypt kernel)
|
||||
*
|
||||
* Copyright (C) 2014-2020 Milan Broz
|
||||
* Copyright (C) 2014-2021 Milan Broz
|
||||
*
|
||||
* This file is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
@@ -21,6 +21,7 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <strings.h>
|
||||
#include "bitops.h"
|
||||
#include "crypto_backend.h"
|
||||
|
||||
@@ -31,16 +32,16 @@
|
||||
* IV documentation: https://gitlab.com/cryptsetup/cryptsetup/wikis/DMCrypt
|
||||
*/
|
||||
struct crypt_sector_iv {
|
||||
enum { IV_NONE, IV_NULL, IV_PLAIN, IV_PLAIN64, IV_ESSIV, IV_BENBI, IV_PLAIN64BE } type;
|
||||
enum { IV_NONE, IV_NULL, IV_PLAIN, IV_PLAIN64, IV_ESSIV, IV_BENBI, IV_PLAIN64BE, IV_EBOIV } type;
|
||||
int iv_size;
|
||||
char *iv;
|
||||
struct crypt_cipher *essiv_cipher;
|
||||
int benbi_shift;
|
||||
struct crypt_cipher *cipher;
|
||||
int shift;
|
||||
};
|
||||
|
||||
/* Block encryption storage context */
|
||||
struct crypt_storage {
|
||||
unsigned sector_shift;
|
||||
size_t sector_size;
|
||||
unsigned iv_shift;
|
||||
struct crypt_cipher *cipher;
|
||||
struct crypt_sector_iv cipher_iv;
|
||||
@@ -56,12 +57,15 @@ static int int_log2(unsigned int x)
|
||||
|
||||
static int crypt_sector_iv_init(struct crypt_sector_iv *ctx,
|
||||
const char *cipher_name, const char *mode_name,
|
||||
const char *iv_name, const void *key, size_t key_length)
|
||||
const char *iv_name, const void *key, size_t key_length,
|
||||
size_t sector_size)
|
||||
{
|
||||
int r;
|
||||
|
||||
memset(ctx, 0, sizeof(*ctx));
|
||||
|
||||
ctx->iv_size = crypt_cipher_ivsize(cipher_name, mode_name);
|
||||
if (ctx->iv_size < 8)
|
||||
if (ctx->iv_size < 0 || (strcmp(mode_name, "ecb") && ctx->iv_size < 8))
|
||||
return -ENOENT;
|
||||
|
||||
if (!strcmp(cipher_name, "cipher_null") ||
|
||||
@@ -86,7 +90,6 @@ static int crypt_sector_iv_init(struct crypt_sector_iv *ctx,
|
||||
char *hash_name = strchr(iv_name, ':');
|
||||
int hash_size;
|
||||
char tmp[256];
|
||||
int r;
|
||||
|
||||
if (!hash_name)
|
||||
return -EINVAL;
|
||||
@@ -114,7 +117,7 @@ static int crypt_sector_iv_init(struct crypt_sector_iv *ctx,
|
||||
return r;
|
||||
}
|
||||
|
||||
r = crypt_cipher_init(&ctx->essiv_cipher, cipher_name, "ecb",
|
||||
r = crypt_cipher_init(&ctx->cipher, cipher_name, "ecb",
|
||||
tmp, hash_size);
|
||||
crypt_backend_memzero(tmp, sizeof(tmp));
|
||||
if (r)
|
||||
@@ -127,7 +130,15 @@ static int crypt_sector_iv_init(struct crypt_sector_iv *ctx,
|
||||
return -EINVAL;
|
||||
|
||||
ctx->type = IV_BENBI;
|
||||
ctx->benbi_shift = SECTOR_SHIFT - log;
|
||||
ctx->shift = SECTOR_SHIFT - log;
|
||||
} else if (!strncasecmp(iv_name, "eboiv", 5)) {
|
||||
r = crypt_cipher_init(&ctx->cipher, cipher_name, "ecb",
|
||||
key, key_length);
|
||||
if (r)
|
||||
return r;
|
||||
|
||||
ctx->type = IV_EBOIV;
|
||||
ctx->shift = int_log2(sector_size);
|
||||
} else
|
||||
return -ENOENT;
|
||||
|
||||
@@ -163,14 +174,20 @@ static int crypt_sector_iv_generate(struct crypt_sector_iv *ctx, uint64_t sector
|
||||
case IV_ESSIV:
|
||||
memset(ctx->iv, 0, ctx->iv_size);
|
||||
*(uint64_t *)ctx->iv = cpu_to_le64(sector);
|
||||
return crypt_cipher_encrypt(ctx->essiv_cipher,
|
||||
return crypt_cipher_encrypt(ctx->cipher,
|
||||
ctx->iv, ctx->iv, ctx->iv_size, NULL, 0);
|
||||
break;
|
||||
case IV_BENBI:
|
||||
memset(ctx->iv, 0, ctx->iv_size);
|
||||
val = cpu_to_be64((sector << ctx->benbi_shift) + 1);
|
||||
val = cpu_to_be64((sector << ctx->shift) + 1);
|
||||
memcpy(ctx->iv + ctx->iv_size - sizeof(val), &val, sizeof(val));
|
||||
break;
|
||||
case IV_EBOIV:
|
||||
memset(ctx->iv, 0, ctx->iv_size);
|
||||
*(uint64_t *)ctx->iv = cpu_to_le64(sector << ctx->shift);
|
||||
return crypt_cipher_encrypt(ctx->cipher,
|
||||
ctx->iv, ctx->iv, ctx->iv_size, NULL, 0);
|
||||
break;
|
||||
default:
|
||||
return -EINVAL;
|
||||
}
|
||||
@@ -180,8 +197,8 @@ static int crypt_sector_iv_generate(struct crypt_sector_iv *ctx, uint64_t sector
|
||||
|
||||
static void crypt_sector_iv_destroy(struct crypt_sector_iv *ctx)
|
||||
{
|
||||
if (ctx->type == IV_ESSIV)
|
||||
crypt_cipher_destroy(ctx->essiv_cipher);
|
||||
if (ctx->type == IV_ESSIV || ctx->type == IV_EBOIV)
|
||||
crypt_cipher_destroy(ctx->cipher);
|
||||
|
||||
if (ctx->iv) {
|
||||
memset(ctx->iv, 0, ctx->iv_size);
|
||||
@@ -197,7 +214,8 @@ int crypt_storage_init(struct crypt_storage **ctx,
|
||||
size_t sector_size,
|
||||
const char *cipher,
|
||||
const char *cipher_mode,
|
||||
const void *key, size_t key_length)
|
||||
const void *key, size_t key_length,
|
||||
bool large_iv)
|
||||
{
|
||||
struct crypt_storage *s;
|
||||
char mode_name[64];
|
||||
@@ -229,14 +247,14 @@ int crypt_storage_init(struct crypt_storage **ctx,
|
||||
return r;
|
||||
}
|
||||
|
||||
r = crypt_sector_iv_init(&s->cipher_iv, cipher, mode_name, cipher_iv, key, key_length);
|
||||
r = crypt_sector_iv_init(&s->cipher_iv, cipher, mode_name, cipher_iv, key, key_length, sector_size);
|
||||
if (r) {
|
||||
crypt_storage_destroy(s);
|
||||
return r;
|
||||
}
|
||||
|
||||
s->sector_shift = int_log2(sector_size);
|
||||
s->iv_shift = s->sector_shift - SECTOR_SHIFT;
|
||||
s->sector_size = sector_size;
|
||||
s->iv_shift = large_iv ? int_log2(sector_size) - SECTOR_SHIFT : 0;
|
||||
|
||||
*ctx = s;
|
||||
return 0;
|
||||
@@ -249,19 +267,20 @@ int crypt_storage_decrypt(struct crypt_storage *ctx,
|
||||
uint64_t i;
|
||||
int r = 0;
|
||||
|
||||
if (length & ((1 << ctx->sector_shift) - 1))
|
||||
if (length & (ctx->sector_size - 1))
|
||||
return -EINVAL;
|
||||
|
||||
length >>= ctx->sector_shift;
|
||||
if (iv_offset & ((ctx->sector_size >> SECTOR_SHIFT) - 1))
|
||||
return -EINVAL;
|
||||
|
||||
for (i = 0; i < length; i++) {
|
||||
r = crypt_sector_iv_generate(&ctx->cipher_iv, iv_offset + (uint64_t)(i << ctx->iv_shift));
|
||||
for (i = 0; i < length; i += ctx->sector_size) {
|
||||
r = crypt_sector_iv_generate(&ctx->cipher_iv, (iv_offset + (i >> SECTOR_SHIFT)) >> ctx->iv_shift);
|
||||
if (r)
|
||||
break;
|
||||
r = crypt_cipher_decrypt(ctx->cipher,
|
||||
&buffer[i << ctx->sector_shift],
|
||||
&buffer[i << ctx->sector_shift],
|
||||
1 << ctx->sector_shift,
|
||||
&buffer[i],
|
||||
&buffer[i],
|
||||
ctx->sector_size,
|
||||
ctx->cipher_iv.iv,
|
||||
ctx->cipher_iv.iv_size);
|
||||
if (r)
|
||||
@@ -278,19 +297,20 @@ int crypt_storage_encrypt(struct crypt_storage *ctx,
|
||||
uint64_t i;
|
||||
int r = 0;
|
||||
|
||||
if (length & ((1 << ctx->sector_shift) - 1))
|
||||
if (length & (ctx->sector_size - 1))
|
||||
return -EINVAL;
|
||||
|
||||
length >>= ctx->sector_shift;
|
||||
if (iv_offset & ((ctx->sector_size >> SECTOR_SHIFT) - 1))
|
||||
return -EINVAL;
|
||||
|
||||
for (i = 0; i < length; i++) {
|
||||
r = crypt_sector_iv_generate(&ctx->cipher_iv, iv_offset + (i << ctx->iv_shift));
|
||||
for (i = 0; i < length; i += ctx->sector_size) {
|
||||
r = crypt_sector_iv_generate(&ctx->cipher_iv, (iv_offset + (i >> SECTOR_SHIFT)) >> ctx->iv_shift);
|
||||
if (r)
|
||||
break;
|
||||
r = crypt_cipher_encrypt(ctx->cipher,
|
||||
&buffer[i << ctx->sector_shift],
|
||||
&buffer[i << ctx->sector_shift],
|
||||
1 << ctx->sector_shift,
|
||||
&buffer[i],
|
||||
&buffer[i],
|
||||
ctx->sector_size,
|
||||
ctx->cipher_iv.iv,
|
||||
ctx->cipher_iv.iv_size);
|
||||
if (r)
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
* Copyright (C) 2004 Free Software Foundation
|
||||
*
|
||||
* cryptsetup related changes
|
||||
* Copyright (C) 2012-2020 Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2012-2020 Milan Broz
|
||||
* Copyright (C) 2012-2021 Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2012-2021 Milan Broz
|
||||
*
|
||||
* This file is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* PBKDF performance check
|
||||
* Copyright (C) 2012-2020 Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2012-2020 Milan Broz
|
||||
* Copyright (C) 2012-2021 Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2012-2021 Milan Broz
|
||||
* Copyright (C) 2016-2020 Ondrej Mosnacek
|
||||
*
|
||||
* This file is free software; you can redistribute it and/or
|
||||
@@ -27,6 +27,10 @@
|
||||
#include <sys/resource.h>
|
||||
#include "crypto_backend.h"
|
||||
|
||||
#ifndef CLOCK_MONOTONIC_RAW
|
||||
#define CLOCK_MONOTONIC_RAW CLOCK_MONOTONIC
|
||||
#endif
|
||||
|
||||
#define BENCH_MIN_MS 250
|
||||
#define BENCH_MIN_MS_FAST 10
|
||||
#define BENCH_PERCENT_ATLEAST 95
|
||||
@@ -44,6 +48,7 @@ int crypt_pbkdf_get_limits(const char *kdf, struct crypt_pbkdf_limits *limits)
|
||||
limits->min_iterations = 1000; /* recommendation in NIST SP 800-132 */
|
||||
limits->max_iterations = UINT32_MAX;
|
||||
limits->min_memory = 0; /* N/A */
|
||||
limits->min_bench_memory=0; /* N/A */
|
||||
limits->max_memory = 0; /* N/A */
|
||||
limits->min_parallel = 0; /* N/A */
|
||||
limits->max_parallel = 0; /* N/A */
|
||||
@@ -51,7 +56,8 @@ int crypt_pbkdf_get_limits(const char *kdf, struct crypt_pbkdf_limits *limits)
|
||||
} else if (!strcmp(kdf, "argon2i") || !strcmp(kdf, "argon2id")) {
|
||||
limits->min_iterations = 4;
|
||||
limits->max_iterations = UINT32_MAX;
|
||||
limits->min_memory = 32;
|
||||
limits->min_memory = 32; /* hard limit */
|
||||
limits->min_bench_memory=64*1024; /* 64 MiB minimum for benchmark */
|
||||
limits->max_memory = 4*1024*1024; /* 4GiB */
|
||||
limits->min_parallel = 1;
|
||||
limits->max_parallel = 4;
|
||||
@@ -70,7 +76,7 @@ static long time_ms(struct rusage *start, struct rusage *end)
|
||||
count_kernel_time = 1;
|
||||
|
||||
/*
|
||||
* FIXME: if there is no self usage info, count system time.
|
||||
* If there is no self usage info, count system time.
|
||||
* This seem like getrusage() bug in some hypervisors...
|
||||
*/
|
||||
if (!end->ru_utime.tv_sec && !start->ru_utime.tv_sec &&
|
||||
@@ -357,8 +363,10 @@ static int crypt_pbkdf_check(const char *kdf, const char *hash,
|
||||
ms = time_ms(&rstart, &rend);
|
||||
if (ms) {
|
||||
PBKDF2_temp = (double)iterations * target_ms / ms;
|
||||
if (PBKDF2_temp > UINT32_MAX)
|
||||
return -EINVAL;
|
||||
if (PBKDF2_temp > UINT32_MAX) {
|
||||
r = -EINVAL;
|
||||
goto out;
|
||||
}
|
||||
*iter_secs = (uint32_t)PBKDF2_temp;
|
||||
}
|
||||
|
||||
@@ -402,15 +410,19 @@ int crypt_pbkdf_perf(const char *kdf, const char *hash,
|
||||
{
|
||||
struct crypt_pbkdf_limits pbkdf_limits;
|
||||
int r = -EINVAL;
|
||||
uint32_t min_memory;
|
||||
|
||||
if (!kdf || !iterations_out || !memory_out)
|
||||
return -EINVAL;
|
||||
|
||||
/* FIXME: whole limits propagation should be more clear here */
|
||||
r = crypt_pbkdf_get_limits(kdf, &pbkdf_limits);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
min_memory = pbkdf_limits.min_bench_memory;
|
||||
if (min_memory > max_memory_kb)
|
||||
min_memory = max_memory_kb;
|
||||
|
||||
*memory_out = 0;
|
||||
*iterations_out = 0;
|
||||
|
||||
@@ -423,7 +435,7 @@ int crypt_pbkdf_perf(const char *kdf, const char *hash,
|
||||
r = crypt_argon2_check(kdf, password, password_size,
|
||||
salt, salt_size, volume_key_size,
|
||||
pbkdf_limits.min_iterations,
|
||||
pbkdf_limits.min_memory,
|
||||
min_memory,
|
||||
max_memory_kb,
|
||||
parallel_threads, time_ms, iterations_out,
|
||||
memory_out, progress, usrptr);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* Integrity volume handling
|
||||
*
|
||||
* Copyright (C) 2016-2020 Milan Broz
|
||||
* Copyright (C) 2016-2021 Milan Broz
|
||||
*
|
||||
* This file is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
@@ -22,7 +22,6 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <fcntl.h>
|
||||
#include <uuid/uuid.h>
|
||||
|
||||
#include "integrity.h"
|
||||
@@ -41,7 +40,7 @@ static int INTEGRITY_read_superblock(struct crypt_device *cd,
|
||||
if (read_lseek_blockwise(devfd, device_block_size(cd, device),
|
||||
device_alignment(device), sb, sizeof(*sb), offset) != sizeof(*sb) ||
|
||||
memcmp(sb->magic, SB_MAGIC, sizeof(sb->magic)) ||
|
||||
sb->version < SB_VERSION_1 || sb->version > SB_VERSION_4) {
|
||||
sb->version < SB_VERSION_1 || sb->version > SB_VERSION_5) {
|
||||
log_std(cd, "No integrity superblock detected on %s.\n",
|
||||
device_path(device));
|
||||
r = -EINVAL;
|
||||
@@ -93,14 +92,15 @@ int INTEGRITY_dump(struct crypt_device *cd, struct device *device, uint64_t offs
|
||||
log_std(cd, "journal_sections %u\n", sb.journal_sections);
|
||||
log_std(cd, "provided_data_sectors %" PRIu64 "\n", sb.provided_data_sectors);
|
||||
log_std(cd, "sector_size %u\n", SECTOR_SIZE << sb.log2_sectors_per_block);
|
||||
if (sb.version == SB_VERSION_2 && (sb.flags & SB_FLAG_RECALCULATING))
|
||||
if (sb.version >= SB_VERSION_2 && (sb.flags & SB_FLAG_RECALCULATING))
|
||||
log_std(cd, "recalc_sector %" PRIu64 "\n", sb.recalc_sector);
|
||||
log_std(cd, "log2_blocks_per_bitmap %u\n", sb.log2_blocks_per_bitmap_bit);
|
||||
log_std(cd, "flags %s%s%s%s\n",
|
||||
log_std(cd, "flags %s%s%s%s%s\n",
|
||||
sb.flags & SB_FLAG_HAVE_JOURNAL_MAC ? "have_journal_mac " : "",
|
||||
sb.flags & SB_FLAG_RECALCULATING ? "recalculating " : "",
|
||||
sb.flags & SB_FLAG_DIRTY_BITMAP ? "dirty_bitmap " : "",
|
||||
sb.flags & SB_FLAG_FIXED_PADDING ? "fix_padding " : "");
|
||||
sb.flags & SB_FLAG_FIXED_PADDING ? "fix_padding " : "",
|
||||
sb.flags & SB_FLAG_FIXED_HMAC ? "fix_hmac " : "");
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -120,7 +120,7 @@ int INTEGRITY_data_sectors(struct crypt_device *cd,
|
||||
return 0;
|
||||
}
|
||||
|
||||
int INTEGRITY_key_size(struct crypt_device *cd, const char *integrity)
|
||||
int INTEGRITY_key_size(struct crypt_device *cd __attribute__((unused)), const char *integrity)
|
||||
{
|
||||
if (!integrity)
|
||||
return 0;
|
||||
@@ -163,7 +163,7 @@ int INTEGRITY_hash_tag_size(const char *integrity)
|
||||
return r < 0 ? 0 : r;
|
||||
}
|
||||
|
||||
int INTEGRITY_tag_size(struct crypt_device *cd,
|
||||
int INTEGRITY_tag_size(struct crypt_device *cd __attribute__((unused)),
|
||||
const char *integrity,
|
||||
const char *cipher,
|
||||
const char *cipher_mode)
|
||||
@@ -189,7 +189,7 @@ int INTEGRITY_tag_size(struct crypt_device *cd,
|
||||
if (!integrity || !strcmp(integrity, "none"))
|
||||
auth_tag_size = 0;
|
||||
else if (!strcmp(integrity, "aead"))
|
||||
auth_tag_size = 16; //FIXME gcm- mode only
|
||||
auth_tag_size = 16; /* gcm- mode only */
|
||||
else if (!strcmp(integrity, "cmac(aes)"))
|
||||
auth_tag_size = 16;
|
||||
else if (!strcmp(integrity, "hmac(sha1)"))
|
||||
@@ -213,7 +213,7 @@ int INTEGRITY_create_dmd_device(struct crypt_device *cd,
|
||||
struct volume_key *journal_crypt_key,
|
||||
struct volume_key *journal_mac_key,
|
||||
struct crypt_dm_active_device *dmd,
|
||||
uint32_t flags)
|
||||
uint32_t flags, uint32_t sb_flags)
|
||||
{
|
||||
int r;
|
||||
|
||||
@@ -224,6 +224,10 @@ int INTEGRITY_create_dmd_device(struct crypt_device *cd,
|
||||
.flags = flags,
|
||||
};
|
||||
|
||||
/* Workaround for kernel dm-integrity table bug */
|
||||
if (sb_flags & SB_FLAG_RECALCULATING)
|
||||
dmd->flags |= CRYPT_ACTIVATE_RECALCULATE;
|
||||
|
||||
r = INTEGRITY_data_sectors(cd, crypt_metadata_device(cd),
|
||||
crypt_get_data_offset(cd) * SECTOR_SIZE, &dmd->size);
|
||||
if (r < 0)
|
||||
@@ -275,6 +279,15 @@ int INTEGRITY_activate_dmd_device(struct crypt_device *cd,
|
||||
return -ENOTSUP;
|
||||
}
|
||||
|
||||
if (r < 0 && (dmd->flags & CRYPT_ACTIVATE_RECALCULATE) &&
|
||||
!(crypt_get_compatibility(cd) & CRYPT_COMPAT_LEGACY_INTEGRITY_RECALC) &&
|
||||
((sb_flags & SB_FLAG_FIXED_HMAC) ?
|
||||
(tgt->u.integrity.vk && !tgt->u.integrity.journal_integrity_key) :
|
||||
(tgt->u.integrity.vk || tgt->u.integrity.journal_integrity_key))) {
|
||||
log_err(cd, _("Kernel refuses to activate insecure recalculate option (see legacy activation options to override)."));
|
||||
return -ENOTSUP;
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
@@ -287,7 +300,8 @@ int INTEGRITY_activate(struct crypt_device *cd,
|
||||
uint32_t flags, uint32_t sb_flags)
|
||||
{
|
||||
struct crypt_dm_active_device dmd = {};
|
||||
int r = INTEGRITY_create_dmd_device(cd, params, vk, journal_crypt_key, journal_mac_key, &dmd, flags);
|
||||
int r = INTEGRITY_create_dmd_device(cd, params, vk, journal_crypt_key,
|
||||
journal_mac_key, &dmd, flags, sb_flags);
|
||||
|
||||
if (r < 0)
|
||||
return r;
|
||||
@@ -316,7 +330,9 @@ int INTEGRITY_format(struct crypt_device *cd,
|
||||
uuid_generate(tmp_uuid_bin);
|
||||
uuid_unparse(tmp_uuid_bin, tmp_uuid);
|
||||
|
||||
snprintf(tmp_name, sizeof(tmp_name), "temporary-cryptsetup-%s", tmp_uuid);
|
||||
r = snprintf(tmp_name, sizeof(tmp_name), "temporary-cryptsetup-%s", tmp_uuid);
|
||||
if (r < 0 || (size_t)r >= sizeof(tmp_name))
|
||||
return -EINVAL;
|
||||
|
||||
/* There is no data area, we can actually use fake zeroed key */
|
||||
if (params && params->integrity_key_size)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* Integrity header definition
|
||||
*
|
||||
* Copyright (C) 2016-2020 Milan Broz
|
||||
* Copyright (C) 2016-2021 Milan Broz
|
||||
*
|
||||
* This file is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
@@ -35,11 +35,13 @@ struct crypt_dm_active_device;
|
||||
#define SB_VERSION_2 2
|
||||
#define SB_VERSION_3 3
|
||||
#define SB_VERSION_4 4
|
||||
#define SB_VERSION_5 5
|
||||
|
||||
#define SB_FLAG_HAVE_JOURNAL_MAC (1 << 0)
|
||||
#define SB_FLAG_RECALCULATING (1 << 1) /* V2 only */
|
||||
#define SB_FLAG_DIRTY_BITMAP (1 << 2) /* V3 only */
|
||||
#define SB_FLAG_FIXED_PADDING (1 << 3) /* V4 only */
|
||||
#define SB_FLAG_FIXED_HMAC (1 << 4) /* V5 only */
|
||||
|
||||
struct superblock {
|
||||
uint8_t magic[8];
|
||||
@@ -64,8 +66,7 @@ int INTEGRITY_dump(struct crypt_device *cd, struct device *device, uint64_t offs
|
||||
int INTEGRITY_data_sectors(struct crypt_device *cd,
|
||||
struct device *device, uint64_t offset,
|
||||
uint64_t *data_sectors);
|
||||
int INTEGRITY_key_size(struct crypt_device *cd,
|
||||
const char *integrity);
|
||||
int INTEGRITY_key_size(struct crypt_device *cd, const char *integrity);
|
||||
int INTEGRITY_tag_size(struct crypt_device *cd,
|
||||
const char *integrity,
|
||||
const char *cipher,
|
||||
@@ -91,7 +92,7 @@ int INTEGRITY_create_dmd_device(struct crypt_device *cd,
|
||||
struct volume_key *journal_crypt_key,
|
||||
struct volume_key *journal_mac_key,
|
||||
struct crypt_dm_active_device *dmd,
|
||||
uint32_t flags);
|
||||
uint32_t flags, uint32_t sb_flags);
|
||||
|
||||
int INTEGRITY_activate_dmd_device(struct crypt_device *cd,
|
||||
const char *name,
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
*
|
||||
* Copyright (C) 2004 Jana Saout <jana@saout.de>
|
||||
* Copyright (C) 2004-2007 Clemens Fruhwirth <clemens@endorphin.org>
|
||||
* Copyright (C) 2009-2020 Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2009-2020 Milan Broz
|
||||
* Copyright (C) 2009-2021 Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2009-2021 Milan Broz
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
@@ -30,6 +30,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <inttypes.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#include "nls.h"
|
||||
#include "bitops.h"
|
||||
@@ -40,45 +41,25 @@
|
||||
#include "utils_fips.h"
|
||||
#include "utils_keyring.h"
|
||||
#include "utils_io.h"
|
||||
#include "crypto_backend.h"
|
||||
#include "crypto_backend/crypto_backend.h"
|
||||
#include "utils_storage_wrappers.h"
|
||||
|
||||
#include "libcryptsetup.h"
|
||||
|
||||
/* to silent gcc -Wcast-qual for const cast */
|
||||
#define CONST_CAST(x) (x)(uintptr_t)
|
||||
#include "libcryptsetup_macros.h"
|
||||
#include "libcryptsetup_symver.h"
|
||||
|
||||
#define SHIFT_4K 12
|
||||
#define SECTOR_SHIFT 9
|
||||
#define SECTOR_SIZE (1 << SECTOR_SHIFT)
|
||||
#define MAX_SECTOR_SIZE 4096 /* min page size among all platforms */
|
||||
#define DEFAULT_DISK_ALIGNMENT 1048576 /* 1MiB */
|
||||
#define DEFAULT_MEM_ALIGNMENT 4096
|
||||
#define LOG_MAX_LEN 4096
|
||||
#define MAX_DM_DEPS 32
|
||||
|
||||
#define CRYPT_SUBDEV "SUBDEV" /* prefix for sublayered devices underneath public crypt types */
|
||||
|
||||
#define at_least(a, b) ({ __typeof__(a) __at_least = (a); (__at_least >= (b))?__at_least:(b); })
|
||||
|
||||
#define MISALIGNED(a, b) ((a) & ((b) - 1))
|
||||
#define MISALIGNED_4K(a) MISALIGNED((a), 1 << SHIFT_4K)
|
||||
#define MISALIGNED_512(a) MISALIGNED((a), 1 << SECTOR_SHIFT)
|
||||
#define NOTPOW2(a) MISALIGNED((a), (a))
|
||||
|
||||
#ifndef ARRAY_SIZE
|
||||
# define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
|
||||
#ifndef O_CLOEXEC
|
||||
#define O_CLOEXEC 0
|
||||
#endif
|
||||
|
||||
#define MOVE_REF(x, y) \
|
||||
do { \
|
||||
typeof (x) *_px = &(x), *_py = &(y); \
|
||||
*_px = *_py; \
|
||||
*_py = NULL; \
|
||||
} while (0)
|
||||
|
||||
struct crypt_device;
|
||||
struct luks2_reenc_context;
|
||||
struct luks2_reencrypt;
|
||||
|
||||
struct volume_key {
|
||||
int id;
|
||||
@@ -139,6 +120,8 @@ void device_sync(struct crypt_device *cd, struct device *device);
|
||||
int device_check_size(struct crypt_device *cd,
|
||||
struct device *device,
|
||||
uint64_t req_offset, int falloc);
|
||||
void device_set_block_size(struct device *device, size_t size);
|
||||
size_t device_optimal_encryption_sector_size(struct crypt_device *cd, struct device *device);
|
||||
|
||||
int device_open_locked(struct crypt_device *cd, struct device *device, int flags);
|
||||
int device_read_lock(struct crypt_device *cd, struct device *device);
|
||||
@@ -179,7 +162,7 @@ char *crypt_get_partition_device(const char *dev_path, uint64_t offset, uint64_t
|
||||
char *crypt_get_base_device(const char *dev_path);
|
||||
uint64_t crypt_dev_partition_offset(const char *dev_path);
|
||||
int lookup_by_disk_id(const char *dm_uuid);
|
||||
int lookup_by_sysfs_uuid_field(const char *dm_uuid, size_t max_len);
|
||||
int lookup_by_sysfs_uuid_field(const char *dm_uuid);
|
||||
int crypt_uuid_cmp(const char *dm_uuid, const char *hdr_uuid);
|
||||
|
||||
size_t crypt_getpagesize(void);
|
||||
@@ -188,11 +171,10 @@ uint64_t crypt_getphysmemory_kb(void);
|
||||
|
||||
int init_crypto(struct crypt_device *ctx);
|
||||
|
||||
void logger(struct crypt_device *cd, int level, const char *file, int line, const char *format, ...) __attribute__ ((format (printf, 5, 6)));
|
||||
#define log_dbg(c, x...) logger(c, CRYPT_LOG_DEBUG, __FILE__, __LINE__, x)
|
||||
#define log_std(c, x...) logger(c, CRYPT_LOG_NORMAL, __FILE__, __LINE__, x)
|
||||
#define log_verbose(c, x...) logger(c, CRYPT_LOG_VERBOSE, __FILE__, __LINE__, x)
|
||||
#define log_err(c, x...) logger(c, CRYPT_LOG_ERROR, __FILE__, __LINE__, x)
|
||||
#define log_dbg(c, x...) crypt_logf(c, CRYPT_LOG_DEBUG, x)
|
||||
#define log_std(c, x...) crypt_logf(c, CRYPT_LOG_NORMAL, x)
|
||||
#define log_verbose(c, x...) crypt_logf(c, CRYPT_LOG_VERBOSE, x)
|
||||
#define log_err(c, x...) crypt_logf(c, CRYPT_LOG_ERROR, x)
|
||||
|
||||
int crypt_get_debug_level(void);
|
||||
|
||||
@@ -217,8 +199,8 @@ int PLAIN_activate(struct crypt_device *cd,
|
||||
uint32_t flags);
|
||||
|
||||
void *crypt_get_hdr(struct crypt_device *cd, const char *type);
|
||||
void crypt_set_reenc_context(struct crypt_device *cd, struct luks2_reenc_context *rh);
|
||||
struct luks2_reenc_context *crypt_get_reenc_context(struct crypt_device *cd);
|
||||
void crypt_set_luks2_reencrypt(struct crypt_device *cd, struct luks2_reencrypt *rh);
|
||||
struct luks2_reencrypt *crypt_get_luks2_reencrypt(struct crypt_device *cd);
|
||||
|
||||
int onlyLUKS2(struct crypt_device *cd);
|
||||
int onlyLUKS2mask(struct crypt_device *cd, uint32_t mask);
|
||||
@@ -244,7 +226,7 @@ int crypt_use_keyring_for_vk(struct crypt_device *cd);
|
||||
void crypt_drop_keyring_key_by_description(struct crypt_device *cd, const char *key_description, key_type_t ktype);
|
||||
void crypt_drop_keyring_key(struct crypt_device *cd, struct volume_key *vks);
|
||||
|
||||
static inline uint64_t version(uint16_t major, uint16_t minor, uint16_t patch, uint16_t release)
|
||||
static inline uint64_t compact_version(uint16_t major, uint16_t minor, uint16_t patch, uint16_t release)
|
||||
{
|
||||
return (uint64_t)release | ((uint64_t)patch << 16) | ((uint64_t)minor << 32) | ((uint64_t)major << 48);
|
||||
}
|
||||
@@ -261,4 +243,12 @@ int crypt_compare_dm_devices(struct crypt_device *cd,
|
||||
const struct crypt_dm_active_device *tgt);
|
||||
static inline void *crypt_zalloc(size_t size) { return calloc(1, size); }
|
||||
|
||||
static inline bool uint64_mult_overflow(uint64_t *u, uint64_t b, size_t size)
|
||||
{
|
||||
*u = (uint64_t)b * size;
|
||||
if ((uint64_t)(*u / size) != b)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
#endif /* INTERNAL_H */
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
*
|
||||
* Copyright (C) 2004 Jana Saout <jana@saout.de>
|
||||
* Copyright (C) 2004-2007 Clemens Fruhwirth <clemens@endorphin.org>
|
||||
* Copyright (C) 2009-2020 Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2009-2020 Milan Broz
|
||||
* Copyright (C) 2009-2021 Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2009-2021 Milan Broz
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
@@ -215,6 +215,15 @@ void crypt_set_log_callback(struct crypt_device *cd,
|
||||
* @param msg log message
|
||||
*/
|
||||
void crypt_log(struct crypt_device *cd, int level, const char *msg);
|
||||
|
||||
/**
|
||||
* Log function with variable arguments.
|
||||
*
|
||||
* @param cd crypt device handle
|
||||
* @param level log level
|
||||
* @param format formatted log message
|
||||
*/
|
||||
void crypt_logf(struct crypt_device *cd, int level, const char *format, ...);
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
@@ -590,7 +599,7 @@ struct crypt_params_luks2 {
|
||||
const struct crypt_params_integrity *integrity_params; /**< Data integrity parameters or @e NULL*/
|
||||
size_t data_alignment; /**< data area alignment in 512B sectors, data offset is multiple of this */
|
||||
const char *data_device; /**< detached encrypted data device or @e NULL */
|
||||
uint32_t sector_size; /**< encryption sector size */
|
||||
uint32_t sector_size; /**< encryption sector size, 0 triggers auto-detection for optimal encryption sector size */
|
||||
const char *label; /**< header label or @e NULL*/
|
||||
const char *subsystem; /**< header subsystem label or @e NULL*/
|
||||
};
|
||||
@@ -652,6 +661,10 @@ uint32_t crypt_get_compatibility(struct crypt_device *cd);
|
||||
|
||||
/** dm-integrity device uses less effective (legacy) padding (old kernels) */
|
||||
#define CRYPT_COMPAT_LEGACY_INTEGRITY_PADDING (1 << 0)
|
||||
/** dm-integrity device does not protect superblock with HMAC (old kernels) */
|
||||
#define CRYPT_COMPAT_LEGACY_INTEGRITY_HMAC (1 << 1)
|
||||
/** dm-integrity allow recalculating of volumes with HMAC keys (old kernels) */
|
||||
#define CRYPT_COMPAT_LEGACY_INTEGRITY_RECALC (1 << 2)
|
||||
|
||||
/**
|
||||
* Convert to new type for already existing device.
|
||||
@@ -1101,6 +1114,16 @@ int crypt_keyslot_destroy(struct crypt_device *cd, int keyslot);
|
||||
#define CRYPT_ACTIVATE_NO_JOURNAL_BITMAP (1 << 20)
|
||||
/** device is suspended (key should be wiped from memory), output only */
|
||||
#define CRYPT_ACTIVATE_SUSPENDED (1 << 21)
|
||||
/** use IV sector counted in sector_size instead of default 512 bytes sectors */
|
||||
#define CRYPT_ACTIVATE_IV_LARGE_SECTORS (1 << 22)
|
||||
/** dm-verity: panic_on_corruption flag - panic kernel on corruption */
|
||||
#define CRYPT_ACTIVATE_PANIC_ON_CORRUPTION (1 << 23)
|
||||
/** dm-crypt: bypass internal workqueue and process read requests synchronously. */
|
||||
#define CRYPT_ACTIVATE_NO_READ_WORKQUEUE (1 << 24)
|
||||
/** dm-crypt: bypass internal workqueue and process write requests synchronously. */
|
||||
#define CRYPT_ACTIVATE_NO_WRITE_WORKQUEUE (1 << 25)
|
||||
/** dm-integrity: reset automatic recalculation */
|
||||
#define CRYPT_ACTIVATE_RECALCULATE_RESET (1 << 26)
|
||||
|
||||
/**
|
||||
* Active device runtime attributes
|
||||
@@ -1343,6 +1366,8 @@ int crypt_activate_by_keyring(struct crypt_device *cd,
|
||||
#define CRYPT_DEACTIVATE_DEFERRED (1 << 0)
|
||||
/** force deactivation - if the device is busy, it is replaced by error device */
|
||||
#define CRYPT_DEACTIVATE_FORCE (1 << 1)
|
||||
/** if set, remove lazy deactivation */
|
||||
#define CRYPT_DEACTIVATE_DEFERRED_CANCEL (1 << 2)
|
||||
|
||||
/**
|
||||
* Deactivate crypt device. This function tries to remove active device-mapper
|
||||
@@ -1446,6 +1471,17 @@ crypt_status_info crypt_status(struct crypt_device *cd, const char *name);
|
||||
*/
|
||||
int crypt_dump(struct crypt_device *cd);
|
||||
|
||||
/**
|
||||
* Dump JSON-formatted information about LUKS2 device
|
||||
*
|
||||
* @param cd crypt device handle (only LUKS2 format supported)
|
||||
* @param json buffer with JSON, if NULL use log callback for output
|
||||
* @param flags dump flags (reserved)
|
||||
*
|
||||
* @return @e 0 on success or negative errno value otherwise.
|
||||
*/
|
||||
int crypt_dump_json(struct crypt_device *cd, const char **json, uint32_t flags);
|
||||
|
||||
/**
|
||||
* Get cipher used in device.
|
||||
*
|
||||
@@ -1477,11 +1513,11 @@ const char *crypt_get_cipher_mode(struct crypt_device *cd);
|
||||
const char *crypt_get_uuid(struct crypt_device *cd);
|
||||
|
||||
/**
|
||||
* Get path to underlaying device.
|
||||
* Get path to underlying device.
|
||||
*
|
||||
* @param cd crypt device handle
|
||||
*
|
||||
* @return path to underlaying device name
|
||||
* @return path to underlying device name
|
||||
*
|
||||
*/
|
||||
const char *crypt_get_device_name(struct crypt_device *cd);
|
||||
@@ -1491,7 +1527,7 @@ const char *crypt_get_device_name(struct crypt_device *cd);
|
||||
*
|
||||
* @param cd crypt device handle
|
||||
*
|
||||
* @return path to underlaying device name
|
||||
* @return path to underlying device name
|
||||
*
|
||||
*/
|
||||
const char *crypt_get_metadata_device_name(struct crypt_device *cd);
|
||||
@@ -1538,6 +1574,21 @@ int crypt_get_volume_key_size(struct crypt_device *cd);
|
||||
*/
|
||||
int crypt_get_sector_size(struct crypt_device *cd);
|
||||
|
||||
/**
|
||||
* Check if initialized LUKS context uses detached header
|
||||
* (LUKS header located on a different device than data.)
|
||||
*
|
||||
* @param cd crypt device handle
|
||||
*
|
||||
* @return @e 1 if detached header is used, @e 0 if not
|
||||
* or negative errno value otherwise.
|
||||
*
|
||||
* @note This is a runtime attribute, it does not say
|
||||
* if a LUKS device requires detached header.
|
||||
* This function works only with LUKS devices.
|
||||
*/
|
||||
int crypt_header_is_detached(struct crypt_device *cd);
|
||||
|
||||
/**
|
||||
* Get device parameters for VERITY device.
|
||||
*
|
||||
@@ -1935,6 +1986,19 @@ int crypt_wipe(struct crypt_device *cd,
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* Get number of tokens supported for device type.
|
||||
*
|
||||
* @param type crypt device type
|
||||
*
|
||||
* @return token count or negative errno otherwise if device
|
||||
* doesn't not support tokens.
|
||||
*
|
||||
* @note Real number of supported tokens for a particular device depends
|
||||
* on usable metadata area size.
|
||||
*/
|
||||
int crypt_token_max(const char *type);
|
||||
|
||||
/** Iterate through all tokens */
|
||||
#define CRYPT_ANY_TOKEN -1
|
||||
|
||||
@@ -2092,6 +2156,15 @@ int crypt_token_is_assigned(struct crypt_device *cd,
|
||||
* @param buffer returned allocated buffer with password
|
||||
* @param buffer_len length of the buffer
|
||||
* @param usrptr user data in @link crypt_activate_by_token @endlink
|
||||
*
|
||||
* @return 0 on success (token passed LUKS2 keyslot passphrase in buffer) or
|
||||
* negative errno otherwise.
|
||||
*
|
||||
* @note Negative ENOANO errno means that token is PIN protected and caller should
|
||||
* use @link crypt_activate_by_token_pin @endlink with PIN provided.
|
||||
*
|
||||
* @note Negative EAGAIN errno means token handler requires additional hardware
|
||||
* not present in the system.
|
||||
*/
|
||||
typedef int (*crypt_token_open_func) (
|
||||
struct crypt_device *cd,
|
||||
@@ -2100,6 +2173,38 @@ typedef int (*crypt_token_open_func) (
|
||||
size_t *buffer_len,
|
||||
void *usrptr);
|
||||
|
||||
/**
|
||||
* Token handler open with passphrase/PIN function prototype.
|
||||
* This function retrieves password from a token and return allocated buffer
|
||||
* containing this password. This buffer has to be deallocated by calling
|
||||
* free() function and content should be wiped before deallocation.
|
||||
*
|
||||
* @param cd crypt device handle
|
||||
* @param token token id
|
||||
* @param pin passphrase (or PIN) to unlock token (may be binary data)
|
||||
* @param pin_size size of @e pin
|
||||
* @param buffer returned allocated buffer with password
|
||||
* @param buffer_len length of the buffer
|
||||
* @param usrptr user data in @link crypt_activate_by_token @endlink
|
||||
*
|
||||
* @return 0 on success (token passed LUKS2 keyslot passphrase in buffer) or
|
||||
* negative errno otherwise.
|
||||
*
|
||||
* @note Negative ENOANO errno means that token is PIN protected and PIN was
|
||||
* missing or wrong.
|
||||
*
|
||||
* @note Negative EAGAIN errno means token handler requires additional hardware
|
||||
* not present in the system.
|
||||
*/
|
||||
typedef int (*crypt_token_open_pin_func) (
|
||||
struct crypt_device *cd,
|
||||
int token,
|
||||
const char *pin,
|
||||
size_t pin_size,
|
||||
char **buffer,
|
||||
size_t *buffer_len,
|
||||
void *usrptr);
|
||||
|
||||
/**
|
||||
* Token handler buffer free function prototype.
|
||||
* This function is used by library to free the buffer with keyslot
|
||||
@@ -2137,6 +2242,16 @@ typedef int (*crypt_token_validate_func) (struct crypt_device *cd, const char *j
|
||||
*/
|
||||
typedef void (*crypt_token_dump_func) (struct crypt_device *cd, const char *json);
|
||||
|
||||
/**
|
||||
* Token handler version function prototype.
|
||||
* This function is supposed to return pointer to version string information.
|
||||
*
|
||||
* @note The returned string is advised to contain only version.
|
||||
* For example '1.0.0' or 'v1.2.3.4'.
|
||||
*
|
||||
*/
|
||||
typedef const char * (*crypt_token_version_func) (void);
|
||||
|
||||
/**
|
||||
* Token handler
|
||||
*/
|
||||
@@ -2157,6 +2272,30 @@ typedef struct {
|
||||
*/
|
||||
int crypt_token_register(const crypt_token_handler *handler);
|
||||
|
||||
/**
|
||||
* Report configured path where library searches for external token handlers
|
||||
*
|
||||
* @return @e absolute path when external tokens are enabled or @e NULL otherwise.
|
||||
*/
|
||||
const char *crypt_token_external_path(void);
|
||||
|
||||
/**
|
||||
* Disable external token handlers (plugins) support
|
||||
* If disabled, it cannot be enabled again.
|
||||
*/
|
||||
void crypt_token_external_disable(void);
|
||||
|
||||
/** ABI version for external token in libcryptsetup-token-<name>.so */
|
||||
#define CRYPT_TOKEN_ABI_VERSION1 "CRYPTSETUP_TOKEN_1.0"
|
||||
|
||||
/** ABI exported symbol for external token */
|
||||
#define CRYPT_TOKEN_ABI_OPEN "cryptsetup_token_open" /* mandatory */
|
||||
#define CRYPT_TOKEN_ABI_OPEN_PIN "cryptsetup_token_open_pin"
|
||||
#define CRYPT_TOKEN_ABI_BUFFER_FREE "cryptsetup_token_buffer_free"
|
||||
#define CRYPT_TOKEN_ABI_VALIDATE "cryptsetup_token_validate"
|
||||
#define CRYPT_TOKEN_ABI_DUMP "cryptsetup_token_dump"
|
||||
#define CRYPT_TOKEN_ABI_VERSION "cryptsetup_token_version"
|
||||
|
||||
/**
|
||||
* Activate device or check key using a token.
|
||||
*
|
||||
@@ -2167,12 +2306,71 @@ int crypt_token_register(const crypt_token_handler *handler);
|
||||
* @param flags activation flags
|
||||
*
|
||||
* @return unlocked key slot number or negative errno otherwise.
|
||||
*
|
||||
* @note EPERM errno means token provided passphrase successfully, but
|
||||
* passphrase did not unlock any keyslot associated with the token.
|
||||
*
|
||||
* @note ENOENT errno means no token (or subsequently assigned keyslot) was
|
||||
* eligible to unlock device.
|
||||
*
|
||||
* @note ENOANO errno means that token is PIN protected and you should call
|
||||
* @link crypt_activate_by_token_pin @endlink with PIN
|
||||
*
|
||||
* @note Negative EAGAIN errno means token handler requires additional hardware
|
||||
* not present in the system.
|
||||
*
|
||||
* @note with @param token set to CRYPT_ANY_TOKEN libcryptsetup runs best effort loop
|
||||
* to unlock device using any available token. It may happen that various token handlers
|
||||
* return different error codes. At the end loop returns error codes in the following
|
||||
* order (from the most significant to the least) any negative errno except those
|
||||
* listed below, non negative token id (success), -ENOANO, -EAGAIN, -EPERM, -ENOENT.
|
||||
*/
|
||||
int crypt_activate_by_token(struct crypt_device *cd,
|
||||
const char *name,
|
||||
int token,
|
||||
void *usrptr,
|
||||
uint32_t flags);
|
||||
|
||||
/**
|
||||
* Activate device or check key using a token with PIN.
|
||||
*
|
||||
* @param cd crypt device handle
|
||||
* @param name name of device to create, if @e NULL only check token
|
||||
* @param type restrict type of token, if @e NULL all types are allowed
|
||||
* @param token requested token to check or CRYPT_ANY_TOKEN to check all
|
||||
* @param pin passphrase (or PIN) to unlock token (may be binary data)
|
||||
* @param pin_size size of @e pin
|
||||
* @param usrptr provided identification in callback
|
||||
* @param flags activation flags
|
||||
*
|
||||
* @return unlocked key slot number or negative errno otherwise.
|
||||
*
|
||||
* @note EPERM errno means token provided passphrase successfully, but
|
||||
* passphrase did not unlock any keyslot associated with the token.
|
||||
*
|
||||
* @note ENOENT errno means no token (or subsequently assigned keyslot) was
|
||||
* eligible to unlock device.
|
||||
*
|
||||
* @note ENOANO errno means that token is PIN protected and was either missing
|
||||
* (NULL) or wrong.
|
||||
*
|
||||
* @note Negative EAGAIN errno means token handler requires additional hardware
|
||||
* not present in the system.
|
||||
*
|
||||
* @note with @param token set to CRYPT_ANY_TOKEN libcryptsetup runs best effort loop
|
||||
* to unlock device using any available token. It may happen that various token handlers
|
||||
* return different error codes. At the end loop returns error codes in the following
|
||||
* order (from the most significant to the least) any negative errno except those
|
||||
* listed below, non negative token id (success), -ENOANO, -EAGAIN, -EPERM, -ENOENT.
|
||||
*/
|
||||
int crypt_activate_by_token_pin(struct crypt_device *cd,
|
||||
const char *name,
|
||||
const char *type,
|
||||
int token,
|
||||
const char *pin,
|
||||
size_t pin_size,
|
||||
void *usrptr,
|
||||
uint32_t flags);
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
@@ -2284,16 +2482,33 @@ int crypt_reencrypt_init_by_keyring(struct crypt_device *cd,
|
||||
const struct crypt_params_reencrypt *params);
|
||||
|
||||
/**
|
||||
* Run data reencryption.
|
||||
* Legacy data reencryption function.
|
||||
*
|
||||
* @param cd crypt device handle
|
||||
* @param progress is a callback funtion reporting device \b size,
|
||||
* @param progress is a callback function reporting device \b size,
|
||||
* current \b offset of reencryption and provided \b usrptr identification
|
||||
*
|
||||
* @return @e 0 on success or negative errno value otherwise.
|
||||
*
|
||||
* @deprecated Use @link crypt_reencrypt_run @endlink instead.
|
||||
*/
|
||||
int crypt_reencrypt(struct crypt_device *cd,
|
||||
int (*progress)(uint64_t size, uint64_t offset, void *usrptr));
|
||||
int (*progress)(uint64_t size, uint64_t offset, void *usrptr))
|
||||
__attribute__((deprecated));
|
||||
|
||||
/**
|
||||
* Run data reencryption.
|
||||
*
|
||||
* @param cd crypt device handle
|
||||
* @param progress is a callback function reporting device \b size,
|
||||
* current \b offset of reencryption and provided \b usrptr identification
|
||||
* @param usrptr progress specific data
|
||||
*
|
||||
* @return @e 0 on success or negative errno value otherwise.
|
||||
*/
|
||||
int crypt_reencrypt_run(struct crypt_device *cd,
|
||||
int (*progress)(uint64_t size, uint64_t offset, void *usrptr),
|
||||
void *usrptr);
|
||||
|
||||
/**
|
||||
* Reencryption status info
|
||||
@@ -2328,17 +2543,15 @@ crypt_reencrypt_info crypt_reencrypt_status(struct crypt_device *cd,
|
||||
*
|
||||
* @param size size of memory in bytes
|
||||
*
|
||||
* @return pointer to allocate memory or @e NULL.
|
||||
* @return pointer to allocated memory or @e NULL.
|
||||
*/
|
||||
void *crypt_safe_alloc(size_t size);
|
||||
|
||||
/**
|
||||
* Release safe memory, content is safely wiped
|
||||
* Release safe memory, content is safely wiped.
|
||||
* The pointer must be allocated with @link crypt_safe_alloc @endlink
|
||||
*
|
||||
* @param data pointer to memory to be deallocated
|
||||
*
|
||||
* @return pointer to allocate memory or @e NULL.
|
||||
*/
|
||||
void crypt_safe_free(void *data);
|
||||
|
||||
@@ -2348,17 +2561,15 @@ void crypt_safe_free(void *data);
|
||||
* @param data pointer to memory to be deallocated
|
||||
* @param size new size of memory in bytes
|
||||
*
|
||||
* @return pointer to allocate memory or @e NULL.
|
||||
* @return pointer to allocated memory or @e NULL.
|
||||
*/
|
||||
void *crypt_safe_realloc(void *data, size_t size);
|
||||
|
||||
/**
|
||||
* Safe clear memory area (compile should not compile this call out).
|
||||
*
|
||||
* @param data pointer to memory to cleared
|
||||
* @param size new size of memory in bytes
|
||||
*
|
||||
* @return pointer to allocate memory or @e NULL.
|
||||
* @param data pointer to memory to be cleared
|
||||
* @param size size of memory in bytes
|
||||
*/
|
||||
void crypt_safe_memzero(void *data, size_t size);
|
||||
|
||||
|
||||
@@ -131,3 +131,16 @@ CRYPTSETUP_2.0 {
|
||||
local:
|
||||
*;
|
||||
};
|
||||
|
||||
CRYPTSETUP_2.4 {
|
||||
global:
|
||||
crypt_reencrypt_run;
|
||||
crypt_token_max;
|
||||
crypt_header_is_detached;
|
||||
crypt_logf;
|
||||
crypt_activate_by_token_pin;
|
||||
crypt_dump_json;
|
||||
crypt_format;
|
||||
crypt_token_external_disable;
|
||||
crypt_token_external_path;
|
||||
} CRYPTSETUP_2.0;
|
||||
|
||||
67
lib/libcryptsetup_macros.h
Normal file
67
lib/libcryptsetup_macros.h
Normal file
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Definitions of common constant and generic macros fo libcryptsetup
|
||||
*
|
||||
* Copyright (C) 2009-2021 Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2009-2021 Milan Broz
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#ifndef _LIBCRYPTSETUP_MACROS_H
|
||||
#define _LIBCRYPTSETUP_MACROS_H
|
||||
|
||||
/* to silent gcc -Wcast-qual for const cast */
|
||||
#define CONST_CAST(x) (x)(uintptr_t)
|
||||
|
||||
#define UNUSED(x) (void)(x)
|
||||
|
||||
#ifndef ARRAY_SIZE
|
||||
# define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
|
||||
#endif
|
||||
|
||||
#define BITFIELD_SIZE(BF_PTR) (sizeof(*(BF_PTR)) * 8)
|
||||
|
||||
#define MOVE_REF(x, y) \
|
||||
do { \
|
||||
__typeof__(x) *_px = &(x), *_py = &(y); \
|
||||
*_px = *_py; \
|
||||
*_py = NULL; \
|
||||
} while (0)
|
||||
|
||||
#define FREE_AND_NULL(x) do { free(x); x = NULL; } while (0)
|
||||
|
||||
#define AT_LEAST(a, b) ({ __typeof__(a) __at_least = (a); (__at_least >= (b))?__at_least:(b); })
|
||||
|
||||
#define SHIFT_4K 12
|
||||
#define SECTOR_SHIFT 9
|
||||
#define SECTOR_SIZE (1 << SECTOR_SHIFT)
|
||||
#define MAX_SECTOR_SIZE 4096 /* min page size among all platforms */
|
||||
#define ROUND_SECTOR(x) (((x) + SECTOR_SIZE - 1) / SECTOR_SIZE)
|
||||
|
||||
#define MISALIGNED(a, b) ((a) & ((b) - 1))
|
||||
#define MISALIGNED_4K(a) MISALIGNED((a), 1 << SHIFT_4K)
|
||||
#define MISALIGNED_512(a) MISALIGNED((a), 1 << SECTOR_SHIFT)
|
||||
#define NOTPOW2(a) MISALIGNED((a), (a))
|
||||
|
||||
#define DEFAULT_DISK_ALIGNMENT 1048576 /* 1MiB */
|
||||
#define DEFAULT_MEM_ALIGNMENT 4096
|
||||
|
||||
#define DM_UUID_LEN 129
|
||||
#define DM_BY_ID_PREFIX "dm-uuid-"
|
||||
#define DM_BY_ID_PREFIX_LEN 8
|
||||
#define DM_UUID_PREFIX "CRYPT-"
|
||||
#define DM_UUID_PREFIX_LEN 6
|
||||
|
||||
#endif /* _LIBCRYPTSETUP_MACROS_H */
|
||||
105
lib/libcryptsetup_symver.h
Normal file
105
lib/libcryptsetup_symver.h
Normal file
@@ -0,0 +1,105 @@
|
||||
/*
|
||||
* Helpers for defining versioned symbols
|
||||
*
|
||||
* Copyright (C) 2021 Red Hat, Inc. All rights reserved.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#ifndef _LIBCRYPTSETUP_SYMVER_H
|
||||
#define _LIBCRYPTSETUP_SYMVER_H
|
||||
|
||||
/*
|
||||
* Note on usage:
|
||||
*
|
||||
* Do not use CRYPT_SYMBOL_EXPORT_NEW and CRYPT_SYMBOL_EXPORT_OLD on public
|
||||
* symbols being exported only once. Linker will handle it automatically as
|
||||
* always.
|
||||
*
|
||||
* It's supposed to be used only with symbols that are exported in at least
|
||||
* two versions simultaneously as follows:
|
||||
*
|
||||
* - the latest version is marked with _NEW variant and oll other compatible
|
||||
* symbols should be marked with _OLD variant
|
||||
*
|
||||
* Examples:
|
||||
*
|
||||
* - int crypt_func_X(unsigned *x, long y) gets introduced in CRYPTSETUP_2.4.
|
||||
*
|
||||
* No need to use any macro referenced here, just add proper version
|
||||
* mapping in libcryptsetup.sym file.
|
||||
*
|
||||
* In later version CRYPTSETUP_2.5 symbol crypt_func_X has to fixed
|
||||
* in incompatible way by adding new function parameter. The new version
|
||||
* has to be added in mapping file libcryptsetup.sym as well.
|
||||
*
|
||||
* The definition of compatible function gets prefixed with following macro:
|
||||
*
|
||||
* CRYPT_SYMBOL_EXPORT_OLD(int, crypt_func_X, 2, 4,
|
||||
* unsigned *x, long y)
|
||||
* {
|
||||
* function body
|
||||
* }
|
||||
*
|
||||
* Whereas new version introduced in CRYPTSETUP_2.5 is defined as follows:
|
||||
*
|
||||
* CRYPT_SYMBOL_EXPORT_NEW(int, crypt_func_X, 2, 5,
|
||||
* unsigned *x, long y, void *new_parameter)
|
||||
* {
|
||||
* function body
|
||||
* }
|
||||
*
|
||||
* If in later version CRYPTSETUP_2.6 yet another version of crypt_func_X gets
|
||||
* introduced it will be prefixed with CRYPT_SYMBOL_EXPORT_NEW(int, crypt_func_X, 2, 6...)
|
||||
* macro and all previous versions CRYPTSETUP_2.4 and CRYPTSETUP_2.5 will be
|
||||
* under CRYPT_SYMBOL_EXPORT_OLD(int, crypt_func_X, ...) macro
|
||||
*/
|
||||
|
||||
#ifdef __has_attribute
|
||||
# if __has_attribute(symver)
|
||||
# define _CRYPT_SYMVER(_local_sym, _public_sym, _ver_str, _maj, _min) \
|
||||
__attribute__((__symver__(#_public_sym _ver_str #_maj "." #_min)))
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if !defined(_CRYPT_SYMVER) && defined(__GNUC__)
|
||||
# define _CRYPT_SYMVER(_local_sym, _public_sym, _ver_str, _maj, _min) \
|
||||
asm(".symver " #_local_sym "," #_public_sym _ver_str #_maj "." #_min);
|
||||
#endif
|
||||
|
||||
#define _CRYPT_FUNC(_public_sym, _prefix_str, _maj, _min, _ret, ...) \
|
||||
_ret __##_public_sym##_v##_maj##_##_min(__VA_ARGS__); \
|
||||
_CRYPT_SYMVER(__##_public_sym##_v##_maj##_##_min, _public_sym, _prefix_str "CRYPTSETUP_", _maj, _min) \
|
||||
_ret __##_public_sym##_v##_maj##_##_min(__VA_ARGS__)
|
||||
|
||||
#ifdef _CRYPT_SYMVER
|
||||
|
||||
# define CRYPT_SYMBOL_EXPORT_OLD(_ret, _public_sym, _maj, _min, ...) \
|
||||
_CRYPT_FUNC(_public_sym, "@", _maj, _min, _ret, __VA_ARGS__)
|
||||
# define CRYPT_SYMBOL_EXPORT_NEW(_ret, _public_sym, _maj, _min, ...) \
|
||||
_CRYPT_FUNC(_public_sym, "@@", _maj, _min, _ret, __VA_ARGS__)
|
||||
|
||||
#else /* no support for symbol versioning at all */
|
||||
|
||||
# define CRYPT_SYMBOL_EXPORT_OLD(_ret, _public_sym, _maj, _min, ...) \
|
||||
static inline __attribute__((unused)) \
|
||||
_ret __##_public_sym##_v##_maj##_##_min(__VA_ARGS__)
|
||||
|
||||
# define CRYPT_SYMBOL_EXPORT_NEW(_ret, _public_sym, _maj, _min, ...) \
|
||||
_ret _public_sym(__VA_ARGS__)
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* _LIBCRYPTSETUP_SYMVER_H */
|
||||
@@ -3,8 +3,8 @@
|
||||
*
|
||||
* Copyright (C) 2004 Jana Saout <jana@saout.de>
|
||||
* Copyright (C) 2004-2007 Clemens Fruhwirth <clemens@endorphin.org>
|
||||
* Copyright (C) 2009-2020 Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2009-2020 Milan Broz
|
||||
* Copyright (C) 2009-2021 Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2009-2021 Milan Broz
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
@@ -24,24 +24,16 @@
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
#include <ctype.h>
|
||||
#include <dirent.h>
|
||||
#include <errno.h>
|
||||
#include <libdevmapper.h>
|
||||
#include <fcntl.h>
|
||||
#include <linux/fs.h>
|
||||
#include <uuid/uuid.h>
|
||||
#include <sys/stat.h>
|
||||
#ifdef HAVE_SYS_SYSMACROS_H
|
||||
# include <sys/sysmacros.h> /* for major, minor */
|
||||
#endif
|
||||
|
||||
#include <assert.h>
|
||||
#include "internal.h"
|
||||
|
||||
#define DM_UUID_LEN 129
|
||||
#define DM_BY_ID_PREFIX "dm-uuid-"
|
||||
#define DM_BY_ID_PREFIX_LEN 8
|
||||
#define DM_UUID_PREFIX "CRYPT-"
|
||||
#define DM_UUID_PREFIX_LEN 6
|
||||
#define DM_CRYPT_TARGET "crypt"
|
||||
#define DM_VERITY_TARGET "verity"
|
||||
#define DM_INTEGRITY_TARGET "integrity"
|
||||
@@ -175,6 +167,9 @@ static void _dm_set_crypt_compat(struct crypt_device *cd,
|
||||
if (_dm_satisfies_version(1, 20, 0, crypt_maj, crypt_min, crypt_patch))
|
||||
_dm_flags |= DM_BITLK_ELEPHANT_SUPPORTED;
|
||||
|
||||
if (_dm_satisfies_version(1, 22, 0, crypt_maj, crypt_min, crypt_patch))
|
||||
_dm_flags |= DM_CRYPT_NO_WORKQUEUE_SUPPORTED;
|
||||
|
||||
_dm_crypt_checked = true;
|
||||
}
|
||||
|
||||
@@ -206,6 +201,9 @@ static void _dm_set_verity_compat(struct crypt_device *cd,
|
||||
if (_dm_satisfies_version(1, 5, 0, verity_maj, verity_min, verity_patch))
|
||||
_dm_flags |= DM_VERITY_SIGNATURE_SUPPORTED;
|
||||
|
||||
if (_dm_satisfies_version(1, 7, 0, verity_maj, verity_min, verity_patch))
|
||||
_dm_flags |= DM_VERITY_PANIC_CORRUPTION_SUPPORTED;
|
||||
|
||||
_dm_verity_checked = true;
|
||||
}
|
||||
|
||||
@@ -231,6 +229,15 @@ static void _dm_set_integrity_compat(struct crypt_device *cd,
|
||||
if (_dm_satisfies_version(1, 4, 0, integrity_maj, integrity_min, integrity_patch))
|
||||
_dm_flags |= DM_INTEGRITY_FIX_PADDING_SUPPORTED;
|
||||
|
||||
if (_dm_satisfies_version(1, 6, 0, integrity_maj, integrity_min, integrity_patch))
|
||||
_dm_flags |= DM_INTEGRITY_DISCARDS_SUPPORTED;
|
||||
|
||||
if (_dm_satisfies_version(1, 7, 0, integrity_maj, integrity_min, integrity_patch))
|
||||
_dm_flags |= DM_INTEGRITY_FIX_HMAC_SUPPORTED;
|
||||
|
||||
if (_dm_satisfies_version(1, 8, 0, integrity_maj, integrity_min, integrity_patch))
|
||||
_dm_flags |= DM_INTEGRITY_RESET_RECALC_SUPPORTED;
|
||||
|
||||
_dm_integrity_checked = true;
|
||||
}
|
||||
|
||||
@@ -254,16 +261,12 @@ static void _dm_check_target(dm_target_type target_type)
|
||||
return;
|
||||
|
||||
if (!(dmt = dm_task_create(DM_DEVICE_GET_TARGET_VERSION)))
|
||||
goto out;
|
||||
return;
|
||||
|
||||
if (!dm_task_set_name(dmt, target_name))
|
||||
goto out;
|
||||
if (dm_task_set_name(dmt, target_name))
|
||||
dm_task_run(dmt);
|
||||
|
||||
if (!dm_task_run(dmt))
|
||||
goto out;
|
||||
out:
|
||||
if (dmt)
|
||||
dm_task_destroy(dmt);
|
||||
dm_task_destroy(dmt);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -287,7 +290,6 @@ static int _dm_check_versions(struct crypt_device *cd, dm_target_type target_typ
|
||||
|
||||
_dm_check_target(target_type);
|
||||
|
||||
/* FIXME: add support to DM so it forces crypt target module load here */
|
||||
if (!(dmt = dm_task_create(DM_DEVICE_LIST_VERSIONS)))
|
||||
goto out;
|
||||
|
||||
@@ -385,10 +387,7 @@ void dm_backend_exit(struct crypt_device *cd)
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* libdevmapper is not context friendly, switch context on every DM call.
|
||||
* FIXME: this is not safe if called in parallel but neither is DM lib.
|
||||
*/
|
||||
/* libdevmapper is not context friendly, switch context on every DM call. */
|
||||
static int dm_init_context(struct crypt_device *cd, dm_target_type target)
|
||||
{
|
||||
_context = cd;
|
||||
@@ -579,9 +578,14 @@ static int cipher_dm2c(char **org_c, char **org_i, const char *c_dm, const char
|
||||
|
||||
i = sscanf(capi, "%" CLENS "[^(](%" CLENS "[^)])", mode, cipher);
|
||||
if (i == 2)
|
||||
snprintf(dmcrypt_tmp, sizeof(dmcrypt_tmp), "%s-%s-%s", cipher, mode, iv);
|
||||
i = snprintf(dmcrypt_tmp, sizeof(dmcrypt_tmp), "%s-%s-%s", cipher, mode, iv);
|
||||
else
|
||||
snprintf(dmcrypt_tmp, sizeof(dmcrypt_tmp), "%s-%s", capi, iv);
|
||||
i = snprintf(dmcrypt_tmp, sizeof(dmcrypt_tmp), "%s-%s", capi, iv);
|
||||
if (i < 0 || (size_t)i >= sizeof(dmcrypt_tmp)) {
|
||||
free(*org_i);
|
||||
*org_i = NULL;
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (!(*org_c = strdup(dmcrypt_tmp))) {
|
||||
free(*org_i);
|
||||
@@ -592,11 +596,18 @@ static int cipher_dm2c(char **org_c, char **org_i, const char *c_dm, const char
|
||||
return 0;
|
||||
}
|
||||
|
||||
static char *_uf(char *buf, size_t buf_size, const char *s, unsigned u)
|
||||
{
|
||||
size_t r = snprintf(buf, buf_size, " %s:%u", s, u);
|
||||
assert(r > 0 && r < buf_size);
|
||||
return buf;
|
||||
}
|
||||
|
||||
/* https://gitlab.com/cryptsetup/cryptsetup/wikis/DMCrypt */
|
||||
static char *get_dm_crypt_params(const struct dm_target *tgt, uint32_t flags)
|
||||
{
|
||||
int r, max_size, null_cipher = 0, num_options = 0, keystr_len = 0;
|
||||
char *params, *hexkey;
|
||||
char *params = NULL, *hexkey = NULL;
|
||||
char sector_feature[32], features[512], integrity_dm[256], cipher_dm[256];
|
||||
|
||||
if (!tgt)
|
||||
@@ -613,44 +624,53 @@ static char *get_dm_crypt_params(const struct dm_target *tgt, uint32_t flags)
|
||||
num_options++;
|
||||
if (flags & CRYPT_ACTIVATE_SUBMIT_FROM_CRYPT_CPUS)
|
||||
num_options++;
|
||||
if (flags & CRYPT_ACTIVATE_NO_READ_WORKQUEUE)
|
||||
num_options++;
|
||||
if (flags & CRYPT_ACTIVATE_NO_WRITE_WORKQUEUE)
|
||||
num_options++;
|
||||
if (flags & CRYPT_ACTIVATE_IV_LARGE_SECTORS)
|
||||
num_options++;
|
||||
if (tgt->u.crypt.integrity)
|
||||
num_options++;
|
||||
|
||||
if (tgt->u.crypt.sector_size != SECTOR_SIZE) {
|
||||
if (tgt->u.crypt.sector_size != SECTOR_SIZE)
|
||||
num_options++;
|
||||
snprintf(sector_feature, sizeof(sector_feature), " sector_size:%u", tgt->u.crypt.sector_size);
|
||||
} else
|
||||
*sector_feature = '\0';
|
||||
|
||||
if (num_options) {
|
||||
snprintf(features, sizeof(features)-1, " %d%s%s%s%s%s", num_options,
|
||||
if (num_options) { /* MAX length int32 + 15 + 15 + 23 + 18 + 19 + 17 + 13 + int32 + integrity_str */
|
||||
r = snprintf(features, sizeof(features), " %d%s%s%s%s%s%s%s%s", num_options,
|
||||
(flags & CRYPT_ACTIVATE_ALLOW_DISCARDS) ? " allow_discards" : "",
|
||||
(flags & CRYPT_ACTIVATE_SAME_CPU_CRYPT) ? " same_cpu_crypt" : "",
|
||||
(flags & CRYPT_ACTIVATE_SUBMIT_FROM_CRYPT_CPUS) ? " submit_from_crypt_cpus" : "",
|
||||
sector_feature, integrity_dm);
|
||||
(flags & CRYPT_ACTIVATE_NO_READ_WORKQUEUE) ? " no_read_workqueue" : "",
|
||||
(flags & CRYPT_ACTIVATE_NO_WRITE_WORKQUEUE) ? " no_write_workqueue" : "",
|
||||
(flags & CRYPT_ACTIVATE_IV_LARGE_SECTORS) ? " iv_large_sectors" : "",
|
||||
(tgt->u.crypt.sector_size != SECTOR_SIZE) ?
|
||||
_uf(sector_feature, sizeof(sector_feature), "sector_size", tgt->u.crypt.sector_size) : "",
|
||||
integrity_dm);
|
||||
if (r < 0 || (size_t)r >= sizeof(features))
|
||||
goto out;
|
||||
} else
|
||||
*features = '\0';
|
||||
|
||||
if (!strncmp(cipher_dm, "cipher_null-", 12))
|
||||
if (crypt_is_cipher_null(cipher_dm))
|
||||
null_cipher = 1;
|
||||
|
||||
if (flags & CRYPT_ACTIVATE_KEYRING_KEY) {
|
||||
if (null_cipher)
|
||||
hexkey = crypt_safe_alloc(2);
|
||||
else if (flags & CRYPT_ACTIVATE_KEYRING_KEY) {
|
||||
keystr_len = strlen(tgt->u.crypt.vk->key_description) + int_log10(tgt->u.crypt.vk->keylength) + 10;
|
||||
hexkey = crypt_safe_alloc(keystr_len);
|
||||
} else
|
||||
hexkey = crypt_safe_alloc(null_cipher ? 2 : (tgt->u.crypt.vk->keylength * 2 + 1));
|
||||
hexkey = crypt_safe_alloc(tgt->u.crypt.vk->keylength * 2 + 1);
|
||||
|
||||
if (!hexkey)
|
||||
return NULL;
|
||||
goto out;
|
||||
|
||||
if (null_cipher)
|
||||
strncpy(hexkey, "-", 2);
|
||||
else if (flags & CRYPT_ACTIVATE_KEYRING_KEY) {
|
||||
r = snprintf(hexkey, keystr_len, ":%zu:logon:%s", tgt->u.crypt.vk->keylength, tgt->u.crypt.vk->key_description);
|
||||
if (r < 0 || r >= keystr_len) {
|
||||
params = NULL;
|
||||
if (r < 0 || r >= keystr_len)
|
||||
goto out;
|
||||
}
|
||||
} else
|
||||
hex_key(hexkey, tgt->u.crypt.vk->keylength, tgt->u.crypt.vk->key);
|
||||
|
||||
@@ -677,10 +697,10 @@ out:
|
||||
/* https://gitlab.com/cryptsetup/cryptsetup/wikis/DMVerity */
|
||||
static char *get_dm_verity_params(const struct dm_target *tgt, uint32_t flags)
|
||||
{
|
||||
int max_size, r, num_options = 0;
|
||||
int max_size, max_fec_size, max_verify_size, r, num_options = 0;
|
||||
struct crypt_params_verity *vp;
|
||||
char *params = NULL, *hexroot = NULL, *hexsalt = NULL;
|
||||
char features[256], fec_features[256], verity_verify_args[512+32];
|
||||
char features[256], *fec_features = NULL, *verity_verify_args = NULL;
|
||||
|
||||
if (!tgt || !tgt->u.verity.vp)
|
||||
return NULL;
|
||||
@@ -688,42 +708,63 @@ static char *get_dm_verity_params(const struct dm_target *tgt, uint32_t flags)
|
||||
vp = tgt->u.verity.vp;
|
||||
|
||||
/* These flags are not compatible */
|
||||
if ((flags & CRYPT_ACTIVATE_RESTART_ON_CORRUPTION) &&
|
||||
(flags & CRYPT_ACTIVATE_PANIC_ON_CORRUPTION))
|
||||
flags &= ~CRYPT_ACTIVATE_RESTART_ON_CORRUPTION;
|
||||
if ((flags & CRYPT_ACTIVATE_IGNORE_CORRUPTION) &&
|
||||
(flags & CRYPT_ACTIVATE_RESTART_ON_CORRUPTION))
|
||||
(flags & (CRYPT_ACTIVATE_RESTART_ON_CORRUPTION|CRYPT_ACTIVATE_PANIC_ON_CORRUPTION)))
|
||||
flags &= ~CRYPT_ACTIVATE_IGNORE_CORRUPTION;
|
||||
|
||||
if (flags & CRYPT_ACTIVATE_IGNORE_CORRUPTION)
|
||||
num_options++;
|
||||
if (flags & CRYPT_ACTIVATE_RESTART_ON_CORRUPTION)
|
||||
num_options++;
|
||||
if (flags & CRYPT_ACTIVATE_PANIC_ON_CORRUPTION)
|
||||
num_options++;
|
||||
if (flags & CRYPT_ACTIVATE_IGNORE_ZERO_BLOCKS)
|
||||
num_options++;
|
||||
if (flags & CRYPT_ACTIVATE_CHECK_AT_MOST_ONCE)
|
||||
num_options++;
|
||||
|
||||
if (tgt->u.verity.fec_device) {
|
||||
max_fec_size = (tgt->u.verity.fec_device ? strlen(device_block_path(tgt->u.verity.fec_device)) : 0) + 256;
|
||||
fec_features = crypt_safe_alloc(max_fec_size);
|
||||
if (!fec_features)
|
||||
goto out;
|
||||
|
||||
if (tgt->u.verity.fec_device) { /* MAX length 21 + path + 11 + int64 + 12 + int64 + 11 + int32 */
|
||||
num_options += 8;
|
||||
snprintf(fec_features, sizeof(fec_features)-1,
|
||||
r = snprintf(fec_features, max_fec_size,
|
||||
" use_fec_from_device %s fec_start %" PRIu64 " fec_blocks %" PRIu64 " fec_roots %" PRIu32,
|
||||
device_block_path(tgt->u.verity.fec_device), tgt->u.verity.fec_offset,
|
||||
vp->data_size + tgt->u.verity.hash_blocks, vp->fec_roots);
|
||||
tgt->u.verity.fec_blocks, vp->fec_roots);
|
||||
if (r < 0 || r >= max_fec_size)
|
||||
goto out;
|
||||
} else
|
||||
*fec_features = '\0';
|
||||
|
||||
if (tgt->u.verity.root_hash_sig_key_desc) {
|
||||
max_verify_size = (tgt->u.verity.root_hash_sig_key_desc ? strlen(tgt->u.verity.root_hash_sig_key_desc) : 0) + 32;
|
||||
verity_verify_args = crypt_safe_alloc(max_verify_size);
|
||||
if (!verity_verify_args)
|
||||
goto out;
|
||||
if (tgt->u.verity.root_hash_sig_key_desc) { /* MAX length 24 + key_str */
|
||||
num_options += 2;
|
||||
snprintf(verity_verify_args, sizeof(verity_verify_args)-1,
|
||||
r = snprintf(verity_verify_args, max_verify_size,
|
||||
" root_hash_sig_key_desc %s", tgt->u.verity.root_hash_sig_key_desc);
|
||||
if (r < 0 || r >= max_verify_size)
|
||||
goto out;
|
||||
} else
|
||||
*verity_verify_args = '\0';
|
||||
|
||||
if (num_options)
|
||||
snprintf(features, sizeof(features)-1, " %d%s%s%s%s", num_options,
|
||||
if (num_options) { /* MAX length int32 + 18 + 22 + 20 + 19 + 19 */
|
||||
r = snprintf(features, sizeof(features), " %d%s%s%s%s%s", num_options,
|
||||
(flags & CRYPT_ACTIVATE_IGNORE_CORRUPTION) ? " ignore_corruption" : "",
|
||||
(flags & CRYPT_ACTIVATE_RESTART_ON_CORRUPTION) ? " restart_on_corruption" : "",
|
||||
(flags & CRYPT_ACTIVATE_PANIC_ON_CORRUPTION) ? " panic_on_corruption" : "",
|
||||
(flags & CRYPT_ACTIVATE_IGNORE_ZERO_BLOCKS) ? " ignore_zero_blocks" : "",
|
||||
(flags & CRYPT_ACTIVATE_CHECK_AT_MOST_ONCE) ? " check_at_most_once" : "");
|
||||
else
|
||||
if (r < 0 || (size_t)r >= sizeof(features))
|
||||
goto out;
|
||||
} else
|
||||
*features = '\0';
|
||||
|
||||
hexroot = crypt_safe_alloc(tgt->u.verity.root_hash_size * 2 + 1);
|
||||
@@ -757,12 +798,13 @@ static char *get_dm_verity_params(const struct dm_target *tgt, uint32_t flags)
|
||||
vp->data_size, tgt->u.verity.hash_offset,
|
||||
vp->hash_name, hexroot, hexsalt, features, fec_features,
|
||||
verity_verify_args);
|
||||
|
||||
if (r < 0 || r >= max_size) {
|
||||
crypt_safe_free(params);
|
||||
params = NULL;
|
||||
}
|
||||
out:
|
||||
crypt_safe_free(fec_features);
|
||||
crypt_safe_free(verity_verify_args);
|
||||
crypt_safe_free(hexroot);
|
||||
crypt_safe_free(hexsalt);
|
||||
return params;
|
||||
@@ -770,143 +812,146 @@ out:
|
||||
|
||||
static char *get_dm_integrity_params(const struct dm_target *tgt, uint32_t flags)
|
||||
{
|
||||
int r, max_size, num_options = 0;
|
||||
char *params, *hexkey, mode;
|
||||
char features[512], feature[256];
|
||||
int r, max_size, max_integrity, max_journal_integrity, max_journal_crypt, num_options = 0;
|
||||
char *params_out = NULL, *params, *hexkey, mode, feature[6][32];
|
||||
char *features, *integrity, *journal_integrity, *journal_crypt;
|
||||
|
||||
if (!tgt)
|
||||
return NULL;
|
||||
|
||||
max_integrity = (tgt->u.integrity.integrity && tgt->u.integrity.vk ? tgt->u.integrity.vk->keylength * 2 : 0) +
|
||||
(tgt->u.integrity.integrity ? strlen(tgt->u.integrity.integrity) : 0) + 32;
|
||||
max_journal_integrity = (tgt->u.integrity.journal_integrity && tgt->u.integrity.journal_integrity_key ?
|
||||
tgt->u.integrity.journal_integrity_key->keylength * 2 : 0) +
|
||||
(tgt->u.integrity.journal_integrity ? strlen(tgt->u.integrity.journal_integrity) : 0) + 32;
|
||||
max_journal_crypt = (tgt->u.integrity.journal_crypt && tgt->u.integrity.journal_crypt_key ?
|
||||
tgt->u.integrity.journal_crypt_key->keylength * 2 : 0) +
|
||||
(tgt->u.integrity.journal_crypt ? strlen(tgt->u.integrity.journal_crypt) : 0) + 32;
|
||||
max_size = strlen(device_block_path(tgt->data_device)) +
|
||||
(tgt->u.integrity.meta_device ? strlen(device_block_path(tgt->u.integrity.meta_device)) : 0) +
|
||||
(tgt->u.integrity.vk ? tgt->u.integrity.vk->keylength * 2 : 0) +
|
||||
(tgt->u.integrity.journal_integrity_key ? tgt->u.integrity.journal_integrity_key->keylength * 2 : 0) +
|
||||
(tgt->u.integrity.journal_crypt_key ? tgt->u.integrity.journal_crypt_key->keylength * 2 : 0) +
|
||||
(tgt->u.integrity.integrity ? strlen(tgt->u.integrity.integrity) : 0) +
|
||||
(tgt->u.integrity.journal_integrity ? strlen(tgt->u.integrity.journal_integrity) : 0) +
|
||||
(tgt->u.integrity.journal_crypt ? strlen(tgt->u.integrity.journal_crypt) : 0) + 128;
|
||||
(tgt->u.integrity.meta_device ? strlen(device_block_path(tgt->u.integrity.meta_device)) : 0) +
|
||||
max_integrity + max_journal_integrity + max_journal_crypt + 512;
|
||||
|
||||
params = crypt_safe_alloc(max_size);
|
||||
if (!params)
|
||||
return NULL;
|
||||
features = crypt_safe_alloc(max_size);
|
||||
integrity = crypt_safe_alloc(max_integrity);
|
||||
journal_integrity = crypt_safe_alloc(max_journal_integrity);
|
||||
journal_crypt = crypt_safe_alloc(max_journal_crypt);
|
||||
if (!params || !features || !integrity || !journal_integrity || !journal_crypt)
|
||||
goto out;
|
||||
|
||||
*features = '\0';
|
||||
if (tgt->u.integrity.journal_size) {
|
||||
num_options++;
|
||||
snprintf(feature, sizeof(feature), "journal_sectors:%u ",
|
||||
(unsigned)(tgt->u.integrity.journal_size / SECTOR_SIZE));
|
||||
strncat(features, feature, sizeof(features) - strlen(features) - 1);
|
||||
}
|
||||
if (tgt->u.integrity.journal_watermark) {
|
||||
num_options++;
|
||||
snprintf(feature, sizeof(feature),
|
||||
/* bitmap overloaded values */
|
||||
(flags & CRYPT_ACTIVATE_NO_JOURNAL_BITMAP) ? "sectors_per_bit:%u " : "journal_watermark:%u ",
|
||||
tgt->u.integrity.journal_watermark);
|
||||
strncat(features, feature, sizeof(features) - strlen(features) - 1);
|
||||
}
|
||||
if (tgt->u.integrity.journal_commit_time) {
|
||||
num_options++;
|
||||
snprintf(feature, sizeof(feature),
|
||||
/* bitmap overloaded values */
|
||||
(flags & CRYPT_ACTIVATE_NO_JOURNAL_BITMAP) ? "bitmap_flush_interval:%u " : "commit_time:%u ",
|
||||
tgt->u.integrity.journal_commit_time);
|
||||
strncat(features, feature, sizeof(features) - strlen(features) - 1);
|
||||
}
|
||||
if (tgt->u.integrity.interleave_sectors) {
|
||||
num_options++;
|
||||
snprintf(feature, sizeof(feature), "interleave_sectors:%u ",
|
||||
tgt->u.integrity.interleave_sectors);
|
||||
strncat(features, feature, sizeof(features) - strlen(features) - 1);
|
||||
}
|
||||
if (tgt->u.integrity.sector_size) {
|
||||
num_options++;
|
||||
snprintf(feature, sizeof(feature), "block_size:%u ",
|
||||
tgt->u.integrity.sector_size);
|
||||
strncat(features, feature, sizeof(features) - strlen(features) - 1);
|
||||
}
|
||||
if (tgt->u.integrity.buffer_sectors) {
|
||||
num_options++;
|
||||
snprintf(feature, sizeof(feature), "buffer_sectors:%u ",
|
||||
tgt->u.integrity.buffer_sectors);
|
||||
strncat(features, feature, sizeof(features) - strlen(features) - 1);
|
||||
}
|
||||
if (tgt->u.integrity.integrity) {
|
||||
if (tgt->u.integrity.integrity) { /* MAX length 16 + str_integrity + str_key */
|
||||
num_options++;
|
||||
|
||||
if (tgt->u.integrity.vk) {
|
||||
hexkey = crypt_safe_alloc(tgt->u.integrity.vk->keylength * 2 + 1);
|
||||
if (!hexkey) {
|
||||
crypt_safe_free(params);
|
||||
return NULL;
|
||||
}
|
||||
if (!hexkey)
|
||||
goto out;
|
||||
hex_key(hexkey, tgt->u.integrity.vk->keylength, tgt->u.integrity.vk->key);
|
||||
} else
|
||||
hexkey = NULL;
|
||||
|
||||
snprintf(feature, sizeof(feature), "internal_hash:%s%s%s ",
|
||||
r = snprintf(integrity, max_integrity, " internal_hash:%s%s%s",
|
||||
tgt->u.integrity.integrity, hexkey ? ":" : "", hexkey ?: "");
|
||||
strncat(features, feature, sizeof(features) - strlen(features) - 1);
|
||||
crypt_safe_free(hexkey);
|
||||
if (r < 0 || r >= max_integrity)
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (tgt->u.integrity.journal_integrity) {
|
||||
if (tgt->u.integrity.journal_integrity) { /* MAX length 14 + str_journal_integrity + str_key */
|
||||
num_options++;
|
||||
|
||||
if (tgt->u.integrity.journal_integrity_key) {
|
||||
hexkey = crypt_safe_alloc(tgt->u.integrity.journal_integrity_key->keylength * 2 + 1);
|
||||
if (!hexkey) {
|
||||
crypt_safe_free(params);
|
||||
return NULL;
|
||||
}
|
||||
if (!hexkey)
|
||||
goto out;
|
||||
hex_key(hexkey, tgt->u.integrity.journal_integrity_key->keylength,
|
||||
tgt->u.integrity.journal_integrity_key->key);
|
||||
} else
|
||||
hexkey = NULL;
|
||||
|
||||
snprintf(feature, sizeof(feature), "journal_mac:%s%s%s ",
|
||||
r = snprintf(journal_integrity, max_journal_integrity, " journal_mac:%s%s%s",
|
||||
tgt->u.integrity.journal_integrity, hexkey ? ":" : "", hexkey ?: "");
|
||||
strncat(features, feature, sizeof(features) - strlen(features) - 1);
|
||||
crypt_safe_free(hexkey);
|
||||
if (r < 0 || r >= max_journal_integrity)
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (tgt->u.integrity.journal_crypt) {
|
||||
if (tgt->u.integrity.journal_crypt) { /* MAX length 15 + str_journal_crypt + str_key */
|
||||
num_options++;
|
||||
|
||||
if (tgt->u.integrity.journal_crypt_key) {
|
||||
hexkey = crypt_safe_alloc(tgt->u.integrity.journal_crypt_key->keylength * 2 + 1);
|
||||
if (!hexkey) {
|
||||
crypt_safe_free(params);
|
||||
return NULL;
|
||||
}
|
||||
if (!hexkey)
|
||||
goto out;
|
||||
hex_key(hexkey, tgt->u.integrity.journal_crypt_key->keylength,
|
||||
tgt->u.integrity.journal_crypt_key->key);
|
||||
} else
|
||||
hexkey = NULL;
|
||||
|
||||
snprintf(feature, sizeof(feature), "journal_crypt:%s%s%s ",
|
||||
r = snprintf(journal_crypt, max_journal_crypt, " journal_crypt:%s%s%s",
|
||||
tgt->u.integrity.journal_crypt, hexkey ? ":" : "", hexkey ?: "");
|
||||
strncat(features, feature, sizeof(features) - strlen(features) - 1);
|
||||
crypt_safe_free(hexkey);
|
||||
}
|
||||
if (tgt->u.integrity.fix_padding) {
|
||||
num_options++;
|
||||
snprintf(feature, sizeof(feature), "fix_padding ");
|
||||
strncat(features, feature, sizeof(features) - strlen(features) - 1);
|
||||
if (r < 0 || r >= max_journal_crypt)
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (flags & CRYPT_ACTIVATE_RECALCULATE) {
|
||||
if (tgt->u.integrity.journal_size)
|
||||
num_options++;
|
||||
if (tgt->u.integrity.journal_watermark)
|
||||
num_options++;
|
||||
if (tgt->u.integrity.journal_commit_time)
|
||||
num_options++;
|
||||
if (tgt->u.integrity.interleave_sectors)
|
||||
num_options++;
|
||||
if (tgt->u.integrity.sector_size)
|
||||
num_options++;
|
||||
if (tgt->u.integrity.buffer_sectors)
|
||||
num_options++;
|
||||
if (tgt->u.integrity.fix_padding)
|
||||
num_options++;
|
||||
if (tgt->u.integrity.fix_hmac)
|
||||
num_options++;
|
||||
if (tgt->u.integrity.legacy_recalc)
|
||||
num_options++;
|
||||
if (tgt->u.integrity.meta_device)
|
||||
num_options++;
|
||||
if (flags & CRYPT_ACTIVATE_RECALCULATE)
|
||||
num_options++;
|
||||
if (flags & CRYPT_ACTIVATE_RECALCULATE_RESET)
|
||||
num_options++;
|
||||
if (flags & CRYPT_ACTIVATE_ALLOW_DISCARDS)
|
||||
num_options++;
|
||||
snprintf(feature, sizeof(feature), "recalculate ");
|
||||
strncat(features, feature, sizeof(features) - strlen(features) - 1);
|
||||
}
|
||||
|
||||
if (tgt->u.integrity.meta_device) {
|
||||
num_options++;
|
||||
snprintf(feature, sizeof(feature), "meta_device:%s ",
|
||||
device_block_path(tgt->u.integrity.meta_device));
|
||||
strncat(features, feature, sizeof(features) - strlen(features) - 1);
|
||||
}
|
||||
r = snprintf(features, max_size, "%d%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s", num_options,
|
||||
tgt->u.integrity.journal_size ? _uf(feature[0], sizeof(feature[0]), /* MAX length 17 + int32 */
|
||||
"journal_sectors", (unsigned)(tgt->u.integrity.journal_size / SECTOR_SIZE)) : "",
|
||||
tgt->u.integrity.journal_watermark ? _uf(feature[1], sizeof(feature[1]), /* MAX length 19 + int32 */
|
||||
/* bitmap overloaded values */
|
||||
(flags & CRYPT_ACTIVATE_NO_JOURNAL_BITMAP) ? "sectors_per_bit" : "journal_watermark",
|
||||
tgt->u.integrity.journal_watermark) : "",
|
||||
tgt->u.integrity.journal_commit_time ? _uf(feature[2], sizeof(feature[2]), /* MAX length 23 + int32 */
|
||||
/* bitmap overloaded values */
|
||||
(flags & CRYPT_ACTIVATE_NO_JOURNAL_BITMAP) ? "bitmap_flush_interval" : "commit_time",
|
||||
tgt->u.integrity.journal_commit_time) : "",
|
||||
tgt->u.integrity.interleave_sectors ? _uf(feature[3], sizeof(feature[3]), /* MAX length 20 + int32 */
|
||||
"interleave_sectors", tgt->u.integrity.interleave_sectors) : "",
|
||||
tgt->u.integrity.sector_size ? _uf(feature[4], sizeof(feature[4]), /* MAX length 12 + int32 */
|
||||
"block_size", tgt->u.integrity.sector_size) : "",
|
||||
tgt->u.integrity.buffer_sectors ? _uf(feature[5], sizeof(feature[5]), /* MAX length 16 + int32 */
|
||||
"buffer_sectors", tgt->u.integrity.buffer_sectors) : "",
|
||||
tgt->u.integrity.integrity ? integrity : "",
|
||||
tgt->u.integrity.journal_integrity ? journal_integrity : "",
|
||||
tgt->u.integrity.journal_crypt ? journal_crypt : "",
|
||||
tgt->u.integrity.fix_padding ? " fix_padding" : "", /* MAX length 12 */
|
||||
tgt->u.integrity.fix_hmac ? " fix_hmac" : "", /* MAX length 9 */
|
||||
tgt->u.integrity.legacy_recalc ? " legacy_recalculate" : "", /* MAX length 19 */
|
||||
flags & CRYPT_ACTIVATE_RECALCULATE ? " recalculate" : "", /* MAX length 12 */
|
||||
flags & CRYPT_ACTIVATE_RECALCULATE_RESET ? " reset_recalculate" : "", /* MAX length 18 */
|
||||
flags & CRYPT_ACTIVATE_ALLOW_DISCARDS ? " allow_discards" : "", /* MAX length 15 */
|
||||
tgt->u.integrity.meta_device ? " meta_device:" : "", /* MAX length 13 + str_device */
|
||||
tgt->u.integrity.meta_device ? device_block_path(tgt->u.integrity.meta_device) : "");
|
||||
if (r < 0 || r >= max_size)
|
||||
goto out;
|
||||
|
||||
if (flags & CRYPT_ACTIVATE_NO_JOURNAL_BITMAP)
|
||||
mode = 'B';
|
||||
@@ -917,19 +962,25 @@ static char *get_dm_integrity_params(const struct dm_target *tgt, uint32_t flags
|
||||
else
|
||||
mode = 'J';
|
||||
|
||||
r = snprintf(params, max_size, "%s %" PRIu64 " %d %c %d %s",
|
||||
r = snprintf(params, max_size, "%s %" PRIu64 " %d %c %s",
|
||||
device_block_path(tgt->data_device), tgt->u.integrity.offset,
|
||||
tgt->u.integrity.tag_size, mode,
|
||||
num_options, *features ? features : "");
|
||||
if (r < 0 || r >= max_size) {
|
||||
crypt_safe_free(params);
|
||||
params = NULL;
|
||||
}
|
||||
tgt->u.integrity.tag_size, mode, features);
|
||||
if (r < 0 || r >= max_size)
|
||||
goto out;
|
||||
|
||||
return params;
|
||||
params_out = params;
|
||||
out:
|
||||
crypt_safe_free(features);
|
||||
crypt_safe_free(integrity);
|
||||
crypt_safe_free(journal_integrity);
|
||||
crypt_safe_free(journal_crypt);
|
||||
if (!params_out)
|
||||
crypt_safe_free(params);
|
||||
|
||||
return params_out;
|
||||
}
|
||||
|
||||
static char *get_dm_linear_params(const struct dm_target *tgt, uint32_t flags)
|
||||
static char *get_dm_linear_params(const struct dm_target *tgt, uint32_t flags __attribute__((unused)))
|
||||
{
|
||||
char *params;
|
||||
int r;
|
||||
@@ -950,7 +1001,7 @@ static char *get_dm_linear_params(const struct dm_target *tgt, uint32_t flags)
|
||||
return params;
|
||||
}
|
||||
|
||||
static char *get_dm_zero_params(const struct dm_target *tgt, uint32_t flags)
|
||||
static char *get_dm_zero_params(const struct dm_target *tgt __attribute__((unused)), uint32_t flags __attribute__((unused)))
|
||||
{
|
||||
char *params = crypt_safe_alloc(1);
|
||||
if (!params)
|
||||
@@ -1032,28 +1083,27 @@ static int _error_device(const char *name, size_t size)
|
||||
return 0;
|
||||
|
||||
if (!dm_task_set_name(dmt, name))
|
||||
goto error;
|
||||
goto out;
|
||||
|
||||
if (!dm_task_add_target(dmt, UINT64_C(0), size, "error", ""))
|
||||
goto error;
|
||||
goto out;
|
||||
|
||||
if (!dm_task_set_ro(dmt))
|
||||
goto error;
|
||||
goto out;
|
||||
|
||||
if (!dm_task_no_open_count(dmt))
|
||||
goto error;
|
||||
goto out;
|
||||
|
||||
if (!dm_task_run(dmt))
|
||||
goto error;
|
||||
goto out;
|
||||
|
||||
if (_dm_resume_device(name, 0)) {
|
||||
_dm_simple(DM_DEVICE_CLEAR, name, 0);
|
||||
goto error;
|
||||
goto out;
|
||||
}
|
||||
|
||||
r = 1;
|
||||
|
||||
error:
|
||||
out:
|
||||
dm_task_destroy(dmt);
|
||||
return r;
|
||||
}
|
||||
@@ -1161,7 +1211,7 @@ static int dm_prepare_uuid(struct crypt_device *cd, const char *name, const char
|
||||
{
|
||||
char *ptr, uuid2[UUID_LEN] = {0};
|
||||
uuid_t uu;
|
||||
unsigned i = 0;
|
||||
int i = 0;
|
||||
|
||||
/* Remove '-' chars */
|
||||
if (uuid) {
|
||||
@@ -1181,9 +1231,11 @@ static int dm_prepare_uuid(struct crypt_device *cd, const char *name, const char
|
||||
type ?: "", type ? "-" : "",
|
||||
uuid2[0] ? uuid2 : "", uuid2[0] ? "-" : "",
|
||||
name);
|
||||
if (i < 0)
|
||||
return 0;
|
||||
|
||||
log_dbg(cd, "DM-UUID is %s", buf);
|
||||
if (i >= buflen)
|
||||
if ((size_t)i >= buflen)
|
||||
log_err(cd, _("DM-UUID for device %s was truncated."), name);
|
||||
|
||||
return 1;
|
||||
@@ -1208,7 +1260,7 @@ int lookup_dm_dev_by_uuid(struct crypt_device *cd, const char *uuid, const char
|
||||
r = lookup_by_disk_id(dev_uuid);
|
||||
if (r == -ENOENT) {
|
||||
log_dbg(cd, "Search by disk id not available. Using sysfs instead.");
|
||||
r = lookup_by_sysfs_uuid_field(dev_uuid + DM_BY_ID_PREFIX_LEN, DM_UUID_LEN);
|
||||
r = lookup_by_sysfs_uuid_field(dev_uuid + DM_BY_ID_PREFIX_LEN);
|
||||
}
|
||||
|
||||
return r;
|
||||
@@ -1294,8 +1346,14 @@ err:
|
||||
return r;
|
||||
}
|
||||
|
||||
static bool dm_device_exists(struct crypt_device *cd, const char *name)
|
||||
{
|
||||
int r = dm_status_device(cd, name);
|
||||
return (r >= 0 || r == -EEXIST);
|
||||
}
|
||||
|
||||
static int _dm_create_device(struct crypt_device *cd, const char *name, const char *type,
|
||||
const char *uuid, struct crypt_dm_active_device *dmd)
|
||||
struct crypt_dm_active_device *dmd)
|
||||
{
|
||||
struct dm_task *dmt = NULL;
|
||||
struct dm_info dmi;
|
||||
@@ -1343,8 +1401,11 @@ static int _dm_create_device(struct crypt_device *cd, const char *name, const ch
|
||||
if (_dm_use_udev() && !_dm_task_set_cookie(dmt, &cookie, udev_flags))
|
||||
goto out;
|
||||
|
||||
if (!dm_task_run(dmt))
|
||||
if (!dm_task_run(dmt)) {
|
||||
if (dm_device_exists(cd, name))
|
||||
r = -EEXIST;
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (dm_task_get_info(dmt, &dmi))
|
||||
r = 0;
|
||||
@@ -1581,6 +1642,14 @@ static int check_retry(struct crypt_device *cd, uint32_t *dmd_flags, uint32_t dm
|
||||
ret = 1;
|
||||
}
|
||||
|
||||
/* Drop no workqueue options if not supported */
|
||||
if ((*dmd_flags & (CRYPT_ACTIVATE_NO_READ_WORKQUEUE | CRYPT_ACTIVATE_NO_WRITE_WORKQUEUE)) &&
|
||||
!(dmt_flags & DM_CRYPT_NO_WORKQUEUE_SUPPORTED)) {
|
||||
log_dbg(cd, "dm-crypt does not support performance options");
|
||||
*dmd_flags = *dmd_flags & ~(CRYPT_ACTIVATE_NO_READ_WORKQUEUE | CRYPT_ACTIVATE_NO_WRITE_WORKQUEUE);
|
||||
ret = 1;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -1597,20 +1666,35 @@ int dm_create_device(struct crypt_device *cd, const char *name,
|
||||
if (dm_init_context(cd, dmd->segment.type))
|
||||
return -ENOTSUP;
|
||||
|
||||
r = _dm_create_device(cd, name, type, dmd->uuid, dmd);
|
||||
r = _dm_create_device(cd, name, type, dmd);
|
||||
|
||||
if (r < 0 && dm_flags(cd, dmd->segment.type, &dmt_flags))
|
||||
goto out;
|
||||
|
||||
if (r && (dmd->segment.type == DM_CRYPT || dmd->segment.type == DM_LINEAR || dmd->segment.type == DM_ZERO) &&
|
||||
check_retry(cd, &dmd->flags, dmt_flags))
|
||||
r = _dm_create_device(cd, name, type, dmd->uuid, dmd);
|
||||
check_retry(cd, &dmd->flags, dmt_flags)) {
|
||||
log_dbg(cd, "Retrying open without incompatible options.");
|
||||
r = _dm_create_device(cd, name, type, dmd);
|
||||
}
|
||||
|
||||
/*
|
||||
* Print warning if activating dm-crypt cipher_null device unless it's reencryption helper or
|
||||
* keyslot encryption helper device (LUKS1 cipher_null devices).
|
||||
*/
|
||||
if (!r && !(dmd->flags & CRYPT_ACTIVATE_PRIVATE) && single_segment(dmd) && dmd->segment.type == DM_CRYPT &&
|
||||
crypt_is_cipher_null(dmd->segment.u.crypt.cipher))
|
||||
log_dbg(cd, "Activated dm-crypt device with cipher_null. Device is not encrypted.");
|
||||
|
||||
if (r == -EINVAL &&
|
||||
dmd->flags & (CRYPT_ACTIVATE_SAME_CPU_CRYPT|CRYPT_ACTIVATE_SUBMIT_FROM_CRYPT_CPUS) &&
|
||||
!(dmt_flags & (DM_SAME_CPU_CRYPT_SUPPORTED|DM_SUBMIT_FROM_CRYPT_CPUS_SUPPORTED)))
|
||||
log_err(cd, _("Requested dm-crypt performance options are not supported."));
|
||||
|
||||
if (r == -EINVAL &&
|
||||
dmd->flags & (CRYPT_ACTIVATE_NO_READ_WORKQUEUE | CRYPT_ACTIVATE_NO_WRITE_WORKQUEUE) &&
|
||||
!(dmt_flags & DM_CRYPT_NO_WORKQUEUE_SUPPORTED))
|
||||
log_err(cd, _("Requested dm-crypt performance options are not supported."));
|
||||
|
||||
if (r == -EINVAL && dmd->flags & (CRYPT_ACTIVATE_IGNORE_CORRUPTION|
|
||||
CRYPT_ACTIVATE_RESTART_ON_CORRUPTION|
|
||||
CRYPT_ACTIVATE_IGNORE_ZERO_BLOCKS|
|
||||
@@ -1618,6 +1702,10 @@ int dm_create_device(struct crypt_device *cd, const char *name,
|
||||
!(dmt_flags & DM_VERITY_ON_CORRUPTION_SUPPORTED))
|
||||
log_err(cd, _("Requested dm-verity data corruption handling options are not supported."));
|
||||
|
||||
if (r == -EINVAL && dmd->flags & CRYPT_ACTIVATE_PANIC_ON_CORRUPTION &&
|
||||
!(dmt_flags & DM_VERITY_PANIC_CORRUPTION_SUPPORTED))
|
||||
log_err(cd, _("Requested dm-verity data corruption handling options are not supported."));
|
||||
|
||||
if (r == -EINVAL && dmd->segment.type == DM_VERITY &&
|
||||
dmd->segment.u.verity.fec_device && !(dmt_flags & DM_VERITY_FEC_SUPPORTED))
|
||||
log_err(cd, _("Requested dm-verity FEC options are not supported."));
|
||||
@@ -1633,6 +1721,14 @@ int dm_create_device(struct crypt_device *cd, const char *name,
|
||||
!(dmt_flags & DM_INTEGRITY_RECALC_SUPPORTED))
|
||||
log_err(cd, _("Requested automatic recalculation of integrity tags is not supported."));
|
||||
|
||||
if (r == -EINVAL && dmd->segment.type == DM_INTEGRITY && (dmd->flags & CRYPT_ACTIVATE_RECALCULATE_RESET) &&
|
||||
!(dmt_flags & DM_INTEGRITY_RESET_RECALC_SUPPORTED))
|
||||
log_err(cd, _("Requested automatic recalculation of integrity tags is not supported."));
|
||||
|
||||
if (r == -EINVAL && dmd->segment.type == DM_INTEGRITY && (dmd->flags & CRYPT_ACTIVATE_ALLOW_DISCARDS) &&
|
||||
!(dmt_flags & DM_INTEGRITY_DISCARDS_SUPPORTED))
|
||||
log_err(cd, _("Discard/TRIM is not supported."));
|
||||
|
||||
if (r == -EINVAL && dmd->segment.type == DM_INTEGRITY && (dmd->flags & CRYPT_ACTIVATE_NO_JOURNAL_BITMAP) &&
|
||||
!(dmt_flags & DM_INTEGRITY_BITMAP_SUPPORTED))
|
||||
log_err(cd, _("Requested dm-integrity bitmap mode is not supported."));
|
||||
@@ -1660,11 +1756,17 @@ int dm_reload_device(struct crypt_device *cd, const char *name,
|
||||
|
||||
if (r == -EINVAL && (dmd->segment.type == DM_CRYPT || dmd->segment.type == DM_LINEAR)) {
|
||||
if ((dmd->flags & (CRYPT_ACTIVATE_SAME_CPU_CRYPT|CRYPT_ACTIVATE_SUBMIT_FROM_CRYPT_CPUS)) &&
|
||||
!dm_flags(cd, DM_CRYPT, &dmt_flags) && !(dmt_flags & (DM_SAME_CPU_CRYPT_SUPPORTED|DM_SUBMIT_FROM_CRYPT_CPUS_SUPPORTED)))
|
||||
!dm_flags(cd, DM_CRYPT, &dmt_flags) && !(dmt_flags & (DM_SAME_CPU_CRYPT_SUPPORTED | DM_SUBMIT_FROM_CRYPT_CPUS_SUPPORTED)))
|
||||
log_err(cd, _("Requested dm-crypt performance options are not supported."));
|
||||
if ((dmd->flags & (CRYPT_ACTIVATE_NO_READ_WORKQUEUE | CRYPT_ACTIVATE_NO_WRITE_WORKQUEUE)) &&
|
||||
!dm_flags(cd, DM_CRYPT, &dmt_flags) && !(dmt_flags & DM_CRYPT_NO_WORKQUEUE_SUPPORTED))
|
||||
log_err(cd, _("Requested dm-crypt performance options are not supported."));
|
||||
if ((dmd->flags & CRYPT_ACTIVATE_ALLOW_DISCARDS) &&
|
||||
!dm_flags(cd, DM_CRYPT, &dmt_flags) && !(dmt_flags & DM_DISCARDS_SUPPORTED))
|
||||
log_err(cd, _("Discard/TRIM is not supported."));
|
||||
if ((dmd->flags & CRYPT_ACTIVATE_ALLOW_DISCARDS) &&
|
||||
!dm_flags(cd, DM_INTEGRITY, &dmt_flags) && !(dmt_flags & DM_INTEGRITY_DISCARDS_SUPPORTED))
|
||||
log_err(cd, _("Discard/TRIM is not supported."));
|
||||
}
|
||||
|
||||
if (!r && resume)
|
||||
@@ -1683,7 +1785,7 @@ static int dm_status_dmi(const char *name, struct dm_info *dmi,
|
||||
int r = -EINVAL;
|
||||
|
||||
if (!(dmt = dm_task_create(DM_DEVICE_STATUS)))
|
||||
goto out;
|
||||
return r;
|
||||
|
||||
if (!dm_task_no_flush(dmt))
|
||||
goto out;
|
||||
@@ -1702,6 +1804,7 @@ static int dm_status_dmi(const char *name, struct dm_info *dmi,
|
||||
goto out;
|
||||
}
|
||||
|
||||
r = -EEXIST;
|
||||
dm_get_next_target(dmt, NULL, &start, &length,
|
||||
&target_type, ¶ms);
|
||||
|
||||
@@ -1724,8 +1827,7 @@ out:
|
||||
if (!r && status_line && !(*status_line = strdup(params)))
|
||||
r = -ENOMEM;
|
||||
|
||||
if (dmt)
|
||||
dm_task_destroy(dmt);
|
||||
dm_task_destroy(dmt);
|
||||
|
||||
return r;
|
||||
}
|
||||
@@ -1900,6 +2002,12 @@ static int _dm_target_query_crypt(struct crypt_device *cd, uint32_t get_flags,
|
||||
*act_flags |= CRYPT_ACTIVATE_SAME_CPU_CRYPT;
|
||||
else if (!strcasecmp(arg, "submit_from_crypt_cpus"))
|
||||
*act_flags |= CRYPT_ACTIVATE_SUBMIT_FROM_CRYPT_CPUS;
|
||||
else if (!strcasecmp(arg, "no_read_workqueue"))
|
||||
*act_flags |= CRYPT_ACTIVATE_NO_READ_WORKQUEUE;
|
||||
else if (!strcasecmp(arg, "no_write_workqueue"))
|
||||
*act_flags |= CRYPT_ACTIVATE_NO_WRITE_WORKQUEUE;
|
||||
else if (!strcasecmp(arg, "iv_large_sectors"))
|
||||
*act_flags |= CRYPT_ACTIVATE_IV_LARGE_SECTORS;
|
||||
else if (sscanf(arg, "integrity:%u:", &val) == 1) {
|
||||
tgt->u.crypt.tag_size = val;
|
||||
rintegrity = strchr(arg + strlen("integrity:"), ':');
|
||||
@@ -2148,6 +2256,8 @@ static int _dm_target_query_verity(struct crypt_device *cd,
|
||||
*act_flags |= CRYPT_ACTIVATE_IGNORE_CORRUPTION;
|
||||
else if (!strcasecmp(arg, "restart_on_corruption"))
|
||||
*act_flags |= CRYPT_ACTIVATE_RESTART_ON_CORRUPTION;
|
||||
else if (!strcasecmp(arg, "panic_on_corruption"))
|
||||
*act_flags |= CRYPT_ACTIVATE_PANIC_ON_CORRUPTION;
|
||||
else if (!strcasecmp(arg, "ignore_zero_blocks"))
|
||||
*act_flags |= CRYPT_ACTIVATE_IGNORE_ZERO_BLOCKS;
|
||||
else if (!strcasecmp(arg, "check_at_most_once"))
|
||||
@@ -2193,11 +2303,16 @@ static int _dm_target_query_verity(struct crypt_device *cd,
|
||||
str = strsep(¶ms, " ");
|
||||
if (!str)
|
||||
goto err;
|
||||
if (!root_hash_sig_key_desc)
|
||||
if (vp && !root_hash_sig_key_desc) {
|
||||
root_hash_sig_key_desc = strdup(str);
|
||||
i++;
|
||||
if (vp)
|
||||
if (!root_hash_sig_key_desc) {
|
||||
r = -ENOMEM;
|
||||
goto err;
|
||||
}
|
||||
/* not stored in params, but cannot be used without vp */
|
||||
vp->flags |= CRYPT_VERITY_ROOT_HASH_SIGNATURE;
|
||||
}
|
||||
i++;
|
||||
} else /* unknown option */
|
||||
goto err;
|
||||
}
|
||||
@@ -2396,8 +2511,16 @@ static int _dm_target_query_integrity(struct crypt_device *cd,
|
||||
}
|
||||
} else if (!strcmp(arg, "recalculate")) {
|
||||
*act_flags |= CRYPT_ACTIVATE_RECALCULATE;
|
||||
} else if (!strcmp(arg, "reset_recalculate")) {
|
||||
*act_flags |= CRYPT_ACTIVATE_RECALCULATE_RESET;
|
||||
} else if (!strcmp(arg, "fix_padding")) {
|
||||
tgt->u.integrity.fix_padding = true;
|
||||
} else if (!strcmp(arg, "fix_hmac")) {
|
||||
tgt->u.integrity.fix_hmac = true;
|
||||
} else if (!strcmp(arg, "legacy_recalculate")) {
|
||||
tgt->u.integrity.legacy_recalc = true;
|
||||
} else if (!strcmp(arg, "allow_discards")) {
|
||||
*act_flags |= CRYPT_ACTIVATE_ALLOW_DISCARDS;
|
||||
} else /* unknown option */
|
||||
goto err;
|
||||
}
|
||||
@@ -2472,7 +2595,7 @@ err:
|
||||
return r;
|
||||
}
|
||||
|
||||
static int _dm_target_query_error(struct crypt_device *cd, struct dm_target *tgt)
|
||||
static int _dm_target_query_error(struct crypt_device *cd __attribute__((unused)), struct dm_target *tgt)
|
||||
{
|
||||
tgt->type = DM_ERROR;
|
||||
tgt->direction = TARGET_QUERY;
|
||||
@@ -2480,7 +2603,7 @@ static int _dm_target_query_error(struct crypt_device *cd, struct dm_target *tgt
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int _dm_target_query_zero(struct crypt_device *cd, struct dm_target *tgt)
|
||||
static int _dm_target_query_zero(struct crypt_device *cd __attribute__((unused)), struct dm_target *tgt)
|
||||
{
|
||||
tgt->type = DM_ZERO;
|
||||
tgt->direction = TARGET_QUERY;
|
||||
@@ -2613,8 +2736,7 @@ static int _dm_query_device(struct crypt_device *cd, const char *name,
|
||||
|
||||
r = (dmi.open_count > 0);
|
||||
out:
|
||||
if (dmt)
|
||||
dm_task_destroy(dmt);
|
||||
dm_task_destroy(dmt);
|
||||
|
||||
if (r < 0)
|
||||
dm_targets_free(cd, dmd);
|
||||
@@ -2643,6 +2765,7 @@ int dm_query_device(struct crypt_device *cd, const char *name,
|
||||
|
||||
static int _process_deps(struct crypt_device *cd, const char *prefix, struct dm_deps *deps, char **names, size_t names_offset, size_t names_length)
|
||||
{
|
||||
#if HAVE_DECL_DM_DEVICE_GET_NAME
|
||||
struct crypt_dm_active_device dmd;
|
||||
char dmname[PATH_MAX];
|
||||
unsigned i;
|
||||
@@ -2681,6 +2804,9 @@ static int _process_deps(struct crypt_device *cd, const char *prefix, struct dm_
|
||||
}
|
||||
|
||||
return count;
|
||||
#else
|
||||
return -EINVAL;
|
||||
#endif
|
||||
}
|
||||
|
||||
int dm_device_deps(struct crypt_device *cd, const char *name, const char *prefix, char **names, size_t names_length)
|
||||
@@ -2831,7 +2957,9 @@ int dm_resume_and_reinstate_key(struct crypt_device *cd, const char *name,
|
||||
if (!(dmt_flags & DM_KEY_WIPE_SUPPORTED))
|
||||
goto out;
|
||||
|
||||
if (vk->key_description)
|
||||
if (!vk->keylength)
|
||||
msg_size = 11; // key set -
|
||||
else if (vk->key_description)
|
||||
msg_size = strlen(vk->key_description) + int_log10(vk->keylength) + 18;
|
||||
else
|
||||
msg_size = vk->keylength * 2 + 10; // key set <key>
|
||||
@@ -2843,7 +2971,9 @@ int dm_resume_and_reinstate_key(struct crypt_device *cd, const char *name,
|
||||
}
|
||||
|
||||
strcpy(msg, "key set ");
|
||||
if (vk->key_description)
|
||||
if (!vk->keylength)
|
||||
snprintf(msg + 8, msg_size - 8, "-");
|
||||
else if (vk->key_description)
|
||||
snprintf(msg + 8, msg_size - 8, ":%zu:logon:%s", vk->keylength, vk->key_description);
|
||||
else
|
||||
hex_key(&msg[8], vk->keylength, vk->key);
|
||||
@@ -2860,6 +2990,11 @@ out:
|
||||
return r;
|
||||
}
|
||||
|
||||
int dm_cancel_deferred_removal(const char *name)
|
||||
{
|
||||
return _dm_message(name, "@cancel_deferred_remove") ? 0 : -ENOTSUP;
|
||||
}
|
||||
|
||||
const char *dm_get_dir(void)
|
||||
{
|
||||
return dm_dir();
|
||||
@@ -2880,18 +3015,13 @@ int dm_crypt_target_set(struct dm_target *tgt, uint64_t seg_offset, uint64_t seg
|
||||
uint64_t iv_offset, uint64_t data_offset, const char *integrity, uint32_t tag_size,
|
||||
uint32_t sector_size)
|
||||
{
|
||||
int r = -EINVAL;
|
||||
|
||||
/* free on error */
|
||||
char *dm_integrity = NULL;
|
||||
|
||||
if (tag_size) {
|
||||
/* Space for IV metadata only */
|
||||
dm_integrity = strdup(integrity ?: "none");
|
||||
if (!dm_integrity) {
|
||||
r = -ENOMEM;
|
||||
goto err;
|
||||
}
|
||||
if (!dm_integrity)
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
tgt->data_device = data_device;
|
||||
@@ -2910,16 +3040,12 @@ int dm_crypt_target_set(struct dm_target *tgt, uint64_t seg_offset, uint64_t seg
|
||||
tgt->u.crypt.sector_size = sector_size;
|
||||
|
||||
return 0;
|
||||
err:
|
||||
free(dm_integrity);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
int dm_verity_target_set(struct dm_target *tgt, uint64_t seg_offset, uint64_t seg_size,
|
||||
struct device *data_device, struct device *hash_device, struct device *fec_device,
|
||||
const char *root_hash, uint32_t root_hash_size, const char *root_hash_sig_key_desc,
|
||||
uint64_t hash_offset_block, uint64_t hash_blocks, struct crypt_params_verity *vp)
|
||||
const char *root_hash, uint32_t root_hash_size, const char* root_hash_sig_key_desc,
|
||||
uint64_t hash_offset_block, uint64_t fec_blocks, struct crypt_params_verity *vp)
|
||||
{
|
||||
if (!data_device || !hash_device || !vp)
|
||||
return -EINVAL;
|
||||
@@ -2937,7 +3063,7 @@ int dm_verity_target_set(struct dm_target *tgt, uint64_t seg_offset, uint64_t se
|
||||
tgt->u.verity.root_hash_sig_key_desc = root_hash_sig_key_desc;
|
||||
tgt->u.verity.hash_offset = hash_offset_block;
|
||||
tgt->u.verity.fec_offset = vp->fec_area_offset / vp->hash_block_size;
|
||||
tgt->u.verity.hash_blocks = hash_blocks;
|
||||
tgt->u.verity.fec_blocks = fec_blocks;
|
||||
tgt->u.verity.vp = vp;
|
||||
|
||||
return 0;
|
||||
@@ -2978,6 +3104,15 @@ int dm_integrity_target_set(struct crypt_device *cd,
|
||||
!(crypt_get_compatibility(cd) & CRYPT_COMPAT_LEGACY_INTEGRITY_PADDING))
|
||||
tgt->u.integrity.fix_padding = true;
|
||||
|
||||
if (!dm_flags(cd, DM_INTEGRITY, &dmi_flags) &&
|
||||
(dmi_flags & DM_INTEGRITY_FIX_HMAC_SUPPORTED) &&
|
||||
!(crypt_get_compatibility(cd) & CRYPT_COMPAT_LEGACY_INTEGRITY_HMAC))
|
||||
tgt->u.integrity.fix_hmac = true;
|
||||
|
||||
/* This flag can be backported, just try to set it always */
|
||||
if (crypt_get_compatibility(cd) & CRYPT_COMPAT_LEGACY_INTEGRITY_RECALC)
|
||||
tgt->u.integrity.legacy_recalc = true;
|
||||
|
||||
if (ip) {
|
||||
tgt->u.integrity.journal_size = ip->journal_size;
|
||||
tgt->u.integrity.journal_watermark = ip->journal_watermark;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/*
|
||||
* loop-AES compatible volume handling
|
||||
*
|
||||
* Copyright (C) 2011-2020 Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2011-2020 Milan Broz
|
||||
* Copyright (C) 2011-2021 Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2011-2021 Milan Broz
|
||||
*
|
||||
* This file is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
@@ -81,7 +81,7 @@ static int hash_keys(struct crypt_device *cd,
|
||||
const char *hash_name;
|
||||
char tweak, *key_ptr;
|
||||
unsigned int i;
|
||||
int r;
|
||||
int r = 0;
|
||||
|
||||
hash_name = hash_override ?: get_hash(key_len_output);
|
||||
tweak = get_tweak(keys_count);
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/*
|
||||
* loop-AES compatible volume handling
|
||||
*
|
||||
* Copyright (C) 2011-2020 Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2011-2020 Milan Broz
|
||||
* Copyright (C) 2011-2021 Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2011-2021 Milan Broz
|
||||
*
|
||||
* This file is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
@@ -23,7 +23,7 @@
|
||||
#define _LOOPAES_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <unistd.h>
|
||||
#include <stddef.h>
|
||||
|
||||
struct crypt_device;
|
||||
struct volume_key;
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* AFsplitter - Anti forensic information splitter
|
||||
*
|
||||
* Copyright (C) 2004 Clemens Fruhwirth <clemens@endorphin.org>
|
||||
* Copyright (C) 2009-2020 Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2009-2021 Red Hat, Inc. All rights reserved.
|
||||
*
|
||||
* AFsplitter diffuses information over a large stripe of data,
|
||||
* therefore supporting secure data destruction.
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* AFsplitter - Anti forensic information splitter
|
||||
*
|
||||
* Copyright (C) 2004 Clemens Fruhwirth <clemens@endorphin.org>
|
||||
* Copyright (C) 2009-2020 Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2009-2021 Red Hat, Inc. All rights reserved.
|
||||
*
|
||||
* AFsplitter diffuses information over a large stripe of data,
|
||||
* therefore supporting secure data destruction.
|
||||
@@ -26,6 +26,9 @@
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
struct crypt_device;
|
||||
struct volume_key;
|
||||
|
||||
/*
|
||||
* AF_split operates on src and produces information split data in
|
||||
* dst. src is assumed to be of the length blocksize. The data stripe
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
* LUKS - Linux Unified Key Setup
|
||||
*
|
||||
* Copyright (C) 2004-2006 Clemens Fruhwirth <clemens@endorphin.org>
|
||||
* Copyright (C) 2009-2020 Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2012-2020 Milan Broz
|
||||
* Copyright (C) 2009-2021 Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2012-2021 Milan Broz
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
@@ -22,7 +22,6 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <sys/stat.h>
|
||||
#include "luks.h"
|
||||
@@ -154,7 +153,7 @@ int LUKS_encrypt_to_storage(char *src, size_t srcLength,
|
||||
return -EINVAL;
|
||||
|
||||
/* Encrypt buffer */
|
||||
r = crypt_storage_init(&s, SECTOR_SIZE, cipher, cipher_mode, vk->key, vk->keylength);
|
||||
r = crypt_storage_init(&s, SECTOR_SIZE, cipher, cipher_mode, vk->key, vk->keylength, false);
|
||||
|
||||
if (r)
|
||||
log_dbg(ctx, "Userspace crypto wrapper cannot use %s-%s (%d).",
|
||||
@@ -219,7 +218,7 @@ int LUKS_decrypt_from_storage(char *dst, size_t dstLength,
|
||||
if (MISALIGNED_512(dstLength))
|
||||
return -EINVAL;
|
||||
|
||||
r = crypt_storage_init(&s, SECTOR_SIZE, cipher, cipher_mode, vk->key, vk->keylength);
|
||||
r = crypt_storage_init(&s, SECTOR_SIZE, cipher, cipher_mode, vk->key, vk->keylength, false);
|
||||
|
||||
if (r)
|
||||
log_dbg(ctx, "Userspace crypto wrapper cannot use %s-%s (%d).",
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
* LUKS - Linux Unified Key Setup
|
||||
*
|
||||
* Copyright (C) 2004-2006 Clemens Fruhwirth <clemens@endorphin.org>
|
||||
* Copyright (C) 2009-2020 Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2013-2020 Milan Broz
|
||||
* Copyright (C) 2009-2021 Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2013-2021 Milan Broz
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
@@ -22,8 +22,6 @@
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <netinet/in.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
@@ -376,8 +374,13 @@ static int _keyslot_repair(struct luks_phdr *phdr, struct crypt_device *ctx)
|
||||
log_err(ctx, _("Non standard key size, manual repair required."));
|
||||
return -EINVAL;
|
||||
}
|
||||
/* cryptsetup 1.0 did not align to 4k, cannot repair this one */
|
||||
if (LUKS_keyslots_offset(phdr) < (LUKS_ALIGN_KEYSLOTS / SECTOR_SIZE)) {
|
||||
|
||||
/*
|
||||
* cryptsetup 1.0 did not align keyslots to 4k, cannot repair this one
|
||||
* Also we cannot trust possibly broken keyslots metadata here through LUKS_keyslots_offset().
|
||||
* Expect first keyslot is aligned, if not, then manual repair is neccessary.
|
||||
*/
|
||||
if (phdr->keyblock[0].keyMaterialOffset < (LUKS_ALIGN_KEYSLOTS / SECTOR_SIZE)) {
|
||||
log_err(ctx, _("Non standard keyslots alignment, manual repair required."));
|
||||
return -EINVAL;
|
||||
}
|
||||
@@ -387,6 +390,8 @@ static int _keyslot_repair(struct luks_phdr *phdr, struct crypt_device *ctx)
|
||||
return -EINVAL;
|
||||
|
||||
vk = crypt_alloc_volume_key(phdr->keyBytes, NULL);
|
||||
if (!vk)
|
||||
return -ENOMEM;
|
||||
|
||||
log_verbose(ctx, _("Repairing keyslots."));
|
||||
|
||||
@@ -467,12 +472,13 @@ static int _check_and_convert_hdr(const char *device,
|
||||
unsigned int i;
|
||||
char luksMagic[] = LUKS_MAGIC;
|
||||
|
||||
if(memcmp(hdr->magic, luksMagic, LUKS_MAGIC_L)) { /* Check magic */
|
||||
hdr->version = be16_to_cpu(hdr->version);
|
||||
if (memcmp(hdr->magic, luksMagic, LUKS_MAGIC_L)) { /* Check magic */
|
||||
log_dbg(ctx, "LUKS header not detected.");
|
||||
if (require_luks_device)
|
||||
log_err(ctx, _("Device %s is not a valid LUKS device."), device);
|
||||
return -EINVAL;
|
||||
} else if((hdr->version = ntohs(hdr->version)) != 1) { /* Convert every uint16/32_t item from network byte order */
|
||||
} else if (hdr->version != 1) {
|
||||
log_err(ctx, _("Unsupported LUKS version %d."), hdr->version);
|
||||
return -EINVAL;
|
||||
}
|
||||
@@ -484,15 +490,15 @@ static int _check_and_convert_hdr(const char *device,
|
||||
}
|
||||
|
||||
/* Header detected */
|
||||
hdr->payloadOffset = ntohl(hdr->payloadOffset);
|
||||
hdr->keyBytes = ntohl(hdr->keyBytes);
|
||||
hdr->mkDigestIterations = ntohl(hdr->mkDigestIterations);
|
||||
hdr->payloadOffset = be32_to_cpu(hdr->payloadOffset);
|
||||
hdr->keyBytes = be32_to_cpu(hdr->keyBytes);
|
||||
hdr->mkDigestIterations = be32_to_cpu(hdr->mkDigestIterations);
|
||||
|
||||
for(i = 0; i < LUKS_NUMKEYS; ++i) {
|
||||
hdr->keyblock[i].active = ntohl(hdr->keyblock[i].active);
|
||||
hdr->keyblock[i].passwordIterations = ntohl(hdr->keyblock[i].passwordIterations);
|
||||
hdr->keyblock[i].keyMaterialOffset = ntohl(hdr->keyblock[i].keyMaterialOffset);
|
||||
hdr->keyblock[i].stripes = ntohl(hdr->keyblock[i].stripes);
|
||||
for (i = 0; i < LUKS_NUMKEYS; ++i) {
|
||||
hdr->keyblock[i].active = be32_to_cpu(hdr->keyblock[i].active);
|
||||
hdr->keyblock[i].passwordIterations = be32_to_cpu(hdr->keyblock[i].passwordIterations);
|
||||
hdr->keyblock[i].keyMaterialOffset = be32_to_cpu(hdr->keyblock[i].keyMaterialOffset);
|
||||
hdr->keyblock[i].stripes = be32_to_cpu(hdr->keyblock[i].stripes);
|
||||
}
|
||||
|
||||
if (LUKS_check_keyslots(ctx, hdr))
|
||||
@@ -644,15 +650,15 @@ int LUKS_write_phdr(struct luks_phdr *hdr,
|
||||
memset(&convHdr._padding, 0, sizeof(convHdr._padding));
|
||||
|
||||
/* Convert every uint16/32_t item to network byte order */
|
||||
convHdr.version = htons(hdr->version);
|
||||
convHdr.payloadOffset = htonl(hdr->payloadOffset);
|
||||
convHdr.keyBytes = htonl(hdr->keyBytes);
|
||||
convHdr.mkDigestIterations = htonl(hdr->mkDigestIterations);
|
||||
convHdr.version = cpu_to_be16(hdr->version);
|
||||
convHdr.payloadOffset = cpu_to_be32(hdr->payloadOffset);
|
||||
convHdr.keyBytes = cpu_to_be32(hdr->keyBytes);
|
||||
convHdr.mkDigestIterations = cpu_to_be32(hdr->mkDigestIterations);
|
||||
for(i = 0; i < LUKS_NUMKEYS; ++i) {
|
||||
convHdr.keyblock[i].active = htonl(hdr->keyblock[i].active);
|
||||
convHdr.keyblock[i].passwordIterations = htonl(hdr->keyblock[i].passwordIterations);
|
||||
convHdr.keyblock[i].keyMaterialOffset = htonl(hdr->keyblock[i].keyMaterialOffset);
|
||||
convHdr.keyblock[i].stripes = htonl(hdr->keyblock[i].stripes);
|
||||
convHdr.keyblock[i].active = cpu_to_be32(hdr->keyblock[i].active);
|
||||
convHdr.keyblock[i].passwordIterations = cpu_to_be32(hdr->keyblock[i].passwordIterations);
|
||||
convHdr.keyblock[i].keyMaterialOffset = cpu_to_be32(hdr->keyblock[i].keyMaterialOffset);
|
||||
convHdr.keyblock[i].stripes = cpu_to_be32(hdr->keyblock[i].stripes);
|
||||
}
|
||||
|
||||
r = write_lseek_blockwise(devfd, device_block_size(ctx, device), device_alignment(device),
|
||||
@@ -794,7 +800,7 @@ int LUKS_generate_phdr(struct luks_phdr *header,
|
||||
|
||||
if (PBKDF2_temp > (double)UINT32_MAX)
|
||||
return -EINVAL;
|
||||
header->mkDigestIterations = at_least((uint32_t)PBKDF2_temp, LUKS_MKD_ITERATIONS_MIN);
|
||||
header->mkDigestIterations = AT_LEAST((uint32_t)PBKDF2_temp, LUKS_MKD_ITERATIONS_MIN);
|
||||
assert(header->mkDigestIterations);
|
||||
|
||||
r = crypt_pbkdf(CRYPT_KDF_PBKDF2, header->hashSpec, vk->key,vk->keylength,
|
||||
@@ -868,7 +874,7 @@ int LUKS_set_key(unsigned int keyIndex,
|
||||
* Final iteration count is at least LUKS_SLOT_ITERATIONS_MIN
|
||||
*/
|
||||
hdr->keyblock[keyIndex].passwordIterations =
|
||||
at_least(pbkdf->iterations, LUKS_SLOT_ITERATIONS_MIN);
|
||||
AT_LEAST(pbkdf->iterations, LUKS_SLOT_ITERATIONS_MIN);
|
||||
log_dbg(ctx, "Key slot %d use %" PRIu32 " password iterations.", keyIndex,
|
||||
hdr->keyblock[keyIndex].passwordIterations);
|
||||
|
||||
@@ -956,12 +962,12 @@ static int LUKS_open_key(unsigned int keyIndex,
|
||||
const char *password,
|
||||
size_t passwordLen,
|
||||
struct luks_phdr *hdr,
|
||||
struct volume_key *vk,
|
||||
struct volume_key **vk,
|
||||
struct crypt_device *ctx)
|
||||
{
|
||||
crypt_keyslot_info ki = LUKS_keyslot_info(hdr, keyIndex);
|
||||
struct volume_key *derived_key;
|
||||
char *AfKey;
|
||||
char *AfKey = NULL;
|
||||
size_t AFEKSize;
|
||||
int r;
|
||||
|
||||
@@ -975,8 +981,13 @@ static int LUKS_open_key(unsigned int keyIndex,
|
||||
if (!derived_key)
|
||||
return -ENOMEM;
|
||||
|
||||
assert(vk->keylength == hdr->keyBytes);
|
||||
AFEKSize = AF_split_sectors(vk->keylength, hdr->keyblock[keyIndex].stripes) * SECTOR_SIZE;
|
||||
*vk = crypt_alloc_volume_key(hdr->keyBytes, NULL);
|
||||
if (!*vk) {
|
||||
r = -ENOMEM;
|
||||
goto out;
|
||||
}
|
||||
|
||||
AFEKSize = AF_split_sectors(hdr->keyBytes, hdr->keyblock[keyIndex].stripes) * SECTOR_SIZE;
|
||||
AfKey = crypt_safe_alloc(AFEKSize);
|
||||
if (!AfKey) {
|
||||
r = -ENOMEM;
|
||||
@@ -987,8 +998,10 @@ static int LUKS_open_key(unsigned int keyIndex,
|
||||
hdr->keyblock[keyIndex].passwordSalt, LUKS_SALTSIZE,
|
||||
derived_key->key, hdr->keyBytes,
|
||||
hdr->keyblock[keyIndex].passwordIterations, 0, 0);
|
||||
if (r < 0)
|
||||
if (r < 0) {
|
||||
log_err(ctx, _("Cannot open keyslot (using hash %s)."), hdr->hashSpec);
|
||||
goto out;
|
||||
}
|
||||
|
||||
log_dbg(ctx, "Reading key slot %d area.", keyIndex);
|
||||
r = LUKS_decrypt_from_storage(AfKey,
|
||||
@@ -1000,16 +1013,20 @@ static int LUKS_open_key(unsigned int keyIndex,
|
||||
if (r < 0)
|
||||
goto out;
|
||||
|
||||
r = AF_merge(ctx, AfKey, vk->key, vk->keylength, hdr->keyblock[keyIndex].stripes, hdr->hashSpec);
|
||||
r = AF_merge(ctx, AfKey, (*vk)->key, (*vk)->keylength, hdr->keyblock[keyIndex].stripes, hdr->hashSpec);
|
||||
if (r < 0)
|
||||
goto out;
|
||||
|
||||
r = LUKS_verify_volume_key(hdr, vk);
|
||||
r = LUKS_verify_volume_key(hdr, *vk);
|
||||
|
||||
/* Allow only empty passphrase with null cipher */
|
||||
if (!r && !strcmp(hdr->cipherName, "cipher_null") && passwordLen)
|
||||
if (!r && crypt_is_cipher_null(hdr->cipherName) && passwordLen)
|
||||
r = -EPERM;
|
||||
out:
|
||||
if (r < 0) {
|
||||
crypt_free_volume_key(*vk);
|
||||
*vk = NULL;
|
||||
}
|
||||
crypt_safe_free(AfKey);
|
||||
crypt_free_volume_key(derived_key);
|
||||
return r;
|
||||
@@ -1025,16 +1042,14 @@ int LUKS_open_key_with_hdr(int keyIndex,
|
||||
unsigned int i, tried = 0;
|
||||
int r;
|
||||
|
||||
*vk = crypt_alloc_volume_key(hdr->keyBytes, NULL);
|
||||
|
||||
if (keyIndex >= 0) {
|
||||
r = LUKS_open_key(keyIndex, password, passwordLen, hdr, *vk, ctx);
|
||||
r = LUKS_open_key(keyIndex, password, passwordLen, hdr, vk, ctx);
|
||||
return (r < 0) ? r : keyIndex;
|
||||
}
|
||||
|
||||
for (i = 0; i < LUKS_NUMKEYS; i++) {
|
||||
r = LUKS_open_key(i, password, passwordLen, hdr, *vk, ctx);
|
||||
if(r == 0)
|
||||
r = LUKS_open_key(i, password, passwordLen, hdr, vk, ctx);
|
||||
if (r == 0)
|
||||
return i;
|
||||
|
||||
/* Do not retry for errors that are no -EPERM or -ENOENT,
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* LUKS - Linux Unified Key Setup
|
||||
*
|
||||
* Copyright (C) 2004-2006 Clemens Fruhwirth <clemens@endorphin.org>
|
||||
* Copyright (C) 2009-2020 Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2009-2021 Red Hat, Inc. All rights reserved.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/*
|
||||
* LUKS - Linux Unified Key Setup v2
|
||||
*
|
||||
* Copyright (C) 2015-2020 Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2015-2020 Milan Broz
|
||||
* Copyright (C) 2015-2021 Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2015-2021 Milan Broz
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
@@ -23,6 +23,8 @@
|
||||
#define _CRYPTSETUP_LUKS2_ONDISK_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "libcryptsetup.h"
|
||||
|
||||
@@ -42,6 +44,8 @@
|
||||
#define LUKS2_BUILTIN_TOKEN_PREFIX "luks2-"
|
||||
#define LUKS2_BUILTIN_TOKEN_PREFIX_LEN 6
|
||||
|
||||
#define LUKS2_TOKEN_NAME_MAX 64
|
||||
|
||||
#define LUKS2_TOKEN_KEYRING LUKS2_BUILTIN_TOKEN_PREFIX "keyring"
|
||||
|
||||
#define LUKS2_DIGEST_MAX 8
|
||||
@@ -59,6 +63,10 @@
|
||||
#define LUKS2_REENCRYPT_MAX_HOTZONE_LENGTH 0x40000000
|
||||
|
||||
struct device;
|
||||
struct luks2_reencrypt;
|
||||
struct crypt_lock_handle;
|
||||
struct crypt_dm_active_device;
|
||||
struct luks_phdr; /* LUKS1 for conversion */
|
||||
|
||||
/*
|
||||
* LUKS2 header on-disk.
|
||||
@@ -94,7 +102,6 @@ struct luks2_hdr_disk {
|
||||
/*
|
||||
* LUKS2 header in-memory.
|
||||
*/
|
||||
typedef struct json_object json_object;
|
||||
struct luks2_hdr {
|
||||
size_t hdr_size;
|
||||
uint64_t seqid;
|
||||
@@ -105,7 +112,7 @@ struct luks2_hdr {
|
||||
uint8_t salt1[LUKS2_SALT_L];
|
||||
uint8_t salt2[LUKS2_SALT_L];
|
||||
char uuid[LUKS2_UUID_L];
|
||||
json_object *jobj;
|
||||
void *jobj;
|
||||
};
|
||||
|
||||
struct luks2_keyslot_params {
|
||||
@@ -127,77 +134,6 @@ struct luks2_keyslot_params {
|
||||
} area;
|
||||
};
|
||||
|
||||
struct reenc_protection {
|
||||
enum { REENC_PROTECTION_NONE = 0, /* none should be 0 always */
|
||||
REENC_PROTECTION_CHECKSUM,
|
||||
REENC_PROTECTION_JOURNAL,
|
||||
REENC_PROTECTION_DATASHIFT } type;
|
||||
|
||||
union {
|
||||
struct {
|
||||
} none;
|
||||
struct {
|
||||
char hash[LUKS2_CHECKSUM_ALG_L]; // or include luks.h
|
||||
struct crypt_hash *ch;
|
||||
size_t hash_size;
|
||||
/* buffer for checksums */
|
||||
void *checksums;
|
||||
size_t checksums_len;
|
||||
} csum;
|
||||
struct {
|
||||
} ds;
|
||||
} p;
|
||||
};
|
||||
|
||||
struct luks2_reenc_context {
|
||||
/* reencryption window attributes */
|
||||
uint64_t offset;
|
||||
uint64_t progress;
|
||||
uint64_t length;
|
||||
uint64_t data_shift;
|
||||
size_t alignment;
|
||||
uint64_t device_size;
|
||||
bool online;
|
||||
bool fixed_length;
|
||||
crypt_reencrypt_direction_info direction;
|
||||
crypt_reencrypt_mode_info mode;
|
||||
|
||||
char *device_name;
|
||||
char *hotzone_name;
|
||||
char *overlay_name;
|
||||
uint32_t flags;
|
||||
|
||||
/* reencryption window persistence attributes */
|
||||
struct reenc_protection rp;
|
||||
|
||||
int reenc_keyslot;
|
||||
|
||||
/* already running reencryption */
|
||||
json_object *jobj_segs_hot;
|
||||
json_object *jobj_segs_post;
|
||||
|
||||
/* backup segments */
|
||||
json_object *jobj_segment_new;
|
||||
int digest_new;
|
||||
json_object *jobj_segment_old;
|
||||
int digest_old;
|
||||
json_object *jobj_segment_moved;
|
||||
|
||||
struct volume_key *vks;
|
||||
|
||||
void *reenc_buffer;
|
||||
ssize_t read;
|
||||
|
||||
struct crypt_storage_wrapper *cw1;
|
||||
struct crypt_storage_wrapper *cw2;
|
||||
|
||||
uint32_t wflags1;
|
||||
uint32_t wflags2;
|
||||
|
||||
struct crypt_lock_handle *reenc_lock;
|
||||
};
|
||||
|
||||
crypt_reencrypt_info LUKS2_reenc_status(struct luks2_hdr *hdr);
|
||||
/*
|
||||
* Supportable header sizes (hdr_disk + JSON area)
|
||||
* Also used as offset for the 2nd header.
|
||||
@@ -220,13 +156,11 @@ crypt_reencrypt_info LUKS2_reenc_status(struct luks2_hdr *hdr);
|
||||
int LUKS2_hdr_version_unlocked(struct crypt_device *cd,
|
||||
const char *backup_file);
|
||||
|
||||
int LUKS2_device_write_lock(struct crypt_device *cd,
|
||||
struct luks2_hdr *hdr, struct device *device);
|
||||
|
||||
int LUKS2_hdr_read(struct crypt_device *cd, struct luks2_hdr *hdr, int repair);
|
||||
int LUKS2_hdr_write(struct crypt_device *cd, struct luks2_hdr *hdr);
|
||||
int LUKS2_hdr_write_force(struct crypt_device *cd, struct luks2_hdr *hdr);
|
||||
int LUKS2_hdr_dump(struct crypt_device *cd, struct luks2_hdr *hdr);
|
||||
int LUKS2_hdr_dump_json(struct crypt_device *cd, struct luks2_hdr *hdr, const char **json);
|
||||
|
||||
int LUKS2_hdr_uuid(struct crypt_device *cd,
|
||||
struct luks2_hdr *hdr,
|
||||
@@ -247,9 +181,9 @@ int LUKS2_hdr_restore(struct crypt_device *cd,
|
||||
struct luks2_hdr *hdr,
|
||||
const char *backup_file);
|
||||
|
||||
uint64_t LUKS2_hdr_and_areas_size(json_object *jobj);
|
||||
uint64_t LUKS2_keyslots_size(json_object *jobj);
|
||||
uint64_t LUKS2_metadata_size(json_object *jobj);
|
||||
uint64_t LUKS2_hdr_and_areas_size(struct luks2_hdr *hdr);
|
||||
uint64_t LUKS2_keyslots_size(struct luks2_hdr *hdr);
|
||||
uint64_t LUKS2_metadata_size(struct luks2_hdr *hdr);
|
||||
|
||||
int LUKS2_keyslot_cipher_incompatible(struct crypt_device *cd, const char *cipher_spec);
|
||||
|
||||
@@ -278,28 +212,11 @@ int LUKS2_keyslot_store(struct crypt_device *cd,
|
||||
const struct volume_key *vk,
|
||||
const struct luks2_keyslot_params *params);
|
||||
|
||||
int LUKS2_keyslot_reencrypt_store(struct crypt_device *cd,
|
||||
struct luks2_hdr *hdr,
|
||||
int keyslot,
|
||||
const void *buffer,
|
||||
size_t buffer_length);
|
||||
|
||||
int LUKS2_keyslot_reencrypt_create(struct crypt_device *cd,
|
||||
struct luks2_hdr *hdr,
|
||||
int keyslot,
|
||||
const struct crypt_params_reencrypt *params);
|
||||
|
||||
int reenc_keyslot_update(struct crypt_device *cd,
|
||||
const struct luks2_reenc_context *rh);
|
||||
|
||||
int LUKS2_keyslot_wipe(struct crypt_device *cd,
|
||||
struct luks2_hdr *hdr,
|
||||
int keyslot,
|
||||
int wipe_area_only);
|
||||
|
||||
int LUKS2_keyslot_dump(struct crypt_device *cd,
|
||||
int keyslot);
|
||||
|
||||
crypt_keyslot_priority LUKS2_keyslot_priority_get(struct crypt_device *cd,
|
||||
struct luks2_hdr *hdr,
|
||||
int keyslot);
|
||||
@@ -310,6 +227,11 @@ int LUKS2_keyslot_priority_set(struct crypt_device *cd,
|
||||
crypt_keyslot_priority priority,
|
||||
int commit);
|
||||
|
||||
int LUKS2_keyslot_swap(struct crypt_device *cd,
|
||||
struct luks2_hdr *hdr,
|
||||
int keyslot,
|
||||
int keyslot2);
|
||||
|
||||
/*
|
||||
* Generic LUKS2 token
|
||||
*/
|
||||
@@ -330,6 +252,12 @@ int LUKS2_token_is_assigned(struct crypt_device *cd,
|
||||
int keyslot,
|
||||
int token);
|
||||
|
||||
int LUKS2_token_assignment_copy(struct crypt_device *cd,
|
||||
struct luks2_hdr *hdr,
|
||||
int keyslot_from,
|
||||
int keyslot_to,
|
||||
int commit);
|
||||
|
||||
int LUKS2_token_create(struct crypt_device *cd,
|
||||
struct luks2_hdr *hdr,
|
||||
int token,
|
||||
@@ -341,89 +269,25 @@ crypt_token_info LUKS2_token_status(struct crypt_device *cd,
|
||||
int token,
|
||||
const char **type);
|
||||
|
||||
int LUKS2_builtin_token_get(struct crypt_device *cd,
|
||||
struct luks2_hdr *hdr,
|
||||
int token,
|
||||
const char *type,
|
||||
void *params);
|
||||
|
||||
int LUKS2_builtin_token_create(struct crypt_device *cd,
|
||||
struct luks2_hdr *hdr,
|
||||
int token,
|
||||
const char *type,
|
||||
const void *params,
|
||||
int commit);
|
||||
|
||||
int LUKS2_token_open_and_activate(struct crypt_device *cd,
|
||||
struct luks2_hdr *hdr,
|
||||
int token,
|
||||
const char *name,
|
||||
uint32_t flags,
|
||||
void *usrptr);
|
||||
|
||||
int LUKS2_token_open_and_activate_any(struct crypt_device *cd,
|
||||
struct luks2_hdr *hdr,
|
||||
int token,
|
||||
const char *name,
|
||||
uint32_t flags);
|
||||
const char *type,
|
||||
const char *pin,
|
||||
size_t pin_size,
|
||||
uint32_t flags,
|
||||
void *usrptr);
|
||||
|
||||
int LUKS2_tokens_count(struct luks2_hdr *hdr);
|
||||
|
||||
/*
|
||||
* Generic LUKS2 segment
|
||||
*/
|
||||
uint64_t json_segment_get_offset(json_object *jobj_segment, unsigned blockwise);
|
||||
const char *json_segment_type(json_object *jobj_segment);
|
||||
uint64_t json_segment_get_iv_offset(json_object *jobj_segment);
|
||||
uint64_t json_segment_get_size(json_object *jobj_segment, unsigned blockwise);
|
||||
const char *json_segment_get_cipher(json_object *jobj_segment);
|
||||
int json_segment_get_sector_size(json_object *jobj_segment);
|
||||
bool json_segment_is_backup(json_object *jobj_segment);
|
||||
json_object *json_segments_get_segment(json_object *jobj_segments, int segment);
|
||||
unsigned json_segments_count(json_object *jobj_segments);
|
||||
void json_segment_remove_flag(json_object *jobj_segment, const char *flag);
|
||||
uint64_t json_segments_get_minimal_offset(json_object *jobj_segments, unsigned blockwise);
|
||||
json_object *json_segment_create_linear(uint64_t offset, const uint64_t *length, unsigned reencryption);
|
||||
json_object *json_segment_create_crypt(uint64_t offset, uint64_t iv_offset, const uint64_t *length, const char *cipher, uint32_t sector_size, unsigned reencryption);
|
||||
int json_segments_segment_in_reencrypt(json_object *jobj_segments);
|
||||
|
||||
int LUKS2_segments_count(struct luks2_hdr *hdr);
|
||||
|
||||
int LUKS2_segment_first_unused_id(struct luks2_hdr *hdr);
|
||||
|
||||
int LUKS2_segment_set_flag(json_object *jobj_segment, const char *flag);
|
||||
|
||||
json_object *LUKS2_get_segment_by_flag(struct luks2_hdr *hdr, const char *flag);
|
||||
|
||||
int LUKS2_get_segment_id_by_flag(struct luks2_hdr *hdr, const char *flag);
|
||||
|
||||
int LUKS2_segments_set(struct crypt_device *cd,
|
||||
int LUKS2_token_keyring_get(struct crypt_device *cd,
|
||||
struct luks2_hdr *hdr,
|
||||
json_object *jobj_segments,
|
||||
int commit);
|
||||
int token,
|
||||
struct crypt_token_params_luks2_keyring *keyring_params);
|
||||
|
||||
uint64_t LUKS2_segment_offset(struct luks2_hdr *hdr,
|
||||
int segment,
|
||||
unsigned blockwise);
|
||||
int LUKS2_token_keyring_json(char *buffer, size_t buffer_size,
|
||||
const struct crypt_token_params_luks2_keyring *keyring_params);
|
||||
|
||||
uint64_t LUKS2_segment_size(struct luks2_hdr *hdr,
|
||||
int segment,
|
||||
unsigned blockwise);
|
||||
|
||||
int LUKS2_segment_is_type(struct luks2_hdr *hdr,
|
||||
int segment,
|
||||
const char *type);
|
||||
|
||||
int LUKS2_segment_by_type(struct luks2_hdr *hdr,
|
||||
const char *type);
|
||||
|
||||
int LUKS2_last_segment_by_type(struct luks2_hdr *hdr,
|
||||
const char *type);
|
||||
|
||||
int LUKS2_get_default_segment(struct luks2_hdr *hdr);
|
||||
|
||||
int LUKS2_reencrypt_digest_new(struct luks2_hdr *hdr);
|
||||
int LUKS2_reencrypt_digest_old(struct luks2_hdr *hdr);
|
||||
int LUKS2_reencrypt_data_offset(struct luks2_hdr *hdr, bool blockwise);
|
||||
void crypt_token_unload_external_all(struct crypt_device *cd);
|
||||
|
||||
/*
|
||||
* Generic LUKS2 digest
|
||||
@@ -432,29 +296,16 @@ int LUKS2_digest_any_matching(struct crypt_device *cd,
|
||||
struct luks2_hdr *hdr,
|
||||
const struct volume_key *vk);
|
||||
|
||||
int LUKS2_digest_by_segment(struct luks2_hdr *hdr, int segment);
|
||||
|
||||
int LUKS2_digest_verify_by_digest(struct crypt_device *cd,
|
||||
struct luks2_hdr *hdr,
|
||||
int digest,
|
||||
const struct volume_key *vk);
|
||||
|
||||
int LUKS2_digest_verify_by_segment(struct crypt_device *cd,
|
||||
struct luks2_hdr *hdr,
|
||||
int segment,
|
||||
const struct volume_key *vk);
|
||||
|
||||
void LUKS2_digests_erase_unused(struct crypt_device *cd,
|
||||
struct luks2_hdr *hdr);
|
||||
|
||||
int LUKS2_digest_verify(struct crypt_device *cd,
|
||||
struct luks2_hdr *hdr,
|
||||
const struct volume_key *vk,
|
||||
int keyslot);
|
||||
|
||||
int LUKS2_digest_dump(struct crypt_device *cd,
|
||||
int digest);
|
||||
|
||||
int LUKS2_digest_assign(struct crypt_device *cd,
|
||||
struct luks2_hdr *hdr,
|
||||
int keyslot,
|
||||
@@ -471,6 +322,8 @@ int LUKS2_digest_segment_assign(struct crypt_device *cd,
|
||||
|
||||
int LUKS2_digest_by_keyslot(struct luks2_hdr *hdr, int keyslot);
|
||||
|
||||
int LUKS2_digest_by_segment(struct luks2_hdr *hdr, int segment);
|
||||
|
||||
int LUKS2_digest_create(struct crypt_device *cd,
|
||||
const char *type,
|
||||
struct luks2_hdr *hdr,
|
||||
@@ -490,20 +343,12 @@ int LUKS2_activate_multi(struct crypt_device *cd,
|
||||
uint64_t device_size,
|
||||
uint32_t flags);
|
||||
|
||||
struct crypt_dm_active_device;
|
||||
|
||||
int LUKS2_deactivate(struct crypt_device *cd,
|
||||
const char *name,
|
||||
struct luks2_hdr *hdr,
|
||||
struct crypt_dm_active_device *dmd,
|
||||
uint32_t flags);
|
||||
|
||||
int LUKS2_reload(struct crypt_device *cd,
|
||||
const char *name,
|
||||
struct volume_key *vks,
|
||||
uint64_t device_size,
|
||||
uint32_t flags);
|
||||
|
||||
int LUKS2_generate_hdr(
|
||||
struct crypt_device *cd,
|
||||
struct luks2_hdr *hdr,
|
||||
@@ -523,7 +368,7 @@ int LUKS2_check_metadata_area_size(uint64_t metadata_size);
|
||||
int LUKS2_check_keyslots_area_size(uint64_t keyslots_size);
|
||||
|
||||
int LUKS2_wipe_header_areas(struct crypt_device *cd,
|
||||
struct luks2_hdr *hdr);
|
||||
struct luks2_hdr *hdr, bool detached_header);
|
||||
|
||||
uint64_t LUKS2_get_data_offset(struct luks2_hdr *hdr);
|
||||
int LUKS2_get_data_size(struct luks2_hdr *hdr, uint64_t *size, bool *dynamic);
|
||||
@@ -535,19 +380,14 @@ int LUKS2_keyslot_params_default(struct crypt_device *cd, struct luks2_hdr *hdr,
|
||||
int LUKS2_get_volume_key_size(struct luks2_hdr *hdr, int segment);
|
||||
int LUKS2_get_keyslot_stored_key_size(struct luks2_hdr *hdr, int keyslot);
|
||||
const char *LUKS2_get_keyslot_cipher(struct luks2_hdr *hdr, int keyslot, size_t *key_size);
|
||||
int LUKS2_keyslot_find_empty(struct luks2_hdr *hdr);
|
||||
int LUKS2_keyslot_find_empty(struct crypt_device *cd, struct luks2_hdr *hdr, size_t keylength);
|
||||
int LUKS2_keyslot_active_count(struct luks2_hdr *hdr, int segment);
|
||||
int LUKS2_keyslot_for_segment(struct luks2_hdr *hdr, int keyslot, int segment);
|
||||
int LUKS2_find_keyslot(struct luks2_hdr *hdr, const char *type);
|
||||
crypt_keyslot_info LUKS2_keyslot_info(struct luks2_hdr *hdr, int keyslot);
|
||||
int LUKS2_keyslot_area(struct luks2_hdr *hdr,
|
||||
int keyslot,
|
||||
uint64_t *offset,
|
||||
uint64_t *length);
|
||||
int LUKS2_keyslot_pbkdf(struct luks2_hdr *hdr, int keyslot, struct crypt_pbkdf_type *pbkdf);
|
||||
int LUKS2_set_keyslots_size(struct crypt_device *cd,
|
||||
struct luks2_hdr *hdr,
|
||||
uint64_t data_offset);
|
||||
|
||||
/*
|
||||
* Permanent activation flags stored in header
|
||||
@@ -570,7 +410,6 @@ int LUKS2_volume_key_load_in_keyring_by_keyslot(struct crypt_device *cd,
|
||||
int LUKS2_volume_key_load_in_keyring_by_digest(struct crypt_device *cd,
|
||||
struct luks2_hdr *hdr, struct volume_key *vk, int digest);
|
||||
|
||||
struct luks_phdr;
|
||||
int LUKS2_luks1_to_luks2(struct crypt_device *cd,
|
||||
struct luks_phdr *hdr1,
|
||||
struct luks2_hdr *hdr2);
|
||||
@@ -589,21 +428,29 @@ int LUKS2_reencrypt_locked_recovery_by_passphrase(struct crypt_device *cd,
|
||||
uint32_t flags,
|
||||
struct volume_key **vks);
|
||||
|
||||
void LUKS2_reenc_context_free(struct crypt_device *cd, struct luks2_reenc_context *rh);
|
||||
void LUKS2_reencrypt_free(struct crypt_device *cd,
|
||||
struct luks2_reencrypt *rh);
|
||||
|
||||
int LUKS2_assembly_multisegment_dmd(struct crypt_device *cd,
|
||||
struct luks2_hdr *hdr,
|
||||
struct volume_key *vks,
|
||||
json_object *jobj_segments,
|
||||
struct crypt_dm_active_device *dmd);
|
||||
crypt_reencrypt_info LUKS2_reencrypt_status(struct luks2_hdr *hdr);
|
||||
|
||||
crypt_reencrypt_info LUKS2_reencrypt_status(struct crypt_device *cd,
|
||||
crypt_reencrypt_info LUKS2_reencrypt_get_params(struct luks2_hdr *hdr,
|
||||
struct crypt_params_reencrypt *params);
|
||||
|
||||
int crypt_reencrypt_lock(struct crypt_device *cd, struct crypt_lock_handle **reencrypt_lock);
|
||||
int crypt_reencrypt_lock_by_dm_uuid(struct crypt_device *cd, const char *dm_uuid, struct crypt_lock_handle **reencrypt_lock);
|
||||
void crypt_reencrypt_unlock(struct crypt_device *cd, struct crypt_lock_handle *reencrypt_lock);
|
||||
int LUKS2_reencrypt_lock(struct crypt_device *cd,
|
||||
struct crypt_lock_handle **reencrypt_lock);
|
||||
|
||||
int luks2_check_device_size(struct crypt_device *cd, struct luks2_hdr *hdr, uint64_t check_size, uint64_t *dev_size, bool activation, bool dynamic);
|
||||
int LUKS2_reencrypt_lock_by_dm_uuid(struct crypt_device *cd,
|
||||
const char *dm_uuid,
|
||||
struct crypt_lock_handle **reencrypt_lock);
|
||||
|
||||
void LUKS2_reencrypt_unlock(struct crypt_device *cd,
|
||||
struct crypt_lock_handle *reencrypt_lock);
|
||||
|
||||
int LUKS2_reencrypt_check_device_size(struct crypt_device *cd,
|
||||
struct luks2_hdr *hdr,
|
||||
uint64_t check_size,
|
||||
uint64_t *dev_size,
|
||||
bool activation,
|
||||
bool dynamic);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/*
|
||||
* LUKS - Linux Unified Key Setup v2, digest handling
|
||||
*
|
||||
* Copyright (C) 2015-2020 Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2015-2020 Milan Broz
|
||||
* Copyright (C) 2015-2021 Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2015-2021 Milan Broz
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
@@ -28,7 +28,7 @@ static const digest_handler *digest_handlers[LUKS2_DIGEST_MAX] = {
|
||||
NULL
|
||||
};
|
||||
|
||||
static const digest_handler *LUKS2_digest_handler_type(struct crypt_device *cd, const char *type)
|
||||
static const digest_handler *LUKS2_digest_handler_type(const char *type)
|
||||
{
|
||||
int i;
|
||||
|
||||
@@ -57,10 +57,10 @@ static const digest_handler *LUKS2_digest_handler(struct crypt_device *cd, int d
|
||||
if (!json_object_object_get_ex(jobj1, "type", &jobj2))
|
||||
return NULL;
|
||||
|
||||
return LUKS2_digest_handler_type(cd, json_object_get_string(jobj2));
|
||||
return LUKS2_digest_handler_type(json_object_get_string(jobj2));
|
||||
}
|
||||
|
||||
static int LUKS2_digest_find_free(struct crypt_device *cd, struct luks2_hdr *hdr)
|
||||
static int LUKS2_digest_find_free(struct luks2_hdr *hdr)
|
||||
{
|
||||
int digest = 0;
|
||||
|
||||
@@ -78,11 +78,11 @@ int LUKS2_digest_create(struct crypt_device *cd,
|
||||
int digest;
|
||||
const digest_handler *dh;
|
||||
|
||||
dh = LUKS2_digest_handler_type(cd, type);
|
||||
dh = LUKS2_digest_handler_type(type);
|
||||
if (!dh)
|
||||
return -EINVAL;
|
||||
|
||||
digest = LUKS2_digest_find_free(cd, hdr);
|
||||
digest = LUKS2_digest_find_free(hdr);
|
||||
if (digest < 0)
|
||||
return -EINVAL;
|
||||
|
||||
@@ -111,7 +111,7 @@ int LUKS2_digest_by_keyslot(struct luks2_hdr *hdr, int keyslot)
|
||||
}
|
||||
|
||||
int LUKS2_digest_verify_by_digest(struct crypt_device *cd,
|
||||
struct luks2_hdr *hdr,
|
||||
struct luks2_hdr *hdr __attribute__((unused)),
|
||||
int digest,
|
||||
const struct volume_key *vk)
|
||||
{
|
||||
@@ -219,7 +219,9 @@ static int assign_one_digest(struct crypt_device *cd, struct luks2_hdr *hdr,
|
||||
if (!jobj_digest_keyslots)
|
||||
return -EINVAL;
|
||||
|
||||
snprintf(num, sizeof(num), "%d", keyslot);
|
||||
if (snprintf(num, sizeof(num), "%d", keyslot) < 0)
|
||||
return -EINVAL;
|
||||
|
||||
if (assign) {
|
||||
jobj1 = LUKS2_array_jobj(jobj_digest_keyslots, num);
|
||||
if (!jobj1)
|
||||
@@ -254,12 +256,11 @@ int LUKS2_digest_assign(struct crypt_device *cd, struct luks2_hdr *hdr,
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
// FIXME: do not write header in nothing changed
|
||||
return commit ? LUKS2_hdr_write(cd, hdr) : 0;
|
||||
}
|
||||
|
||||
static int assign_all_segments(struct crypt_device *cd, struct luks2_hdr *hdr,
|
||||
int digest, int assign)
|
||||
static int assign_all_segments(struct crypt_device *cd __attribute__((unused)),
|
||||
struct luks2_hdr *hdr, int digest, int assign)
|
||||
{
|
||||
json_object *jobj1, *jobj_digest, *jobj_digest_segments;
|
||||
|
||||
@@ -304,7 +305,9 @@ static int assign_one_segment(struct crypt_device *cd, struct luks2_hdr *hdr,
|
||||
if (!jobj_digest_segments)
|
||||
return -EINVAL;
|
||||
|
||||
snprintf(num, sizeof(num), "%d", segment);
|
||||
if (snprintf(num, sizeof(num), "%d", segment) < 0)
|
||||
return -EINVAL;
|
||||
|
||||
if (assign) {
|
||||
jobj1 = LUKS2_array_jobj(jobj_digest_segments, num);
|
||||
if (!jobj1)
|
||||
@@ -349,7 +352,6 @@ int LUKS2_digest_segment_assign(struct crypt_device *cd, struct luks2_hdr *hdr,
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
// FIXME: do not write header in nothing changed
|
||||
return commit ? LUKS2_hdr_write(cd, hdr) : 0;
|
||||
}
|
||||
|
||||
@@ -441,7 +443,7 @@ int LUKS2_volume_key_load_in_keyring_by_keyslot(struct crypt_device *cd,
|
||||
}
|
||||
|
||||
int LUKS2_volume_key_load_in_keyring_by_digest(struct crypt_device *cd,
|
||||
struct luks2_hdr *hdr, struct volume_key *vk, int digest)
|
||||
struct luks2_hdr *hdr __attribute__((unused)), struct volume_key *vk, int digest)
|
||||
{
|
||||
char *desc = get_key_description_by_digest(cd, digest);
|
||||
int r;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/*
|
||||
* LUKS - Linux Unified Key Setup v2, PBKDF2 digest handler (LUKS1 compatible)
|
||||
*
|
||||
* Copyright (C) 2015-2020 Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2015-2020 Milan Broz
|
||||
* Copyright (C) 2015-2021 Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2015-2021 Milan Broz
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/*
|
||||
* LUKS - Linux Unified Key Setup v2
|
||||
*
|
||||
* Copyright (C) 2015-2020 Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2015-2020 Milan Broz
|
||||
* Copyright (C) 2015-2021 Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2015-2021 Milan Broz
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
@@ -175,13 +175,13 @@ static void hdr_to_disk(struct luks2_hdr *hdr,
|
||||
hdr_disk->hdr_offset = cpu_to_be64(offset);
|
||||
hdr_disk->seqid = cpu_to_be64(hdr->seqid);
|
||||
|
||||
strncpy(hdr_disk->label, hdr->label, LUKS2_LABEL_L);
|
||||
memcpy(hdr_disk->label, hdr->label, MIN(strlen(hdr->label), LUKS2_LABEL_L));
|
||||
hdr_disk->label[LUKS2_LABEL_L - 1] = '\0';
|
||||
strncpy(hdr_disk->subsystem, hdr->subsystem, LUKS2_LABEL_L);
|
||||
memcpy(hdr_disk->subsystem, hdr->subsystem, MIN(strlen(hdr->subsystem), LUKS2_LABEL_L));
|
||||
hdr_disk->subsystem[LUKS2_LABEL_L - 1] = '\0';
|
||||
strncpy(hdr_disk->checksum_alg, hdr->checksum_alg, LUKS2_CHECKSUM_ALG_L);
|
||||
memcpy(hdr_disk->checksum_alg, hdr->checksum_alg, MIN(strlen(hdr->checksum_alg), LUKS2_CHECKSUM_ALG_L));
|
||||
hdr_disk->checksum_alg[LUKS2_CHECKSUM_ALG_L - 1] = '\0';
|
||||
strncpy(hdr_disk->uuid, hdr->uuid, LUKS2_UUID_L);
|
||||
memcpy(hdr_disk->uuid, hdr->uuid, MIN(strlen(hdr->uuid), LUKS2_UUID_L));
|
||||
hdr_disk->uuid[LUKS2_UUID_L - 1] = '\0';
|
||||
|
||||
memcpy(hdr_disk->salt, secondary ? hdr->salt2 : hdr->salt1, LUKS2_SALT_L);
|
||||
@@ -301,8 +301,6 @@ static int hdr_write_disk(struct crypt_device *cd,
|
||||
log_dbg(cd, "Trying to write LUKS2 header (%zu bytes) at offset %" PRIu64 ".",
|
||||
hdr->hdr_size, offset);
|
||||
|
||||
/* FIXME: read-only device silent fail? */
|
||||
|
||||
devfd = device_open_locked(cd, device, O_RDWR);
|
||||
if (devfd < 0)
|
||||
return devfd == -1 ? -EINVAL : devfd;
|
||||
@@ -385,7 +383,7 @@ int LUKS2_device_write_lock(struct crypt_device *cd, struct luks2_hdr *hdr, stru
|
||||
}
|
||||
|
||||
/* run sequence id check only on first write lock (r == 1) and w/o LUKS2 reencryption in-progress */
|
||||
if (r == 1 && !crypt_get_reenc_context(cd)) {
|
||||
if (r == 1 && !crypt_get_luks2_reencrypt(cd)) {
|
||||
log_dbg(cd, "Checking context sequence id matches value stored on disk.");
|
||||
if (LUKS2_check_sequence_id(cd, hdr, device)) {
|
||||
device_write_unlock(cd, device);
|
||||
@@ -413,7 +411,7 @@ int LUKS2_disk_hdr_write(struct crypt_device *cd, struct luks2_hdr *hdr, struct
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
r = device_check_size(cd, crypt_metadata_device(cd), LUKS2_hdr_and_areas_size(hdr->jobj), 1);
|
||||
r = device_check_size(cd, crypt_metadata_device(cd), LUKS2_hdr_and_areas_size(hdr), 1);
|
||||
if (r)
|
||||
return r;
|
||||
|
||||
@@ -669,9 +667,9 @@ int LUKS2_disk_hdr_read(struct crypt_device *cd, struct luks2_hdr *hdr,
|
||||
|
||||
/* check header with keyslots to fit the device */
|
||||
if (state_hdr1 == HDR_OK)
|
||||
hdr_size = LUKS2_hdr_and_areas_size(jobj_hdr1);
|
||||
hdr_size = LUKS2_hdr_and_areas_size_jobj(jobj_hdr1);
|
||||
else if (state_hdr2 == HDR_OK)
|
||||
hdr_size = LUKS2_hdr_and_areas_size(jobj_hdr2);
|
||||
hdr_size = LUKS2_hdr_and_areas_size_jobj(jobj_hdr2);
|
||||
else {
|
||||
r = (state_hdr1 == HDR_FAIL_IO && state_hdr2 == HDR_FAIL_IO) ? -EIO : -EINVAL;
|
||||
goto err;
|
||||
@@ -788,14 +786,11 @@ int LUKS2_hdr_version_unlocked(struct crypt_device *cd, const char *backup_file)
|
||||
flags |= O_DIRECT;
|
||||
|
||||
devfd = open(device_path(device), flags);
|
||||
if (devfd < 0)
|
||||
goto err;
|
||||
|
||||
if ((read_lseek_blockwise(devfd, device_block_size(cd, device),
|
||||
if (devfd != -1 && (read_lseek_blockwise(devfd, device_block_size(cd, device),
|
||||
device_alignment(device), &hdr, sizeof(hdr), 0) == sizeof(hdr)) &&
|
||||
!memcmp(hdr.magic, LUKS2_MAGIC_1ST, LUKS2_MAGIC_L))
|
||||
r = (int)be16_to_cpu(hdr.version);
|
||||
err:
|
||||
|
||||
if (devfd != -1)
|
||||
close(devfd);
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/*
|
||||
* LUKS - Linux Unified Key Setup v2
|
||||
*
|
||||
* Copyright (C) 2015-2020 Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2015-2020 Milan Broz
|
||||
* Copyright (C) 2015-2021 Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2015-2021 Milan Broz
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
@@ -23,7 +23,6 @@
|
||||
#define _CRYPTSETUP_LUKS2_INTERNAL_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <json-c/json.h>
|
||||
|
||||
@@ -31,8 +30,6 @@
|
||||
#include "base64.h"
|
||||
#include "luks2.h"
|
||||
|
||||
#define UNUSED(x) (void)(x)
|
||||
|
||||
/* override useless forward slash escape when supported by json-c */
|
||||
#ifndef JSON_C_TO_STRING_NOSLASHESCAPE
|
||||
#define JSON_C_TO_STRING_NOSLASHESCAPE 0
|
||||
@@ -45,6 +42,8 @@ int LUKS2_disk_hdr_read(struct crypt_device *cd, struct luks2_hdr *hdr,
|
||||
struct device *device, int do_recovery, int do_blkprobe);
|
||||
int LUKS2_disk_hdr_write(struct crypt_device *cd, struct luks2_hdr *hdr,
|
||||
struct device *device, bool seqid_check);
|
||||
int LUKS2_device_write_lock(struct crypt_device *cd,
|
||||
struct luks2_hdr *hdr, struct device *device);
|
||||
|
||||
/*
|
||||
* JSON struct access helpers
|
||||
@@ -59,9 +58,9 @@ json_object *LUKS2_get_segments_jobj(struct luks2_hdr *hdr);
|
||||
void hexprint_base64(struct crypt_device *cd, json_object *jobj,
|
||||
const char *sep, const char *line_sep);
|
||||
|
||||
uint64_t json_object_get_uint64(json_object *jobj);
|
||||
uint32_t json_object_get_uint32(json_object *jobj);
|
||||
json_object *json_object_new_uint64(uint64_t value);
|
||||
uint64_t crypt_jobj_get_uint64(json_object *jobj);
|
||||
uint32_t crypt_jobj_get_uint32(json_object *jobj);
|
||||
json_object *crypt_jobj_new_uint64(uint64_t value);
|
||||
|
||||
int json_object_object_add_by_uint(json_object *jobj, unsigned key, json_object *jobj_val);
|
||||
void json_object_object_del_by_uint(json_object *jobj, unsigned key);
|
||||
@@ -93,8 +92,8 @@ void LUKS2_keyslots_repair(struct crypt_device *cd, json_object *jobj_hdr);
|
||||
/*
|
||||
* JSON array helpers
|
||||
*/
|
||||
struct json_object *LUKS2_array_jobj(struct json_object *array, const char *num);
|
||||
struct json_object *LUKS2_array_remove(struct json_object *array, const char *num);
|
||||
json_object *LUKS2_array_jobj(json_object *array, const char *num);
|
||||
json_object *LUKS2_array_remove(json_object *array, const char *num);
|
||||
|
||||
/*
|
||||
* Plugins API
|
||||
@@ -163,28 +162,53 @@ typedef struct {
|
||||
digest_dump_func dump;
|
||||
} digest_handler;
|
||||
|
||||
/**
|
||||
* LUKS2 token handlers (internal use only)
|
||||
int keyring_open(struct crypt_device *cd,
|
||||
int token,
|
||||
char **buffer,
|
||||
size_t *buffer_len,
|
||||
void *usrptr);
|
||||
|
||||
void keyring_dump(struct crypt_device *cd, const char *json);
|
||||
|
||||
int keyring_validate(struct crypt_device *cd, const char *json);
|
||||
|
||||
struct crypt_token_handler_v2 {
|
||||
const char *name;
|
||||
crypt_token_open_func open;
|
||||
crypt_token_buffer_free_func buffer_free;
|
||||
crypt_token_validate_func validate;
|
||||
crypt_token_dump_func dump;
|
||||
|
||||
/* here ends v1. Do not touch anything above */
|
||||
|
||||
crypt_token_open_pin_func open_pin;
|
||||
crypt_token_version_func version;
|
||||
|
||||
void *dlhandle;
|
||||
};
|
||||
|
||||
/*
|
||||
* Initial sequence of structure members in union 'u' must be always
|
||||
* identical. Version 4 must fully contain version 3 which must
|
||||
* subsequently fully contain version 2, etc.
|
||||
*
|
||||
* See C standard, section 6.5.2.3, item 5.
|
||||
*/
|
||||
typedef int (*builtin_token_get_func) (json_object *jobj_token, void *params);
|
||||
typedef int (*builtin_token_set_func) (json_object **jobj_token, const void *params);
|
||||
|
||||
typedef struct {
|
||||
/* internal only section used by builtin tokens */
|
||||
builtin_token_get_func get;
|
||||
builtin_token_set_func set;
|
||||
/* public token handler */
|
||||
const crypt_token_handler *h;
|
||||
} token_handler;
|
||||
|
||||
int token_keyring_set(json_object **, const void *);
|
||||
int token_keyring_get(json_object *, void *);
|
||||
struct crypt_token_handler_internal {
|
||||
uint32_t version;
|
||||
union {
|
||||
crypt_token_handler v1; /* deprecated public structure */
|
||||
struct crypt_token_handler_v2 v2; /* internal helper v2 structure */
|
||||
} u;
|
||||
};
|
||||
|
||||
int LUKS2_find_area_gap(struct crypt_device *cd, struct luks2_hdr *hdr,
|
||||
size_t keylength, uint64_t *area_offset, uint64_t *area_length);
|
||||
int LUKS2_find_area_max_gap(struct crypt_device *cd, struct luks2_hdr *hdr,
|
||||
uint64_t *area_offset, uint64_t *area_length);
|
||||
|
||||
uint64_t LUKS2_hdr_and_areas_size_jobj(json_object *jobj);
|
||||
|
||||
int LUKS2_check_cipher(struct crypt_device *cd,
|
||||
size_t keylength,
|
||||
const char *cipher,
|
||||
@@ -201,4 +225,119 @@ static inline const char *crypt_reencrypt_mode_to_str(crypt_reencrypt_mode_info
|
||||
return "<unknown>";
|
||||
}
|
||||
|
||||
/*
|
||||
* Generic LUKS2 keyslot
|
||||
*/
|
||||
int LUKS2_keyslot_reencrypt_store(struct crypt_device *cd,
|
||||
struct luks2_hdr *hdr,
|
||||
int keyslot,
|
||||
const void *buffer,
|
||||
size_t buffer_length);
|
||||
|
||||
int LUKS2_keyslot_reencrypt_create(struct crypt_device *cd,
|
||||
struct luks2_hdr *hdr,
|
||||
int keyslot,
|
||||
const struct crypt_params_reencrypt *params);
|
||||
|
||||
int LUKS2_keyslot_dump(struct crypt_device *cd,
|
||||
int keyslot);
|
||||
|
||||
/* JSON helpers */
|
||||
uint64_t json_segment_get_offset(json_object *jobj_segment, unsigned blockwise);
|
||||
const char *json_segment_type(json_object *jobj_segment);
|
||||
uint64_t json_segment_get_iv_offset(json_object *jobj_segment);
|
||||
uint64_t json_segment_get_size(json_object *jobj_segment, unsigned blockwise);
|
||||
const char *json_segment_get_cipher(json_object *jobj_segment);
|
||||
int json_segment_get_sector_size(json_object *jobj_segment);
|
||||
bool json_segment_is_backup(json_object *jobj_segment);
|
||||
json_object *json_segments_get_segment(json_object *jobj_segments, int segment);
|
||||
unsigned json_segments_count(json_object *jobj_segments);
|
||||
void json_segment_remove_flag(json_object *jobj_segment, const char *flag);
|
||||
uint64_t json_segments_get_minimal_offset(json_object *jobj_segments, unsigned blockwise);
|
||||
json_object *json_segment_create_linear(uint64_t offset, const uint64_t *length, unsigned reencryption);
|
||||
json_object *json_segment_create_crypt(uint64_t offset, uint64_t iv_offset, const uint64_t *length, const char *cipher, uint32_t sector_size, unsigned reencryption);
|
||||
int json_segments_segment_in_reencrypt(json_object *jobj_segments);
|
||||
|
||||
int LUKS2_assembly_multisegment_dmd(struct crypt_device *cd,
|
||||
struct luks2_hdr *hdr,
|
||||
struct volume_key *vks,
|
||||
json_object *jobj_segments,
|
||||
struct crypt_dm_active_device *dmd);
|
||||
|
||||
/*
|
||||
* Generic LUKS2 segment
|
||||
*/
|
||||
int LUKS2_segments_count(struct luks2_hdr *hdr);
|
||||
|
||||
int LUKS2_segment_first_unused_id(struct luks2_hdr *hdr);
|
||||
|
||||
int LUKS2_segment_set_flag(json_object *jobj_segment, const char *flag);
|
||||
|
||||
json_object *LUKS2_get_segment_by_flag(struct luks2_hdr *hdr, const char *flag);
|
||||
|
||||
int LUKS2_get_segment_id_by_flag(struct luks2_hdr *hdr, const char *flag);
|
||||
|
||||
int LUKS2_segments_set(struct crypt_device *cd,
|
||||
struct luks2_hdr *hdr,
|
||||
json_object *jobj_segments,
|
||||
int commit);
|
||||
|
||||
uint64_t LUKS2_segment_offset(struct luks2_hdr *hdr,
|
||||
int segment,
|
||||
unsigned blockwise);
|
||||
|
||||
uint64_t LUKS2_segment_size(struct luks2_hdr *hdr,
|
||||
int segment,
|
||||
unsigned blockwise);
|
||||
|
||||
int LUKS2_segment_is_type(struct luks2_hdr *hdr,
|
||||
int segment,
|
||||
const char *type);
|
||||
|
||||
int LUKS2_segment_by_type(struct luks2_hdr *hdr,
|
||||
const char *type);
|
||||
|
||||
int LUKS2_last_segment_by_type(struct luks2_hdr *hdr,
|
||||
const char *type);
|
||||
|
||||
int LUKS2_get_default_segment(struct luks2_hdr *hdr);
|
||||
|
||||
int LUKS2_reencrypt_digest_new(struct luks2_hdr *hdr);
|
||||
int LUKS2_reencrypt_digest_old(struct luks2_hdr *hdr);
|
||||
int LUKS2_reencrypt_data_offset(struct luks2_hdr *hdr, bool blockwise);
|
||||
|
||||
/*
|
||||
* Generic LUKS2 digest
|
||||
*/
|
||||
int LUKS2_digest_verify_by_digest(struct crypt_device *cd,
|
||||
struct luks2_hdr *hdr,
|
||||
int digest,
|
||||
const struct volume_key *vk);
|
||||
|
||||
void LUKS2_digests_erase_unused(struct crypt_device *cd,
|
||||
struct luks2_hdr *hdr);
|
||||
|
||||
int LUKS2_digest_dump(struct crypt_device *cd,
|
||||
int digest);
|
||||
|
||||
/*
|
||||
* Generic LUKS2 token
|
||||
*/
|
||||
int LUKS2_tokens_count(struct luks2_hdr *hdr);
|
||||
|
||||
/*
|
||||
* LUKS2 generic
|
||||
*/
|
||||
int LUKS2_reload(struct crypt_device *cd,
|
||||
const char *name,
|
||||
struct volume_key *vks,
|
||||
uint64_t device_size,
|
||||
uint32_t flags);
|
||||
|
||||
int LUKS2_keyslot_for_segment(struct luks2_hdr *hdr, int keyslot, int segment);
|
||||
int LUKS2_find_keyslot(struct luks2_hdr *hdr, const char *type);
|
||||
int LUKS2_set_keyslots_size(struct crypt_device *cd,
|
||||
struct luks2_hdr *hdr,
|
||||
uint64_t data_offset);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/*
|
||||
* LUKS - Linux Unified Key Setup v2, LUKS2 header format code
|
||||
*
|
||||
* Copyright (C) 2015-2020 Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2015-2020 Milan Broz
|
||||
* Copyright (C) 2015-2021 Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2015-2021 Milan Broz
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
@@ -30,7 +30,7 @@ struct area {
|
||||
|
||||
static size_t get_area_size(size_t keylength)
|
||||
{
|
||||
//FIXME: calculate this properly, for now it is AF_split_sectors
|
||||
/* for now it is AF_split_sectors */
|
||||
return size_round_up(keylength * 4000, 4096);
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ static size_t get_min_offset(struct luks2_hdr *hdr)
|
||||
|
||||
static size_t get_max_offset(struct luks2_hdr *hdr)
|
||||
{
|
||||
return LUKS2_hdr_and_areas_size(hdr->jobj);
|
||||
return LUKS2_hdr_and_areas_size(hdr);
|
||||
}
|
||||
|
||||
int LUKS2_find_area_max_gap(struct crypt_device *cd, struct luks2_hdr *hdr,
|
||||
@@ -177,8 +177,11 @@ int LUKS2_find_area_gap(struct crypt_device *cd, struct luks2_hdr *hdr,
|
||||
|
||||
log_dbg(cd, "Found area %zu -> %zu", offset, length + offset);
|
||||
|
||||
*area_offset = offset;
|
||||
*area_length = length;
|
||||
if (area_offset)
|
||||
*area_offset = offset;
|
||||
if (area_length)
|
||||
*area_length = length;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -216,7 +219,7 @@ int LUKS2_generate_hdr(
|
||||
struct json_object *jobj_segment, *jobj_integrity, *jobj_keyslots, *jobj_segments, *jobj_config;
|
||||
char cipher[128];
|
||||
uuid_t partitionUuid;
|
||||
int digest;
|
||||
int r, digest;
|
||||
uint64_t mdev_size;
|
||||
|
||||
if (!metadata_size)
|
||||
@@ -244,7 +247,8 @@ int LUKS2_generate_hdr(
|
||||
/* Decrease keyslots_size due to metadata device being too small */
|
||||
if (!device_size(crypt_metadata_device(cd), &mdev_size) &&
|
||||
((keyslots_size + get_min_offset(hdr)) > mdev_size) &&
|
||||
device_fallocate(crypt_metadata_device(cd), keyslots_size + get_min_offset(hdr)))
|
||||
device_fallocate(crypt_metadata_device(cd), keyslots_size + get_min_offset(hdr)) &&
|
||||
(get_min_offset(hdr) <= mdev_size))
|
||||
keyslots_size = mdev_size - get_min_offset(hdr);
|
||||
}
|
||||
|
||||
@@ -289,9 +293,11 @@ int LUKS2_generate_hdr(
|
||||
uuid_unparse(partitionUuid, hdr->uuid);
|
||||
|
||||
if (*cipherMode != '\0')
|
||||
snprintf(cipher, sizeof(cipher), "%s-%s", cipherName, cipherMode);
|
||||
r = snprintf(cipher, sizeof(cipher), "%s-%s", cipherName, cipherMode);
|
||||
else
|
||||
snprintf(cipher, sizeof(cipher), "%s", cipherName);
|
||||
r = snprintf(cipher, sizeof(cipher), "%s", cipherName);
|
||||
if (r < 0 || (size_t)r >= sizeof(cipher))
|
||||
return -EINVAL;
|
||||
|
||||
hdr->jobj = json_object_new_object();
|
||||
|
||||
@@ -325,8 +331,8 @@ int LUKS2_generate_hdr(
|
||||
|
||||
json_object_object_add_by_uint(jobj_segments, 0, jobj_segment);
|
||||
|
||||
json_object_object_add(jobj_config, "json_size", json_object_new_uint64(metadata_size - LUKS2_HDR_BIN_LEN));
|
||||
json_object_object_add(jobj_config, "keyslots_size", json_object_new_uint64(keyslots_size));
|
||||
json_object_object_add(jobj_config, "json_size", crypt_jobj_new_uint64(metadata_size - LUKS2_HDR_BIN_LEN));
|
||||
json_object_object_add(jobj_config, "keyslots_size", crypt_jobj_new_uint64(keyslots_size));
|
||||
|
||||
JSON_DBG(cd, hdr->jobj, "Header JSON:");
|
||||
return 0;
|
||||
@@ -337,7 +343,7 @@ err:
|
||||
}
|
||||
|
||||
int LUKS2_wipe_header_areas(struct crypt_device *cd,
|
||||
struct luks2_hdr *hdr)
|
||||
struct luks2_hdr *hdr, bool detached_header)
|
||||
{
|
||||
int r;
|
||||
uint64_t offset, length;
|
||||
@@ -352,7 +358,7 @@ int LUKS2_wipe_header_areas(struct crypt_device *cd,
|
||||
return -EINVAL;
|
||||
|
||||
/* On detached header wipe at least the first 4k */
|
||||
if (length == 0) {
|
||||
if (detached_header) {
|
||||
length = 4096;
|
||||
wipe_block = 4096;
|
||||
}
|
||||
@@ -368,7 +374,7 @@ int LUKS2_wipe_header_areas(struct crypt_device *cd,
|
||||
/* Wipe keyslot area */
|
||||
wipe_block = 1024 * 1024;
|
||||
offset = get_min_offset(hdr);
|
||||
length = LUKS2_keyslots_size(hdr->jobj);
|
||||
length = LUKS2_keyslots_size(hdr);
|
||||
|
||||
log_dbg(cd, "Wiping keyslots area (0x%06" PRIx64 " - 0x%06" PRIx64") with random data.",
|
||||
offset, length + offset);
|
||||
@@ -377,8 +383,7 @@ int LUKS2_wipe_header_areas(struct crypt_device *cd,
|
||||
offset, length, wipe_block, NULL, NULL);
|
||||
}
|
||||
|
||||
/* FIXME: what if user wanted to keep original keyslots size? */
|
||||
int LUKS2_set_keyslots_size(struct crypt_device *cd,
|
||||
int LUKS2_set_keyslots_size(struct crypt_device *cd __attribute__((unused)),
|
||||
struct luks2_hdr *hdr,
|
||||
uint64_t data_offset)
|
||||
{
|
||||
@@ -400,6 +405,6 @@ int LUKS2_set_keyslots_size(struct crypt_device *cd,
|
||||
if (!json_object_object_get_ex(hdr->jobj, "config", &jobj_config))
|
||||
return 1;
|
||||
|
||||
json_object_object_add(jobj_config, "keyslots_size", json_object_new_uint64(keyslots_size));
|
||||
json_object_object_add(jobj_config, "keyslots_size", crypt_jobj_new_uint64(keyslots_size));
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
* LUKS - Linux Unified Key Setup v2
|
||||
*
|
||||
* Copyright (C) 2015-2020 Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2015-2020 Milan Broz
|
||||
* Copyright (C) 2015-2020 Ondrej Kozina
|
||||
* Copyright (C) 2015-2021 Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2015-2021 Milan Broz
|
||||
* Copyright (C) 2015-2021 Ondrej Kozina
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
@@ -45,11 +45,11 @@ void hexprint_base64(struct crypt_device *cd, json_object *jobj,
|
||||
&buf, &buf_len))
|
||||
return;
|
||||
|
||||
for (i = 0; i < buf_len / 2; i++)
|
||||
log_std(cd, "%02hhx%s", buf[i], sep);
|
||||
log_std(cd, "\n\t%s", line_sep);
|
||||
for (i = buf_len / 2; i < buf_len; i++)
|
||||
for (i = 0; i < buf_len; i++) {
|
||||
if (i && !(i % 16))
|
||||
log_std(cd, "\n\t%s", line_sep);
|
||||
log_std(cd, "%02hhx%s", buf[i], sep);
|
||||
}
|
||||
log_std(cd, "\n");
|
||||
free(buf);
|
||||
}
|
||||
@@ -219,7 +219,7 @@ int LUKS2_get_default_segment(struct luks2_hdr *hdr)
|
||||
* json_type_int needs to be validated first.
|
||||
* See validate_json_uint32()
|
||||
*/
|
||||
uint32_t json_object_get_uint32(json_object *jobj)
|
||||
uint32_t crypt_jobj_get_uint32(json_object *jobj)
|
||||
{
|
||||
return json_object_get_int64(jobj);
|
||||
}
|
||||
@@ -234,21 +234,21 @@ static json_bool json_str_to_uint64(json_object *jobj, uint64_t *value)
|
||||
tmp = strtoull(json_object_get_string(jobj), &endptr, 10);
|
||||
if (*endptr || errno) {
|
||||
*value = 0;
|
||||
return FALSE;
|
||||
return 0;
|
||||
}
|
||||
|
||||
*value = tmp;
|
||||
return TRUE;
|
||||
return 1;
|
||||
}
|
||||
|
||||
uint64_t json_object_get_uint64(json_object *jobj)
|
||||
uint64_t crypt_jobj_get_uint64(json_object *jobj)
|
||||
{
|
||||
uint64_t r;
|
||||
json_str_to_uint64(jobj, &r);
|
||||
return r;
|
||||
}
|
||||
|
||||
json_object *json_object_new_uint64(uint64_t value)
|
||||
json_object *crypt_jobj_new_uint64(uint64_t value)
|
||||
{
|
||||
/* 18446744073709551615 */
|
||||
char num[21];
|
||||
@@ -273,9 +273,9 @@ static json_bool numbered(struct crypt_device *cd, const char *name, const char
|
||||
for (i = 0; key[i]; i++)
|
||||
if (!isdigit(key[i])) {
|
||||
log_dbg(cd, "%s \"%s\" is not in numbered form.", name, key);
|
||||
return FALSE;
|
||||
return 0;
|
||||
}
|
||||
return TRUE;
|
||||
return 1;
|
||||
}
|
||||
|
||||
json_object *json_contains(struct crypt_device *cd, json_object *jobj, const char *name,
|
||||
@@ -300,7 +300,7 @@ json_bool validate_json_uint32(json_object *jobj)
|
||||
errno = 0;
|
||||
tmp = json_object_get_int64(jobj);
|
||||
|
||||
return (errno || tmp < 0 || tmp > UINT32_MAX) ? FALSE : TRUE;
|
||||
return (errno || tmp < 0 || tmp > UINT32_MAX) ? 0 : 1;
|
||||
}
|
||||
|
||||
static json_bool validate_keyslots_array(struct crypt_device *cd,
|
||||
@@ -313,17 +313,17 @@ static json_bool validate_keyslots_array(struct crypt_device *cd,
|
||||
jobj = json_object_array_get_idx(jarr, i);
|
||||
if (!json_object_is_type(jobj, json_type_string)) {
|
||||
log_dbg(cd, "Illegal value type in keyslots array at index %d.", i);
|
||||
return FALSE;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!json_contains(cd, jobj_keys, "", "Keyslots section",
|
||||
json_object_get_string(jobj), json_type_object))
|
||||
return FALSE;
|
||||
return 0;
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static json_bool validate_segments_array(struct crypt_device *cd,
|
||||
@@ -336,17 +336,17 @@ static json_bool validate_segments_array(struct crypt_device *cd,
|
||||
jobj = json_object_array_get_idx(jarr, i);
|
||||
if (!json_object_is_type(jobj, json_type_string)) {
|
||||
log_dbg(cd, "Illegal value type in segments array at index %d.", i);
|
||||
return FALSE;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!json_contains(cd, jobj_segments, "", "Segments section",
|
||||
json_object_get_string(jobj), json_type_object))
|
||||
return FALSE;
|
||||
return 0;
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static json_bool segment_has_digest(const char *segment_name, json_object *jobj_digests)
|
||||
@@ -357,10 +357,10 @@ static json_bool segment_has_digest(const char *segment_name, json_object *jobj_
|
||||
UNUSED(key);
|
||||
json_object_object_get_ex(val, "segments", &jobj_segments);
|
||||
if (LUKS2_array_jobj(jobj_segments, segment_name))
|
||||
return TRUE;
|
||||
return 1;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static json_bool validate_intervals(struct crypt_device *cd,
|
||||
@@ -372,18 +372,18 @@ static json_bool validate_intervals(struct crypt_device *cd,
|
||||
while (i < length) {
|
||||
if (ix[i].offset < 2 * metadata_size) {
|
||||
log_dbg(cd, "Illegal area offset: %" PRIu64 ".", ix[i].offset);
|
||||
return FALSE;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!ix[i].length) {
|
||||
log_dbg(cd, "Area length must be greater than zero.");
|
||||
return FALSE;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ((ix[i].offset + ix[i].length) > keyslots_area_end) {
|
||||
log_dbg(cd, "Area [%" PRIu64 ", %" PRIu64 "] overflows binary keyslots area (ends at offset: %" PRIu64 ").",
|
||||
ix[i].offset, ix[i].offset + ix[i].length, keyslots_area_end);
|
||||
return FALSE;
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (j = 0; j < length; j++) {
|
||||
@@ -393,17 +393,18 @@ static json_bool validate_intervals(struct crypt_device *cd,
|
||||
log_dbg(cd, "Overlapping areas [%" PRIu64 ",%" PRIu64 "] and [%" PRIu64 ",%" PRIu64 "].",
|
||||
ix[i].offset, ix[i].offset + ix[i].length,
|
||||
ix[j].offset, ix[j].offset + ix[j].length);
|
||||
return FALSE;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int LUKS2_keyslot_validate(struct crypt_device *cd, json_object *hdr_jobj, json_object *hdr_keyslot, const char *key)
|
||||
static int LUKS2_keyslot_validate(struct crypt_device *cd, json_object *hdr_jobj __attribute__((unused)),
|
||||
json_object *hdr_keyslot, const char *key)
|
||||
{
|
||||
json_object *jobj_key_size;
|
||||
|
||||
@@ -455,7 +456,7 @@ static int hdr_validate_json_size(struct crypt_device *cd, json_object *hdr_jobj
|
||||
|
||||
json = json_object_to_json_string_ext(hdr_jobj,
|
||||
JSON_C_TO_STRING_PLAIN | JSON_C_TO_STRING_NOSLASHESCAPE);
|
||||
json_area_size = json_object_get_uint64(jobj1);
|
||||
json_area_size = crypt_jobj_get_uint64(jobj1);
|
||||
json_size = (uint64_t)strlen(json);
|
||||
|
||||
if (hdr_json_size != json_area_size) {
|
||||
@@ -516,7 +517,7 @@ static int hdr_validate_tokens(struct crypt_device *cd, json_object *hdr_jobj)
|
||||
|
||||
static int hdr_validate_crypt_segment(struct crypt_device *cd,
|
||||
json_object *jobj, const char *key, json_object *jobj_digests,
|
||||
uint64_t offset, uint64_t size)
|
||||
uint64_t offset __attribute__((unused)), uint64_t size)
|
||||
{
|
||||
json_object *jobj_ivoffset, *jobj_sector_size, *jobj_integrity;
|
||||
uint32_t sector_size;
|
||||
@@ -543,7 +544,7 @@ static int hdr_validate_crypt_segment(struct crypt_device *cd,
|
||||
return 1;
|
||||
}
|
||||
|
||||
sector_size = json_object_get_uint32(jobj_sector_size);
|
||||
sector_size = crypt_jobj_get_uint32(jobj_sector_size);
|
||||
if (!sector_size || MISALIGNED_512(sector_size)) {
|
||||
log_dbg(cd, "Illegal sector size: %" PRIu32, sector_size);
|
||||
return 1;
|
||||
@@ -594,9 +595,9 @@ static bool validate_segment_intervals(struct crypt_device *cd,
|
||||
static int hdr_validate_segments(struct crypt_device *cd, json_object *hdr_jobj)
|
||||
{
|
||||
json_object *jobj_segments, *jobj_digests, *jobj_offset, *jobj_size, *jobj_type, *jobj_flags, *jobj;
|
||||
struct interval *intervals;
|
||||
uint64_t offset, size;
|
||||
int i, r, count, first_backup = -1;
|
||||
struct interval *intervals = NULL;
|
||||
|
||||
if (!json_object_object_get_ex(hdr_jobj, "segments", &jobj_segments)) {
|
||||
log_dbg(cd, "Missing segments section.");
|
||||
@@ -676,10 +677,18 @@ static int hdr_validate_segments(struct crypt_device *cd, json_object *hdr_jobj)
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* avoid needlessly large allocation when first backup segment is invalid */
|
||||
if (first_backup >= count) {
|
||||
log_dbg(cd, "Gap between last regular segment and backup segment at key %d.", first_backup);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (first_backup < 0)
|
||||
first_backup = count;
|
||||
|
||||
intervals = malloc(first_backup * sizeof(*intervals));
|
||||
if ((size_t)first_backup < SIZE_MAX / sizeof(*intervals))
|
||||
intervals = malloc(first_backup * sizeof(*intervals));
|
||||
|
||||
if (!intervals) {
|
||||
log_dbg(cd, "Not enough memory.");
|
||||
return 1;
|
||||
@@ -712,7 +721,7 @@ static int hdr_validate_segments(struct crypt_device *cd, json_object *hdr_jobj)
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint64_t LUKS2_metadata_size(json_object *jobj)
|
||||
static uint64_t LUKS2_metadata_size_jobj(json_object *jobj)
|
||||
{
|
||||
json_object *jobj1, *jobj2;
|
||||
uint64_t json_size;
|
||||
@@ -724,6 +733,11 @@ uint64_t LUKS2_metadata_size(json_object *jobj)
|
||||
return json_size + LUKS2_HDR_BIN_LEN;
|
||||
}
|
||||
|
||||
uint64_t LUKS2_metadata_size(struct luks2_hdr *hdr)
|
||||
{
|
||||
return LUKS2_metadata_size_jobj(hdr->jobj);
|
||||
}
|
||||
|
||||
static int hdr_validate_areas(struct crypt_device *cd, json_object *hdr_jobj)
|
||||
{
|
||||
struct interval *intervals;
|
||||
@@ -739,7 +753,7 @@ static int hdr_validate_areas(struct crypt_device *cd, json_object *hdr_jobj)
|
||||
return 1;
|
||||
|
||||
/* config is already validated */
|
||||
metadata_size = LUKS2_metadata_size(hdr_jobj);
|
||||
metadata_size = LUKS2_metadata_size_jobj(hdr_jobj);
|
||||
|
||||
length = json_object_object_length(jobj_keyslots);
|
||||
|
||||
@@ -785,7 +799,7 @@ static int hdr_validate_areas(struct crypt_device *cd, json_object *hdr_jobj)
|
||||
return 1;
|
||||
}
|
||||
|
||||
ret = validate_intervals(cd, length, intervals, metadata_size, LUKS2_hdr_and_areas_size(hdr_jobj)) ? 0 : 1;
|
||||
ret = validate_intervals(cd, length, intervals, metadata_size, LUKS2_hdr_and_areas_size_jobj(hdr_jobj)) ? 0 : 1;
|
||||
|
||||
free(intervals);
|
||||
|
||||
@@ -970,13 +984,16 @@ int LUKS2_hdr_read(struct crypt_device *cd, struct luks2_hdr *hdr, int repair)
|
||||
return r;
|
||||
}
|
||||
|
||||
int LUKS2_hdr_write_force(struct crypt_device *cd, struct luks2_hdr *hdr)
|
||||
static int hdr_cleanup_and_validate(struct crypt_device *cd, struct luks2_hdr *hdr)
|
||||
{
|
||||
/* NOTE: is called before LUKS2 validation routines */
|
||||
/* erase unused digests (no assigned keyslot or segment) */
|
||||
LUKS2_digests_erase_unused(cd, hdr);
|
||||
|
||||
if (LUKS2_hdr_validate(cd, hdr->jobj, hdr->hdr_size - LUKS2_HDR_BIN_LEN))
|
||||
return LUKS2_hdr_validate(cd, hdr->jobj, hdr->hdr_size - LUKS2_HDR_BIN_LEN);
|
||||
}
|
||||
|
||||
int LUKS2_hdr_write_force(struct crypt_device *cd, struct luks2_hdr *hdr)
|
||||
{
|
||||
if (hdr_cleanup_and_validate(cd, hdr))
|
||||
return -EINVAL;
|
||||
|
||||
return LUKS2_disk_hdr_write(cd, hdr, crypt_metadata_device(cd), false);
|
||||
@@ -984,11 +1001,7 @@ int LUKS2_hdr_write_force(struct crypt_device *cd, struct luks2_hdr *hdr)
|
||||
|
||||
int LUKS2_hdr_write(struct crypt_device *cd, struct luks2_hdr *hdr)
|
||||
{
|
||||
/* NOTE: is called before LUKS2 validation routines */
|
||||
/* erase unused digests (no assigned keyslot or segment) */
|
||||
LUKS2_digests_erase_unused(cd, hdr);
|
||||
|
||||
if (LUKS2_hdr_validate(cd, hdr->jobj, hdr->hdr_size - LUKS2_HDR_BIN_LEN))
|
||||
if (hdr_cleanup_and_validate(cd, hdr))
|
||||
return -EINVAL;
|
||||
|
||||
return LUKS2_disk_hdr_write(cd, hdr, crypt_metadata_device(cd), true);
|
||||
@@ -1034,7 +1047,7 @@ void LUKS2_hdr_free(struct crypt_device *cd, struct luks2_hdr *hdr)
|
||||
log_dbg(cd, "LUKS2 header still in use");
|
||||
}
|
||||
|
||||
uint64_t LUKS2_keyslots_size(json_object *jobj)
|
||||
static uint64_t LUKS2_keyslots_size_jobj(json_object *jobj)
|
||||
{
|
||||
json_object *jobj1, *jobj2;
|
||||
uint64_t keyslots_size;
|
||||
@@ -1046,9 +1059,19 @@ uint64_t LUKS2_keyslots_size(json_object *jobj)
|
||||
return keyslots_size;
|
||||
}
|
||||
|
||||
uint64_t LUKS2_hdr_and_areas_size(json_object *jobj)
|
||||
uint64_t LUKS2_keyslots_size(struct luks2_hdr *hdr)
|
||||
{
|
||||
return 2 * LUKS2_metadata_size(jobj) + LUKS2_keyslots_size(jobj);
|
||||
return LUKS2_keyslots_size_jobj(hdr->jobj);
|
||||
}
|
||||
|
||||
uint64_t LUKS2_hdr_and_areas_size_jobj(json_object *jobj)
|
||||
{
|
||||
return 2 * LUKS2_metadata_size_jobj(jobj) + LUKS2_keyslots_size_jobj(jobj);
|
||||
}
|
||||
|
||||
uint64_t LUKS2_hdr_and_areas_size(struct luks2_hdr *hdr)
|
||||
{
|
||||
return LUKS2_hdr_and_areas_size_jobj(hdr->jobj);
|
||||
}
|
||||
|
||||
int LUKS2_hdr_backup(struct crypt_device *cd, struct luks2_hdr *hdr,
|
||||
@@ -1060,7 +1083,7 @@ int LUKS2_hdr_backup(struct crypt_device *cd, struct luks2_hdr *hdr,
|
||||
ssize_t ret, buffer_size;
|
||||
char *buffer = NULL;
|
||||
|
||||
hdr_size = LUKS2_hdr_and_areas_size(hdr->jobj);
|
||||
hdr_size = LUKS2_hdr_and_areas_size(hdr);
|
||||
buffer_size = size_round_up(hdr_size, crypt_getpagesize());
|
||||
|
||||
buffer = crypt_safe_alloc(buffer_size);
|
||||
@@ -1171,7 +1194,7 @@ int LUKS2_hdr_restore(struct crypt_device *cd, struct luks2_hdr *hdr,
|
||||
goto out;
|
||||
}
|
||||
|
||||
buffer_size = LUKS2_hdr_and_areas_size(hdr_file.jobj);
|
||||
buffer_size = LUKS2_hdr_and_areas_size(&hdr_file);
|
||||
buffer = crypt_safe_alloc(buffer_size);
|
||||
if (!buffer) {
|
||||
r = -ENOMEM;
|
||||
@@ -1211,7 +1234,7 @@ int LUKS2_hdr_restore(struct crypt_device *cd, struct luks2_hdr *hdr,
|
||||
goto out;
|
||||
}
|
||||
/* FIXME: what could go wrong? Erase if we're fine with consequences */
|
||||
if (buffer_size != (ssize_t) LUKS2_hdr_and_areas_size(tmp_hdr.jobj)) {
|
||||
if (buffer_size != (ssize_t) LUKS2_hdr_and_areas_size(&tmp_hdr)) {
|
||||
log_err(cd, _("Binary header with keyslot areas size differ on device and backup, restore failed."));
|
||||
r = -EINVAL;
|
||||
goto out;
|
||||
@@ -1290,6 +1313,8 @@ static const struct {
|
||||
{ CRYPT_ACTIVATE_SAME_CPU_CRYPT, "same-cpu-crypt" },
|
||||
{ CRYPT_ACTIVATE_SUBMIT_FROM_CRYPT_CPUS, "submit-from-crypt-cpus" },
|
||||
{ CRYPT_ACTIVATE_NO_JOURNAL, "no-journal" },
|
||||
{ CRYPT_ACTIVATE_NO_READ_WORKQUEUE, "no-read-workqueue" },
|
||||
{ CRYPT_ACTIVATE_NO_WRITE_WORKQUEUE, "no-write-workqueue" },
|
||||
{ 0, NULL }
|
||||
};
|
||||
|
||||
@@ -1567,7 +1592,7 @@ static void hdr_dump_keyslots(struct crypt_device *cd, json_object *hdr_jobj)
|
||||
log_std(cd, " %s: %s%s\n", slot, tmps, r == -ENOENT ? " (unbound)" : "");
|
||||
|
||||
if (json_object_object_get_ex(val, "key_size", &jobj2))
|
||||
log_std(cd, "\tKey: %u bits\n", json_object_get_uint32(jobj2) * 8);
|
||||
log_std(cd, "\tKey: %u bits\n", crypt_jobj_get_uint32(jobj2) * 8);
|
||||
|
||||
log_std(cd, "\tPriority: %s\n", get_priority_desc(val));
|
||||
|
||||
@@ -1611,7 +1636,7 @@ static void hdr_dump_tokens(struct crypt_device *cd, json_object *hdr_jobj)
|
||||
json_object_object_get_ex(val, "keyslots", &jobj2);
|
||||
for (i = 0; i < (int) json_object_array_length(jobj2); i++) {
|
||||
jobj3 = json_object_array_get_idx(jobj2, i);
|
||||
log_std(cd, "\tKeyslot: %s\n", json_object_get_string(jobj3));
|
||||
log_std(cd, "\tKeyslot: %s\n", json_object_get_string(jobj3));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1650,7 +1675,7 @@ static void hdr_dump_segments(struct crypt_device *cd, json_object *hdr_jobj)
|
||||
log_std(cd, "\tcipher: %s\n", json_object_get_string(jobj1));
|
||||
|
||||
if (json_object_object_get_ex(jobj_segment, "sector_size", &jobj1))
|
||||
log_std(cd, "\tsector: %" PRIu32 " [bytes]\n", json_object_get_uint32(jobj1));
|
||||
log_std(cd, "\tsector: %" PRIu32 " [bytes]\n", crypt_jobj_get_uint32(jobj1));
|
||||
|
||||
if (json_object_object_get_ex(jobj_segment, "integrity", &jobj1) &&
|
||||
json_object_object_get_ex(jobj1, "type", &jobj2))
|
||||
@@ -1705,8 +1730,8 @@ int LUKS2_hdr_dump(struct crypt_device *cd, struct luks2_hdr *hdr)
|
||||
log_std(cd, "LUKS header information\n");
|
||||
log_std(cd, "Version: \t%u\n", hdr->version);
|
||||
log_std(cd, "Epoch: \t%" PRIu64 "\n", hdr->seqid);
|
||||
log_std(cd, "Metadata area: \t%" PRIu64 " [bytes]\n", LUKS2_metadata_size(hdr->jobj));
|
||||
log_std(cd, "Keyslots area: \t%" PRIu64 " [bytes]\n", LUKS2_keyslots_size(hdr->jobj));
|
||||
log_std(cd, "Metadata area: \t%" PRIu64 " [bytes]\n", LUKS2_metadata_size(hdr));
|
||||
log_std(cd, "Keyslots area: \t%" PRIu64 " [bytes]\n", LUKS2_keyslots_size(hdr));
|
||||
log_std(cd, "UUID: \t%s\n", *hdr->uuid ? hdr->uuid : "(no UUID)");
|
||||
log_std(cd, "Label: \t%s\n", *hdr->label ? hdr->label : "(no label)");
|
||||
log_std(cd, "Subsystem: \t%s\n", *hdr->subsystem ? hdr->subsystem : "(no subsystem)");
|
||||
@@ -1720,6 +1745,24 @@ int LUKS2_hdr_dump(struct crypt_device *cd, struct luks2_hdr *hdr)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int LUKS2_hdr_dump_json(struct crypt_device *cd, struct luks2_hdr *hdr, const char **json)
|
||||
{
|
||||
const char *json_buf;
|
||||
|
||||
json_buf = json_object_to_json_string_ext(hdr->jobj,
|
||||
JSON_C_TO_STRING_PRETTY | JSON_C_TO_STRING_NOSLASHESCAPE);
|
||||
|
||||
if (!json_buf)
|
||||
return -EINVAL;
|
||||
|
||||
if (json)
|
||||
*json = json_buf;
|
||||
else
|
||||
crypt_log(cd, CRYPT_LOG_NORMAL, json_buf);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int LUKS2_get_data_size(struct luks2_hdr *hdr, uint64_t *size, bool *dynamic)
|
||||
{
|
||||
int sector_size;
|
||||
@@ -1747,7 +1790,7 @@ int LUKS2_get_data_size(struct luks2_hdr *hdr, uint64_t *size, bool *dynamic)
|
||||
return 0;
|
||||
}
|
||||
|
||||
tmp += json_object_get_uint64(jobj_size);
|
||||
tmp += crypt_jobj_get_uint64(jobj_size);
|
||||
}
|
||||
|
||||
/* impossible, real device size must not be zero */
|
||||
@@ -1765,7 +1808,7 @@ uint64_t LUKS2_get_data_offset(struct luks2_hdr *hdr)
|
||||
crypt_reencrypt_info ri;
|
||||
json_object *jobj;
|
||||
|
||||
ri = LUKS2_reenc_status(hdr);
|
||||
ri = LUKS2_reencrypt_status(hdr);
|
||||
if (ri == CRYPT_REENCRYPT_CLEAN || ri == CRYPT_REENCRYPT_CRASH) {
|
||||
jobj = LUKS2_get_segment_by_flag(hdr, "backup-final");
|
||||
if (jobj)
|
||||
@@ -1793,7 +1836,7 @@ const char *LUKS2_get_cipher(struct luks2_hdr *hdr, int segment)
|
||||
return json_segment_get_cipher(jobj_segment) ?: "null";
|
||||
}
|
||||
|
||||
crypt_reencrypt_info LUKS2_reenc_status(struct luks2_hdr *hdr)
|
||||
crypt_reencrypt_info LUKS2_reencrypt_status(struct luks2_hdr *hdr)
|
||||
{
|
||||
uint32_t reqs;
|
||||
|
||||
@@ -2157,7 +2200,12 @@ int LUKS2_activate(struct crypt_device *cd,
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
r = INTEGRITY_create_dmd_device(cd, NULL, NULL, NULL, NULL, &dmdi, dmd.flags);
|
||||
if (dmd.flags & CRYPT_ACTIVATE_ALLOW_DISCARDS) {
|
||||
log_err(cd, _("Discard/TRIM is not supported."));
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
r = INTEGRITY_create_dmd_device(cd, NULL, NULL, NULL, NULL, &dmdi, dmd.flags, 0);
|
||||
if (r)
|
||||
return r;
|
||||
|
||||
@@ -2231,7 +2279,7 @@ int LUKS2_deactivate(struct crypt_device *cd, const char *name, struct luks2_hdr
|
||||
goto out;
|
||||
|
||||
if (contains_reencryption_helper(deps)) {
|
||||
r = crypt_reencrypt_lock_by_dm_uuid(cd, dmd->uuid, &reencrypt_lock);
|
||||
r = LUKS2_reencrypt_lock_by_dm_uuid(cd, dmd->uuid, &reencrypt_lock);
|
||||
if (r) {
|
||||
if (r == -EBUSY)
|
||||
log_err(cd, _("Reencryption in-progress. Cannot deactivate device."));
|
||||
@@ -2310,7 +2358,7 @@ int LUKS2_deactivate(struct crypt_device *cd, const char *name, struct luks2_hdr
|
||||
}
|
||||
|
||||
out:
|
||||
crypt_reencrypt_unlock(cd, reencrypt_lock);
|
||||
LUKS2_reencrypt_unlock(cd, reencrypt_lock);
|
||||
dep = deps;
|
||||
while (*dep)
|
||||
free(*dep++);
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/*
|
||||
* LUKS - Linux Unified Key Setup v2, keyslot handling
|
||||
*
|
||||
* Copyright (C) 2015-2020 Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2015-2020 Milan Broz
|
||||
* Copyright (C) 2015-2021 Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2015-2021 Milan Broz
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
@@ -32,7 +32,7 @@ static const keyslot_handler *keyslot_handlers[LUKS2_KEYSLOTS_MAX] = {
|
||||
};
|
||||
|
||||
static const keyslot_handler
|
||||
*LUKS2_keyslot_handler_type(struct crypt_device *cd, const char *type)
|
||||
*LUKS2_keyslot_handler_type(struct crypt_device *cd __attribute__((unused)), const char *type)
|
||||
{
|
||||
int i;
|
||||
|
||||
@@ -65,15 +65,22 @@ static const keyslot_handler
|
||||
return LUKS2_keyslot_handler_type(cd, json_object_get_string(jobj2));
|
||||
}
|
||||
|
||||
int LUKS2_keyslot_find_empty(struct luks2_hdr *hdr)
|
||||
int LUKS2_keyslot_find_empty(struct crypt_device *cd, struct luks2_hdr *hdr, size_t keylength)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < LUKS2_KEYSLOTS_MAX; i++)
|
||||
if (!LUKS2_get_keyslot_jobj(hdr, i))
|
||||
return i;
|
||||
break;
|
||||
|
||||
return -EINVAL;
|
||||
if (i == LUKS2_KEYSLOTS_MAX)
|
||||
return -EINVAL;
|
||||
|
||||
/* Check also there is a space for the key in keyslots area */
|
||||
if (keylength && LUKS2_find_area_gap(cd, hdr, keylength, NULL, NULL) < 0)
|
||||
return -ENOSPC;
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
/* Check if a keyslot is assigned to specific segment */
|
||||
@@ -148,7 +155,7 @@ int LUKS2_keyslot_cipher_incompatible(struct crypt_device *cd, const char *ciphe
|
||||
{
|
||||
char cipher[MAX_CIPHER_LEN], cipher_mode[MAX_CIPHER_LEN];
|
||||
|
||||
if (!cipher_spec || !strcmp(cipher_spec, "null") || !strcmp(cipher_spec, "cipher_null"))
|
||||
if (!cipher_spec || crypt_is_cipher_null(cipher_spec))
|
||||
return 1;
|
||||
|
||||
if (crypt_parse_name_and_mode(cipher_spec, cipher, NULL, cipher_mode) < 0)
|
||||
@@ -300,11 +307,11 @@ int LUKS2_keyslot_area(struct luks2_hdr *hdr,
|
||||
|
||||
if (!json_object_object_get_ex(jobj_area, "offset", &jobj))
|
||||
return -EINVAL;
|
||||
*offset = json_object_get_uint64(jobj);
|
||||
*offset = crypt_jobj_get_uint64(jobj);
|
||||
|
||||
if (!json_object_object_get_ex(jobj_area, "size", &jobj))
|
||||
return -EINVAL;
|
||||
*length = json_object_get_uint64(jobj);
|
||||
*length = crypt_jobj_get_uint64(jobj);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -545,7 +552,7 @@ out:
|
||||
|
||||
if (r == -ENOMEM)
|
||||
log_err(cd, _("Not enough available memory to open a keyslot."));
|
||||
else if (r != -EPERM)
|
||||
else if (r != -EPERM && r != -ENOENT)
|
||||
log_err(cd, _("Keyslot open failed."));
|
||||
}
|
||||
return r;
|
||||
@@ -582,7 +589,7 @@ int LUKS2_keyslot_open(struct crypt_device *cd,
|
||||
if (r < 0) {
|
||||
if (r == -ENOMEM)
|
||||
log_err(cd, _("Not enough available memory to open a keyslot."));
|
||||
else if (r != -EPERM)
|
||||
else if (r != -EPERM && r != -ENOENT)
|
||||
log_err(cd, _("Keyslot open failed."));
|
||||
}
|
||||
|
||||
@@ -600,7 +607,6 @@ int LUKS2_keyslot_reencrypt_create(struct crypt_device *cd,
|
||||
if (keyslot == CRYPT_ANY_SLOT)
|
||||
return -EINVAL;
|
||||
|
||||
/* FIXME: find keyslot by type */
|
||||
h = LUKS2_keyslot_handler_type(cd, "reencrypt");
|
||||
if (!h)
|
||||
return -EINVAL;
|
||||
@@ -769,7 +775,7 @@ int LUKS2_keyslot_dump(struct crypt_device *cd, int keyslot)
|
||||
return h->dump(cd, keyslot);
|
||||
}
|
||||
|
||||
crypt_keyslot_priority LUKS2_keyslot_priority_get(struct crypt_device *cd,
|
||||
crypt_keyslot_priority LUKS2_keyslot_priority_get(struct crypt_device *cd __attribute__((unused)),
|
||||
struct luks2_hdr *hdr, int keyslot)
|
||||
{
|
||||
json_object *jobj_keyslot, *jobj_priority;
|
||||
@@ -805,7 +811,7 @@ int placeholder_keyslot_alloc(struct crypt_device *cd,
|
||||
int keyslot,
|
||||
uint64_t area_offset,
|
||||
uint64_t area_length,
|
||||
size_t volume_key_len)
|
||||
size_t volume_key_len __attribute__((unused)))
|
||||
{
|
||||
struct luks2_hdr *hdr;
|
||||
json_object *jobj_keyslots, *jobj_keyslot, *jobj_area;
|
||||
@@ -835,8 +841,8 @@ int placeholder_keyslot_alloc(struct crypt_device *cd,
|
||||
|
||||
/* Area object */
|
||||
jobj_area = json_object_new_object();
|
||||
json_object_object_add(jobj_area, "offset", json_object_new_uint64(area_offset));
|
||||
json_object_object_add(jobj_area, "size", json_object_new_uint64(area_length));
|
||||
json_object_object_add(jobj_area, "offset", crypt_jobj_new_uint64(area_offset));
|
||||
json_object_object_add(jobj_area, "size", crypt_jobj_new_uint64(area_length));
|
||||
json_object_object_add(jobj_keyslot, "area", jobj_area);
|
||||
|
||||
json_object_object_add_by_uint(jobj_keyslots, keyslot, jobj_keyslot);
|
||||
@@ -935,3 +941,40 @@ int LUKS2_find_keyslot(struct luks2_hdr *hdr, const char *type)
|
||||
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
/* assumes valid header, it does not move references in tokens/digests etc! */
|
||||
int LUKS2_keyslot_swap(struct crypt_device *cd, struct luks2_hdr *hdr,
|
||||
int keyslot, int keyslot2)
|
||||
{
|
||||
json_object *jobj_keyslots, *jobj_keyslot, *jobj_keyslot2;
|
||||
int r;
|
||||
|
||||
if (!json_object_object_get_ex(hdr->jobj, "keyslots", &jobj_keyslots))
|
||||
return -EINVAL;
|
||||
|
||||
jobj_keyslot = LUKS2_get_keyslot_jobj(hdr, keyslot);
|
||||
if (!jobj_keyslot)
|
||||
return -EINVAL;
|
||||
|
||||
jobj_keyslot2 = LUKS2_get_keyslot_jobj(hdr, keyslot2);
|
||||
if (!jobj_keyslot2)
|
||||
return -EINVAL;
|
||||
|
||||
/* This transfer owner of object, no need for json_object_put */
|
||||
json_object_get(jobj_keyslot);
|
||||
json_object_get(jobj_keyslot2);
|
||||
|
||||
json_object_object_del_by_uint(jobj_keyslots, keyslot);
|
||||
r = json_object_object_add_by_uint(jobj_keyslots, keyslot, jobj_keyslot2);
|
||||
if (r < 0) {
|
||||
log_dbg(cd, "Failed to swap keyslot %d.", keyslot);
|
||||
return r;
|
||||
}
|
||||
|
||||
json_object_object_del_by_uint(jobj_keyslots, keyslot2);
|
||||
r = json_object_object_add_by_uint(jobj_keyslots, keyslot2, jobj_keyslot);
|
||||
if (r < 0)
|
||||
log_dbg(cd, "Failed to swap keyslot2 %d.", keyslot2);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/*
|
||||
* LUKS - Linux Unified Key Setup v2, LUKS2 type keyslot handler
|
||||
*
|
||||
* Copyright (C) 2015-2020 Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2015-2020 Milan Broz
|
||||
* Copyright (C) 2015-2021 Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2015-2021 Milan Broz
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
@@ -48,7 +48,7 @@ static int luks2_encrypt_to_storage(char *src, size_t srcLength,
|
||||
return -EINVAL;
|
||||
|
||||
/* Encrypt buffer */
|
||||
r = crypt_storage_init(&s, SECTOR_SIZE, cipher, cipher_mode, vk->key, vk->keylength);
|
||||
r = crypt_storage_init(&s, SECTOR_SIZE, cipher, cipher_mode, vk->key, vk->keylength, false);
|
||||
if (r) {
|
||||
log_err(cd, _("Cannot use %s-%s cipher for keyslot encryption."), cipher, cipher_mode);
|
||||
return r;
|
||||
@@ -103,7 +103,7 @@ static int luks2_decrypt_from_storage(char *dst, size_t dstLength,
|
||||
if (MISALIGNED_512(dstLength))
|
||||
return -EINVAL;
|
||||
|
||||
r = crypt_storage_init(&s, SECTOR_SIZE, cipher, cipher_mode, vk->key, vk->keylength);
|
||||
r = crypt_storage_init(&s, SECTOR_SIZE, cipher, cipher_mode, vk->key, vk->keylength, false);
|
||||
if (r) {
|
||||
log_err(cd, _("Cannot use %s-%s cipher for keyslot encryption."), cipher, cipher_mode);
|
||||
return r;
|
||||
@@ -220,7 +220,7 @@ static int luks2_keyslot_set_key(struct crypt_device *cd,
|
||||
|
||||
if (!json_object_object_get_ex(jobj_area, "offset", &jobj2))
|
||||
return -EINVAL;
|
||||
area_offset = json_object_get_uint64(jobj2);
|
||||
area_offset = crypt_jobj_get_uint64(jobj2);
|
||||
|
||||
if (!json_object_object_get_ex(jobj_area, "encryption", &jobj2))
|
||||
return -EINVAL;
|
||||
@@ -313,7 +313,7 @@ static int luks2_keyslot_get_key(struct crypt_device *cd,
|
||||
|
||||
if (!json_object_object_get_ex(jobj_area, "offset", &jobj2))
|
||||
return -EINVAL;
|
||||
area_offset = json_object_get_uint64(jobj2);
|
||||
area_offset = crypt_jobj_get_uint64(jobj2);
|
||||
|
||||
if (!json_object_object_get_ex(jobj_area, "encryption", &jobj2))
|
||||
return -EINVAL;
|
||||
@@ -325,13 +325,6 @@ static int luks2_keyslot_get_key(struct crypt_device *cd,
|
||||
return -EINVAL;
|
||||
keyslot_key_len = json_object_get_int(jobj2);
|
||||
|
||||
/*
|
||||
* If requested, serialize unlocking for memory-hard KDF. Usually NOOP.
|
||||
*/
|
||||
if (pbkdf.max_memory_kb > MIN_MEMORY_FOR_SERIALIZE_LOCK_KB)
|
||||
try_serialize_lock = true;
|
||||
if (try_serialize_lock && crypt_serialize_lock(cd))
|
||||
return -EINVAL;
|
||||
/*
|
||||
* Allocate derived key storage space.
|
||||
*/
|
||||
@@ -342,9 +335,18 @@ static int luks2_keyslot_get_key(struct crypt_device *cd,
|
||||
AFEKSize = AF_split_sectors(volume_key_len, LUKS_STRIPES) * SECTOR_SIZE;
|
||||
AfKey = crypt_safe_alloc(AFEKSize);
|
||||
if (!AfKey) {
|
||||
crypt_free_volume_key(derived_key);
|
||||
return -ENOMEM;
|
||||
r = -ENOMEM;
|
||||
goto out;
|
||||
}
|
||||
|
||||
/*
|
||||
* If requested, serialize unlocking for memory-hard KDF. Usually NOOP.
|
||||
*/
|
||||
if (pbkdf.max_memory_kb > MIN_MEMORY_FOR_SERIALIZE_LOCK_KB)
|
||||
try_serialize_lock = true;
|
||||
if (try_serialize_lock && (r = crypt_serialize_lock(cd)))
|
||||
goto out;
|
||||
|
||||
/*
|
||||
* Calculate derived key, decrypt keyslot content and merge it.
|
||||
*/
|
||||
@@ -367,6 +369,7 @@ static int luks2_keyslot_get_key(struct crypt_device *cd,
|
||||
if (r == 0)
|
||||
r = AF_merge(cd, AfKey, volume_key, volume_key_len, LUKS_STRIPES, af_hash);
|
||||
|
||||
out:
|
||||
crypt_free_volume_key(derived_key);
|
||||
crypt_safe_free(AfKey);
|
||||
|
||||
@@ -462,7 +465,7 @@ static int luks2_keyslot_alloc(struct crypt_device *cd,
|
||||
return -EINVAL;
|
||||
|
||||
if (keyslot == CRYPT_ANY_SLOT)
|
||||
keyslot = LUKS2_keyslot_find_empty(hdr);
|
||||
keyslot = LUKS2_keyslot_find_empty(cd, hdr, 0);
|
||||
|
||||
if (keyslot < 0 || keyslot >= LUKS2_KEYSLOTS_MAX)
|
||||
return -ENOMEM;
|
||||
@@ -494,8 +497,8 @@ static int luks2_keyslot_alloc(struct crypt_device *cd,
|
||||
/* Area object */
|
||||
jobj_area = json_object_new_object();
|
||||
json_object_object_add(jobj_area, "type", json_object_new_string("raw"));
|
||||
json_object_object_add(jobj_area, "offset", json_object_new_uint64(area_offset));
|
||||
json_object_object_add(jobj_area, "size", json_object_new_uint64(area_length));
|
||||
json_object_object_add(jobj_area, "offset", crypt_jobj_new_uint64(area_offset));
|
||||
json_object_object_add(jobj_area, "size", crypt_jobj_new_uint64(area_length));
|
||||
json_object_object_add(jobj_keyslot, "area", jobj_area);
|
||||
|
||||
json_object_object_add_by_uint(jobj_keyslots, keyslot, jobj_keyslot);
|
||||
@@ -607,7 +610,7 @@ static int luks2_keyslot_dump(struct crypt_device *cd, int keyslot)
|
||||
log_std(cd, "\tCipher: %s\n", json_object_get_string(jobj1));
|
||||
|
||||
json_object_object_get_ex(jobj_area, "key_size", &jobj1);
|
||||
log_std(cd, "\tCipher key: %u bits\n", json_object_get_uint32(jobj1) * 8);
|
||||
log_std(cd, "\tCipher key: %u bits\n", crypt_jobj_get_uint32(jobj1) * 8);
|
||||
|
||||
json_object_object_get_ex(jobj_kdf, "type", &jobj1);
|
||||
log_std(cd, "\tPBKDF: %s\n", json_object_get_string(jobj1));
|
||||
@@ -617,7 +620,7 @@ static int luks2_keyslot_dump(struct crypt_device *cd, int keyslot)
|
||||
log_std(cd, "\tHash: %s\n", json_object_get_string(jobj1));
|
||||
|
||||
json_object_object_get_ex(jobj_kdf, "iterations", &jobj1);
|
||||
log_std(cd, "\tIterations: %" PRIu64 "\n", json_object_get_uint64(jobj1));
|
||||
log_std(cd, "\tIterations: %" PRIu64 "\n", crypt_jobj_get_uint64(jobj1));
|
||||
} else {
|
||||
json_object_object_get_ex(jobj_kdf, "time", &jobj1);
|
||||
log_std(cd, "\tTime cost: %" PRIu64 "\n", json_object_get_int64(jobj1));
|
||||
@@ -640,10 +643,10 @@ static int luks2_keyslot_dump(struct crypt_device *cd, int keyslot)
|
||||
log_std(cd, "\tAF hash: %s\n", json_object_get_string(jobj1));
|
||||
|
||||
json_object_object_get_ex(jobj_area, "offset", &jobj1);
|
||||
log_std(cd, "\tArea offset:%" PRIu64 " [bytes]\n", json_object_get_uint64(jobj1));
|
||||
log_std(cd, "\tArea offset:%" PRIu64 " [bytes]\n", crypt_jobj_get_uint64(jobj1));
|
||||
|
||||
json_object_object_get_ex(jobj_area, "size", &jobj1);
|
||||
log_std(cd, "\tArea length:%" PRIu64 " [bytes]\n", json_object_get_uint64(jobj1));
|
||||
log_std(cd, "\tArea length:%" PRIu64 " [bytes]\n", crypt_jobj_get_uint64(jobj1));
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -735,7 +738,7 @@ static int luks2_keyslot_update(struct crypt_device *cd,
|
||||
return r;
|
||||
}
|
||||
|
||||
static void luks2_keyslot_repair(struct crypt_device *cd, json_object *jobj_keyslot)
|
||||
static void luks2_keyslot_repair(struct crypt_device *cd __attribute__((unused)), json_object *jobj_keyslot)
|
||||
{
|
||||
const char *type;
|
||||
json_object *jobj_kdf, *jobj_type;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/*
|
||||
* LUKS - Linux Unified Key Setup v2, reencryption keyslot handler
|
||||
*
|
||||
* Copyright (C) 2016-2020, Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2016-2020, Ondrej Kozina
|
||||
* Copyright (C) 2016-2021, Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2016-2021, Ondrej Kozina
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
@@ -21,12 +21,12 @@
|
||||
|
||||
#include "luks2_internal.h"
|
||||
|
||||
static int reenc_keyslot_open(struct crypt_device *cd,
|
||||
int keyslot,
|
||||
const char *password,
|
||||
size_t password_len,
|
||||
char *volume_key,
|
||||
size_t volume_key_len)
|
||||
static int reenc_keyslot_open(struct crypt_device *cd __attribute__((unused)),
|
||||
int keyslot __attribute__((unused)),
|
||||
const char *password __attribute__((unused)),
|
||||
size_t password_len __attribute__((unused)),
|
||||
char *volume_key __attribute__((unused)),
|
||||
size_t volume_key_len __attribute__((unused)))
|
||||
{
|
||||
return -ENOENT;
|
||||
}
|
||||
@@ -67,13 +67,13 @@ int reenc_keyslot_alloc(struct crypt_device *cd,
|
||||
|
||||
if (params->data_shift) {
|
||||
json_object_object_add(jobj_area, "type", json_object_new_string("datashift"));
|
||||
json_object_object_add(jobj_area, "shift_size", json_object_new_uint64(params->data_shift << SECTOR_SHIFT));
|
||||
json_object_object_add(jobj_area, "shift_size", crypt_jobj_new_uint64(params->data_shift << SECTOR_SHIFT));
|
||||
} else
|
||||
/* except data shift protection, initial setting is irrelevant. Type can be changed during reencryption */
|
||||
json_object_object_add(jobj_area, "type", json_object_new_string("none"));
|
||||
|
||||
json_object_object_add(jobj_area, "offset", json_object_new_uint64(area_offset));
|
||||
json_object_object_add(jobj_area, "size", json_object_new_uint64(area_length));
|
||||
json_object_object_add(jobj_area, "offset", crypt_jobj_new_uint64(area_offset));
|
||||
json_object_object_add(jobj_area, "size", crypt_jobj_new_uint64(area_length));
|
||||
|
||||
json_object_object_add(jobj_keyslot, "type", json_object_new_string("reencrypt"));
|
||||
json_object_object_add(jobj_keyslot, "key_size", json_object_new_int(1)); /* useless but mandatory */
|
||||
@@ -113,8 +113,8 @@ static int reenc_keyslot_store_data(struct crypt_device *cd,
|
||||
!json_object_object_get_ex(jobj_area, "size", &jobj_length))
|
||||
return -EINVAL;
|
||||
|
||||
area_offset = json_object_get_uint64(jobj_offset);
|
||||
area_length = json_object_get_uint64(jobj_length);
|
||||
area_offset = crypt_jobj_get_uint64(jobj_offset);
|
||||
area_length = crypt_jobj_get_uint64(jobj_length);
|
||||
|
||||
if (!area_offset || !area_length || ((uint64_t)buffer_len > area_length))
|
||||
return -EINVAL;
|
||||
@@ -176,42 +176,8 @@ static int reenc_keyslot_store(struct crypt_device *cd,
|
||||
return r < 0 ? r : keyslot;
|
||||
}
|
||||
|
||||
int reenc_keyslot_update(struct crypt_device *cd,
|
||||
const struct luks2_reenc_context *rh)
|
||||
{
|
||||
json_object *jobj_keyslot, *jobj_area, *jobj_area_type;
|
||||
struct luks2_hdr *hdr;
|
||||
|
||||
if (!(hdr = crypt_get_hdr(cd, CRYPT_LUKS2)))
|
||||
return -EINVAL;
|
||||
|
||||
jobj_keyslot = LUKS2_get_keyslot_jobj(hdr, rh->reenc_keyslot);
|
||||
if (!jobj_keyslot)
|
||||
return -EINVAL;
|
||||
|
||||
json_object_object_get_ex(jobj_keyslot, "area", &jobj_area);
|
||||
json_object_object_get_ex(jobj_area, "type", &jobj_area_type);
|
||||
|
||||
if (rh->rp.type == REENC_PROTECTION_CHECKSUM) {
|
||||
log_dbg(cd, "Updating reencrypt keyslot for checksum protection.");
|
||||
json_object_object_add(jobj_area, "type", json_object_new_string("checksum"));
|
||||
json_object_object_add(jobj_area, "hash", json_object_new_string(rh->rp.p.csum.hash));
|
||||
json_object_object_add(jobj_area, "sector_size", json_object_new_int64(rh->alignment));
|
||||
} else if (rh->rp.type == REENC_PROTECTION_NONE) {
|
||||
log_dbg(cd, "Updating reencrypt keyslot for none protection.");
|
||||
json_object_object_add(jobj_area, "type", json_object_new_string("none"));
|
||||
json_object_object_del(jobj_area, "hash");
|
||||
} else if (rh->rp.type == REENC_PROTECTION_JOURNAL) {
|
||||
log_dbg(cd, "Updating reencrypt keyslot for journal protection.");
|
||||
json_object_object_add(jobj_area, "type", json_object_new_string("journal"));
|
||||
json_object_object_del(jobj_area, "hash");
|
||||
} else
|
||||
log_dbg(cd, "No update of reencrypt keyslot needed.");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int reenc_keyslot_wipe(struct crypt_device *cd, int keyslot)
|
||||
static int reenc_keyslot_wipe(struct crypt_device *cd __attribute__((unused)),
|
||||
int keyslot __attribute__((unused)))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@@ -242,14 +208,14 @@ static int reenc_keyslot_dump(struct crypt_device *cd, int keyslot)
|
||||
log_std(cd, "\t%-12s%d [bytes]\n", "Hash data:", json_object_get_int(jobj1));
|
||||
} else if (!strcmp(json_object_get_string(jobj_resilience), "datashift")) {
|
||||
json_object_object_get_ex(jobj_area, "shift_size", &jobj1);
|
||||
log_std(cd, "\t%-12s%" PRIu64 "[bytes]\n", "Shift size:", json_object_get_uint64(jobj1));
|
||||
log_std(cd, "\t%-12s%" PRIu64 "[bytes]\n", "Shift size:", crypt_jobj_get_uint64(jobj1));
|
||||
}
|
||||
|
||||
json_object_object_get_ex(jobj_area, "offset", &jobj1);
|
||||
log_std(cd, "\tArea offset:%" PRIu64 " [bytes]\n", json_object_get_uint64(jobj1));
|
||||
log_std(cd, "\tArea offset:%" PRIu64 " [bytes]\n", crypt_jobj_get_uint64(jobj1));
|
||||
|
||||
json_object_object_get_ex(jobj_area, "size", &jobj1);
|
||||
log_std(cd, "\tArea length:%" PRIu64 " [bytes]\n", json_object_get_uint64(jobj1));
|
||||
log_std(cd, "\tArea length:%" PRIu64 " [bytes]\n", crypt_jobj_get_uint64(jobj1));
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -304,7 +270,7 @@ static int reenc_keyslot_validate(struct crypt_device *cd, json_object *jobj_key
|
||||
return -EINVAL;
|
||||
if (!validate_json_uint32(jobj_sector_size))
|
||||
return -EINVAL;
|
||||
sector_size = json_object_get_uint32(jobj_sector_size);
|
||||
sector_size = crypt_jobj_get_uint32(jobj_sector_size);
|
||||
if (sector_size < SECTOR_SIZE || NOTPOW2(sector_size)) {
|
||||
log_dbg(cd, "Invalid sector_size (%" PRIu32 ") for checksum resilience mode.", sector_size);
|
||||
return -EINVAL;
|
||||
@@ -313,7 +279,7 @@ static int reenc_keyslot_validate(struct crypt_device *cd, json_object *jobj_key
|
||||
if (!(jobj_shift_size = json_contains(cd, jobj_area, "type:datashift", "Keyslot area", "shift_size", json_type_string)))
|
||||
return -EINVAL;
|
||||
|
||||
shift_size = json_object_get_uint64(jobj_shift_size);
|
||||
shift_size = crypt_jobj_get_uint64(jobj_shift_size);
|
||||
if (!shift_size)
|
||||
return -EINVAL;
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
* LUKS - Linux Unified Key Setup v2, LUKS1 conversion code
|
||||
*
|
||||
* Copyright (C) 2015-2020 Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2015-2020 Ondrej Kozina
|
||||
* Copyright (C) 2015-2020 Milan Broz
|
||||
* Copyright (C) 2015-2021 Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2015-2021 Ondrej Kozina
|
||||
* Copyright (C) 2015-2021 Milan Broz
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
@@ -91,8 +91,8 @@ static int json_luks1_keyslot(const struct luks_phdr *hdr_v1, int keyslot, struc
|
||||
}
|
||||
area_size = offs_b - offs_a;
|
||||
json_object_object_add(jobj_area, "key_size", json_object_new_int(hdr_v1->keyBytes));
|
||||
json_object_object_add(jobj_area, "offset", json_object_new_uint64(offset));
|
||||
json_object_object_add(jobj_area, "size", json_object_new_uint64(area_size));
|
||||
json_object_object_add(jobj_area, "offset", crypt_jobj_new_uint64(offset));
|
||||
json_object_object_add(jobj_area, "size", crypt_jobj_new_uint64(area_size));
|
||||
json_object_object_add(keyslot_obj, "area", jobj_area);
|
||||
|
||||
*keyslot_object = keyslot_obj;
|
||||
@@ -145,7 +145,7 @@ static int json_luks1_segment(const struct luks_phdr *hdr_v1, struct json_object
|
||||
/* offset field */
|
||||
number = (uint64_t)hdr_v1->payloadOffset * SECTOR_SIZE;
|
||||
|
||||
field = json_object_new_uint64(number);
|
||||
field = crypt_jobj_new_uint64(number);
|
||||
if (!field) {
|
||||
json_object_put(segment_obj);
|
||||
return -ENOMEM;
|
||||
@@ -401,8 +401,9 @@ static int json_luks1_object(struct luks_phdr *hdr_v1, struct json_object **luks
|
||||
json_object_object_add(luks1_obj, "config", field);
|
||||
|
||||
json_size = LUKS2_HDR_16K_LEN - LUKS2_HDR_BIN_LEN;
|
||||
json_object_object_add(field, "json_size", json_object_new_uint64(json_size));
|
||||
json_object_object_add(field, "keyslots_size", json_object_new_uint64(keyslots_size));
|
||||
json_object_object_add(field, "json_size", crypt_jobj_new_uint64(json_size));
|
||||
keyslots_size -= (keyslots_size % 4096);
|
||||
json_object_object_add(field, "keyslots_size", crypt_jobj_new_uint64(keyslots_size));
|
||||
|
||||
*luks1_object = luks1_obj;
|
||||
return 0;
|
||||
@@ -418,8 +419,8 @@ static void move_keyslot_offset(json_object *jobj, int offset_add)
|
||||
UNUSED(key);
|
||||
json_object_object_get_ex(val, "area", &jobj_area);
|
||||
json_object_object_get_ex(jobj_area, "offset", &jobj2);
|
||||
offset = json_object_get_uint64(jobj2) + offset_add;
|
||||
json_object_object_add(jobj_area, "offset", json_object_new_uint64(offset));
|
||||
offset = crypt_jobj_get_uint64(jobj2) + offset_add;
|
||||
json_object_object_add(jobj_area, "offset", crypt_jobj_new_uint64(offset));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -572,7 +573,13 @@ int LUKS2_luks1_to_luks2(struct crypt_device *cd, struct luks_phdr *hdr1, struct
|
||||
* It duplicates check in LUKS2_hdr_write() but we don't want to move
|
||||
* keyslot areas in case it would fail later
|
||||
*/
|
||||
if (max_size < LUKS2_hdr_and_areas_size(hdr2->jobj)) {
|
||||
if (max_size < LUKS2_hdr_and_areas_size(hdr2)) {
|
||||
r = -EINVAL;
|
||||
goto out;
|
||||
}
|
||||
|
||||
/* check future LUKS2 metadata before moving keyslots area */
|
||||
if (LUKS2_hdr_validate(cd, hdr2->jobj, hdr2->hdr_size - LUKS2_HDR_BIN_LEN)) {
|
||||
r = -EINVAL;
|
||||
goto out;
|
||||
}
|
||||
@@ -586,6 +593,14 @@ int LUKS2_luks1_to_luks2(struct crypt_device *cd, struct luks_phdr *hdr1, struct
|
||||
// move keyslots 4k -> 32k offset
|
||||
buf_offset = 2 * LUKS2_HDR_16K_LEN;
|
||||
buf_size = luks1_size - LUKS_ALIGN_KEYSLOTS;
|
||||
|
||||
/* check future LUKS2 keyslots area is at least as large as LUKS1 keyslots area */
|
||||
if (buf_size > LUKS2_keyslots_size(hdr2)) {
|
||||
log_err(cd, _("Unable to move keyslot area. LUKS2 keyslots area too small."));
|
||||
r = -EINVAL;
|
||||
goto out;
|
||||
}
|
||||
|
||||
if ((r = move_keyslot_areas(cd, 8 * SECTOR_SIZE, buf_offset, buf_size)) < 0) {
|
||||
log_err(cd, _("Unable to move keyslot area."));
|
||||
goto out;
|
||||
@@ -660,7 +675,7 @@ static int keyslot_LUKS1_compatible(struct crypt_device *cd, struct luks2_hdr *h
|
||||
int LUKS2_luks2_to_luks1(struct crypt_device *cd, struct luks2_hdr *hdr2, struct luks_phdr *hdr1)
|
||||
{
|
||||
size_t buf_size, buf_offset;
|
||||
char cipher[LUKS_CIPHERNAME_L-1], cipher_mode[LUKS_CIPHERMODE_L-1];
|
||||
char cipher[LUKS_CIPHERNAME_L], cipher_mode[LUKS_CIPHERMODE_L];
|
||||
char digest[LUKS_DIGESTSIZE], digest_salt[LUKS_SALTSIZE];
|
||||
const char *hash;
|
||||
size_t len;
|
||||
@@ -749,7 +764,7 @@ int LUKS2_luks2_to_luks1(struct crypt_device *cd, struct luks2_hdr *hdr2, struct
|
||||
return -EINVAL;
|
||||
if (!json_object_object_get_ex(jobj_area, "offset", &jobj1))
|
||||
return -EINVAL;
|
||||
offset = json_object_get_uint64(jobj1);
|
||||
offset = crypt_jobj_get_uint64(jobj1);
|
||||
} else {
|
||||
if (LUKS2_find_area_gap(cd, hdr2, key_size, &offset, &area_length))
|
||||
return -EINVAL;
|
||||
@@ -781,7 +796,7 @@ int LUKS2_luks2_to_luks1(struct crypt_device *cd, struct luks2_hdr *hdr2, struct
|
||||
|
||||
if (!json_object_object_get_ex(jobj_kdf, "iterations", &jobj1))
|
||||
continue;
|
||||
hdr1->keyblock[i].passwordIterations = json_object_get_uint32(jobj1);
|
||||
hdr1->keyblock[i].passwordIterations = crypt_jobj_get_uint32(jobj1);
|
||||
|
||||
if (!json_object_object_get_ex(jobj_kdf, "salt", &jobj1))
|
||||
continue;
|
||||
@@ -809,8 +824,10 @@ int LUKS2_luks2_to_luks1(struct crypt_device *cd, struct luks2_hdr *hdr2, struct
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
strncpy(hdr1->cipherName, cipher, sizeof(hdr1->cipherName) - 1);
|
||||
strncpy(hdr1->cipherMode, cipher_mode, sizeof(hdr1->cipherMode) - 1);
|
||||
strncpy(hdr1->cipherName, cipher, LUKS_CIPHERNAME_L - 1);
|
||||
hdr1->cipherName[LUKS_CIPHERNAME_L-1] = '\0';
|
||||
strncpy(hdr1->cipherMode, cipher_mode, LUKS_CIPHERMODE_L - 1);
|
||||
hdr1->cipherMode[LUKS_CIPHERMODE_L-1] = '\0';
|
||||
|
||||
if (!json_object_object_get_ex(jobj_keyslot, "kdf", &jobj_kdf))
|
||||
return -EINVAL;
|
||||
@@ -822,7 +839,7 @@ int LUKS2_luks2_to_luks1(struct crypt_device *cd, struct luks2_hdr *hdr2, struct
|
||||
|
||||
if (!json_object_object_get_ex(jobj_digest, "iterations", &jobj1))
|
||||
return -EINVAL;
|
||||
hdr1->mkDigestIterations = json_object_get_uint32(jobj1);
|
||||
hdr1->mkDigestIterations = crypt_jobj_get_uint32(jobj1);
|
||||
|
||||
if (!json_object_object_get_ex(jobj_digest, "digest", &jobj1))
|
||||
return -EINVAL;
|
||||
@@ -847,7 +864,7 @@ int LUKS2_luks2_to_luks1(struct crypt_device *cd, struct luks2_hdr *hdr2, struct
|
||||
|
||||
if (!json_object_object_get_ex(jobj_segment, "offset", &jobj1))
|
||||
return -EINVAL;
|
||||
offset = json_object_get_uint64(jobj1) / SECTOR_SIZE;
|
||||
offset = crypt_jobj_get_uint64(jobj1) / SECTOR_SIZE;
|
||||
if (offset > UINT32_MAX)
|
||||
return -EINVAL;
|
||||
/* FIXME: LUKS1 requires offset == 0 || offset >= luks1_hdr_size */
|
||||
@@ -866,7 +883,7 @@ int LUKS2_luks2_to_luks1(struct crypt_device *cd, struct luks2_hdr *hdr2, struct
|
||||
|
||||
// move keyslots 32k -> 4k offset
|
||||
buf_offset = 2 * LUKS2_HDR_16K_LEN;
|
||||
buf_size = LUKS2_keyslots_size(hdr2->jobj);
|
||||
buf_size = LUKS2_keyslots_size(hdr2);
|
||||
r = move_keyslot_areas(cd, buf_offset, 8 * SECTOR_SIZE, buf_size);
|
||||
if (r < 0) {
|
||||
log_err(cd, _("Unable to move keyslot area."));
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,8 +1,8 @@
|
||||
/*
|
||||
* LUKS - Linux Unified Key Setup v2, internal segment handling
|
||||
*
|
||||
* Copyright (C) 2018-2020, Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2018-2020, Ondrej Kozina
|
||||
* Copyright (C) 2018-2021, Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2018-2021, Ondrej Kozina
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
@@ -55,7 +55,7 @@ uint64_t json_segment_get_offset(json_object *jobj_segment, unsigned blockwise)
|
||||
!json_object_object_get_ex(jobj_segment, "offset", &jobj))
|
||||
return 0;
|
||||
|
||||
return blockwise ? json_object_get_uint64(jobj) >> SECTOR_SHIFT : json_object_get_uint64(jobj);
|
||||
return blockwise ? crypt_jobj_get_uint64(jobj) >> SECTOR_SHIFT : crypt_jobj_get_uint64(jobj);
|
||||
}
|
||||
|
||||
const char *json_segment_type(json_object *jobj_segment)
|
||||
@@ -77,7 +77,7 @@ uint64_t json_segment_get_iv_offset(json_object *jobj_segment)
|
||||
!json_object_object_get_ex(jobj_segment, "iv_tweak", &jobj))
|
||||
return 0;
|
||||
|
||||
return json_object_get_uint64(jobj);
|
||||
return crypt_jobj_get_uint64(jobj);
|
||||
}
|
||||
|
||||
uint64_t json_segment_get_size(json_object *jobj_segment, unsigned blockwise)
|
||||
@@ -88,7 +88,7 @@ uint64_t json_segment_get_size(json_object *jobj_segment, unsigned blockwise)
|
||||
!json_object_object_get_ex(jobj_segment, "size", &jobj))
|
||||
return 0;
|
||||
|
||||
return blockwise ? json_object_get_uint64(jobj) >> SECTOR_SHIFT : json_object_get_uint64(jobj);
|
||||
return blockwise ? crypt_jobj_get_uint64(jobj) >> SECTOR_SHIFT : crypt_jobj_get_uint64(jobj);
|
||||
}
|
||||
|
||||
const char *json_segment_get_cipher(json_object *jobj_segment)
|
||||
@@ -229,8 +229,8 @@ static json_object *_segment_create_generic(const char *type, uint64_t offset, c
|
||||
return NULL;
|
||||
|
||||
json_object_object_add(jobj, "type", json_object_new_string(type));
|
||||
json_object_object_add(jobj, "offset", json_object_new_uint64(offset));
|
||||
json_object_object_add(jobj, "size", length ? json_object_new_uint64(*length) : json_object_new_string("dynamic"));
|
||||
json_object_object_add(jobj, "offset", crypt_jobj_new_uint64(offset));
|
||||
json_object_object_add(jobj, "size", length ? crypt_jobj_new_uint64(*length) : json_object_new_string("dynamic"));
|
||||
|
||||
return jobj;
|
||||
}
|
||||
@@ -252,7 +252,7 @@ json_object *json_segment_create_crypt(uint64_t offset,
|
||||
if (!jobj)
|
||||
return NULL;
|
||||
|
||||
json_object_object_add(jobj, "iv_tweak", json_object_new_uint64(iv_offset));
|
||||
json_object_object_add(jobj, "iv_tweak", crypt_jobj_new_uint64(iv_offset));
|
||||
json_object_object_add(jobj, "encryption", json_object_new_string(cipher));
|
||||
json_object_object_add(jobj, "sector_size", json_object_new_int(sector_size));
|
||||
if (reencryption)
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/*
|
||||
* LUKS - Linux Unified Key Setup v2, token handling
|
||||
*
|
||||
* Copyright (C) 2016-2020 Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2016-2020 Milan Broz
|
||||
* Copyright (C) 2016-2021 Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2016-2021 Milan Broz
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
@@ -19,39 +19,197 @@
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#include <ctype.h>
|
||||
#include <dlfcn.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "luks2_internal.h"
|
||||
|
||||
/* Builtin tokens */
|
||||
extern const crypt_token_handler keyring_handler;
|
||||
#if USE_EXTERNAL_TOKENS
|
||||
static bool external_tokens_enabled = true;
|
||||
#else
|
||||
static bool external_tokens_enabled = false;
|
||||
#endif
|
||||
|
||||
static token_handler token_handlers[LUKS2_TOKENS_MAX] = {
|
||||
static struct crypt_token_handler_internal token_handlers[LUKS2_TOKENS_MAX] = {
|
||||
/* keyring builtin token */
|
||||
{
|
||||
.get = token_keyring_get,
|
||||
.set = token_keyring_set,
|
||||
.h = &keyring_handler
|
||||
},
|
||||
.version = 1,
|
||||
.u = {
|
||||
.v1 = { .name = LUKS2_TOKEN_KEYRING,
|
||||
.open = keyring_open,
|
||||
.validate = keyring_validate,
|
||||
.dump = keyring_dump }
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
void crypt_token_external_disable(void)
|
||||
{
|
||||
external_tokens_enabled = false;
|
||||
}
|
||||
|
||||
const char *crypt_token_external_path(void)
|
||||
{
|
||||
return external_tokens_enabled ? EXTERNAL_LUKS2_TOKENS_PATH : NULL;
|
||||
}
|
||||
|
||||
#if USE_EXTERNAL_TOKENS
|
||||
static void *token_dlvsym(struct crypt_device *cd,
|
||||
void *handle,
|
||||
const char *symbol,
|
||||
const char *version)
|
||||
{
|
||||
char *error;
|
||||
void *sym;
|
||||
|
||||
log_dbg(cd, "Loading symbol %s@%s.", symbol, version);
|
||||
|
||||
sym = dlvsym(handle, symbol, version);
|
||||
error = dlerror();
|
||||
|
||||
if (error)
|
||||
log_dbg(cd, "%s", error);
|
||||
|
||||
return sym;
|
||||
}
|
||||
#endif
|
||||
|
||||
static bool token_validate_v1(struct crypt_device *cd, const crypt_token_handler *h)
|
||||
{
|
||||
if (!h)
|
||||
return false;
|
||||
|
||||
if (!h->name) {
|
||||
log_dbg(cd, "Error: token handler does not provide name attribute.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!h->open) {
|
||||
log_dbg(cd, "Error: token handler does not provide open function.");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#if USE_EXTERNAL_TOKENS
|
||||
static bool token_validate_v2(struct crypt_device *cd, const struct crypt_token_handler_internal *h)
|
||||
{
|
||||
if (!h)
|
||||
return false;
|
||||
|
||||
if (!token_validate_v1(cd, &h->u.v1))
|
||||
return false;
|
||||
|
||||
if (!h->u.v2.version) {
|
||||
log_dbg(cd, "Error: token handler does not provide " CRYPT_TOKEN_ABI_VERSION " function.");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool external_token_name_valid(const char *name)
|
||||
{
|
||||
if (!*name || strlen(name) > LUKS2_TOKEN_NAME_MAX)
|
||||
return false;
|
||||
|
||||
while (*name) {
|
||||
if (!isalnum(*name) && *name != '-' && *name != '_')
|
||||
return false;
|
||||
name++;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
static int
|
||||
crypt_token_load_external(struct crypt_device *cd, const char *name, struct crypt_token_handler_internal *ret)
|
||||
{
|
||||
#if USE_EXTERNAL_TOKENS
|
||||
struct crypt_token_handler_v2 *token;
|
||||
void *h;
|
||||
char buf[PATH_MAX];
|
||||
int r;
|
||||
|
||||
if (!external_tokens_enabled)
|
||||
return -ENOTSUP;
|
||||
|
||||
if (!ret || !name)
|
||||
return -EINVAL;
|
||||
|
||||
if (!external_token_name_valid(name)) {
|
||||
log_dbg(cd, "External token name (%.*s) invalid.", LUKS2_TOKEN_NAME_MAX, name);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
token = &ret->u.v2;
|
||||
|
||||
r = snprintf(buf, sizeof(buf), "%s/libcryptsetup-token-%s.so", crypt_token_external_path(), name);
|
||||
if (r < 0 || (size_t)r >= sizeof(buf))
|
||||
return -EINVAL;
|
||||
|
||||
assert(*buf == '/');
|
||||
|
||||
log_dbg(cd, "Trying to load %s.", buf);
|
||||
|
||||
h = dlopen(buf, RTLD_LAZY);
|
||||
if (!h) {
|
||||
log_dbg(cd, "%s", dlerror());
|
||||
return -EINVAL;
|
||||
}
|
||||
dlerror();
|
||||
|
||||
token->name = strdup(name);
|
||||
token->open = token_dlvsym(cd, h, CRYPT_TOKEN_ABI_OPEN, CRYPT_TOKEN_ABI_VERSION1);
|
||||
token->buffer_free = token_dlvsym(cd, h, CRYPT_TOKEN_ABI_BUFFER_FREE, CRYPT_TOKEN_ABI_VERSION1);
|
||||
token->validate = token_dlvsym(cd, h, CRYPT_TOKEN_ABI_VALIDATE, CRYPT_TOKEN_ABI_VERSION1);
|
||||
token->dump = token_dlvsym(cd, h, CRYPT_TOKEN_ABI_DUMP, CRYPT_TOKEN_ABI_VERSION1);
|
||||
token->open_pin = token_dlvsym(cd, h, CRYPT_TOKEN_ABI_OPEN_PIN, CRYPT_TOKEN_ABI_VERSION1);
|
||||
token->version = token_dlvsym(cd, h, CRYPT_TOKEN_ABI_VERSION, CRYPT_TOKEN_ABI_VERSION1);
|
||||
|
||||
if (!token_validate_v2(cd, ret)) {
|
||||
free(CONST_CAST(void *)token->name);
|
||||
dlclose(h);
|
||||
memset(token, 0, sizeof(*token));
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
/* Token loaded, possible error here means only debug message fail and can be ignored */
|
||||
r = snprintf(buf, sizeof(buf), "%s", token->version() ?: "");
|
||||
if (r < 0 || (size_t)r >= sizeof(buf))
|
||||
*buf = '\0';
|
||||
|
||||
log_dbg(cd, "Token handler %s-%s loaded successfully.", token->name, buf);
|
||||
|
||||
token->dlhandle = h;
|
||||
ret->version = 2;
|
||||
|
||||
return 0;
|
||||
#else
|
||||
return -ENOTSUP;
|
||||
#endif
|
||||
}
|
||||
|
||||
static int is_builtin_candidate(const char *type)
|
||||
{
|
||||
return !strncmp(type, LUKS2_BUILTIN_TOKEN_PREFIX, LUKS2_BUILTIN_TOKEN_PREFIX_LEN);
|
||||
}
|
||||
|
||||
int crypt_token_register(const crypt_token_handler *handler)
|
||||
static int crypt_token_find_free(struct crypt_device *cd, const char *name, int *index)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (is_builtin_candidate(handler->name)) {
|
||||
log_dbg(NULL, "'" LUKS2_BUILTIN_TOKEN_PREFIX "' is reserved prefix for builtin tokens.");
|
||||
if (is_builtin_candidate(name)) {
|
||||
log_dbg(cd, "'" LUKS2_BUILTIN_TOKEN_PREFIX "' is reserved prefix for builtin tokens.");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
for (i = 0; i < LUKS2_TOKENS_MAX && token_handlers[i].h; i++) {
|
||||
if (!strcmp(token_handlers[i].h->name, handler->name)) {
|
||||
log_dbg(NULL, "Keyslot handler %s is already registered.", handler->name);
|
||||
for (i = 0; i < LUKS2_TOKENS_MAX && token_handlers[i].u.v1.name; i++) {
|
||||
if (!strcmp(token_handlers[i].u.v1.name, name)) {
|
||||
log_dbg(cd, "Keyslot handler %s is already registered.", name);
|
||||
return -EINVAL;
|
||||
}
|
||||
}
|
||||
@@ -59,32 +217,68 @@ int crypt_token_register(const crypt_token_handler *handler)
|
||||
if (i == LUKS2_TOKENS_MAX)
|
||||
return -EINVAL;
|
||||
|
||||
token_handlers[i].h = handler;
|
||||
if (index)
|
||||
*index = i;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const token_handler
|
||||
*LUKS2_token_handler_type_internal(struct crypt_device *cd, const char *type)
|
||||
int crypt_token_register(const crypt_token_handler *handler)
|
||||
{
|
||||
int i, r;
|
||||
|
||||
if (!token_validate_v1(NULL, handler))
|
||||
return -EINVAL;
|
||||
|
||||
r = crypt_token_find_free(NULL, handler->name, &i);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
token_handlers[i].version = 1;
|
||||
token_handlers[i].u.v1 = *handler;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void crypt_token_unload_external_all(struct crypt_device *cd)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < LUKS2_TOKENS_MAX && token_handlers[i].h; i++)
|
||||
if (!strcmp(token_handlers[i].h->name, type))
|
||||
return token_handlers + i;
|
||||
for (i = LUKS2_TOKENS_MAX - 1; i >= 0; i--) {
|
||||
if (token_handlers[i].version < 2)
|
||||
continue;
|
||||
|
||||
return NULL;
|
||||
log_dbg(cd, "Unloading %s token handler.", token_handlers[i].u.v2.name);
|
||||
|
||||
free(CONST_CAST(void *)token_handlers[i].u.v2.name);
|
||||
|
||||
if (dlclose(CONST_CAST(void *)token_handlers[i].u.v2.dlhandle))
|
||||
log_dbg(cd, "%s", dlerror());
|
||||
}
|
||||
}
|
||||
|
||||
static const crypt_token_handler
|
||||
static const void
|
||||
*LUKS2_token_handler_type(struct crypt_device *cd, const char *type)
|
||||
{
|
||||
const token_handler *th = LUKS2_token_handler_type_internal(cd, type);
|
||||
int i;
|
||||
|
||||
return th ? th->h : NULL;
|
||||
for (i = 0; i < LUKS2_TOKENS_MAX && token_handlers[i].u.v1.name; i++)
|
||||
if (!strcmp(token_handlers[i].u.v1.name, type))
|
||||
return &token_handlers[i].u;
|
||||
|
||||
if (i >= LUKS2_TOKENS_MAX)
|
||||
return NULL;
|
||||
|
||||
if (is_builtin_candidate(type))
|
||||
return NULL;
|
||||
|
||||
if (crypt_token_load_external(cd, type, &token_handlers[i]))
|
||||
return NULL;
|
||||
|
||||
return &token_handlers[i].u;
|
||||
}
|
||||
|
||||
static const token_handler
|
||||
*LUKS2_token_handler_internal(struct crypt_device *cd, int token)
|
||||
static const void
|
||||
*LUKS2_token_handler(struct crypt_device *cd, int token)
|
||||
{
|
||||
struct luks2_hdr *hdr;
|
||||
json_object *jobj1, *jobj2;
|
||||
@@ -101,15 +295,7 @@ static const token_handler
|
||||
if (!json_object_object_get_ex(jobj1, "type", &jobj2))
|
||||
return NULL;
|
||||
|
||||
return LUKS2_token_handler_type_internal(cd, json_object_get_string(jobj2));
|
||||
}
|
||||
|
||||
static const crypt_token_handler
|
||||
*LUKS2_token_handler(struct crypt_device *cd, int token)
|
||||
{
|
||||
const token_handler *th = LUKS2_token_handler_internal(cd, token);
|
||||
|
||||
return th ? th->h : NULL;
|
||||
return LUKS2_token_handler_type(cd, json_object_get_string(jobj2));
|
||||
}
|
||||
|
||||
static int LUKS2_token_find_free(struct luks2_hdr *hdr)
|
||||
@@ -130,7 +316,6 @@ int LUKS2_token_create(struct crypt_device *cd,
|
||||
int commit)
|
||||
{
|
||||
const crypt_token_handler *h;
|
||||
const token_handler *th;
|
||||
json_object *jobj_tokens, *jobj_type, *jobj;
|
||||
enum json_tokener_error jerr;
|
||||
char num[16];
|
||||
@@ -147,7 +332,8 @@ int LUKS2_token_create(struct crypt_device *cd,
|
||||
if (!json_object_object_get_ex(hdr->jobj, "tokens", &jobj_tokens))
|
||||
return -EINVAL;
|
||||
|
||||
snprintf(num, sizeof(num), "%d", token);
|
||||
if (snprintf(num, sizeof(num), "%d", token) < 0)
|
||||
return -EINVAL;
|
||||
|
||||
/* Remove token */
|
||||
if (!json)
|
||||
@@ -166,16 +352,14 @@ int LUKS2_token_create(struct crypt_device *cd,
|
||||
}
|
||||
|
||||
json_object_object_get_ex(jobj, "type", &jobj_type);
|
||||
if (is_builtin_candidate(json_object_get_string(jobj_type))) {
|
||||
th = LUKS2_token_handler_type_internal(cd, json_object_get_string(jobj_type));
|
||||
if (!th || !th->set) {
|
||||
log_dbg(cd, "%s is builtin token candidate with missing handler", json_object_get_string(jobj_type));
|
||||
json_object_put(jobj);
|
||||
return -EINVAL;
|
||||
}
|
||||
h = th->h;
|
||||
} else
|
||||
h = LUKS2_token_handler_type(cd, json_object_get_string(jobj_type));
|
||||
h = LUKS2_token_handler_type(cd, json_object_get_string(jobj_type));
|
||||
|
||||
if (is_builtin_candidate(json_object_get_string(jobj_type)) && !h) {
|
||||
log_dbg(cd, "%s is builtin token candidate with missing handler",
|
||||
json_object_get_string(jobj_type));
|
||||
json_object_put(jobj);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (h && h->validate && h->validate(cd, json)) {
|
||||
json_object_put(jobj);
|
||||
@@ -203,7 +387,7 @@ crypt_token_info LUKS2_token_status(struct crypt_device *cd,
|
||||
const char **type)
|
||||
{
|
||||
const char *tmp;
|
||||
const token_handler *th;
|
||||
const crypt_token_handler *th;
|
||||
json_object *jobj_type, *jobj_token;
|
||||
|
||||
if (token < 0 || token >= LUKS2_TOKENS_MAX)
|
||||
@@ -215,10 +399,10 @@ crypt_token_info LUKS2_token_status(struct crypt_device *cd,
|
||||
json_object_object_get_ex(jobj_token, "type", &jobj_type);
|
||||
tmp = json_object_get_string(jobj_type);
|
||||
|
||||
if ((th = LUKS2_token_handler_type_internal(cd, tmp))) {
|
||||
if ((th = LUKS2_token_handler_type(cd, tmp))) {
|
||||
if (type)
|
||||
*type = th->h->name;
|
||||
return th->set ? CRYPT_TOKEN_INTERNAL : CRYPT_TOKEN_EXTERNAL;
|
||||
*type = th->name;
|
||||
return is_builtin_candidate(tmp) ? CRYPT_TOKEN_INTERNAL : CRYPT_TOKEN_EXTERNAL;
|
||||
}
|
||||
|
||||
if (type)
|
||||
@@ -227,95 +411,109 @@ crypt_token_info LUKS2_token_status(struct crypt_device *cd,
|
||||
return is_builtin_candidate(tmp) ? CRYPT_TOKEN_INTERNAL_UNKNOWN : CRYPT_TOKEN_EXTERNAL_UNKNOWN;
|
||||
}
|
||||
|
||||
int LUKS2_builtin_token_get(struct crypt_device *cd,
|
||||
struct luks2_hdr *hdr,
|
||||
int token,
|
||||
const char *type,
|
||||
void *params)
|
||||
static const char *token_json_to_string(json_object *jobj_token)
|
||||
{
|
||||
const token_handler *th = LUKS2_token_handler_type_internal(cd, type);
|
||||
|
||||
// internal error
|
||||
assert(th && th->get);
|
||||
|
||||
return th->get(LUKS2_get_token_jobj(hdr, token), params) ?: token;
|
||||
return json_object_to_json_string_ext(jobj_token,
|
||||
JSON_C_TO_STRING_PLAIN | JSON_C_TO_STRING_NOSLASHESCAPE);
|
||||
}
|
||||
|
||||
int LUKS2_builtin_token_create(struct crypt_device *cd,
|
||||
struct luks2_hdr *hdr,
|
||||
int token,
|
||||
const char *type,
|
||||
const void *params,
|
||||
int commit)
|
||||
static int token_is_usable(struct luks2_hdr *hdr, json_object *jobj_token, int segment, crypt_keyslot_priority minimal_priority)
|
||||
{
|
||||
const token_handler *th;
|
||||
int r;
|
||||
json_object *jobj_token, *jobj_tokens;
|
||||
crypt_keyslot_priority keyslot_priority;
|
||||
json_object *jobj_array;
|
||||
int i, keyslot, len, r = -ENOENT;
|
||||
|
||||
th = LUKS2_token_handler_type_internal(cd, type);
|
||||
|
||||
// at this point all builtin handlers must exist and have validate fn defined
|
||||
assert(th && th->set && th->h->validate);
|
||||
|
||||
if (token == CRYPT_ANY_TOKEN) {
|
||||
if ((token = LUKS2_token_find_free(hdr)) < 0)
|
||||
log_err(cd, _("No free token slot."));
|
||||
}
|
||||
if (token < 0 || token >= LUKS2_TOKENS_MAX)
|
||||
if (!jobj_token)
|
||||
return -EINVAL;
|
||||
|
||||
r = th->set(&jobj_token, params);
|
||||
if (r) {
|
||||
log_err(cd, _("Failed to create builtin token %s."), type);
|
||||
return r;
|
||||
if (!json_object_object_get_ex(jobj_token, "keyslots", &jobj_array))
|
||||
return -EINVAL;
|
||||
|
||||
if (segment < 0 && segment != CRYPT_ANY_SEGMENT)
|
||||
return -EINVAL;
|
||||
|
||||
/* no assigned keyslot returns -ENOENT even for CRYPT_ANY_SEGMENT */
|
||||
len = json_object_array_length(jobj_array);
|
||||
if (len <= 0)
|
||||
return -ENOENT;
|
||||
|
||||
for (i = 0; i < len; i++) {
|
||||
keyslot = atoi(json_object_get_string(json_object_array_get_idx(jobj_array, i)));
|
||||
|
||||
keyslot_priority = LUKS2_keyslot_priority_get(NULL, hdr, keyslot);
|
||||
if (keyslot_priority == CRYPT_SLOT_PRIORITY_INVALID)
|
||||
return -EINVAL;
|
||||
|
||||
if (keyslot_priority < minimal_priority)
|
||||
continue;
|
||||
|
||||
r = LUKS2_keyslot_for_segment(hdr, keyslot, segment);
|
||||
if (r != -ENOENT)
|
||||
return r;
|
||||
}
|
||||
|
||||
// builtin tokens must produce valid json
|
||||
r = LUKS2_token_validate(cd, hdr->jobj, jobj_token, "new");
|
||||
assert(!r);
|
||||
r = th->h->validate(cd, json_object_to_json_string_ext(jobj_token,
|
||||
JSON_C_TO_STRING_PLAIN | JSON_C_TO_STRING_NOSLASHESCAPE));
|
||||
assert(!r);
|
||||
return r;
|
||||
}
|
||||
|
||||
json_object_object_get_ex(hdr->jobj, "tokens", &jobj_tokens);
|
||||
json_object_object_add_by_uint(jobj_tokens, token, jobj_token);
|
||||
if (LUKS2_check_json_size(cd, hdr)) {
|
||||
log_dbg(cd, "Not enough space in header json area for new %s token.", type);
|
||||
json_object_object_del_by_uint(jobj_tokens, token);
|
||||
return -ENOSPC;
|
||||
static int translate_errno(struct crypt_device *cd, int ret_val, const char *type)
|
||||
{
|
||||
if ((ret_val > 0 || ret_val == -EINVAL || ret_val == -EPERM) && !is_builtin_candidate(type)) {
|
||||
log_dbg(cd, "%s token handler returned %d. Changing to %d.", type, ret_val, -ENOENT);
|
||||
ret_val = -ENOENT;
|
||||
}
|
||||
|
||||
if (commit)
|
||||
return LUKS2_hdr_write(cd, hdr) ?: token;
|
||||
|
||||
return token;
|
||||
return ret_val;
|
||||
}
|
||||
|
||||
static int LUKS2_token_open(struct crypt_device *cd,
|
||||
struct luks2_hdr *hdr,
|
||||
int token,
|
||||
json_object *jobj_token,
|
||||
const char *type,
|
||||
int segment,
|
||||
crypt_keyslot_priority priority,
|
||||
const char *pin,
|
||||
size_t pin_size,
|
||||
char **buffer,
|
||||
size_t *buffer_len,
|
||||
void *usrptr)
|
||||
{
|
||||
const char *json;
|
||||
const crypt_token_handler *h;
|
||||
const struct crypt_token_handler_v2 *h;
|
||||
json_object *jobj_type;
|
||||
int r;
|
||||
|
||||
assert(token >= 0);
|
||||
assert(jobj_token);
|
||||
assert(priority >= 0);
|
||||
|
||||
if (type) {
|
||||
if (!json_object_object_get_ex(jobj_token, "type", &jobj_type))
|
||||
return -EINVAL;
|
||||
if (strcmp(type, json_object_get_string(jobj_type)))
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
r = token_is_usable(hdr, jobj_token, segment, priority);
|
||||
if (r < 0) {
|
||||
if (r == -ENOENT)
|
||||
log_dbg(cd, "Token %d unusable for segment %d with desired keyslot priority %d.", token, segment, priority);
|
||||
return r;
|
||||
}
|
||||
|
||||
if (!(h = LUKS2_token_handler(cd, token)))
|
||||
return -ENOENT;
|
||||
|
||||
if (h->validate) {
|
||||
if (LUKS2_token_json_get(cd, hdr, token, &json))
|
||||
return -EINVAL;
|
||||
|
||||
if (h->validate(cd, json)) {
|
||||
log_dbg(cd, "Token %d (%s) validation failed.", token, h->name);
|
||||
return -EINVAL;
|
||||
}
|
||||
if (h->validate && h->validate(cd, token_json_to_string(jobj_token))) {
|
||||
log_dbg(cd, "Token %d (%s) validation failed.", token, h->name);
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
r = h->open(cd, token, buffer, buffer_len, usrptr);
|
||||
if (pin && !h->open_pin)
|
||||
r = -ENOENT;
|
||||
else if (pin)
|
||||
r = translate_errno(cd, h->open_pin(cd, token, pin, pin_size, buffer, buffer_len, usrptr), h->name);
|
||||
else
|
||||
r = translate_errno(cd, h->open(cd, token, buffer, buffer_len, usrptr), h->name);
|
||||
if (r < 0)
|
||||
log_dbg(cd, "Token %d (%s) open failed with %d.", token, h->name, r);
|
||||
|
||||
@@ -329,7 +527,7 @@ static void LUKS2_token_buffer_free(struct crypt_device *cd,
|
||||
{
|
||||
const crypt_token_handler *h = LUKS2_token_handler(cd, token);
|
||||
|
||||
if (h->buffer_free)
|
||||
if (h && h->buffer_free)
|
||||
h->buffer_free(buffer, buffer_len);
|
||||
else {
|
||||
crypt_safe_memzero(buffer, buffer_len);
|
||||
@@ -337,121 +535,216 @@ static void LUKS2_token_buffer_free(struct crypt_device *cd,
|
||||
}
|
||||
}
|
||||
|
||||
static bool break_loop_retval(int r)
|
||||
{
|
||||
if (r == -ENOENT || r == -EPERM || r == -EAGAIN || r == -ENOANO)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
static void update_return_errno(int r, int *stored)
|
||||
{
|
||||
if (*stored == -ENOANO)
|
||||
return;
|
||||
else if (r == -ENOANO)
|
||||
*stored = r;
|
||||
else if (r == -EAGAIN && *stored != -ENOANO)
|
||||
*stored = r;
|
||||
else if (r == -EPERM && (*stored != -ENOANO && *stored != -EAGAIN))
|
||||
*stored = r;
|
||||
}
|
||||
|
||||
static int LUKS2_keyslot_open_by_token(struct crypt_device *cd,
|
||||
struct luks2_hdr *hdr,
|
||||
int token,
|
||||
int segment,
|
||||
crypt_keyslot_priority priority,
|
||||
const char *buffer,
|
||||
size_t buffer_len,
|
||||
struct volume_key **vk)
|
||||
{
|
||||
const crypt_token_handler *h;
|
||||
json_object *jobj_token, *jobj_token_keyslots, *jobj;
|
||||
crypt_keyslot_priority keyslot_priority;
|
||||
json_object *jobj_token, *jobj_token_keyslots, *jobj_type, *jobj;
|
||||
unsigned int num = 0;
|
||||
int i, r;
|
||||
|
||||
if (!(h = LUKS2_token_handler(cd, token)))
|
||||
return -ENOENT;
|
||||
int i, r = -ENOENT, stored_retval = -ENOENT;
|
||||
|
||||
jobj_token = LUKS2_get_token_jobj(hdr, token);
|
||||
if (!jobj_token)
|
||||
return -EINVAL;
|
||||
|
||||
if (!json_object_object_get_ex(jobj_token, "type", &jobj_type))
|
||||
return -EINVAL;
|
||||
|
||||
json_object_object_get_ex(jobj_token, "keyslots", &jobj_token_keyslots);
|
||||
if (!jobj_token_keyslots)
|
||||
return -EINVAL;
|
||||
|
||||
/* Try to open keyslot referenced in token */
|
||||
r = -EINVAL;
|
||||
for (i = 0; i < (int) json_object_array_length(jobj_token_keyslots) && r < 0; i++) {
|
||||
jobj = json_object_array_get_idx(jobj_token_keyslots, i);
|
||||
num = atoi(json_object_get_string(jobj));
|
||||
log_dbg(cd, "Trying to open keyslot %u with token %d (type %s).", num, token, h->name);
|
||||
keyslot_priority = LUKS2_keyslot_priority_get(NULL, hdr, num);
|
||||
if (keyslot_priority == CRYPT_SLOT_PRIORITY_INVALID)
|
||||
return -EINVAL;
|
||||
if (keyslot_priority < priority)
|
||||
continue;
|
||||
log_dbg(cd, "Trying to open keyslot %u with token %d (type %s).", num, token, json_object_get_string(jobj_type));
|
||||
r = LUKS2_keyslot_open(cd, num, segment, buffer, buffer_len, vk);
|
||||
/* short circuit on fatal error */
|
||||
if (r < 0 && r != -EPERM && r != -ENOENT)
|
||||
return r;
|
||||
/* save -EPERM in case no other keyslot is usable */
|
||||
if (r == -EPERM)
|
||||
stored_retval = r;
|
||||
}
|
||||
|
||||
if (r < 0)
|
||||
return r;
|
||||
return stored_retval;
|
||||
|
||||
return num;
|
||||
}
|
||||
|
||||
int LUKS2_token_open_and_activate(struct crypt_device *cd,
|
||||
struct luks2_hdr *hdr,
|
||||
int token,
|
||||
const char *name,
|
||||
uint32_t flags,
|
||||
void *usrptr)
|
||||
static bool token_is_blocked(int token, uint32_t *block_list)
|
||||
{
|
||||
int keyslot, r;
|
||||
char *buffer;
|
||||
size_t buffer_len;
|
||||
struct volume_key *vk = NULL;
|
||||
/* it is safe now, but have assert in case LUKS2_TOKENS_MAX grows */
|
||||
assert(token >= 0 && (size_t)token < BITFIELD_SIZE(block_list));
|
||||
|
||||
r = LUKS2_token_open(cd, hdr, token, &buffer, &buffer_len, usrptr);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = LUKS2_keyslot_open_by_token(cd, hdr, token,
|
||||
(flags & CRYPT_ACTIVATE_ALLOW_UNBOUND_KEY) ?
|
||||
CRYPT_ANY_SEGMENT : CRYPT_DEFAULT_SEGMENT,
|
||||
buffer, buffer_len, &vk);
|
||||
|
||||
LUKS2_token_buffer_free(cd, token, buffer, buffer_len);
|
||||
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
keyslot = r;
|
||||
|
||||
if ((name || (flags & CRYPT_ACTIVATE_KEYRING_KEY)) && crypt_use_keyring_for_vk(cd)) {
|
||||
if (!(r = LUKS2_volume_key_load_in_keyring_by_keyslot(cd, hdr, vk, keyslot)))
|
||||
flags |= CRYPT_ACTIVATE_KEYRING_KEY;
|
||||
}
|
||||
|
||||
if (r >= 0 && name)
|
||||
r = LUKS2_activate(cd, name, vk, flags);
|
||||
|
||||
if (r < 0)
|
||||
crypt_drop_keyring_key(cd, vk);
|
||||
crypt_free_volume_key(vk);
|
||||
|
||||
return r < 0 ? r : keyslot;
|
||||
return (*block_list & (1 << token));
|
||||
}
|
||||
|
||||
int LUKS2_token_open_and_activate_any(struct crypt_device *cd,
|
||||
static void token_block(int token, uint32_t *block_list)
|
||||
{
|
||||
/* it is safe now, but have assert in case LUKS2_TOKENS_MAX grows */
|
||||
assert(token >= 0 && (size_t)token < BITFIELD_SIZE(block_list));
|
||||
|
||||
*block_list |= (1 << token);
|
||||
}
|
||||
|
||||
static int token_open_priority(struct crypt_device *cd,
|
||||
struct luks2_hdr *hdr,
|
||||
const char *name,
|
||||
uint32_t flags)
|
||||
json_object *jobj_tokens,
|
||||
const char *type,
|
||||
int segment,
|
||||
crypt_keyslot_priority priority,
|
||||
const char *pin,
|
||||
size_t pin_size,
|
||||
void *usrptr,
|
||||
int *stored_retval,
|
||||
uint32_t *block_list,
|
||||
struct volume_key **vk)
|
||||
{
|
||||
char *buffer;
|
||||
json_object *tokens_jobj;
|
||||
size_t buffer_len;
|
||||
int keyslot, token, r = -EINVAL;
|
||||
size_t buffer_size;
|
||||
int token, r;
|
||||
|
||||
assert(stored_retval);
|
||||
assert(block_list);
|
||||
|
||||
json_object_object_foreach(jobj_tokens, slot, val) {
|
||||
token = atoi(slot);
|
||||
if (token_is_blocked(token, block_list))
|
||||
continue;
|
||||
r = LUKS2_token_open(cd, hdr, token, val, type, segment, priority, pin, pin_size, &buffer, &buffer_size, usrptr);
|
||||
if (!r) {
|
||||
r = LUKS2_keyslot_open_by_token(cd, hdr, token, segment, priority,
|
||||
buffer, buffer_size, vk);
|
||||
LUKS2_token_buffer_free(cd, token, buffer, buffer_size);
|
||||
}
|
||||
|
||||
if (r == -ENOANO)
|
||||
token_block(token, block_list);
|
||||
|
||||
if (break_loop_retval(r))
|
||||
return r;
|
||||
|
||||
update_return_errno(r, stored_retval);
|
||||
}
|
||||
|
||||
return *stored_retval;
|
||||
}
|
||||
|
||||
static int token_open_any(struct crypt_device *cd, struct luks2_hdr *hdr, const char *type, int segment, const char *pin, size_t pin_size, void *usrptr, struct volume_key **vk)
|
||||
{
|
||||
json_object *jobj_tokens;
|
||||
int r, retval = -ENOENT;
|
||||
uint32_t blocked = 0; /* bitmap with tokens blocked from loop by returning -ENOANO (wrong/missing pin) */
|
||||
|
||||
json_object_object_get_ex(hdr->jobj, "tokens", &jobj_tokens);
|
||||
|
||||
/* passing usrptr for CRYPT_ANY_TOKEN does not make sense without specific type */
|
||||
if (!type)
|
||||
usrptr = NULL;
|
||||
|
||||
r = token_open_priority(cd, hdr, jobj_tokens, type, segment, CRYPT_SLOT_PRIORITY_PREFER, pin, pin_size, usrptr, &retval, &blocked, vk);
|
||||
if (break_loop_retval(r))
|
||||
return r;
|
||||
|
||||
return token_open_priority(cd, hdr, jobj_tokens, type, segment, CRYPT_SLOT_PRIORITY_NORMAL, pin, pin_size, usrptr, &retval, &blocked, vk);
|
||||
}
|
||||
|
||||
int LUKS2_token_open_and_activate(struct crypt_device *cd,
|
||||
struct luks2_hdr *hdr,
|
||||
int token,
|
||||
const char *name,
|
||||
const char *type,
|
||||
const char *pin,
|
||||
size_t pin_size,
|
||||
uint32_t flags,
|
||||
void *usrptr)
|
||||
{
|
||||
bool use_keyring;
|
||||
char *buffer;
|
||||
size_t buffer_size;
|
||||
json_object *jobj_token;
|
||||
int keyslot, segment, r = -ENOENT;
|
||||
struct volume_key *vk = NULL;
|
||||
|
||||
json_object_object_get_ex(hdr->jobj, "tokens", &tokens_jobj);
|
||||
|
||||
json_object_object_foreach(tokens_jobj, slot, val) {
|
||||
UNUSED(val);
|
||||
token = atoi(slot);
|
||||
|
||||
r = LUKS2_token_open(cd, hdr, token, &buffer, &buffer_len, NULL);
|
||||
if (r < 0)
|
||||
continue;
|
||||
|
||||
r = LUKS2_keyslot_open_by_token(cd, hdr, token,
|
||||
(flags & CRYPT_ACTIVATE_ALLOW_UNBOUND_KEY) ?
|
||||
CRYPT_ANY_SEGMENT : CRYPT_DEFAULT_SEGMENT,
|
||||
buffer, buffer_len, &vk);
|
||||
LUKS2_token_buffer_free(cd, token, buffer, buffer_len);
|
||||
if (r >= 0)
|
||||
break;
|
||||
if (flags & CRYPT_ACTIVATE_ALLOW_UNBOUND_KEY)
|
||||
segment = CRYPT_ANY_SEGMENT;
|
||||
else {
|
||||
segment = LUKS2_get_default_segment(hdr);
|
||||
if (segment < 0)
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (token >= 0 && token < LUKS2_TOKENS_MAX) {
|
||||
if ((jobj_token = LUKS2_get_token_jobj(hdr, token))) {
|
||||
r = LUKS2_token_open(cd, hdr, token, jobj_token, type, segment, CRYPT_SLOT_PRIORITY_IGNORE, pin, pin_size, &buffer, &buffer_size, usrptr);
|
||||
if (!r) {
|
||||
r = LUKS2_keyslot_open_by_token(cd, hdr, token, segment, CRYPT_SLOT_PRIORITY_IGNORE,
|
||||
buffer, buffer_size, &vk);
|
||||
LUKS2_token_buffer_free(cd, token, buffer, buffer_size);
|
||||
}
|
||||
}
|
||||
} else if (token == CRYPT_ANY_TOKEN)
|
||||
/*
|
||||
* return priorities (ordered form least to most significant):
|
||||
* ENOENT - unusable for activation (no token handler, invalid token metadata, not assigned to volume segment, etc)
|
||||
* EPERM - usable but token provided passphrase did not not unlock any assigned keyslot
|
||||
* EAGAIN - usable but not ready (token HW is missing)
|
||||
* ENOANO - ready, but token pin is wrong or missing
|
||||
*
|
||||
* success (>= 0) or any other negative errno short-circuits token activation loop
|
||||
* immediately
|
||||
*/
|
||||
r = token_open_any(cd, hdr, type, segment, pin, pin_size, usrptr, &vk);
|
||||
else
|
||||
return -EINVAL;
|
||||
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
assert(vk);
|
||||
|
||||
keyslot = r;
|
||||
|
||||
if (r >= 0 && (name || (flags & CRYPT_ACTIVATE_KEYRING_KEY)) && crypt_use_keyring_for_vk(cd)) {
|
||||
if (!crypt_use_keyring_for_vk(cd))
|
||||
use_keyring = false;
|
||||
else
|
||||
use_keyring = ((name && !crypt_is_cipher_null(crypt_get_cipher(cd))) ||
|
||||
(flags & CRYPT_ACTIVATE_KEYRING_KEY));
|
||||
|
||||
if (use_keyring) {
|
||||
if (!(r = LUKS2_volume_key_load_in_keyring_by_keyslot(cd, hdr, vk, keyslot)))
|
||||
flags |= CRYPT_ACTIVATE_KEYRING_KEY;
|
||||
}
|
||||
@@ -480,7 +773,7 @@ void LUKS2_token_dump(struct crypt_device *cd, int token)
|
||||
}
|
||||
}
|
||||
|
||||
int LUKS2_token_json_get(struct crypt_device *cd, struct luks2_hdr *hdr,
|
||||
int LUKS2_token_json_get(struct crypt_device *cd __attribute__((unused)), struct luks2_hdr *hdr,
|
||||
int token, const char **json)
|
||||
{
|
||||
json_object *jobj_token;
|
||||
@@ -489,8 +782,7 @@ int LUKS2_token_json_get(struct crypt_device *cd, struct luks2_hdr *hdr,
|
||||
if (!jobj_token)
|
||||
return -EINVAL;
|
||||
|
||||
*json = json_object_to_json_string_ext(jobj_token,
|
||||
JSON_C_TO_STRING_PLAIN | JSON_C_TO_STRING_NOSLASHESCAPE);
|
||||
*json = token_json_to_string(jobj_token);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -510,7 +802,9 @@ static int assign_one_keyslot(struct crypt_device *cd, struct luks2_hdr *hdr,
|
||||
if (!jobj_token_keyslots)
|
||||
return -EINVAL;
|
||||
|
||||
snprintf(num, sizeof(num), "%d", keyslot);
|
||||
if (snprintf(num, sizeof(num), "%d", keyslot) < 0)
|
||||
return -EINVAL;
|
||||
|
||||
if (assign) {
|
||||
jobj1 = LUKS2_array_jobj(jobj_token_keyslots, num);
|
||||
if (!jobj1)
|
||||
@@ -569,23 +863,18 @@ int LUKS2_token_assign(struct crypt_device *cd, struct luks2_hdr *hdr,
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
// FIXME: do not write header in nothing changed
|
||||
if (commit)
|
||||
return LUKS2_hdr_write(cd, hdr) ?: token;
|
||||
|
||||
return token;
|
||||
}
|
||||
|
||||
int LUKS2_token_is_assigned(struct crypt_device *cd, struct luks2_hdr *hdr,
|
||||
int keyslot, int token)
|
||||
static int token_is_assigned(struct luks2_hdr *hdr, int keyslot, int token)
|
||||
{
|
||||
int i;
|
||||
json_object *jobj_token, *jobj_token_keyslots, *jobj;
|
||||
json_object *jobj, *jobj_token_keyslots,
|
||||
*jobj_token = LUKS2_get_token_jobj(hdr, token);
|
||||
|
||||
if (keyslot < 0 || keyslot >= LUKS2_KEYSLOTS_MAX || token < 0 || token >= LUKS2_TOKENS_MAX)
|
||||
return -EINVAL;
|
||||
|
||||
jobj_token = LUKS2_get_token_jobj(hdr, token);
|
||||
if (!jobj_token)
|
||||
return -ENOENT;
|
||||
|
||||
@@ -600,6 +889,15 @@ int LUKS2_token_is_assigned(struct crypt_device *cd, struct luks2_hdr *hdr,
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
int LUKS2_token_is_assigned(struct crypt_device *cd __attribute__((unused)), struct luks2_hdr *hdr,
|
||||
int keyslot, int token)
|
||||
{
|
||||
if (keyslot < 0 || keyslot >= LUKS2_KEYSLOTS_MAX || token < 0 || token >= LUKS2_TOKENS_MAX)
|
||||
return -EINVAL;
|
||||
|
||||
return token_is_assigned(hdr, keyslot, token);
|
||||
}
|
||||
|
||||
int LUKS2_tokens_count(struct luks2_hdr *hdr)
|
||||
{
|
||||
json_object *jobj_tokens = LUKS2_get_tokens_jobj(hdr);
|
||||
@@ -608,3 +906,28 @@ int LUKS2_tokens_count(struct luks2_hdr *hdr)
|
||||
|
||||
return json_object_object_length(jobj_tokens);
|
||||
}
|
||||
|
||||
int LUKS2_token_assignment_copy(struct crypt_device *cd,
|
||||
struct luks2_hdr *hdr,
|
||||
int keyslot_from,
|
||||
int keyslot_to,
|
||||
int commit)
|
||||
{
|
||||
int i, r;
|
||||
|
||||
if (keyslot_from < 0 || keyslot_from >= LUKS2_KEYSLOTS_MAX || keyslot_to < 0 || keyslot_to >= LUKS2_KEYSLOTS_MAX)
|
||||
return -EINVAL;
|
||||
|
||||
r = LUKS2_tokens_count(hdr);
|
||||
if (r <= 0)
|
||||
return r;
|
||||
|
||||
for (i = 0; i < LUKS2_TOKENS_MAX; i++) {
|
||||
if (!token_is_assigned(hdr, keyslot_from, i)) {
|
||||
if ((r = assign_one_token(cd, hdr, keyslot_to, i, 1)))
|
||||
return r;
|
||||
}
|
||||
}
|
||||
|
||||
return commit ? LUKS2_hdr_write(cd, hdr) : 0;
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/*
|
||||
* LUKS - Linux Unified Key Setup v2, kernel keyring token
|
||||
*
|
||||
* Copyright (C) 2016-2020 Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2016-2020 Ondrej Kozina
|
||||
* Copyright (C) 2016-2021 Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2016-2021 Ondrej Kozina
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
@@ -23,7 +23,7 @@
|
||||
|
||||
#include "luks2_internal.h"
|
||||
|
||||
static int keyring_open(struct crypt_device *cd,
|
||||
int keyring_open(struct crypt_device *cd,
|
||||
int token,
|
||||
char **buffer,
|
||||
size_t *buffer_len,
|
||||
@@ -45,16 +45,16 @@ static int keyring_open(struct crypt_device *cd,
|
||||
r = keyring_get_passphrase(json_object_get_string(jobj_key), buffer, buffer_len);
|
||||
if (r == -ENOTSUP) {
|
||||
log_dbg(cd, "Kernel keyring features disabled.");
|
||||
return -EINVAL;
|
||||
return -ENOENT;
|
||||
} else if (r < 0) {
|
||||
log_dbg(cd, "keyring_get_passphrase failed (error %d)", r);
|
||||
return -EINVAL;
|
||||
return -EPERM;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int keyring_validate(struct crypt_device *cd __attribute__((unused)),
|
||||
int keyring_validate(struct crypt_device *cd __attribute__((unused)),
|
||||
const char *json)
|
||||
{
|
||||
enum json_tokener_error jerr;
|
||||
@@ -92,7 +92,7 @@ out:
|
||||
return r;
|
||||
}
|
||||
|
||||
static void keyring_dump(struct crypt_device *cd, const char *json)
|
||||
void keyring_dump(struct crypt_device *cd, const char *json)
|
||||
{
|
||||
enum json_tokener_error jerr;
|
||||
json_object *jobj_token, *jobj_key;
|
||||
@@ -111,47 +111,25 @@ static void keyring_dump(struct crypt_device *cd, const char *json)
|
||||
json_object_put(jobj_token);
|
||||
}
|
||||
|
||||
int token_keyring_set(json_object **jobj_builtin_token,
|
||||
const void *params)
|
||||
int LUKS2_token_keyring_json(char *buffer, size_t buffer_size,
|
||||
const struct crypt_token_params_luks2_keyring *keyring_params)
|
||||
{
|
||||
json_object *jobj_token, *jobj;
|
||||
const struct crypt_token_params_luks2_keyring *keyring_params = (const struct crypt_token_params_luks2_keyring *) params;
|
||||
int r;
|
||||
|
||||
jobj_token = json_object_new_object();
|
||||
if (!jobj_token)
|
||||
return -ENOMEM;
|
||||
r = snprintf(buffer, buffer_size, "{ \"type\": \"%s\", \"keyslots\":[],\"key_description\":\"%s\"}",
|
||||
LUKS2_TOKEN_KEYRING, keyring_params->key_description);
|
||||
if (r < 0 || (size_t)r >= buffer_size)
|
||||
return -EINVAL;
|
||||
|
||||
jobj = json_object_new_string(LUKS2_TOKEN_KEYRING);
|
||||
if (!jobj) {
|
||||
json_object_put(jobj_token);
|
||||
return -ENOMEM;
|
||||
}
|
||||
json_object_object_add(jobj_token, "type", jobj);
|
||||
|
||||
jobj = json_object_new_array();
|
||||
if (!jobj) {
|
||||
json_object_put(jobj_token);
|
||||
return -ENOMEM;
|
||||
}
|
||||
json_object_object_add(jobj_token, "keyslots", jobj);
|
||||
|
||||
jobj = json_object_new_string(keyring_params->key_description);
|
||||
if (!jobj) {
|
||||
json_object_put(jobj_token);
|
||||
return -ENOMEM;
|
||||
}
|
||||
json_object_object_add(jobj_token, "key_description", jobj);
|
||||
|
||||
*jobj_builtin_token = jobj_token;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int token_keyring_get(json_object *jobj_token,
|
||||
void *params)
|
||||
int LUKS2_token_keyring_get(struct crypt_device *cd __attribute__((unused)), struct luks2_hdr *hdr,
|
||||
int token, struct crypt_token_params_luks2_keyring *keyring_params)
|
||||
{
|
||||
json_object *jobj;
|
||||
struct crypt_token_params_luks2_keyring *keyring_params = (struct crypt_token_params_luks2_keyring *) params;
|
||||
json_object *jobj_token, *jobj;
|
||||
|
||||
jobj_token = LUKS2_get_token_jobj(hdr, token);
|
||||
json_object_object_get_ex(jobj_token, "type", &jobj);
|
||||
assert(!strcmp(json_object_get_string(jobj), LUKS2_TOKEN_KEYRING));
|
||||
|
||||
@@ -159,12 +137,5 @@ int token_keyring_get(json_object *jobj_token,
|
||||
|
||||
keyring_params->key_description = json_object_get_string(jobj);
|
||||
|
||||
return 0;
|
||||
return token;
|
||||
}
|
||||
|
||||
const crypt_token_handler keyring_handler = {
|
||||
.name = LUKS2_TOKEN_KEYRING,
|
||||
.open = keyring_open,
|
||||
.validate = keyring_validate,
|
||||
.dump = keyring_dump
|
||||
};
|
||||
|
||||
13
lib/random.c
13
lib/random.c
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* cryptsetup kernel RNG access functions
|
||||
*
|
||||
* Copyright (C) 2010-2020 Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2010-2021 Red Hat, Inc. All rights reserved.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
@@ -20,7 +20,6 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <assert.h>
|
||||
#include <sys/select.h>
|
||||
@@ -28,10 +27,6 @@
|
||||
#include "libcryptsetup.h"
|
||||
#include "internal.h"
|
||||
|
||||
#ifndef O_CLOEXEC
|
||||
#define O_CLOEXEC 0
|
||||
#endif
|
||||
|
||||
static int random_initialised = 0;
|
||||
|
||||
#define URANDOM_DEVICE "/dev/urandom"
|
||||
@@ -158,20 +153,20 @@ int crypt_random_init(struct crypt_device *ctx)
|
||||
if(urandom_fd == -1)
|
||||
urandom_fd = open(URANDOM_DEVICE, O_RDONLY | O_CLOEXEC);
|
||||
if(urandom_fd == -1)
|
||||
goto fail;
|
||||
goto err;
|
||||
|
||||
/* Used for CRYPT_RND_KEY */
|
||||
if(random_fd == -1)
|
||||
random_fd = open(RANDOM_DEVICE, O_RDONLY | O_NONBLOCK | O_CLOEXEC);
|
||||
if(random_fd == -1)
|
||||
goto fail;
|
||||
goto err;
|
||||
|
||||
if (crypt_fips_mode())
|
||||
log_verbose(ctx, _("Running in FIPS mode."));
|
||||
|
||||
random_initialised = 1;
|
||||
return 0;
|
||||
fail:
|
||||
err:
|
||||
crypt_random_exit();
|
||||
log_err(ctx, _("Fatal error during RNG initialisation."));
|
||||
return -ENOSYS;
|
||||
|
||||
601
lib/setup.c
601
lib/setup.c
File diff suppressed because it is too large
Load Diff
@@ -1,8 +1,8 @@
|
||||
/*
|
||||
* TCRYPT (TrueCrypt-compatible) and VeraCrypt volume handling
|
||||
*
|
||||
* Copyright (C) 2012-2020 Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2012-2020 Milan Broz
|
||||
* Copyright (C) 2012-2021 Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2012-2021 Milan Broz
|
||||
*
|
||||
* This file is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
@@ -23,7 +23,6 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <fcntl.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "libcryptsetup.h"
|
||||
@@ -275,11 +274,11 @@ static int decrypt_blowfish_le_cbc(struct tcrypt_alg *alg,
|
||||
const char *key, char *buf)
|
||||
{
|
||||
int bs = alg->iv_size;
|
||||
char iv[bs], iv_old[bs];
|
||||
char iv[8], iv_old[8];
|
||||
struct crypt_cipher *cipher = NULL;
|
||||
int i, j, r;
|
||||
|
||||
assert(bs == 2*sizeof(uint32_t));
|
||||
assert(bs == 8);
|
||||
|
||||
r = crypt_cipher_init(&cipher, "blowfish", "ecb",
|
||||
&key[alg->key_offset], alg->key_size);
|
||||
@@ -381,12 +380,15 @@ static int TCRYPT_decrypt_hdr_one(struct tcrypt_alg *alg, const char *mode,
|
||||
static int TCRYPT_decrypt_cbci(struct tcrypt_algs *ciphers,
|
||||
const char *key, struct tcrypt_phdr *hdr)
|
||||
{
|
||||
struct crypt_cipher *cipher[ciphers->chain_count];
|
||||
struct crypt_cipher *cipher[3];
|
||||
unsigned int bs = ciphers->cipher[0].iv_size;
|
||||
char *buf = (char*)&hdr->e, iv[bs], iv_old[bs];
|
||||
char *buf = (char*)&hdr->e, iv[16], iv_old[16];
|
||||
unsigned int i, j;
|
||||
int r = -EINVAL;
|
||||
|
||||
assert(ciphers->chain_count <= 3);
|
||||
assert(bs <= 16);
|
||||
|
||||
TCRYPT_remove_whitening(buf, &key[8]);
|
||||
|
||||
memcpy(iv, &key[ciphers->cipher[0].iv_offset], bs);
|
||||
@@ -426,13 +428,15 @@ out:
|
||||
}
|
||||
|
||||
static int TCRYPT_decrypt_hdr(struct crypt_device *cd, struct tcrypt_phdr *hdr,
|
||||
const char *key, uint32_t flags)
|
||||
const char *key, struct crypt_params_tcrypt *params)
|
||||
{
|
||||
struct tcrypt_phdr hdr2;
|
||||
int i, j, r = -EINVAL;
|
||||
|
||||
for (i = 0; tcrypt_cipher[i].chain_count; i++) {
|
||||
if (!(flags & CRYPT_TCRYPT_LEGACY_MODES) && tcrypt_cipher[i].legacy)
|
||||
if (params->cipher && !strstr(tcrypt_cipher[i].long_name, params->cipher))
|
||||
continue;
|
||||
if (!(params->flags & CRYPT_TCRYPT_LEGACY_MODES) && tcrypt_cipher[i].legacy)
|
||||
continue;
|
||||
log_dbg(cd, "TCRYPT: trying cipher %s-%s",
|
||||
tcrypt_cipher[i].long_name, tcrypt_cipher[i].mode);
|
||||
@@ -464,7 +468,7 @@ static int TCRYPT_decrypt_hdr(struct crypt_device *cd, struct tcrypt_phdr *hdr,
|
||||
r = i;
|
||||
break;
|
||||
}
|
||||
if ((flags & CRYPT_TCRYPT_VERA_MODES) &&
|
||||
if ((params->flags & CRYPT_TCRYPT_VERA_MODES) &&
|
||||
!strncmp(hdr2.d.magic, VCRYPT_HDR_MAGIC, TCRYPT_HDR_MAGIC_LEN)) {
|
||||
log_dbg(cd, "TCRYPT: Signature magic detected (Veracrypt).");
|
||||
memcpy(&hdr->e, &hdr2.e, TCRYPT_HDR_LEN);
|
||||
@@ -479,8 +483,8 @@ static int TCRYPT_decrypt_hdr(struct crypt_device *cd, struct tcrypt_phdr *hdr,
|
||||
}
|
||||
|
||||
static int TCRYPT_pool_keyfile(struct crypt_device *cd,
|
||||
unsigned char pool[TCRYPT_KEY_POOL_LEN],
|
||||
const char *keyfile)
|
||||
unsigned char pool[VCRYPT_KEY_POOL_LEN],
|
||||
const char *keyfile, int keyfiles_pool_length)
|
||||
{
|
||||
unsigned char *data;
|
||||
int i, j, fd, data_size, r = -EIO;
|
||||
@@ -512,7 +516,7 @@ static int TCRYPT_pool_keyfile(struct crypt_device *cd,
|
||||
pool[j++] += (unsigned char)(crc >> 16);
|
||||
pool[j++] += (unsigned char)(crc >> 8);
|
||||
pool[j++] += (unsigned char)(crc);
|
||||
j %= TCRYPT_KEY_POOL_LEN;
|
||||
j %= keyfiles_pool_length;
|
||||
}
|
||||
r = 0;
|
||||
out:
|
||||
@@ -527,29 +531,39 @@ static int TCRYPT_init_hdr(struct crypt_device *cd,
|
||||
struct tcrypt_phdr *hdr,
|
||||
struct crypt_params_tcrypt *params)
|
||||
{
|
||||
unsigned char pwd[TCRYPT_KEY_POOL_LEN] = {};
|
||||
size_t passphrase_size;
|
||||
unsigned char pwd[VCRYPT_KEY_POOL_LEN] = {};
|
||||
size_t passphrase_size, max_passphrase_size;
|
||||
char *key;
|
||||
unsigned int i, skipped = 0, iterations;
|
||||
int r = -EPERM;
|
||||
int r = -EPERM, keyfiles_pool_length;
|
||||
|
||||
if (posix_memalign((void*)&key, crypt_getpagesize(), TCRYPT_HDR_KEY_LEN))
|
||||
return -ENOMEM;
|
||||
|
||||
if (params->flags & CRYPT_TCRYPT_VERA_MODES &&
|
||||
params->passphrase_size > TCRYPT_KEY_POOL_LEN) {
|
||||
/* Really. Keyfile pool length depends on passphrase size in Veracrypt. */
|
||||
max_passphrase_size = VCRYPT_KEY_POOL_LEN;
|
||||
keyfiles_pool_length = VCRYPT_KEY_POOL_LEN;
|
||||
} else {
|
||||
max_passphrase_size = TCRYPT_KEY_POOL_LEN;
|
||||
keyfiles_pool_length = TCRYPT_KEY_POOL_LEN;
|
||||
}
|
||||
|
||||
if (params->keyfiles_count)
|
||||
passphrase_size = TCRYPT_KEY_POOL_LEN;
|
||||
passphrase_size = max_passphrase_size;
|
||||
else
|
||||
passphrase_size = params->passphrase_size;
|
||||
|
||||
if (params->passphrase_size > TCRYPT_KEY_POOL_LEN) {
|
||||
log_err(cd, _("Maximum TCRYPT passphrase length (%d) exceeded."),
|
||||
TCRYPT_KEY_POOL_LEN);
|
||||
if (params->passphrase_size > max_passphrase_size) {
|
||||
log_err(cd, _("Maximum TCRYPT passphrase length (%zu) exceeded."),
|
||||
max_passphrase_size);
|
||||
goto out;
|
||||
}
|
||||
|
||||
/* Calculate pool content from keyfiles */
|
||||
for (i = 0; i < params->keyfiles_count; i++) {
|
||||
r = TCRYPT_pool_keyfile(cd, pwd, params->keyfiles[i]);
|
||||
r = TCRYPT_pool_keyfile(cd, pwd, params->keyfiles[i], keyfiles_pool_length);
|
||||
if (r < 0)
|
||||
goto out;
|
||||
}
|
||||
@@ -559,6 +573,8 @@ static int TCRYPT_init_hdr(struct crypt_device *cd,
|
||||
pwd[i] += params->passphrase[i];
|
||||
|
||||
for (i = 0; tcrypt_kdf[i].name; i++) {
|
||||
if (params->hash_name && strcmp(params->hash_name, tcrypt_kdf[i].hash))
|
||||
continue;
|
||||
if (!(params->flags & CRYPT_TCRYPT_LEGACY_MODES) && tcrypt_kdf[i].legacy)
|
||||
continue;
|
||||
if (!(params->flags & CRYPT_TCRYPT_VERA_MODES) && tcrypt_kdf[i].veracrypt)
|
||||
@@ -589,7 +605,7 @@ static int TCRYPT_init_hdr(struct crypt_device *cd,
|
||||
}
|
||||
|
||||
/* Decrypt header */
|
||||
r = TCRYPT_decrypt_hdr(cd, hdr, key, params->flags);
|
||||
r = TCRYPT_decrypt_hdr(cd, hdr, key, params);
|
||||
if (r == -ENOENT) {
|
||||
skipped++;
|
||||
r = -EPERM;
|
||||
@@ -740,7 +756,7 @@ int TCRYPT_activate(struct crypt_device *cd,
|
||||
return -ENOTSUP;
|
||||
}
|
||||
|
||||
if (hdr->d.sector_size && hdr->d.sector_size != SECTOR_SIZE) {
|
||||
if (hdr->d.sector_size % SECTOR_SIZE) {
|
||||
log_err(cd, _("Activation is not supported for %d sector size."),
|
||||
hdr->d.sector_size);
|
||||
return -ENOTSUP;
|
||||
@@ -760,15 +776,12 @@ int TCRYPT_activate(struct crypt_device *cd,
|
||||
if (!algs)
|
||||
return -EINVAL;
|
||||
|
||||
if (hdr->d.sector_size == 0)
|
||||
return -EINVAL;
|
||||
|
||||
if (params->flags & CRYPT_TCRYPT_SYSTEM_HEADER)
|
||||
dmd.size = 0;
|
||||
else if (params->flags & CRYPT_TCRYPT_HIDDEN_HEADER)
|
||||
dmd.size = hdr->d.hidden_volume_size / hdr->d.sector_size;
|
||||
dmd.size = hdr->d.hidden_volume_size / SECTOR_SIZE;
|
||||
else
|
||||
dmd.size = hdr->d.volume_size / hdr->d.sector_size;
|
||||
dmd.size = hdr->d.volume_size / SECTOR_SIZE;
|
||||
|
||||
if (dmd.flags & CRYPT_ACTIVATE_SHARED)
|
||||
device_check = DEV_OK;
|
||||
@@ -1016,41 +1029,32 @@ uint64_t TCRYPT_get_data_offset(struct crypt_device *cd,
|
||||
{
|
||||
uint64_t size;
|
||||
|
||||
/* No real header loaded, initialized by active device */
|
||||
if (!hdr->d.version)
|
||||
goto hdr_offset;
|
||||
|
||||
/* Mapping through whole device, not partition! */
|
||||
if (params->flags & CRYPT_TCRYPT_SYSTEM_HEADER) {
|
||||
if (crypt_dev_is_partition(device_path(crypt_metadata_device(cd))))
|
||||
if (!hdr->d.version) {
|
||||
/* No real header loaded, initialized by active device, use default mk_offset */
|
||||
} else if (params->flags & CRYPT_TCRYPT_SYSTEM_HEADER) {
|
||||
/* Mapping through whole device, not partition! */
|
||||
if (crypt_dev_is_partition(device_path(crypt_data_device(cd))))
|
||||
return 0;
|
||||
goto hdr_offset;
|
||||
}
|
||||
|
||||
if (params->mode && !strncmp(params->mode, "xts", 3)) {
|
||||
} else if (params->mode && !strncmp(params->mode, "xts", 3)) {
|
||||
if (hdr->d.version < 3)
|
||||
return 1;
|
||||
|
||||
if (params->flags & CRYPT_TCRYPT_HIDDEN_HEADER) {
|
||||
if (hdr->d.version > 3)
|
||||
return (hdr->d.mk_offset / hdr->d.sector_size);
|
||||
return (hdr->d.mk_offset / SECTOR_SIZE);
|
||||
if (device_size(crypt_metadata_device(cd), &size) < 0)
|
||||
return 0;
|
||||
return (size - hdr->d.hidden_volume_size +
|
||||
(TCRYPT_HDR_HIDDEN_OFFSET_OLD)) / hdr->d.sector_size;
|
||||
(TCRYPT_HDR_HIDDEN_OFFSET_OLD)) / SECTOR_SIZE;
|
||||
}
|
||||
goto hdr_offset;
|
||||
}
|
||||
|
||||
if (params->flags & CRYPT_TCRYPT_HIDDEN_HEADER) {
|
||||
} else if (params->flags & CRYPT_TCRYPT_HIDDEN_HEADER) {
|
||||
if (device_size(crypt_metadata_device(cd), &size) < 0)
|
||||
return 0;
|
||||
return (size - hdr->d.hidden_volume_size +
|
||||
(TCRYPT_HDR_HIDDEN_OFFSET_OLD)) / hdr->d.sector_size;
|
||||
(TCRYPT_HDR_HIDDEN_OFFSET_OLD)) / SECTOR_SIZE;
|
||||
}
|
||||
|
||||
hdr_offset:
|
||||
return hdr->d.mk_offset / hdr->d.sector_size;
|
||||
return hdr->d.mk_offset / SECTOR_SIZE;
|
||||
}
|
||||
|
||||
uint64_t TCRYPT_get_iv_offset(struct crypt_device *cd,
|
||||
@@ -1064,10 +1068,10 @@ uint64_t TCRYPT_get_iv_offset(struct crypt_device *cd,
|
||||
else if (params->mode && !strncmp(params->mode, "lrw", 3))
|
||||
iv_offset = 0;
|
||||
else
|
||||
iv_offset = hdr->d.mk_offset / hdr->d.sector_size;
|
||||
iv_offset = hdr->d.mk_offset / SECTOR_SIZE;
|
||||
|
||||
if (params->flags & CRYPT_TCRYPT_SYSTEM_HEADER)
|
||||
iv_offset += crypt_dev_partition_offset(device_path(crypt_metadata_device(cd)));
|
||||
iv_offset += crypt_dev_partition_offset(device_path(crypt_data_device(cd)));
|
||||
|
||||
return iv_offset;
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/*
|
||||
* TCRYPT (TrueCrypt-compatible) header definition
|
||||
*
|
||||
* Copyright (C) 2012-2020 Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2012-2020 Milan Broz
|
||||
* Copyright (C) 2012-2021 Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2012-2021 Milan Broz
|
||||
*
|
||||
* This file is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
@@ -42,6 +42,7 @@
|
||||
|
||||
#define TCRYPT_LRW_IKEY_LEN 16
|
||||
#define TCRYPT_KEY_POOL_LEN 64
|
||||
#define VCRYPT_KEY_POOL_LEN 128
|
||||
#define TCRYPT_KEYFILE_LEN 1048576
|
||||
|
||||
#define TCRYPT_HDR_FLAG_SYSTEM (1 << 0)
|
||||
@@ -74,7 +75,6 @@ struct tcrypt_phdr {
|
||||
|
||||
struct crypt_device;
|
||||
struct crypt_params_tcrypt;
|
||||
struct crypt_dm_active_device;
|
||||
struct dm_target;
|
||||
struct volume_key;
|
||||
struct device;
|
||||
|
||||
30
lib/utils.c
30
lib/utils.c
@@ -3,8 +3,8 @@
|
||||
*
|
||||
* Copyright (C) 2004 Jana Saout <jana@saout.de>
|
||||
* Copyright (C) 2004-2007 Clemens Fruhwirth <clemens@endorphin.org>
|
||||
* Copyright (C) 2009-2020 Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2009-2020 Milan Broz
|
||||
* Copyright (C) 2009-2021 Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2009-2021 Milan Broz
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
@@ -23,7 +23,6 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/resource.h>
|
||||
#include <sys/stat.h>
|
||||
@@ -172,8 +171,7 @@ int crypt_keyfile_device_read(struct crypt_device *cd, const char *keyfile,
|
||||
|
||||
if (isatty(fd)) {
|
||||
log_err(cd, _("Cannot read keyfile from a terminal."));
|
||||
r = -EINVAL;
|
||||
goto out_err;
|
||||
goto out;
|
||||
}
|
||||
|
||||
/* If not requested otherwise, we limit input to prevent memory exhaustion */
|
||||
@@ -189,7 +187,7 @@ int crypt_keyfile_device_read(struct crypt_device *cd, const char *keyfile,
|
||||
if (keyfile) {
|
||||
if (stat(keyfile, &st) < 0) {
|
||||
log_err(cd, _("Failed to stat key file."));
|
||||
goto out_err;
|
||||
goto out;
|
||||
}
|
||||
if (S_ISREG(st.st_mode)) {
|
||||
regular_file = 1;
|
||||
@@ -197,7 +195,7 @@ int crypt_keyfile_device_read(struct crypt_device *cd, const char *keyfile,
|
||||
|
||||
if (keyfile_offset > file_read_size) {
|
||||
log_err(cd, _("Cannot seek to requested keyfile offset."));
|
||||
goto out_err;
|
||||
goto out;
|
||||
}
|
||||
file_read_size -= keyfile_offset;
|
||||
|
||||
@@ -212,13 +210,13 @@ int crypt_keyfile_device_read(struct crypt_device *cd, const char *keyfile,
|
||||
pass = crypt_safe_alloc(buflen);
|
||||
if (!pass) {
|
||||
log_err(cd, _("Out of memory while reading passphrase."));
|
||||
goto out_err;
|
||||
goto out;
|
||||
}
|
||||
|
||||
/* Discard keyfile_offset bytes on input */
|
||||
if (keyfile_offset && keyfile_seek(fd, keyfile_offset) < 0) {
|
||||
log_err(cd, _("Cannot seek to requested keyfile offset."));
|
||||
goto out_err;
|
||||
goto out;
|
||||
}
|
||||
|
||||
for (i = 0, newline = 0; i < key_size; i += char_read) {
|
||||
@@ -228,7 +226,7 @@ int crypt_keyfile_device_read(struct crypt_device *cd, const char *keyfile,
|
||||
if (!pass) {
|
||||
log_err(cd, _("Out of memory while reading passphrase."));
|
||||
r = -ENOMEM;
|
||||
goto out_err;
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -248,7 +246,7 @@ int crypt_keyfile_device_read(struct crypt_device *cd, const char *keyfile,
|
||||
if (char_read < 0) {
|
||||
log_err(cd, _("Error reading passphrase."));
|
||||
r = -EPIPE;
|
||||
goto out_err;
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (char_read == 0)
|
||||
@@ -265,24 +263,24 @@ int crypt_keyfile_device_read(struct crypt_device *cd, const char *keyfile,
|
||||
if (!i && !regular_file && !newline) {
|
||||
log_err(cd, _("Nothing to read on input."));
|
||||
r = -EPIPE;
|
||||
goto out_err;
|
||||
goto out;
|
||||
}
|
||||
|
||||
/* Fail if we exceeded internal default (no specified size) */
|
||||
if (unlimited_read && i == key_size) {
|
||||
log_err(cd, _("Maximum keyfile size exceeded."));
|
||||
goto out_err;
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (!unlimited_read && i != key_size) {
|
||||
log_err(cd, _("Cannot read requested amount of data."));
|
||||
goto out_err;
|
||||
goto out;
|
||||
}
|
||||
|
||||
*key = pass;
|
||||
*key_size_read = i;
|
||||
r = 0;
|
||||
out_err:
|
||||
out:
|
||||
if (fd != STDIN_FILENO)
|
||||
close(fd);
|
||||
|
||||
@@ -319,7 +317,7 @@ int kernel_version(uint64_t *kversion)
|
||||
}
|
||||
|
||||
if (!r)
|
||||
*kversion = version(maj, min, patch, rel);
|
||||
*kversion = compact_version(maj, min, patch, rel);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/*
|
||||
* libcryptsetup - cryptsetup library, cipher benchmark
|
||||
*
|
||||
* Copyright (C) 2012-2020 Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2012-2020 Milan Broz
|
||||
* Copyright (C) 2012-2021 Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2012-2021 Milan Broz
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
@@ -48,6 +48,12 @@ int crypt_benchmark(struct crypt_device *cd,
|
||||
if (posix_memalign(&buffer, crypt_getpagesize(), buffer_size))
|
||||
goto out;
|
||||
|
||||
r = crypt_cipher_ivsize(cipher, cipher_mode);
|
||||
if (r >= 0 && iv_size != (size_t)r) {
|
||||
log_dbg(cd, "IV length for benchmark adjusted to %i bytes (requested %zu).", r, iv_size);
|
||||
iv_size = r;
|
||||
}
|
||||
|
||||
if (iv_size) {
|
||||
iv = malloc(iv_size);
|
||||
if (!iv)
|
||||
@@ -71,9 +77,9 @@ int crypt_benchmark(struct crypt_device *cd,
|
||||
|
||||
if (r == -ERANGE)
|
||||
log_dbg(cd, "Measured cipher runtime is too low.");
|
||||
else if (r == -ENOTSUP || r == -ENOENT)
|
||||
log_dbg(cd, "Cannot initialize cipher %s, mode %s.", cipher, cipher_mode);
|
||||
|
||||
else if (r)
|
||||
log_dbg(cd, "Cannot initialize cipher %s, mode %s, key size %zu, IV size %zu.",
|
||||
cipher, cipher_mode, volume_key_size, iv_size);
|
||||
out:
|
||||
free(buffer);
|
||||
free(key);
|
||||
@@ -190,7 +196,7 @@ int crypt_benchmark_pbkdf_internal(struct crypt_device *cd,
|
||||
PBKDF2_tmp = ((double)pbkdf->iterations * pbkdf->time_ms / 1000.);
|
||||
if (PBKDF2_tmp > (double)UINT32_MAX)
|
||||
return -EINVAL;
|
||||
pbkdf->iterations = at_least((uint32_t)PBKDF2_tmp, pbkdf_limits.min_iterations);
|
||||
pbkdf->iterations = AT_LEAST((uint32_t)PBKDF2_tmp, pbkdf_limits.min_iterations);
|
||||
} else {
|
||||
/* Already benchmarked */
|
||||
if (pbkdf->iterations) {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* blkid probe utilities
|
||||
*
|
||||
* Copyright (C) 2018-2020 Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2018-2021 Red Hat, Inc. All rights reserved.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
@@ -310,9 +310,9 @@ int blk_supported(void)
|
||||
|
||||
off_t blk_get_offset(struct blkid_handle *h)
|
||||
{
|
||||
const char *offset;
|
||||
off_t offset_value = -1;
|
||||
#ifdef HAVE_BLKID
|
||||
const char *offset;
|
||||
if (blk_is_superblock(h)) {
|
||||
if (!blkid_probe_lookup_value(h->pr, "SBMAGIC_OFFSET", &offset, NULL))
|
||||
offset_value = strtoll(offset, NULL, 10);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* blkid probe utilities
|
||||
*
|
||||
* Copyright (C) 2018-2020 Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2018-2021 Red Hat, Inc. All rights reserved.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
@@ -21,6 +21,8 @@
|
||||
#ifndef _UTILS_BLKID_H
|
||||
#define _UTILS_BLKID_H
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
struct blkid_handle;
|
||||
|
||||
typedef enum { PRB_OK = 0, PRB_EMPTY, PRB_AMBIGUOUS, PRB_FAIL } blk_probe_status;
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user