sys-fs/cryptsetup: Sync to cryptsetup 2.4.3

sync ref: 9ca608da6b

Signed-off-by: Sayan Chowdhury <schowdhury@microsoft.com>
This commit is contained in:
Sayan Chowdhury 2022-02-18 14:21:49 +05:30
parent 04d51ed887
commit a44e49d7a6
10 changed files with 93 additions and 328 deletions

View File

@ -0,0 +1 @@
- cryptsetup ([CVE-2021-4122](https://nvd.nist.gov/vuln/detail/CVE-2021-4122))

View File

@ -0,0 +1 @@
- cryptsetup [2.4.3](https://lore.kernel.org/all/572c18a7bf60cb1b0f67c3a03c531d7e7ed31832.camel@scientia.net/T/)

View File

@ -1,2 +1 @@
DIST cryptsetup-2.3.6.tar.xz 11154148 BLAKE2B 23a7d6fdeed2b8fb0492e800266a263b12dcf2b8c4304bda82e46d2de90b6c05a97a40f0f6f9c337b3dc428d51689d76953de5cc4daed210967cf0ea0ff503d2 SHA512 5b25cc806140d24181a0e4f0e7b0bd3caa8263aa502e8633b41c980f06ecba2e6acbf9c2d9cc4a785d38ce90d86dd8d22c52b28b9ca4a15824c2e8bdb3656665
DIST cryptsetup-2.4.1.tar.xz 11171180 BLAKE2B 6b999a19df54276d295eb2f1729be2eefb5fb09cd29aae5f7c0b93c539b4b552f92327f2474e0f4793a3c7f8a264a4ef927178dabfc9ba56012bdf9949ef9ada SHA512 17fc73c180e41acbd4ebeddebaf54f8baeef09fce7f154aa9c55936a58bda7adcc7b1bb257336c22295d7b5af426fc8dfd0e4e644e4a52098bcb8a2adb562ca7
DIST cryptsetup-2.4.3.tar.xz 11242152 BLAKE2B f5859d794d626cb19426a2c9afc4655fac3a1bae462daa42b37b925882804d5146aadff8733799dea89dcfdc311e628e5b806754495824705709ba105f91682f SHA512 2d52498497be37a837126d9cdc9b6331236eccf857c3482fe3347eb88fccc3cd0fd3d8b4490569603e18cfaa462431ae194bce0328f3eafa8bfe3e02e135a26e

View File

@ -1,9 +1,9 @@
# Copyright 1999-2021 Gentoo Authors
# Copyright 1999-2022 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
EAPI=7
inherit autotools linux-info tmpfiles
inherit linux-info tmpfiles
DESCRIPTION="Tool to setup encrypted devices with dm-crypt"
HOMEPAGE="https://gitlab.com/cryptsetup/cryptsetup/blob/master/README.md"
@ -12,24 +12,28 @@ SRC_URI="https://www.kernel.org/pub/linux/utils/${PN}/v$(ver_cut 1-2)/${P/_/-}.t
LICENSE="GPL-2+"
SLOT="0/12" # libcryptsetup.so version
[[ ${PV} != *_rc* ]] && \
KEYWORDS="~alpha amd64 arm arm64 hppa ~ia64 ~mips ppc ppc64 ~riscv ~s390 sparc x86"
KEYWORDS="~alpha ~amd64 ~arm ~arm64 ~hppa ~ia64 ~mips ~ppc ~ppc64 ~riscv ~s390 ~sparc ~x86"
CRYPTO_BACKENDS="gcrypt kernel nettle +openssl"
# we don't support nss since it doesn't allow cryptsetup to be built statically
# and it's missing ripemd160 support so it can't provide full backward compatibility
IUSE="${CRYPTO_BACKENDS} +argon2 nls pwquality reencrypt static static-libs +udev urandom"
IUSE="${CRYPTO_BACKENDS} +argon2 nls pwquality reencrypt ssh static static-libs test +udev urandom"
RESTRICT="!test? ( test )"
REQUIRED_USE="^^ ( ${CRYPTO_BACKENDS//+/} )
static? ( !gcrypt !udev )" #496612
static? ( !gcrypt !ssh !udev )" # 496612, 832711
LIB_DEPEND="
dev-libs/json-c:=[static-libs(+)]
dev-libs/libgpg-error[static-libs(+)]
dev-libs/popt[static-libs(+)]
>=sys-apps/util-linux-2.31-r1[static-libs(+)]
argon2? ( app-crypt/argon2:=[static-libs(+)] )
gcrypt? ( dev-libs/libgcrypt:0=[static-libs(+)] )
gcrypt? (
dev-libs/libgcrypt:0=[static-libs(+)]
dev-libs/libgpg-error[static-libs(+)]
)
nettle? ( >=dev-libs/nettle-2.4[static-libs(+)] )
openssl? ( dev-libs/openssl:0=[static-libs(+)] )
pwquality? ( dev-libs/libpwquality[static-libs(+)] )
ssh? ( net-libs/libssh[static-libs(+)] )
sys-fs/lvm2[static-libs(+)]"
# We have to always depend on ${LIB_DEPEND} rather than put behind
# !static? () because we provide a shared library which links against
@ -37,16 +41,16 @@ LIB_DEPEND="
RDEPEND="static-libs? ( ${LIB_DEPEND} )
${LIB_DEPEND//\[static-libs\([+-]\)\]}
udev? ( virtual/libudev:= )"
# vim-core needed for xxd in tests
DEPEND="${RDEPEND}
static? ( ${LIB_DEPEND} )"
static? ( ${LIB_DEPEND} )
test? ( app-editors/vim-core )"
BDEPEND="
virtual/pkgconfig
"
S="${WORKDIR}/${P/_/-}"
PATCHES=( "${FILESDIR}"/${PN}-2.0.4-fix-static-pwquality-build.patch )
pkg_setup() {
local CONFIG_CHECK="~DM_CRYPT ~CRYPTO ~CRYPTO_CBC ~CRYPTO_SHA256"
local WARNING_DM_CRYPT="CONFIG_DM_CRYPT:\tis not set (required for cryptsetup)\n"
@ -59,7 +63,6 @@ pkg_setup() {
src_prepare() {
sed -i '/^LOOPDEV=/s:$: || exit 0:' tests/{compat,mode}-test || die
default
eautoreconf
}
src_configure() {
@ -81,10 +84,12 @@ src_configure() {
$(use_enable nls)
$(use_enable pwquality)
$(use_enable reencrypt cryptsetup-reencrypt)
$(use_enable !static external-tokens)
$(use_enable static static-cryptsetup)
$(use_enable static-libs static)
$(use_enable udev)
$(use_enable !urandom dev-random)
$(use_enable ssh ssh-token)
$(usex argon2 '' '--with-luks2-pbkdf=pbkdf2')
)
econf "${myeconfargs[@]}"
@ -110,6 +115,10 @@ src_install() {
if use static ; then
mv "${ED}"/sbin/cryptsetup{.static,} || die
mv "${ED}"/sbin/veritysetup{.static,} || die
mv "${ED}"/sbin/integritysetup{.static,} || die
if use ssh ; then
mv "${ED}"/sbin/cryptsetup-ssh{.static,} || die
fi
if use reencrypt ; then
mv "${ED}"/sbin/cryptsetup-reencrypt{.static,} || die
fi
@ -118,8 +127,8 @@ src_install() {
dodoc docs/v*ReleaseNotes
newconfd "${FILESDIR}"/1.6.7-dmcrypt.confd dmcrypt
newinitd "${FILESDIR}"/1.6.7-dmcrypt.rc dmcrypt
newconfd "${FILESDIR}"/2.4.3-dmcrypt.confd dmcrypt
newinitd "${FILESDIR}"/2.4.3-dmcrypt.rc dmcrypt
}
pkg_postinst() {

View File

@ -1,9 +1,9 @@
# Copyright 1999-2021 Gentoo Authors
# Copyright 1999-2022 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
EAPI=7
inherit autotools linux-info tmpfiles
inherit linux-info tmpfiles
DESCRIPTION="Tool to setup encrypted devices with dm-crypt"
HOMEPAGE="https://gitlab.com/cryptsetup/cryptsetup/blob/master/README.md"
@ -12,13 +12,14 @@ SRC_URI="https://www.kernel.org/pub/linux/utils/${PN}/v$(ver_cut 1-2)/${P/_/-}.t
LICENSE="GPL-2+"
SLOT="0/12" # libcryptsetup.so version
[[ ${PV} != *_rc* ]] && \
KEYWORDS="~alpha ~amd64 ~arm ~arm64 ~hppa ~ia64 ~mips ~ppc ~ppc64 ~riscv ~s390 ~sparc ~x86"
KEYWORDS="~alpha amd64 arm arm64 hppa ~ia64 ~mips ppc ppc64 ~riscv ~s390 sparc x86"
CRYPTO_BACKENDS="gcrypt kernel nettle +openssl"
# we don't support nss since it doesn't allow cryptsetup to be built statically
# and it's missing ripemd160 support so it can't provide full backward compatibility
IUSE="${CRYPTO_BACKENDS} +argon2 nls pwquality reencrypt ssh static static-libs +udev urandom"
IUSE="${CRYPTO_BACKENDS} +argon2 nls pwquality reencrypt ssh static static-libs test +udev urandom"
RESTRICT="!test? ( test )"
REQUIRED_USE="^^ ( ${CRYPTO_BACKENDS//+/} )
static? ( !gcrypt !udev )" #496612
static? ( !gcrypt !ssh !udev )" # 496612, 832711
LIB_DEPEND="
dev-libs/json-c:=[static-libs(+)]
@ -40,21 +41,16 @@ LIB_DEPEND="
RDEPEND="static-libs? ( ${LIB_DEPEND} )
${LIB_DEPEND//\[static-libs\([+-]\)\]}
udev? ( virtual/libudev:= )"
# vim-core needed for xxd in tests
DEPEND="${RDEPEND}
static? ( ${LIB_DEPEND} )"
static? ( ${LIB_DEPEND} )
test? ( app-editors/vim-core )"
BDEPEND="
virtual/pkgconfig
"
S="${WORKDIR}/${P/_/-}"
PATCHES=(
"${FILESDIR}"/cryptsetup-2.4.1-external-tokens.patch
# Remove autotools/eautoreconf when this patch is dropped.
"${FILESDIR}"/cryptsetup-2.4.1-fix-static-pwquality-build.patch
)
pkg_setup() {
local CONFIG_CHECK="~DM_CRYPT ~CRYPTO ~CRYPTO_CBC ~CRYPTO_SHA256"
local WARNING_DM_CRYPT="CONFIG_DM_CRYPT:\tis not set (required for cryptsetup)\n"
@ -67,7 +63,6 @@ pkg_setup() {
src_prepare() {
sed -i '/^LOOPDEV=/s:$: || exit 0:' tests/{compat,mode}-test || die
default
eautoreconf
}
src_configure() {

View File

@ -44,6 +44,7 @@ dmcrypt_retries=5
# for blkid (see -t option). This is safer than using
# the full path to the device.
# key='</path/to/keyfile>[:<mode>]' == Fullpath from / or from inside removable media.
# header='</path/to/header>' == Full path to detached LUKS header file.
# remdev='<dev>' == Device that will be assigned to removable media.
# gpg_options='<opts>' == Default are --quiet --decrypt
# options='<opts>' == cryptsetup, for LUKS you can only use --readonly
@ -52,6 +53,8 @@ dmcrypt_retries=5
# be looked up automatically.
# pre_mount='cmds' == commands to execute before mounting partition.
# post_mount='cmds' == commands to execute after mounting partition.
# wait=5 == wait given amount of seconds for source or
# detached header file appear.
#-----------
# Supported Modes
# gpg == decrypt and pipe key into cryptsetup.
@ -79,6 +82,12 @@ dmcrypt_retries=5
#source='/dev/hda5'
#key='/full/path/to/homekey'
## /home with regular keyfile and detached header
#target=crypt-home
#source='/dev/hda5'
#key='/full/path/to/homekey'
#header='/full/path/to/header/file'
## /home with gpg protected key
#target=crypt-home
#source='/dev/hda5'

View File

@ -3,6 +3,7 @@
# Distributed under the terms of the GNU General Public License v2
depend() {
use modules
before checkfs fsck
if grep -qs ^swap= "${conf_file}" ; then
@ -21,7 +22,7 @@ fi
# Setup mappings for an individual target/swap
# Note: This relies on variables localized in the main body below.
dm_crypt_execute() {
local dev ret mode foo
local dev ret mode foo source_dev
if [ -z "${target}" -a -z "${swap}" ] ; then
return
@ -31,6 +32,7 @@ dm_crypt_execute() {
: ${dmcrypt_key_timeout:=1}
: ${dmcrypt_max_timeout:=300}
: ${dmcrypt_retries:=5}
: ${wait:=5}
# Handle automatic look up of the source path.
if [ -z "${source}" -a -n "${loop_file}" ] ; then
@ -38,7 +40,16 @@ dm_crypt_execute() {
fi
case ${source} in
*=*)
source=$(blkid -l -t "${source}" -o device)
i=0
while [ ${i} -lt ${wait} ]; do
if source_dev="$(blkid -l -t "${source}" -o device)"; then
source="${source_dev}"
break
fi
: $((i += 1))
einfo "waiting for source \"${source}\" for ${target}..."
sleep 1
done
;;
esac
if [ -z "${source}" ] || [ ! -e "${source}" ] ; then
@ -46,11 +57,28 @@ dm_crypt_execute() {
return
fi
if [ -n "${header}" ] ; then
header_opt="--header=${header}"
i=0
while [ ! -e "${header}" ] && [ ${i} -lt ${wait} ] ; do
: $((i += 1))
einfo "Waiting for header ${header} to appear for ${target} ${i}/${dmcrypt_max_timeout} ..."
sleep 1
done
if [ ${i} -gt ${wait} ] || [ ${i} -eq ${wait} ] ; then
ewarn "Waited ${i} times for header file ${header}. Aborting ${target}."
return
fi
else
header_opt=""
fi
if [ -n "${target}" ] ; then
# let user set options, otherwise leave empty
: ${options:=' '}
elif [ -n "${swap}" ] ; then
if cryptsetup isLuks ${source} 2>/dev/null ; then
if cryptsetup ${header_opt} isLuks ${source} 2>/dev/null ; then
ewarn "The swap you have defined is a LUKS partition. Aborting crypt-swap setup."
return
fi
@ -71,7 +99,7 @@ dm_crypt_execute() {
# open <device> <name> # <device> is $source
# create <name> <device> # <name> is $target
local arg1="create" arg2="${target}" arg3="${source}"
if cryptsetup isLuks ${source} 2>/dev/null ; then
if cryptsetup ${header_opt} isLuks ${source} 2>/dev/null ; then
arg1="open"
arg2="${source}"
arg3="${target}"
@ -81,7 +109,7 @@ dm_crypt_execute() {
# ${target} is active:
# Newer versions report:
# ${target} is active[ and is in use.]
if cryptsetup status ${target} | egrep -q ' is active' ; then
if cryptsetup ${header_opt} status ${target} | egrep -q ' is active' ; then
einfo "dm-crypt mapping ${target} is already configured"
return
fi
@ -171,7 +199,7 @@ dm_crypt_execute() {
else
mode=none
fi
ebegin " ${target} using: ${options} ${arg1} ${arg2} ${arg3}"
ebegin " ${target} using: ${header_opt} ${options} ${arg1} ${arg2} ${arg3}"
if [ "${mode}" = "gpg" ] ; then
: ${gpg_options:='-q -d'}
# gpg available ?
@ -181,7 +209,7 @@ dm_crypt_execute() {
# paranoid, don't store key in a variable, pipe it so it stays very little in ram unprotected.
# save stdin stdout stderr "values"
timeout ${dmcrypt_max_timeout} gpg ${gpg_options} ${key} 2>/dev/null | \
cryptsetup --key-file - ${options} ${arg1} ${arg2} ${arg3}
cryptsetup ${header_opt} --key-file - ${options} ${arg1} ${arg2} ${arg3}
ret=$?
# The timeout command exits 124 when it times out.
[ ${ret} -eq 0 -o ${ret} -eq 124 ] && break
@ -196,11 +224,11 @@ dm_crypt_execute() {
fi
else
if [ "${mode}" = "reg" ] ; then
cryptsetup ${options} -d ${key} ${arg1} ${arg2} ${arg3}
cryptsetup ${header_opt} ${options} -d ${key} ${arg1} ${arg2} ${arg3}
ret=$?
eend ${ret} "failure running cryptsetup"
else
cryptsetup ${options} ${arg1} ${arg2} ${arg3}
cryptsetup ${header_opt} ${options} ${arg1} ${arg2} ${arg3}
ret=$?
eend ${ret} "failure running cryptsetup"
fi
@ -236,7 +264,7 @@ get_bootparam_val() {
}
start() {
local header=true cryptfs_status=0
local print_header=true cryptfs_status=0
local gpg_options key loop_file target targetline options pre_mount post_mount source swap remdev
local x
@ -256,8 +284,8 @@ start() {
rc_*) continue ;;
esac
${header} && ebegin "Setting up dm-crypt mappings"
header=false
${print_header} && ebegin "Setting up dm-crypt mappings"
print_header=false
# check for the start of a new target/swap
case ${targetline} in
@ -266,10 +294,10 @@ start() {
dm_crypt_execute
# Prepare for the next target/swap by resetting variables
unset gpg_options key loop_file target options pre_mount post_mount source swap remdev
unset gpg_options key loop_file target options pre_mount post_mount source swap remdev wait header header_opt
;;
gpg_options=*|remdev=*|key=*|loop_file=*|options=*|pre_mount=*|post_mount=*|source=*)
gpg_options=*|remdev=*|key=*|loop_file=*|options=*|pre_mount=*|post_mount=*|wait=*|source=*|header=*)
if [ -z "${target}${swap}" ] ; then
ewarn "Ignoring setting outside target/swap section: ${targetline}"
continue
@ -297,14 +325,14 @@ start() {
}
stop() {
local line header
local line print_header
# Break down all mappings
header=true
print_header=true
egrep "^(target|swap)=" ${conf_file} | \
while read line ; do
${header} && einfo "Removing dm-crypt mappings"
header=false
${print_header} && einfo "Removing dm-crypt mappings"
print_header=false
target= swap=
eval ${line}
@ -316,16 +344,16 @@ stop() {
fi
ebegin " ${target}"
cryptsetup remove ${target}
cryptsetup ${header_opt} remove ${target}
eend $?
done
# Break down loop devices
header=true
print_header=true
grep '^source=./dev/loop' ${conf_file} | \
while read line ; do
${header} && einfo "Detaching dm-crypt loop devices"
header=false
${print_header} && einfo "Detaching dm-crypt loop devices"
print_header=false
source=
eval ${line}

View File

@ -1,18 +0,0 @@
--- a/src/Makemodule.am 2018-07-31 14:32:46.000000000 +0200
+++ b/src/Makemodule.am 2018-08-12 17:13:26.000000000 +0200
@@ -64,6 +64,7 @@
$(veritysetup_LDADD) \
@CRYPTO_STATIC_LIBS@ \
@DEVMAPPER_STATIC_LIBS@ \
+ @PWQUALITY_STATIC_LIBS@ \
@UUID_LIBS@
endif
endif
@@ -93,6 +94,7 @@
$(integritysetup_LDADD) \
@CRYPTO_STATIC_LIBS@ \
@DEVMAPPER_STATIC_LIBS@ \
+ @PWQUALITY_STATIC_LIBS@ \
@UUID_LIBS@
endif
endif

View File

@ -1,34 +0,0 @@
From a1b577c085cc9ef6b95c4556ec8815070828ee6c Mon Sep 17 00:00:00 2001
From: Hector Martin <marcan@marcan.st>
Date: Fri, 17 Sep 2021 05:44:18 +0000
Subject: [PATCH] Do not attempt to unload external tokens if
USE_EXTERNAL_TOKENS is disabled.
This allows building a static binary as long as --disable-external-tokens is used
---
lib/luks2/luks2_token.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/lib/luks2/luks2_token.c b/lib/luks2/luks2_token.c
index d34cebf5..88d84418 100644
--- a/lib/luks2/luks2_token.c
+++ b/lib/luks2/luks2_token.c
@@ -245,6 +245,7 @@ int crypt_token_register(const crypt_token_handler *handler)
void crypt_token_unload_external_all(struct crypt_device *cd)
{
+#if USE_EXTERNAL_TOKENS
int i;
for (i = LUKS2_TOKENS_MAX - 1; i >= 0; i--) {
@@ -258,6 +259,7 @@ void crypt_token_unload_external_all(struct crypt_device *cd)
if (dlclose(CONST_CAST(void *)token_handlers[i].u.v2.dlhandle))
log_dbg(cd, "%s", dlerror());
}
+#endif
}
static const void
--
GitLab

View File

@ -1,225 +0,0 @@
From 26cc1644b489578c76ec6f576614ca885c00a35d Mon Sep 17 00:00:00 2001
From: Milan Broz <gmazyland@gmail.com>
Date: Wed, 6 Oct 2021 12:27:25 +0200
Subject: [PATCH 1/2] Do not link integritysetup and veritysetup with
pwquality.
These tools do not read passphrases, no need to link to these libraries.
Just move the helper code that introduced this dependence as a side-effect.
Fixes: #677
---
src/Makemodule.am | 6 -----
src/utils_password.c | 56 --------------------------------------------
src/utils_tools.c | 56 ++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 56 insertions(+), 62 deletions(-)
diff --git a/src/Makemodule.am b/src/Makemodule.am
index a6dc50cf..f2b896bf 100644
--- a/src/Makemodule.am
+++ b/src/Makemodule.am
@@ -52,7 +52,6 @@ veritysetup_SOURCES = \
src/utils_arg_names.h \
src/utils_arg_macros.h \
src/utils_tools.c \
- src/utils_password.c \
src/veritysetup.c \
src/veritysetup_args.h \
src/veritysetup_arg_list.h \
@@ -61,8 +60,6 @@ veritysetup_SOURCES = \
veritysetup_LDADD = $(LDADD) \
libcryptsetup.la \
@POPT_LIBS@ \
- @PWQUALITY_LIBS@ \
- @PASSWDQC_LIBS@ \
@BLKID_LIBS@
sbin_PROGRAMS += veritysetup
@@ -91,7 +88,6 @@ integritysetup_SOURCES = \
src/utils_arg_names.h \
src/utils_arg_macros.h \
src/utils_tools.c \
- src/utils_password.c \
src/utils_blockdev.c \
src/integritysetup.c \
src/integritysetup_args.h \
@@ -101,8 +97,6 @@ integritysetup_SOURCES = \
integritysetup_LDADD = $(LDADD) \
libcryptsetup.la \
@POPT_LIBS@ \
- @PWQUALITY_LIBS@ \
- @PASSWDQC_LIBS@ \
@UUID_LIBS@ \
@BLKID_LIBS@
diff --git a/src/utils_password.c b/src/utils_password.c
index 58f3a7b3..65618b9c 100644
--- a/src/utils_password.c
+++ b/src/utils_password.c
@@ -318,59 +318,3 @@ void tools_passphrase_msg(int r)
else if (r == -ENOENT)
log_err(_("No usable keyslot is available."));
}
-
-int tools_read_mk(const char *file, char **key, int keysize)
-{
- int fd = -1, r = -EINVAL;
-
- if (keysize <= 0 || !key)
- return -EINVAL;
-
- *key = crypt_safe_alloc(keysize);
- if (!*key)
- return -ENOMEM;
-
- fd = open(file, O_RDONLY);
- if (fd == -1) {
- log_err(_("Cannot read keyfile %s."), file);
- goto out;
- }
-
- if (read_buffer(fd, *key, keysize) != keysize) {
- log_err(_("Cannot read %d bytes from keyfile %s."), keysize, file);
- goto out;
- }
- r = 0;
-out:
- if (fd != -1)
- close(fd);
-
- if (r) {
- crypt_safe_free(*key);
- *key = NULL;
- }
-
- return r;
-}
-
-int tools_write_mk(const char *file, const char *key, int keysize)
-{
- int fd, r = -EINVAL;
-
- if (keysize <= 0 || !key)
- return -EINVAL;
-
- fd = open(file, O_CREAT|O_EXCL|O_WRONLY, S_IRUSR);
- if (fd < 0) {
- log_err(_("Cannot open keyfile %s for write."), file);
- return r;
- }
-
- if (write_buffer(fd, key, keysize) == keysize)
- r = 0;
- else
- log_err(_("Cannot write to keyfile %s."), file);
-
- close(fd);
- return r;
-}
diff --git a/src/utils_tools.c b/src/utils_tools.c
index dbd83695..cf66e4c4 100644
--- a/src/utils_tools.c
+++ b/src/utils_tools.c
@@ -493,3 +493,59 @@ int tools_reencrypt_progress(uint64_t size, uint64_t offset, void *usrptr)
return r;
}
+
+int tools_read_mk(const char *file, char **key, int keysize)
+{
+ int fd = -1, r = -EINVAL;
+
+ if (keysize <= 0 || !key)
+ return -EINVAL;
+
+ *key = crypt_safe_alloc(keysize);
+ if (!*key)
+ return -ENOMEM;
+
+ fd = open(file, O_RDONLY);
+ if (fd == -1) {
+ log_err(_("Cannot read keyfile %s."), file);
+ goto out;
+ }
+
+ if (read_buffer(fd, *key, keysize) != keysize) {
+ log_err(_("Cannot read %d bytes from keyfile %s."), keysize, file);
+ goto out;
+ }
+ r = 0;
+out:
+ if (fd != -1)
+ close(fd);
+
+ if (r) {
+ crypt_safe_free(*key);
+ *key = NULL;
+ }
+
+ return r;
+}
+
+int tools_write_mk(const char *file, const char *key, int keysize)
+{
+ int fd, r = -EINVAL;
+
+ if (keysize <= 0 || !key)
+ return -EINVAL;
+
+ fd = open(file, O_CREAT|O_EXCL|O_WRONLY, S_IRUSR);
+ if (fd < 0) {
+ log_err(_("Cannot open keyfile %s for write."), file);
+ return r;
+ }
+
+ if (write_buffer(fd, key, keysize) == keysize)
+ r = 0;
+ else
+ log_err(_("Cannot write to keyfile %s."), file);
+
+ close(fd);
+ return r;
+}
--
GitLab
From d20beacba060f34e3ab0d71d191f59434031e98f Mon Sep 17 00:00:00 2001
From: Milan Broz <gmazyland@gmail.com>
Date: Wed, 6 Oct 2021 12:45:20 +0200
Subject: [PATCH 2/2] Remove redundant link to uuid lib for static build.
Veritysetup does not need to link this library at all, for others
we have link already in flags.
---
src/Makemodule.am | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/src/Makemodule.am b/src/Makemodule.am
index f2b896bf..49e0c5aa 100644
--- a/src/Makemodule.am
+++ b/src/Makemodule.am
@@ -71,8 +71,7 @@ veritysetup_static_LDFLAGS = $(AM_LDFLAGS) -all-static
veritysetup_static_LDADD = \
$(veritysetup_LDADD) \
@CRYPTO_STATIC_LIBS@ \
- @DEVMAPPER_STATIC_LIBS@ \
- @UUID_LIBS@
+ @DEVMAPPER_STATIC_LIBS@
endif
endif
@@ -109,8 +108,7 @@ integritysetup_static_LDFLAGS = $(AM_LDFLAGS) -all-static
integritysetup_static_LDADD = \
$(integritysetup_LDADD) \
@CRYPTO_STATIC_LIBS@ \
- @DEVMAPPER_STATIC_LIBS@ \
- @UUID_LIBS@
+ @DEVMAPPER_STATIC_LIBS@
endif
endif
--
GitLab