mirror of
https://gitlab.com/cryptsetup/cryptsetup.git
synced 2025-12-10 18:30:00 +01:00
Compare commits
174 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
59cf9969f9 | ||
|
|
98ec1e314a | ||
|
|
a9b327c12a | ||
|
|
eaa93a8116 | ||
|
|
018494b6b3 | ||
|
|
3d7a0f741a | ||
|
|
3858b1815c | ||
|
|
4eca4e8fce | ||
|
|
39abe23e0e | ||
|
|
80faafea48 | ||
|
|
f658ea6ba4 | ||
|
|
fa0a24f726 | ||
|
|
24abdf4e72 | ||
|
|
677572a425 | ||
|
|
30d6a8a8f9 | ||
|
|
9fc40d35d3 | ||
|
|
5a032abc33 | ||
|
|
6df6c0a363 | ||
|
|
e2e57e5776 | ||
|
|
3d8cb44c61 | ||
|
|
05dad56f75 | ||
|
|
69361fec1c | ||
|
|
4e0398aef0 | ||
|
|
51ab9da665 | ||
|
|
855a232403 | ||
|
|
96241cea6a | ||
|
|
9e5c87b449 | ||
|
|
7d1b40a3a6 | ||
|
|
969be38a7a | ||
|
|
93382071a5 | ||
|
|
426a8b9df0 | ||
|
|
83811b5ea9 | ||
|
|
56a01574ff | ||
|
|
c68cd0a483 | ||
|
|
b2135a75e2 | ||
|
|
91e8f5ffd9 | ||
|
|
855628f796 | ||
|
|
db8ce3f818 | ||
|
|
973474503a | ||
|
|
4e2561df6d | ||
|
|
b01ec20703 | ||
|
|
ca1b41cf96 | ||
|
|
7825e0d4a6 | ||
|
|
c8c28cf6dd | ||
|
|
fb8aa6d03b | ||
|
|
207383782a | ||
|
|
f25a1c92ec | ||
|
|
44a9e7aa62 | ||
|
|
27eee9cfcb | ||
|
|
196477d194 | ||
|
|
1e68d73bc3 | ||
|
|
17bb1e2fdd | ||
|
|
ba7fd45ba6 | ||
|
|
7058b81bb6 | ||
|
|
b40018860b | ||
|
|
e97ac9f58c | ||
|
|
75447d0d80 | ||
|
|
c760ae36ea | ||
|
|
dbd20776bc | ||
|
|
3ebbceaef2 | ||
|
|
d733e4d0e8 | ||
|
|
4d6d6edcff | ||
|
|
1380efa1c6 | ||
|
|
bce9d695e3 | ||
|
|
bea6e0da74 | ||
|
|
e064406f85 | ||
|
|
3d58f480ee | ||
|
|
660edf7959 | ||
|
|
312efd8582 | ||
|
|
ec657332c6 | ||
|
|
e123263975 | ||
|
|
e8f2bb4a1a | ||
|
|
6e71e2d6ed | ||
|
|
2f6698d1a7 | ||
|
|
d20929194f | ||
|
|
0a6f89cfa6 | ||
|
|
c74f17c6e7 | ||
|
|
616dd5a304 | ||
|
|
79442539c7 | ||
|
|
92b24fd758 | ||
|
|
4a43a2773a | ||
|
|
74c943c352 | ||
|
|
bc49c83ace | ||
|
|
ed28583f17 | ||
|
|
5345a73ca0 | ||
|
|
36f424ce71 | ||
|
|
a757d84b91 | ||
|
|
255464b0ae | ||
|
|
4c350f4d72 | ||
|
|
7cca38632f | ||
|
|
d8bbfb118b | ||
|
|
178bc9ee39 | ||
|
|
7d4d1baaa7 | ||
|
|
f82c1bf90f | ||
|
|
8d856d4e17 | ||
|
|
fb49d9630d | ||
|
|
7866e71d6f | ||
|
|
d2ee949d88 | ||
|
|
3a29cbbf5d | ||
|
|
51bf5435f9 | ||
|
|
505effe085 | ||
|
|
82f8fb653c | ||
|
|
829a2379a1 | ||
|
|
b5894ce1ab | ||
|
|
1bc6caceb1 | ||
|
|
78f33946f1 | ||
|
|
0d90efac88 | ||
|
|
82490aaaa3 | ||
|
|
782f4c5029 | ||
|
|
d63d399c17 | ||
|
|
745c75b5b0 | ||
|
|
1d615cf6dd | ||
|
|
7f0ddcbed4 | ||
|
|
efa7c4574c | ||
|
|
e2b4479543 | ||
|
|
7c23bdb868 | ||
|
|
fa5d46592e | ||
|
|
e5e09d889b | ||
|
|
7dbd007ac1 | ||
|
|
dbb80e41c7 | ||
|
|
33cc4739da | ||
|
|
5518198f97 | ||
|
|
1a81925764 | ||
|
|
15df5904f2 | ||
|
|
07a06f2f40 | ||
|
|
fd94f036c1 | ||
|
|
03607db1f8 | ||
|
|
c2fcc7aebd | ||
|
|
8dbb72e296 | ||
|
|
513e88fd77 | ||
|
|
8360a85169 | ||
|
|
b56a450a31 | ||
|
|
569b485d02 | ||
|
|
bd888e30a6 | ||
|
|
b86c51afeb | ||
|
|
56f47d3899 | ||
|
|
284672c081 | ||
|
|
6f6b54a5fd | ||
|
|
154c344115 | ||
|
|
cccb7780ec | ||
|
|
aa762d5cc1 | ||
|
|
68cc46fc22 | ||
|
|
06bd23d120 | ||
|
|
2f4990868e | ||
|
|
03213ac230 | ||
|
|
fb1b287773 | ||
|
|
7ceaf3f313 | ||
|
|
3f20b04e42 | ||
|
|
82e6ca7202 | ||
|
|
8a170d0e80 | ||
|
|
72be05c817 | ||
|
|
b79ccb782b | ||
|
|
9c8c636ece | ||
|
|
63a5bd5ef6 | ||
|
|
e75f5de2ed | ||
|
|
6df1a69430 | ||
|
|
e7ca35091c | ||
|
|
03ecfe3478 | ||
|
|
f5bf9ef9fa | ||
|
|
f61eb8b427 | ||
|
|
a4f78e1c98 | ||
|
|
d1c3ad2703 | ||
|
|
d7279eeda1 | ||
|
|
9c2d918474 | ||
|
|
16aec64d1b | ||
|
|
04d2ff7689 | ||
|
|
0cd7cac03f | ||
|
|
b2c1ec2f83 | ||
|
|
a15008d876 | ||
|
|
ac535923e0 | ||
|
|
f695e155ec | ||
|
|
9412d9a0f1 | ||
|
|
57eba0d6f5 | ||
|
|
4a9862a666 |
28
.github/workflows/cibuild-setup-ubuntu.sh
vendored
28
.github/workflows/cibuild-setup-ubuntu.sh
vendored
@@ -1,28 +0,0 @@
|
||||
#!/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
38
.github/workflows/cibuild.sh
vendored
@@ -1,38 +0,0 @@
|
||||
#!/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
29
.github/workflows/cibuild.yml
vendored
@@ -1,29 +0,0 @@
|
||||
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
|
||||
48
.github/workflows/coverity.yml
vendored
48
.github/workflows/coverity.yml
vendored
@@ -1,48 +0,0 @@
|
||||
name: Coverity test
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- 'coverity_scan'
|
||||
paths-ignore:
|
||||
- 'docs/**'
|
||||
|
||||
jobs:
|
||||
latest:
|
||||
runs-on: ubuntu-latest
|
||||
if: github.repository == 'mbroz/cryptsetup'
|
||||
steps:
|
||||
- name: Repository checkout
|
||||
uses: actions/checkout@v1
|
||||
- name: Ubuntu setup
|
||||
run: sudo -E .github/workflows/cibuild-setup-ubuntu.sh
|
||||
env:
|
||||
COMPILER: "gcc"
|
||||
COMPILER_VERSION: "11"
|
||||
- name: Install Coverity
|
||||
run: |
|
||||
wget -q https://scan.coverity.com/download/cxx/linux64 --post-data "token=$TOKEN&project=mbroz/cryptsetup" -O cov-analysis-linux64.tar.gz
|
||||
mkdir cov-analysis-linux64
|
||||
tar xzf cov-analysis-linux64.tar.gz --strip 1 -C cov-analysis-linux64
|
||||
env:
|
||||
TOKEN: ${{ secrets.COVERITY_SCAN_TOKEN }}
|
||||
- name: Run autoconf & configure
|
||||
run: |
|
||||
./autogen.sh
|
||||
./configure
|
||||
- name: Run cov-build
|
||||
run: |
|
||||
export PATH=`pwd`/cov-analysis-linux64/bin:$PATH
|
||||
cov-build --dir cov-int make
|
||||
- name: Submit to Coverity Scan
|
||||
run: |
|
||||
tar czvf cryptsetup.tgz cov-int
|
||||
curl \
|
||||
--form project=mbroz/cryptsetup \
|
||||
--form token=$TOKEN \
|
||||
--form email=gmazyland@gmail.com \
|
||||
--form file=@cryptsetup.tgz \
|
||||
--form version=trunk \
|
||||
--form description="`./cryptsetup --version`" \
|
||||
https://scan.coverity.com/builds?project=mbroz/cryptsetup
|
||||
env:
|
||||
TOKEN: ${{ secrets.COVERITY_SCAN_TOKEN }}
|
||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -25,7 +25,6 @@ config.sub
|
||||
configure
|
||||
cryptsetup
|
||||
cryptsetup-reencrypt
|
||||
cryptsetup-ssh
|
||||
depcomp
|
||||
install-sh
|
||||
integritysetup
|
||||
|
||||
113
.gitlab-ci.yml
113
.gitlab-ci.yml
@@ -1,113 +0,0 @@
|
||||
stages:
|
||||
- test
|
||||
|
||||
.debian-prep:
|
||||
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
|
||||
|
||||
.dnf-openssl-backend:
|
||||
before_script:
|
||||
- >
|
||||
sudo dnf -y -q install
|
||||
autoconf automake device-mapper-devel gcc gettext-devel json-c-devel
|
||||
libargon2-devel libblkid-devel libpwquality-devel libselinux-devel
|
||||
libssh-devel libtool libuuid-devel make popt-devel
|
||||
libsepol-devel.x86_64 netcat openssh-clients passwd pkgconfig sharutils
|
||||
sshpass tar uuid-devel vim-common device-mapper expect gettext git jq
|
||||
keyutils openssl-devel openssl
|
||||
- sudo -E git clean -xdf
|
||||
- ./autogen.sh
|
||||
- ./configure --enable-fips --enable-pwquality --enable-libargon2 --with-crypto_backend=openssl
|
||||
|
||||
# Merge request: Build and run only non-root tests
|
||||
test-mergerq-job-debian-noroot:
|
||||
extends:
|
||||
- .debian-prep
|
||||
tags:
|
||||
- libvirt
|
||||
- debian10
|
||||
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-debian:
|
||||
extends:
|
||||
- .debian-prep
|
||||
tags:
|
||||
- libvirt
|
||||
- debian10
|
||||
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 || $CI_COMMIT_BRANCH =~ /v2\..\.x$/
|
||||
script:
|
||||
- make -j
|
||||
- make -j -C tests check-programs
|
||||
- sudo -E make check
|
||||
- sudo -E make clean
|
||||
|
||||
test-main-commit-job-dnf:
|
||||
extends:
|
||||
- .dnf-openssl-backend
|
||||
tags:
|
||||
- libvirt
|
||||
- fedora-rawhide
|
||||
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 || $CI_COMMIT_BRANCH =~ /v2\..\.x$/
|
||||
script:
|
||||
- make -j
|
||||
- make -j -C tests check-programs
|
||||
- sudo -E make check
|
||||
|
||||
test-mergerq-job-dnf:
|
||||
extends:
|
||||
- .dnf-openssl-backend
|
||||
tags:
|
||||
- libvirt
|
||||
- fedora-rawhide
|
||||
stage: test
|
||||
interruptible: true
|
||||
variables:
|
||||
RUN_SSH_PLUGIN_TEST: "1"
|
||||
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
|
||||
- sudo -E make check
|
||||
|
||||
include:
|
||||
- local: .gitlab/ci/gitlab-shared-docker.yml
|
||||
- local: .gitlab/ci/compilation-gcc.gitlab-ci.yml
|
||||
- local: .gitlab/ci/compilation-clang.gitlab-ci.yml
|
||||
@@ -1,49 +0,0 @@
|
||||
#!/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:?}"
|
||||
|
||||
grep -E '^deb' /etc/apt/sources.list > /etc/apt/sources.list~
|
||||
sed -Ei 's/^deb /deb-src /' /etc/apt/sources.list~
|
||||
cat /etc/apt/sources.list~ >> /etc/apt/sources.list
|
||||
|
||||
apt-get -y update --fix-missing
|
||||
DEBIAN_FRONTEND=noninteractive apt-get -yq install software-properties-common wget lsb-release
|
||||
RELEASE="$(lsb_release -cs)"
|
||||
|
||||
if [[ $COMPILER == "gcc" ]]; then
|
||||
# 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)
|
||||
elif [[ $COMPILER == "clang" ]]; then
|
||||
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add -
|
||||
add-apt-repository "deb http://apt.llvm.org/${RELEASE}/ llvm-toolchain-${RELEASE}-${COMPILER_VERSION} main"
|
||||
|
||||
# scan-build
|
||||
PACKAGES+=(clang-tools-$COMPILER_VERSION clang-$COMPILER_VERSION lldb-$COMPILER_VERSION lld-$COMPILER_VERSION clangd-$COMPILER_VERSION)
|
||||
PACKAGES+=(perl)
|
||||
else
|
||||
exit 1
|
||||
fi
|
||||
|
||||
apt-get -y update --fix-missing
|
||||
DEBIAN_FRONTEND=noninteractive apt-get -yq install "${PACKAGES[@]}"
|
||||
apt-get -y build-dep cryptsetup
|
||||
|
||||
echo "====================== VERSIONS ==================="
|
||||
if [[ $COMPILER == "clang" ]]; then
|
||||
scan-build${COMPILER_VERSION:+-$COMPILER_VERSION} --help
|
||||
fi
|
||||
|
||||
${COMPILER}-$COMPILER_VERSION -v
|
||||
echo "====================== END VERSIONS ==================="
|
||||
@@ -1,55 +0,0 @@
|
||||
#!/bin/bash
|
||||
# clang -Wall plus other important warnings not included in -Wall
|
||||
|
||||
for arg in "$@"
|
||||
do
|
||||
case $arg in
|
||||
-O*) Wuninitialized=-Wuninitialized;; # only makes sense with `-O'
|
||||
esac
|
||||
done
|
||||
|
||||
CLANG="clang${COMPILER_VERSION:+-$COMPILER_VERSION}"
|
||||
|
||||
#PEDANTIC="-std=gnu99"
|
||||
#PEDANTIC="-pedantic -std=gnu99"
|
||||
#PEDANTIC="-pedantic -std=gnu99 -Wno-variadic-macros"
|
||||
#CONVERSION="-Wconversion"
|
||||
|
||||
EXTRA="-Wextra \
|
||||
-Wsign-compare \
|
||||
-Werror-implicit-function-declaration \
|
||||
-Wpointer-arith \
|
||||
-Wwrite-strings \
|
||||
-Wswitch \
|
||||
-Wmissing-format-attribute \
|
||||
-Winit-self \
|
||||
-Wdeclaration-after-statement \
|
||||
-Wold-style-definition \
|
||||
-Wno-missing-field-initializers \
|
||||
-Wno-unused-parameter \
|
||||
-Wno-attributes \
|
||||
-Wno-long-long"
|
||||
|
||||
exec $CLANG $PEDANTIC $CONVERSION \
|
||||
-Wall $Wuninitialized \
|
||||
-Wno-switch \
|
||||
-Wdisabled-optimization \
|
||||
-Wwrite-strings \
|
||||
-Wpointer-arith \
|
||||
-Wbad-function-cast \
|
||||
-Wmissing-prototypes \
|
||||
-Wmissing-declarations \
|
||||
-Wstrict-prototypes \
|
||||
-Wnested-externs \
|
||||
-Wcomment \
|
||||
-Winline \
|
||||
-Wcast-align \
|
||||
-Wcast-qual \
|
||||
-Wredundant-decls $EXTRA \
|
||||
"$@" 2>&1 | {
|
||||
if [[ $USE_FILTER -eq 1 ]]; then
|
||||
.gitlab/ci/warnings_filter.py
|
||||
else
|
||||
cat
|
||||
fi
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
test-clang-compilation:
|
||||
extends:
|
||||
- .gitlab-shared-clang
|
||||
script:
|
||||
- export CFLAGS="-Wall -Werror"
|
||||
- ./configure --enable-pwquality --enable-libargon2
|
||||
- make -j
|
||||
|
||||
# Clang doesn't support json output, so we cannot use the warnings filter
|
||||
# test-clang-Wall-script:
|
||||
# extends:
|
||||
# - .gitlab-shared-clang
|
||||
# script:
|
||||
# - export CFLAGS="-g -O0"
|
||||
# - export CC=".gitlab/ci/clang-Wall"
|
||||
# - ./configure --enable-pwquality --enable-libargon2
|
||||
# - make -j CFLAGS="-g -O0 -Werror"
|
||||
|
||||
test-scan-build:
|
||||
extends:
|
||||
- .gitlab-shared-clang
|
||||
script:
|
||||
- scan-build${COMPILER_VERSION:+-$COMPILER_VERSION} -V ./configure CFLAGS="-g -O0" --enable-internal-sse-argon2 --enable-pwquality --enable-libargon2
|
||||
- make clean
|
||||
- scan-build${COMPILER_VERSION:+-$COMPILER_VERSION} -maxloop 10 make -j
|
||||
@@ -1,24 +0,0 @@
|
||||
test-gcc-compilation:
|
||||
extends:
|
||||
- .gitlab-shared-gcc
|
||||
script:
|
||||
- export CFLAGS="-Wall -Werror"
|
||||
- ./configure --enable-pwquality --enable-libargon2
|
||||
- make -j
|
||||
|
||||
test-gcc-Wall-script:
|
||||
extends:
|
||||
- .gitlab-shared-gcc
|
||||
script:
|
||||
- export CFLAGS="-g -O0"
|
||||
- export CC=".gitlab/ci/gcc-Wall"
|
||||
- USE_FILTER=0 ./configure --enable-pwquality --enable-libargon2
|
||||
- USE_FILTER=1 make -j CFLAGS="-g -O0 -fdiagnostics-format=json"
|
||||
|
||||
test-gcc-fanalyzer:
|
||||
extends:
|
||||
- .gitlab-shared-gcc
|
||||
script:
|
||||
- export CFLAGS="-Wall -Werror -g -O0 -fanalyzer -fdiagnostics-path-format=separate-events"
|
||||
- ./configure --enable-pwquality --enable-libargon2
|
||||
- make -j
|
||||
@@ -1,61 +0,0 @@
|
||||
#!/bin/bash
|
||||
# gcc -Wall plus other important warnings not included in -Wall
|
||||
|
||||
for arg in "$@"
|
||||
do
|
||||
case $arg in
|
||||
-O*) Wuninitialized=-Wuninitialized;; # only makes sense with `-O'
|
||||
esac
|
||||
done
|
||||
|
||||
GCC="gcc${COMPILER_VERSION:+-$COMPILER_VERSION}"
|
||||
|
||||
#PEDANTIC="-std=gnu99"
|
||||
#PEDANTIC="-pedantic -std=gnu99"
|
||||
#PEDANTIC="-pedantic -std=gnu99 -Wno-variadic-macros"
|
||||
#CONVERSION="-Wconversion"
|
||||
# -Wpacked \
|
||||
|
||||
|
||||
EXTRA="-Wextra \
|
||||
-Wsign-compare \
|
||||
-Werror-implicit-function-declaration \
|
||||
-Wpointer-arith \
|
||||
-Wwrite-strings \
|
||||
-Wswitch \
|
||||
-Wmissing-format-attribute \
|
||||
-Wstrict-aliasing=3 \
|
||||
-Winit-self \
|
||||
-Wunsafe-loop-optimizations \
|
||||
-Wdeclaration-after-statement \
|
||||
-Wold-style-definition \
|
||||
-Wno-missing-field-initializers \
|
||||
-Wno-unused-parameter \
|
||||
-Wno-attributes \
|
||||
-Wno-long-long \
|
||||
-Wmaybe-uninitialized \
|
||||
-Wvla"
|
||||
|
||||
exec $GCC $PEDANTIC $CONVERSION \
|
||||
-Wall $Wuninitialized \
|
||||
-Wno-switch \
|
||||
-Wdisabled-optimization \
|
||||
-Wwrite-strings \
|
||||
-Wpointer-arith \
|
||||
-Wbad-function-cast \
|
||||
-Wmissing-prototypes \
|
||||
-Wmissing-declarations \
|
||||
-Wstrict-prototypes \
|
||||
-Wnested-externs \
|
||||
-Wcomment \
|
||||
-Winline \
|
||||
-Wcast-align \
|
||||
-Wcast-qual \
|
||||
-Wredundant-decls $EXTRA \
|
||||
"$@" 2>&1 | {
|
||||
if [[ $USE_FILTER -eq 1 ]]; then
|
||||
.gitlab/ci/warnings_filter.py
|
||||
else
|
||||
cat
|
||||
fi
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
.gitlab-shared-docker:
|
||||
image: ubuntu:focal
|
||||
tags:
|
||||
- gitlab-org-docker
|
||||
stage: test
|
||||
interruptible: true
|
||||
rules:
|
||||
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH || $CI_COMMIT_BRANCH =~ /v2\..\.x$/
|
||||
before_script:
|
||||
- .gitlab/ci/cibuild-setup-ubuntu.sh
|
||||
- export CC="${COMPILER}${COMPILER_VERSION:+-$COMPILER_VERSION}"
|
||||
- export CXX="${COMPILER}++${COMPILER_VERSION:+-$COMPILER_VERSION}"
|
||||
- ./autogen.sh
|
||||
|
||||
.gitlab-shared-gcc:
|
||||
extends:
|
||||
- .gitlab-shared-docker
|
||||
variables:
|
||||
COMPILER: "gcc"
|
||||
COMPILER_VERSION: "11"
|
||||
RUN_SSH_PLUGIN_TEST: "1"
|
||||
|
||||
.gitlab-shared-clang:
|
||||
extends:
|
||||
- .gitlab-shared-docker
|
||||
variables:
|
||||
COMPILER: "clang"
|
||||
COMPILER_VERSION: "13"
|
||||
RUN_SSH_PLUGIN_TEST: "1"
|
||||
@@ -1,31 +0,0 @@
|
||||
#!/usr/bin/python3
|
||||
|
||||
import sys
|
||||
import json
|
||||
import linecache
|
||||
|
||||
if __name__ == "__main__":
|
||||
json_string = sys.stdin.read()
|
||||
if json_string in [None, ""]:
|
||||
sys.exit(0)
|
||||
|
||||
parsed = json.loads(json_string)
|
||||
#print(json.dumps(parsed, indent=4, sort_keys=True))
|
||||
|
||||
r = 0
|
||||
|
||||
for o in parsed:
|
||||
kind = o["kind"]
|
||||
|
||||
start = o["locations"][0]["caret"]
|
||||
l = linecache.getline(start["file"], int(start["line"]))
|
||||
|
||||
ignored = "json_object_object_foreach" in l
|
||||
|
||||
print(f"{o['kind']} {'ignored' if ignored else 'FOUND'} in {start['file']}:{start['line']}:{start['column']} {o['message']}")
|
||||
print(f"line contains:\n\t{l}", end="")
|
||||
|
||||
if not ignored:
|
||||
r = 1
|
||||
|
||||
sys.exit(r)
|
||||
166
.travis-functions.sh
Normal file
166
.travis-functions.sh
Normal file
@@ -0,0 +1,166 @@
|
||||
#!/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 \
|
||||
dkms \
|
||||
linux-headers-$(uname -r) \
|
||||
linux-modules-extra-$(uname -r) \
|
||||
|| return
|
||||
|
||||
# For VeraCrypt test
|
||||
sudo apt-get install gost-crypto-dkms
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
42
.travis.yml
Normal file
42
.travis.yml
Normal file
@@ -0,0 +1,42 @@
|
||||
language: c
|
||||
|
||||
sudo: required
|
||||
os: linux
|
||||
dist: focal
|
||||
group: edge
|
||||
|
||||
compiler:
|
||||
- gcc
|
||||
|
||||
env:
|
||||
# MAKE_CHECK="gcrypt"
|
||||
- MAKE_CHECK="openssl"
|
||||
# MAKE_CHECK="kernel"
|
||||
|
||||
branches:
|
||||
only:
|
||||
- master
|
||||
- wip-luks2
|
||||
- v2.3.x
|
||||
|
||||
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
|
||||
6
ChangeLog
Normal file
6
ChangeLog
Normal file
@@ -0,0 +1,6 @@
|
||||
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
|
||||
88
FAQ
88
FAQ
@@ -51,7 +51,7 @@ A. Contributors
|
||||
security model BEFORE you face such a disaster! In particular, make
|
||||
sure you have a current header backup before doing any potentially
|
||||
dangerous operations. The LUKS2 header should be a bit more resilient
|
||||
as critical data starts later and is stored twice, but you can decidely
|
||||
as critical data starts later and is stored twice, but you can decidedly
|
||||
still destroy it or a keyslot permanently by accident.
|
||||
|
||||
DEBUG COMMANDS: While the --debug and --debug-json options should not
|
||||
@@ -235,31 +235,6 @@ A. Contributors
|
||||
nothing and are sure you did not confirm, then you should look into a
|
||||
possible compromise of your email account.
|
||||
|
||||
* 1.9 What can I do if cryptsetup is running out of memory?
|
||||
|
||||
Memory issues are generally related to the key derivation function. You may
|
||||
be able to tune usage with the options --pbkdf-memory or --pbkdf pbkdf2.
|
||||
|
||||
|
||||
* 1.10 Can cryptsetup be run without root access?
|
||||
|
||||
Elevated privileges are required to use cryptsetup and LUKS. Some operations
|
||||
require root access. There are a few features which will work without root
|
||||
access with the right switches but there are caveats.
|
||||
|
||||
|
||||
* 1.11 What are the problems with running as non root?
|
||||
|
||||
The first issue is one of permissions to devices. Generally, root or a group
|
||||
such as disk has ownership of the storage devices. The non root user will
|
||||
need write access to the block device used for LUKS.
|
||||
|
||||
Next, file locking is managed in /run/cryptsetup. You may use
|
||||
--disable-locks but cryptsetup will no longer protect you from race
|
||||
conditions and problems with concurrent access to the same devices.
|
||||
|
||||
Also, device mapper requires root access. cryptsetup uses device mapper to
|
||||
manage the decrypted container.
|
||||
|
||||
2. Setup
|
||||
|
||||
@@ -424,14 +399,6 @@ A. Contributors
|
||||
it in some other way. The PC is just not set-up for a really secure
|
||||
boot-chain (whatever some people may claim).
|
||||
|
||||
That said, if you want an encrypted root partition, you have to store
|
||||
an initrd with cryptsetup somewhere else. The traditional approach is
|
||||
to have a separate partition under /boot for that. You can also put that
|
||||
initrd on a bootable memory stick, bootable CD or bootable external
|
||||
drive as well. The kernel and Grub typically go to the same location
|
||||
as that initrd. A minimal example what such an initrd can look like is
|
||||
given in Section 9.
|
||||
|
||||
(2) Fully encrypted raw block device: For this, put LUKS on the raw
|
||||
device (e.g. /dev/sdb) and put a filesystem into the LUKS container, no
|
||||
partitioning whatsoever involved. This is very suitable for things like
|
||||
@@ -851,7 +818,7 @@ A. Contributors
|
||||
|
||||
|
||||
* 2.20 How do I wipe only the LUKS header?
|
||||
|
||||
|
||||
This does _not_ describe an emergency wipe procedure, see Item 5.4 for
|
||||
that. This procedure here is intended to be used when the data should
|
||||
stay intact, e.g. when you change your LUKS container to use a detached
|
||||
@@ -864,26 +831,20 @@ A. Contributors
|
||||
cryptsetup luksDump <device with LUKS container>
|
||||
|
||||
-> ...
|
||||
Payload offset: <number> [of 512 byte sectors]
|
||||
Payload offset: <number>
|
||||
...
|
||||
|
||||
02) Take the result number, multiply by 512 zeros and write to
|
||||
the start of the device, e.g. using one of the following alternatives:
|
||||
the start of the device, e.g. like this:
|
||||
|
||||
dd bs=512 count=<number> if=/dev/zero of=<device>
|
||||
|
||||
|
||||
head -c <number * 512> /dev/zero > /dev/<device>
|
||||
|
||||
|
||||
LUKS2:
|
||||
(warning, untested! Remember that backup?) This assumes the
|
||||
LUKS2: (warning, untested! Remember that backup?) This assumes the
|
||||
LUKS2 container uses the defaults, in particular there is only one data
|
||||
segment.
|
||||
01) Determine the data-segment offset using luksDump, same
|
||||
segment. 01) Determine the data-segment offset using luksDump, same
|
||||
as above for LUKS1:
|
||||
|
||||
cryptsetup luksDump <device with LUKS container>
|
||||
-> ...
|
||||
Data segments:
|
||||
0: crypt
|
||||
@@ -893,7 +854,7 @@ A. Contributors
|
||||
02) Overwrite the stated number of bytes from the start of the device.
|
||||
Just to give yet another way to get a defined number of zeros:
|
||||
|
||||
head -c <number> /dev/zero > /dev/<device>
|
||||
head -c /dev/zero > /dev/<device>
|
||||
|
||||
|
||||
3. Common Problems
|
||||
@@ -1008,7 +969,7 @@ A. Contributors
|
||||
that is intact.
|
||||
|
||||
In order to find out whether a key-slot is damaged one has to look for
|
||||
"non-random looking" data in it. There is a tool that automatizes this
|
||||
"non-random looking" data in it. There is a tool that automates this
|
||||
for LUKS1 in the cryptsetup distribution from version 1.6.0 onwards. It
|
||||
is located in misc/keyslot_checker/. Instructions how to use and how to
|
||||
interpret results are in the README file. Note that this tool requires
|
||||
@@ -1246,17 +1207,6 @@ A. Contributors
|
||||
countries like the US or the UK are not civilized and do not have fair
|
||||
laws.
|
||||
|
||||
As a side-note, standards for biometrics (fingerprint, retina,
|
||||
vein-pattern, etc.) are often different and much lower. If you put
|
||||
your LUKS passphrase into a device that can be unlocked using biometrics,
|
||||
they may force a biometric sample in many countries where they could not
|
||||
force you to give them a passphrase you solely have in your memory and
|
||||
can claim to have forgotten if needed (it happens). If you need protection
|
||||
on this level, make sure you know what the respective legal situation is,
|
||||
also while traveling, and make sure you decide beforehand what you
|
||||
will do if push comes to shove as they will definitely put you under
|
||||
as much pressure as they can legally apply.
|
||||
|
||||
This means that if you have a large set of random-looking data, they can
|
||||
already lock you up. Hidden containers (encryption hidden within
|
||||
encryption), as possible with Truecrypt, do not help either. They will
|
||||
@@ -1658,8 +1608,9 @@ A. Contributors
|
||||
|
||||
cryptsetup -c aes-xts-plain64 luksFormat <device>
|
||||
|
||||
There is a potential security issue with XTS mode and large blocks.
|
||||
LUKS and dm-crypt always use 512B blocks and the issue does not apply.
|
||||
There is a potential security issue with XTS mode and blocks larger
|
||||
than 2^20 bytes or so. LUKS and dm-crypt always use smaller blocks
|
||||
and the issue does not apply.
|
||||
|
||||
|
||||
* 5.17 Is LUKS FIPS-140-2 certified?
|
||||
@@ -2678,7 +2629,7 @@ offset length name data type description
|
||||
safe under these circumstances, then you have bigger problems than this
|
||||
somewhat expected behavior.
|
||||
|
||||
The CVE was exagerrated and should not be assigned to upstream
|
||||
The CVE was exaggerated and should not be assigned to upstream
|
||||
cryptsetup in the first place (it is a distro specific initrd issue).
|
||||
It was driven more by a try to make a splash for self-aggrandizement,
|
||||
than by any actual security concerns. Ignore it.
|
||||
@@ -3002,24 +2953,9 @@ offset length name data type description
|
||||
start of the device, nothing gets stored somewhere in the middle or at
|
||||
the end.
|
||||
|
||||
* 10.12 What is a LUKS2 Token?
|
||||
|
||||
A LUKS2 token is an object that describes "how to get a passphrase or
|
||||
key" to unlock particular keyslot. A LUKS2 token is stored as json data
|
||||
in the LUKS2 header. The token can be related to all keyslots or a
|
||||
specific one. As the token is stored in JSON formay it is text by
|
||||
default but binary data can be encoded into it according to the JSON
|
||||
conventions.
|
||||
|
||||
Documentation on the last changes to LUKS2 tokens can be found in the
|
||||
release notes. As of version 2.4 of cryptsetup, there are significant
|
||||
features. The standard documentation for working with tokens is
|
||||
in the luks2 reference available as PDF on the project page.
|
||||
|
||||
|
||||
11. References and Further Reading
|
||||
|
||||
|
||||
* Purpose of this Section
|
||||
|
||||
The purpose of this section is to collect references to all materials
|
||||
|
||||
229
INSTALL
Normal file
229
INSTALL
Normal file
@@ -0,0 +1,229 @@
|
||||
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 = README.md COPYING.LGPL FAQ docs misc autogen.sh
|
||||
EXTRA_DIST = COPYING.LGPL FAQ docs misc
|
||||
SUBDIRS = po tests
|
||||
CLEANFILES =
|
||||
DISTCLEAN_TARGETS =
|
||||
@@ -11,8 +11,7 @@ AM_CPPFLAGS = \
|
||||
-DLIBDIR=\""$(libdir)"\" \
|
||||
-DPREFIX=\""$(prefix)"\" \
|
||||
-DSYSCONFDIR=\""$(sysconfdir)"\" \
|
||||
-DVERSION=\""$(VERSION)"\" \
|
||||
-DEXTERNAL_LUKS2_TOKENS_PATH=\"${EXTERNAL_LUKS2_TOKENS_PATH}\"
|
||||
-DVERSION=\""$(VERSION)"\"
|
||||
AM_CFLAGS = -Wall
|
||||
AM_LDFLAGS =
|
||||
|
||||
@@ -20,13 +19,10 @@ LDADD = $(LTLIBINTL) -lm
|
||||
|
||||
tmpfilesddir = @DEFAULT_TMPFILESDIR@
|
||||
|
||||
include_HEADERS =
|
||||
lib_LTLIBRARIES =
|
||||
noinst_LTLIBRARIES =
|
||||
sbin_PROGRAMS =
|
||||
man8_MANS =
|
||||
tmpfilesd_DATA =
|
||||
pkgconfig_DATA =
|
||||
|
||||
include man/Makemodule.am
|
||||
|
||||
@@ -39,14 +35,12 @@ 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-external-tokens --enable-ssh-token
|
||||
--enable-internal-argon2 --enable-internal-sse-argon2
|
||||
|
||||
distclean-local:
|
||||
-find . -name \*~ -o -name \*.orig -o -name \*.rej | xargs rm -f
|
||||
@@ -54,9 +48,3 @@ 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 || :
|
||||
|
||||
32
README
Normal file
32
README
Normal file
@@ -0,0 +1,32 @@
|
||||
|
||||
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: https://www.saout.de/mailman/listinfo/dm-crypt
|
||||
ARCHIVE: https://lore.kernel.org/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:
|
||||
https://translationproject.org/domain/cryptsetup.html
|
||||
53
README.md
53
README.md
@@ -10,7 +10,7 @@ These include **plain** **dm-crypt** volumes, **LUKS** volumes, **loop-AES**,
|
||||
|
||||
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 **integritysetup** to setup
|
||||
and, since version 2.0, **integritysetup** to setup
|
||||
[DMIntegrity](https://gitlab.com/cryptsetup/cryptsetup/wikis/DMIntegrity) block integrity kernel module.
|
||||
|
||||
|
||||
@@ -20,8 +20,6 @@ LUKS Design
|
||||
only facilitate compatibility among distributions, but also provides secure management of multiple user passwords.
|
||||
LUKS stores all necessary setup information in the partition header, enabling to transport or migrate data seamlessly.
|
||||
|
||||
### Specifications
|
||||
|
||||
Last version of the LUKS2 format specification is
|
||||
[available here](https://gitlab.com/cryptsetup/LUKS2-docs).
|
||||
|
||||
@@ -46,16 +44,16 @@ Download
|
||||
--------
|
||||
All release tarballs and release notes are hosted on [kernel.org](https://www.kernel.org/pub/linux/utils/cryptsetup/).
|
||||
|
||||
**The latest stable cryptsetup version is 2.4.3**
|
||||
* [cryptsetup-2.4.3.tar.xz](https://www.kernel.org/pub/linux/utils/cryptsetup/v2.4/cryptsetup-2.4.3.tar.xz)
|
||||
* Signature [cryptsetup-2.4.3.tar.sign](https://www.kernel.org/pub/linux/utils/cryptsetup/v2.4/cryptsetup-2.4.3.tar.sign)
|
||||
**The latest stable cryptsetup version is 2.3.5**
|
||||
* [cryptsetup-2.3.5.tar.xz](https://www.kernel.org/pub/linux/utils/cryptsetup/v2.3/cryptsetup-2.3.5.tar.xz)
|
||||
* Signature [cryptsetup-2.3.5.tar.sign](https://www.kernel.org/pub/linux/utils/cryptsetup/v2.3/cryptsetup-2.3.5.tar.sign)
|
||||
_(You need to decompress file first to check signature.)_
|
||||
* [Cryptsetup 2.4.3 Release Notes](https://www.kernel.org/pub/linux/utils/cryptsetup/v2.4/v2.4.3-ReleaseNotes).
|
||||
* [Cryptsetup 2.3.5 Release Notes](https://www.kernel.org/pub/linux/utils/cryptsetup/v2.3/v2.3.5-ReleaseNotes).
|
||||
|
||||
Previous versions
|
||||
* [Version 2.3.7](https://www.kernel.org/pub/linux/utils/cryptsetup/v2.3/cryptsetup-2.3.7.tar.xz) -
|
||||
[Signature](https://www.kernel.org/pub/linux/utils/cryptsetup/v2.3/cryptsetup-2.3.7.tar.sign) -
|
||||
[Release Notes](https://www.kernel.org/pub/linux/utils/cryptsetup/v2.3/v2.3.7-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 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).
|
||||
@@ -71,37 +69,12 @@ The libcryptsetup API/ABI changes are tracked in [compatibility report](https://
|
||||
|
||||
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 yourself, some packages are required for compilation. Please always prefer distro specific build tools to manually configuring cryptsetup.
|
||||
For available compile options, check ``configure --help`` for more info. If you are using a git snapshot, you need to generate a 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 the internal testsuite you also need to install `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 the internal testsuite you also need to install `sharutils dmsetup jq xxd expect keyutils netcat passwd openssh-client sshpass`
|
||||
|
||||
Note that the list could change as the distributions evolve.
|
||||
|
||||
Help!
|
||||
-----
|
||||
Please always read [FAQ](https://gitlab.com/cryptsetup/cryptsetup/wikis/FrequentlyAskedQuestions) first.
|
||||
For cryptsetup and LUKS related questions, please use the dm-crypt mailing list, [dm-crypt@saout.de](mailto:dm-crypt@saout.de).
|
||||
|
||||
### Documentation
|
||||
If you want to subscribe just send an empty mail to [dm-crypt-subscribe@saout.de](mailto:dm-crypt-subscribe@saout.de).
|
||||
|
||||
Please read the following documentation before posting questions in the mailing list. You will be able to ask better questions and better understand the answers.
|
||||
|
||||
* [FAQ](https://gitlab.com/cryptsetup/cryptsetup/wikis/FrequentlyAskedQuestions)
|
||||
* LUKS Specifications
|
||||
* manuals (aka man page, man pages, man-page)
|
||||
|
||||
The FAQ is online and in the source code for the project. The Specifications are referenced above in this document. The man pages are in source and should be available after installation using standard man commands. e.g. man cryptsetup
|
||||
|
||||
### Mailing List
|
||||
|
||||
For cryptsetup and LUKS related questions, please use the dm-crypt mailing list, [dm-crypt@saout.de](mailto:dm-crypt@saout.de). To subscribe send an empty mail to [dm-crypt-subscribe@saout.de](mailto:dm-crypt-subscribe@saout.de).
|
||||
|
||||
You can also browse and/or search the mailing list archives using the following resources:
|
||||
|
||||
* [list archive](https://www.saout.de/pipermail/dm-crypt/)
|
||||
* [web interface on lore.kernel.org](https://lore.kernel.org/dm-crypt/)
|
||||
* [marc.info](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
Normal file
1
TODO
Normal file
@@ -0,0 +1 @@
|
||||
Please see issues tracked at https://gitlab.com/cryptsetup/cryptsetup/issues.
|
||||
@@ -29,10 +29,10 @@ DIE=0
|
||||
DIE=1
|
||||
}
|
||||
|
||||
(grep "^LT_INIT" $srcdir/configure.ac >/dev/null) && {
|
||||
(libtoolize --version) < /dev/null > /dev/null 2>&1 || {
|
||||
(grep "^AM_PROG_LIBTOOL" $srcdir/configure.ac >/dev/null) && {
|
||||
(libtool --version) < /dev/null > /dev/null 2>&1 || {
|
||||
echo
|
||||
echo "**Error**: You must have libtoolize installed."
|
||||
echo "**Error**: You must have libtool installed."
|
||||
echo "Download the appropriate package for your distribution."
|
||||
DIE=1
|
||||
}
|
||||
|
||||
68
configure.ac
68
configure.ac
@@ -1,9 +1,9 @@
|
||||
AC_PREREQ([2.67])
|
||||
AC_INIT([cryptsetup],[2.4.3])
|
||||
AC_INIT([cryptsetup],[2.3.5])
|
||||
|
||||
dnl library version from <major>.<minor>.<release>[-<suffix>]
|
||||
LIBCRYPTSETUP_VERSION=$(echo $PACKAGE_VERSION | cut -f1 -d-)
|
||||
LIBCRYPTSETUP_VERSION_INFO=19:0:7
|
||||
LIBCRYPTSETUP_VERSION_INFO=18:0:6
|
||||
|
||||
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 foreign])
|
||||
AM_INIT_AUTOMAKE([dist-xz 1.12 serial-tests subdir-objects])
|
||||
|
||||
if test "x$prefix" = "xNONE"; then
|
||||
sysconfdir=/etc
|
||||
@@ -30,7 +30,6 @@ 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
|
||||
@@ -58,6 +57,7 @@ dnl ==========================================================================
|
||||
AC_C_RESTRICT
|
||||
|
||||
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])],
|
||||
@@ -115,39 +115,6 @@ 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])
|
||||
dnl we need dynamic library loading here
|
||||
saved_LIBS=$LIBS
|
||||
AC_SEARCH_LIBS([dlsym],[dl])
|
||||
AC_CHECK_FUNCS([dlvsym])
|
||||
AC_SUBST(DL_LIBS, $LIBS)
|
||||
LIBS=$saved_LIBS
|
||||
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 LUKS2 online reencryption
|
||||
AC_ARG_ENABLE([luks2-reencryption],
|
||||
AS_HELP_STRING([--disable-luks2-reencryption], [disable LUKS2 online reencryption extension]),
|
||||
[], [enable_luks2_reencryption=yes])
|
||||
if test "x$enable_luks2_reencryption" = "xyes"; then
|
||||
AC_DEFINE(USE_LUKS2_REENCRYPTION, 1, [Use LUKS2 online reencryption extension])
|
||||
fi
|
||||
|
||||
dnl ==========================================================================
|
||||
|
||||
AM_GNU_GETTEXT([external],[need-ngettext])
|
||||
@@ -413,17 +380,6 @@ 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 and argp 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>])
|
||||
AC_CHECK_HEADER([argp.h], [], AC_MSG_ERROR([You need argp library.]))
|
||||
saved_LIBS=$LIBS
|
||||
AC_SEARCH_LIBS([argp_usage],[argp])
|
||||
AC_SUBST(ARGP_LIBS, $LIBS)
|
||||
LIBS=$saved_LIBS
|
||||
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]]),
|
||||
@@ -580,8 +536,6 @@ 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])
|
||||
|
||||
@@ -637,7 +591,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], [argon2id])
|
||||
CS_STR_WITH([luks2-pbkdf], [Default PBKDF algorithm (pbkdf2 or argon2i/argon2id) for LUKS2], [argon2i])
|
||||
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])
|
||||
@@ -650,8 +604,7 @@ 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([integrity-keyfile-size-maxkb],[maximum integritysetup keyfile size (in KiB)], [4])
|
||||
CS_NUM_WITH([passphrase-size-max],[maximum passphrase size (in characters)], [512])
|
||||
CS_NUM_WITH([passphrase-size-max],[maximum keyfile 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])
|
||||
@@ -679,15 +632,6 @@ 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,4 +1,4 @@
|
||||
# Doxyfile 1.9.1
|
||||
# Doxyfile 1.8.8
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
# Project related configuration options
|
||||
@@ -12,7 +12,6 @@ OUTPUT_DIRECTORY = doxygen_api_docs
|
||||
CREATE_SUBDIRS = NO
|
||||
ALLOW_UNICODE_NAMES = NO
|
||||
OUTPUT_LANGUAGE = English
|
||||
OUTPUT_TEXT_DIRECTION = None
|
||||
BRIEF_MEMBER_DESC = YES
|
||||
REPEAT_BRIEF = YES
|
||||
ABBREVIATE_BRIEF =
|
||||
@@ -23,47 +22,40 @@ STRIP_FROM_PATH =
|
||||
STRIP_FROM_INC_PATH =
|
||||
SHORT_NAMES = NO
|
||||
JAVADOC_AUTOBRIEF = NO
|
||||
JAVADOC_BANNER = NO
|
||||
QT_AUTOBRIEF = NO
|
||||
MULTILINE_CPP_IS_BRIEF = NO
|
||||
PYTHON_DOCSTRING = YES
|
||||
INHERIT_DOCS = YES
|
||||
SEPARATE_MEMBER_PAGES = NO
|
||||
TAB_SIZE = 8
|
||||
ALIASES =
|
||||
TCL_SUBST =
|
||||
OPTIMIZE_OUTPUT_FOR_C = YES
|
||||
OPTIMIZE_OUTPUT_JAVA = NO
|
||||
OPTIMIZE_FOR_FORTRAN = NO
|
||||
OPTIMIZE_OUTPUT_VHDL = NO
|
||||
OPTIMIZE_OUTPUT_SLICE = NO
|
||||
EXTENSION_MAPPING =
|
||||
MARKDOWN_SUPPORT = YES
|
||||
TOC_INCLUDE_HEADINGS = 5
|
||||
AUTOLINK_SUPPORT = YES
|
||||
BUILTIN_STL_SUPPORT = NO
|
||||
CPP_CLI_SUPPORT = NO
|
||||
SIP_SUPPORT = NO
|
||||
IDL_PROPERTY_SUPPORT = YES
|
||||
DISTRIBUTE_GROUP_DOC = NO
|
||||
GROUP_NESTED_COMPOUNDS = NO
|
||||
SUBGROUPING = YES
|
||||
INLINE_GROUPED_CLASSES = NO
|
||||
INLINE_SIMPLE_STRUCTS = NO
|
||||
TYPEDEF_HIDES_STRUCT = YES
|
||||
LOOKUP_CACHE_SIZE = 0
|
||||
NUM_PROC_THREADS = 1
|
||||
#---------------------------------------------------------------------------
|
||||
# Build related configuration options
|
||||
#---------------------------------------------------------------------------
|
||||
EXTRACT_ALL = NO
|
||||
EXTRACT_PRIVATE = NO
|
||||
EXTRACT_PRIV_VIRTUAL = NO
|
||||
EXTRACT_PACKAGE = NO
|
||||
EXTRACT_STATIC = NO
|
||||
EXTRACT_LOCAL_CLASSES = YES
|
||||
EXTRACT_LOCAL_METHODS = NO
|
||||
EXTRACT_ANON_NSPACES = NO
|
||||
RESOLVE_UNNAMED_PARAMS = YES
|
||||
HIDE_UNDOC_MEMBERS = NO
|
||||
HIDE_UNDOC_CLASSES = NO
|
||||
HIDE_FRIEND_COMPOUNDS = NO
|
||||
@@ -71,7 +63,6 @@ HIDE_IN_BODY_DOCS = NO
|
||||
INTERNAL_DOCS = NO
|
||||
CASE_SENSE_NAMES = YES
|
||||
HIDE_SCOPE_NAMES = NO
|
||||
HIDE_COMPOUND_REFERENCE= NO
|
||||
SHOW_INCLUDE_FILES = YES
|
||||
SHOW_GROUPED_MEMB_INC = NO
|
||||
FORCE_LOCAL_INCLUDES = NO
|
||||
@@ -102,14 +93,13 @@ WARNINGS = YES
|
||||
WARN_IF_UNDOCUMENTED = YES
|
||||
WARN_IF_DOC_ERROR = YES
|
||||
WARN_NO_PARAMDOC = NO
|
||||
WARN_AS_ERROR = NO
|
||||
WARN_FORMAT = "$file:$line: $text"
|
||||
WARN_LOGFILE =
|
||||
#---------------------------------------------------------------------------
|
||||
# Configuration options related to the input files
|
||||
#---------------------------------------------------------------------------
|
||||
INPUT = doxygen_index.h \
|
||||
../lib/libcryptsetup.h
|
||||
INPUT = "doxygen_index.h" \
|
||||
"../lib/libcryptsetup.h"
|
||||
INPUT_ENCODING = UTF-8
|
||||
FILE_PATTERNS =
|
||||
RECURSIVE = NO
|
||||
@@ -117,7 +107,7 @@ EXCLUDE =
|
||||
EXCLUDE_SYMLINKS = NO
|
||||
EXCLUDE_PATTERNS =
|
||||
EXCLUDE_SYMBOLS =
|
||||
EXAMPLE_PATH = examples
|
||||
EXAMPLE_PATH = "examples"
|
||||
EXAMPLE_PATTERNS =
|
||||
EXAMPLE_RECURSIVE = NO
|
||||
IMAGE_PATH =
|
||||
@@ -139,13 +129,12 @@ SOURCE_TOOLTIPS = YES
|
||||
USE_HTAGS = NO
|
||||
VERBATIM_HEADERS = YES
|
||||
CLANG_ASSISTED_PARSING = NO
|
||||
CLANG_ADD_INC_PATHS = YES
|
||||
CLANG_OPTIONS =
|
||||
CLANG_DATABASE_PATH =
|
||||
#---------------------------------------------------------------------------
|
||||
# Configuration options related to the alphabetical class index
|
||||
#---------------------------------------------------------------------------
|
||||
ALPHABETICAL_INDEX = YES
|
||||
COLS_IN_ALPHA_INDEX = 5
|
||||
IGNORE_PREFIX =
|
||||
#---------------------------------------------------------------------------
|
||||
# Configuration options related to the HTML output
|
||||
@@ -162,7 +151,6 @@ HTML_COLORSTYLE_HUE = 220
|
||||
HTML_COLORSTYLE_SAT = 100
|
||||
HTML_COLORSTYLE_GAMMA = 80
|
||||
HTML_TIMESTAMP = YES
|
||||
HTML_DYNAMIC_MENUS = YES
|
||||
HTML_DYNAMIC_SECTIONS = NO
|
||||
HTML_INDEX_NUM_ENTRIES = 100
|
||||
GENERATE_DOCSET = NO
|
||||
@@ -192,10 +180,8 @@ GENERATE_TREEVIEW = NO
|
||||
ENUM_VALUES_PER_LINE = 4
|
||||
TREEVIEW_WIDTH = 250
|
||||
EXT_LINKS_IN_WINDOW = NO
|
||||
HTML_FORMULA_FORMAT = png
|
||||
FORMULA_FONTSIZE = 10
|
||||
FORMULA_TRANSPARENT = YES
|
||||
FORMULA_MACROFILE =
|
||||
USE_MATHJAX = NO
|
||||
MATHJAX_FORMAT = HTML-CSS
|
||||
MATHJAX_RELPATH = http://www.mathjax.org/mathjax
|
||||
@@ -215,13 +201,11 @@ GENERATE_LATEX = YES
|
||||
LATEX_OUTPUT = latex
|
||||
LATEX_CMD_NAME = latex
|
||||
MAKEINDEX_CMD_NAME = makeindex
|
||||
LATEX_MAKEINDEX_CMD = makeindex
|
||||
COMPACT_LATEX = NO
|
||||
PAPER_TYPE = a4
|
||||
EXTRA_PACKAGES =
|
||||
LATEX_HEADER =
|
||||
LATEX_FOOTER =
|
||||
LATEX_EXTRA_STYLESHEET =
|
||||
LATEX_EXTRA_FILES =
|
||||
PDF_HYPERLINKS = YES
|
||||
USE_PDFLATEX = YES
|
||||
@@ -229,8 +213,6 @@ LATEX_BATCHMODE = NO
|
||||
LATEX_HIDE_INDICES = NO
|
||||
LATEX_SOURCE_CODE = NO
|
||||
LATEX_BIB_STYLE = plain
|
||||
LATEX_TIMESTAMP = NO
|
||||
LATEX_EMOJI_DIRECTORY =
|
||||
#---------------------------------------------------------------------------
|
||||
# Configuration options related to the RTF output
|
||||
#---------------------------------------------------------------------------
|
||||
@@ -240,7 +222,6 @@ COMPACT_RTF = NO
|
||||
RTF_HYPERLINKS = NO
|
||||
RTF_STYLESHEET_FILE =
|
||||
RTF_EXTENSIONS_FILE =
|
||||
RTF_SOURCE_CODE = NO
|
||||
#---------------------------------------------------------------------------
|
||||
# Configuration options related to the man page output
|
||||
#---------------------------------------------------------------------------
|
||||
@@ -255,7 +236,6 @@ MAN_LINKS = NO
|
||||
GENERATE_XML = NO
|
||||
XML_OUTPUT = xml
|
||||
XML_PROGRAMLISTING = YES
|
||||
XML_NS_MEMB_FILE_SCOPE = NO
|
||||
#---------------------------------------------------------------------------
|
||||
# Configuration options related to the DOCBOOK output
|
||||
#---------------------------------------------------------------------------
|
||||
@@ -293,10 +273,12 @@ GENERATE_TAGFILE =
|
||||
ALLEXTERNALS = NO
|
||||
EXTERNAL_GROUPS = YES
|
||||
EXTERNAL_PAGES = YES
|
||||
PERL_PATH =
|
||||
#---------------------------------------------------------------------------
|
||||
# Configuration options related to the dot tool
|
||||
#---------------------------------------------------------------------------
|
||||
CLASS_DIAGRAMS = YES
|
||||
MSCGEN_PATH =
|
||||
DIA_PATH =
|
||||
HIDE_UNDOC_RELATIONS = YES
|
||||
HAVE_DOT = NO
|
||||
@@ -309,8 +291,6 @@ COLLABORATION_GRAPH = YES
|
||||
GROUP_GRAPHS = YES
|
||||
UML_LOOK = NO
|
||||
UML_LIMIT_NUM_FIELDS = 10
|
||||
DOT_UML_DETAILS = NO
|
||||
DOT_WRAP_THRESHOLD = 17
|
||||
TEMPLATE_RELATIONS = NO
|
||||
INCLUDE_GRAPH = YES
|
||||
INCLUDED_BY_GRAPH = YES
|
||||
@@ -325,8 +305,6 @@ DOTFILE_DIRS =
|
||||
MSCFILE_DIRS =
|
||||
DIAFILE_DIRS =
|
||||
PLANTUML_JAR_PATH =
|
||||
PLANTUML_CFG_FILE =
|
||||
PLANTUML_INCLUDE_PATH =
|
||||
DOT_GRAPH_MAX_NODES = 50
|
||||
MAX_DOT_GRAPH_DEPTH = 0
|
||||
DOT_TRANSPARENT = NO
|
||||
|
||||
Binary file not shown.
@@ -1,56 +0,0 @@
|
||||
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".
|
||||
@@ -1,302 +0,0 @@
|
||||
Cryptsetup 2.4.0 Release Notes
|
||||
==============================
|
||||
Stable release 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,47 +0,0 @@
|
||||
Cryptsetup 2.4.1 Release Notes
|
||||
==============================
|
||||
Stable bug-fix release with minor extensions.
|
||||
|
||||
All users of cryptsetup 2.4.0 should upgrade to this version.
|
||||
|
||||
Changes since version 2.4.0
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
* Fix compilation for libc implementations without dlvsym().
|
||||
|
||||
Some alternative libc implementations (like musl) do not provide
|
||||
versioned symbols dlvsym function. Code now fallbacks to dlsym
|
||||
operation for dynamic LUKS2 token load.
|
||||
It is up to maintainers to ensure that LUKS2 token plugins are
|
||||
compiled for the supported version.
|
||||
|
||||
* Fix compilation and tests on systems with non-standard libraries
|
||||
(standalone argp library, external gettext library, BusyBox
|
||||
implementations of standard tools).
|
||||
|
||||
* Try to workaround some issues on systems without udev support.
|
||||
NOTE: non-udev systems cannot provide all functionality for kernel
|
||||
device-mapper, and some operations can fail.
|
||||
|
||||
* Fixes for OpenSSL3 crypto backend (including FIPS mode).
|
||||
Because cryptsetup still requires some hash functions implemented
|
||||
in OpenSSL3 legacy provider, crypto backend now uses its library
|
||||
context and tries to load both default and legacy OpenSSL3 providers.
|
||||
|
||||
If FIPS mode is detected, no library context is used, and it is up
|
||||
to the OpenSSL system-wide policy to load proper providers.
|
||||
|
||||
NOTE: We still use some deprecated API in the OpenSSL3 backend,
|
||||
and there are some known problems in OpenSSL 3.0.0.
|
||||
|
||||
* Print error message when assigning a token to an inactive keyslot.
|
||||
|
||||
* Fix offset bug in LUKS2 encryption code if --offset option was used.
|
||||
|
||||
* Do not allow LUKS2 decryption for devices with data offset.
|
||||
Such devices cannot be used after decryption.
|
||||
|
||||
* Fix LUKS1 cryptsetup repair command for some specific problems.
|
||||
Repair code can now fix wrongly used initialization vector
|
||||
specification in ECB mode (that is insecure anyway!) and repair
|
||||
the upper-case hash specification in the LUKS1 header.
|
||||
@@ -1,37 +0,0 @@
|
||||
Cryptsetup 2.4.2 Release Notes
|
||||
==============================
|
||||
Stable bug-fix release.
|
||||
|
||||
All users of cryptsetup 2.4.1 should upgrade to this version.
|
||||
|
||||
Changes since version 2.4.1
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
* Fix possible large memory allocation if LUKS2 header size is invalid.
|
||||
LUKS2 code read the full header to buffer to verify the checksum.
|
||||
The maximal supported header size now limits the memory allocation.
|
||||
|
||||
* Fix memory corruption in debug message printing LUKS2 checksum.
|
||||
|
||||
* veritysetup: remove link to the UUID library for the static build.
|
||||
|
||||
* Remove link to pwquality library for integritysetup and veritysetup.
|
||||
These tools do not read passphrases.
|
||||
|
||||
* OpenSSL3 backend: avoid remaining deprecated calls in API.
|
||||
Crypto backend no longer use API deprecated in OpenSSL 3.0
|
||||
|
||||
|
||||
* Check if kernel device-mapper create device failed in an early phase.
|
||||
This happens when a concurrent creation of device-mapper devices
|
||||
meets in the very early state.
|
||||
|
||||
* Do not set compiler optimization flag for Argon2 KDF if the memory
|
||||
wipe is implemented in libc.
|
||||
|
||||
* Do not attempt to unload LUKS2 tokens if external tokens are disabled.
|
||||
This allows building a static binary with --disable-external-tokens.
|
||||
|
||||
* LUKS convert: also check sysfs for device activity.
|
||||
If udev symlink is missing, code fallbacks to sysfs scan to prevent
|
||||
data corruption for the active device.
|
||||
@@ -1,101 +0,0 @@
|
||||
Cryptsetup 2.4.3 Release Notes
|
||||
==============================
|
||||
Stable security bug-fix release that fixes CVE-2021-4122.
|
||||
|
||||
All users of cryptsetup 2.4.x must upgrade to this version.
|
||||
|
||||
Changes since version 2.4.2
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
* Fix possible attacks against data confidentiality through LUKS2 online
|
||||
reencryption extension crash recovery (CVE-2021-4122).
|
||||
|
||||
An attacker can modify on-disk metadata to simulate decryption in
|
||||
progress with crashed (unfinished) reencryption step and persistently
|
||||
decrypt part of the LUKS device.
|
||||
|
||||
This attack requires repeated physical access to the LUKS device but
|
||||
no knowledge of user passphrases.
|
||||
|
||||
The decryption step is performed after a valid user activates
|
||||
the device with a correct passphrase and modified metadata.
|
||||
There are no visible warnings for the user that such recovery happened
|
||||
(except using the luksDump command). The attack can also be reversed
|
||||
afterward (simulating crashed encryption from a plaintext) with
|
||||
possible modification of revealed plaintext.
|
||||
|
||||
The size of possible decrypted data depends on configured LUKS2 header
|
||||
size (metadata size is configurable for LUKS2).
|
||||
With the default parameters (16 MiB LUKS2 header) and only one
|
||||
allocated keyslot (512 bit key for AES-XTS), simulated decryption with
|
||||
checksum resilience SHA1 (20 bytes checksum for 4096-byte blocks),
|
||||
the maximal decrypted size can be over 3GiB.
|
||||
|
||||
The attack is not applicable to LUKS1 format, but the attacker can
|
||||
update metadata in place to LUKS2 format as an additional step.
|
||||
For such a converted LUKS2 header, the keyslot area is limited to
|
||||
decrypted size (with SHA1 checksums) over 300 MiB.
|
||||
|
||||
The issue is present in all cryptsetup releases since 2.2.0.
|
||||
Versions 1.x, 2.0.x, and 2.1.x are not affected, as these do not
|
||||
contain LUKS2 reencryption extension.
|
||||
|
||||
The problem was caused by reusing a mechanism designed for actual
|
||||
reencryption operation without reassessing the security impact for new
|
||||
encryption and decryption operations. While the reencryption requires
|
||||
calculating and verifying both key digests, no digest was needed to
|
||||
initiate decryption recovery if the destination is plaintext (no
|
||||
encryption key). Also, some metadata (like encryption cipher) is not
|
||||
protected, and an attacker could change it. Note that LUKS2 protects
|
||||
visible metadata only when a random change occurs. It does not protect
|
||||
against intentional modification but such modification must not cause
|
||||
a violation of data confidentiality.
|
||||
|
||||
The fix introduces additional digest protection of reencryption
|
||||
metadata. The digest is calculated from known keys and critical
|
||||
reencryption metadata. Now an attacker cannot create correct metadata
|
||||
digest without knowledge of a passphrase for used keyslots.
|
||||
For more details, see LUKS2 On-Disk Format Specification version 1.1.0.
|
||||
|
||||
The former reencryption operation (without the additional digest) is no
|
||||
longer supported (reencryption with the digest is not backward
|
||||
compatible). You need to finish in-progress reencryption before
|
||||
updating to new packages. The alternative approach is to perform
|
||||
a repair command from the updated package to recalculate reencryption
|
||||
digest and fix metadata.
|
||||
The reencryption repair operation always require a user passphrase.
|
||||
|
||||
WARNING: Devices with older reencryption in progress can be no longer
|
||||
activated without performing the action mentioned above.
|
||||
|
||||
Encryption in progress can be detected by running the luksDump command
|
||||
(output includes reencrypt keyslot with reencryption parameters). Also,
|
||||
during the active reencryption, no keyslot operations are available
|
||||
(change of passphrases, etc.).
|
||||
|
||||
The issue was found by Milan Broz as cryptsetup maintainer.
|
||||
|
||||
Other changes
|
||||
~~~~~~~~~~~~~
|
||||
* Add configure option --disable-luks2-reencryption to completely disable
|
||||
LUKS2 reencryption code.
|
||||
|
||||
When used, the libcryptsetup library can read metadata with
|
||||
reencryption code, but all reencryption API calls and cryptsetup
|
||||
reencrypt commands are disabled.
|
||||
|
||||
Devices with online reencryption in progress cannot be activated.
|
||||
This option can cause some incompatibilities. Please use with care.
|
||||
|
||||
* Improve internal metadata validation code for reencryption metadata.
|
||||
|
||||
* Add updated documentation for LUKS2 On-Disk Format Specification
|
||||
version 1.1.0 (with reencryption extension description and updated
|
||||
metadata description). See docs/on-disk-format-luks2.pdf or online
|
||||
version in https://gitlab.com/cryptsetup/LUKS2-docs repository.
|
||||
|
||||
* Fix support for bitlk (BitLocker compatible) startup key with new
|
||||
metadata entry introduced in Windows 11.
|
||||
|
||||
* Fix space restriction for LUKS2 reencryption with data shift.
|
||||
The code required more space than was needed.
|
||||
@@ -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,7 +15,15 @@ libutils_io_la_SOURCES = \
|
||||
lib/utils_io.c \
|
||||
lib/utils_io.h
|
||||
|
||||
libcryptsetup_la_CPPFLAGS = $(AM_CPPFLAGS)
|
||||
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_DEPENDENCIES = libutils_io.la libcrypto_backend.la lib/libcryptsetup.sym
|
||||
|
||||
@@ -32,9 +40,7 @@ libcryptsetup_la_LIBADD = \
|
||||
@LIBARGON2_LIBS@ \
|
||||
@JSON_C_LIBS@ \
|
||||
@BLKID_LIBS@ \
|
||||
@DL_LIBS@ \
|
||||
$(LTLIBICONV) \
|
||||
$(LTLIBINTL) \
|
||||
libcrypto_backend.la \
|
||||
libutils_io.la
|
||||
|
||||
@@ -44,8 +50,6 @@ 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 \
|
||||
@@ -100,7 +104,6 @@ libcryptsetup_la_SOURCES = \
|
||||
lib/luks2/luks2_keyslot_luks2.c \
|
||||
lib/luks2/luks2_keyslot_reenc.c \
|
||||
lib/luks2/luks2_reencrypt.c \
|
||||
lib/luks2/luks2_reencrypt_digest.c \
|
||||
lib/luks2/luks2_segment.c \
|
||||
lib/luks2/luks2_token_keyring.c \
|
||||
lib/luks2/luks2_token.c \
|
||||
|
||||
@@ -869,20 +869,13 @@ 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,
|
||||
const struct bitlk_metadata *params)
|
||||
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;
|
||||
struct bitlk_guid guid;
|
||||
char guid_buf[UUID_STR_LEN] = {0};
|
||||
|
||||
while (end - start > 2) {
|
||||
/* size of this entry */
|
||||
@@ -899,7 +892,8 @@ static int parse_external_key_entry(struct crypt_device *cd,
|
||||
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_PROPERTY && key_entry_type != BITLK_ENTRY_TYPE_VOLUME_GUID) {
|
||||
/* 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;
|
||||
}
|
||||
@@ -914,15 +908,7 @@ static int parse_external_key_entry(struct crypt_device *cd,
|
||||
/* optional "ExternalKey" string, we can safely ignore it */
|
||||
} else if (key_entry_value == BITLK_ENTRY_VALUE_STRING)
|
||||
;
|
||||
/* GUID of the BitLocker device we are trying to open with this key */
|
||||
else if (key_entry_value == BITLK_ENTRY_VALUE_GUID) {
|
||||
memcpy(&guid, data + start + BITLK_ENTRY_HEADER_LEN, sizeof(struct bitlk_guid));
|
||||
guid_to_string(&guid, guid_buf);
|
||||
if (strcmp(guid_buf, params->guid) != 0) {
|
||||
log_err(cd, _("BEK file GUID '%s' does not match GUID of the volume."), guid_buf);
|
||||
return -EINVAL;
|
||||
}
|
||||
} else {
|
||||
else {
|
||||
log_err(cd, _("Unexpected metadata entry value '%u' found when parsing external key."), key_entry_value);
|
||||
return -EINVAL;
|
||||
}
|
||||
@@ -939,8 +925,7 @@ 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,
|
||||
const struct bitlk_metadata *params)
|
||||
struct volume_key **su_key)
|
||||
{
|
||||
struct bitlk_bek_header bek_header = {0};
|
||||
char guid_buf[UUID_STR_LEN] = {0};
|
||||
@@ -962,12 +947,12 @@ static int get_startup_key(struct crypt_device *cd,
|
||||
return -EPERM;
|
||||
|
||||
if (bek_header.metadata_version != 1) {
|
||||
log_err(cd, _("Unsupported BEK metadata version %" PRIu32), bek_header.metadata_version);
|
||||
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);
|
||||
log_err(cd, "Unexpected BEK metadata size %" PRIu32 " does not match BEK file length", bek_header.metadata_size);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
@@ -990,7 +975,7 @@ static int get_startup_key(struct crypt_device *cd,
|
||||
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, params);
|
||||
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);
|
||||
@@ -1116,17 +1101,45 @@ out:
|
||||
return r;
|
||||
}
|
||||
|
||||
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(struct crypt_device *cd,
|
||||
const char *name,
|
||||
const char *password,
|
||||
size_t passwordLen,
|
||||
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 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) {
|
||||
@@ -1157,7 +1170,7 @@ int BITLK_get_volume_key(struct crypt_device *cd,
|
||||
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, params);
|
||||
r = get_startup_key(cd, password, passwordLen, next_vmk, &vmk_dec_key);
|
||||
if (r) {
|
||||
next_vmk = next_vmk->next;
|
||||
continue;
|
||||
@@ -1187,7 +1200,7 @@ int BITLK_get_volume_key(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) {
|
||||
@@ -1208,66 +1221,28 @@ int BITLK_get_volume_key(struct crypt_device *cd,
|
||||
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;
|
||||
/* Password verify only */
|
||||
if (!name) {
|
||||
crypt_free_volume_key(open_fvek_key);
|
||||
return r;
|
||||
}
|
||||
|
||||
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)
|
||||
if (r) {
|
||||
crypt_free_volume_key(open_fvek_key);
|
||||
return r;
|
||||
}
|
||||
|
||||
/* there will be always 4 dm-zero segments: 3x metadata, 1x FS header */
|
||||
for (i = 0; i < 3; i++) {
|
||||
@@ -1402,57 +1377,6 @@ static int _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;
|
||||
}
|
||||
|
||||
@@ -29,7 +29,6 @@
|
||||
|
||||
struct crypt_device;
|
||||
struct device;
|
||||
struct volume_key;
|
||||
|
||||
#define BITLK_NONCE_SIZE 12
|
||||
#define BITLK_SALT_SIZE 16
|
||||
@@ -61,7 +60,6 @@ typedef enum {
|
||||
BITLK_ENTRY_TYPE_STARTUP_KEY = 0x0006,
|
||||
BITLK_ENTRY_TYPE_DESCRIPTION = 0x0007,
|
||||
BITLK_ENTRY_TYPE_VOLUME_HEADER = 0x000f,
|
||||
BITLK_ENTRY_TYPE_VOLUME_GUID = 0x0019,
|
||||
} BITLKFVEEntryType;
|
||||
|
||||
typedef enum {
|
||||
@@ -77,7 +75,6 @@ typedef enum {
|
||||
BITLK_ENTRY_VALUE_EXTERNAL_KEY = 0x0009,
|
||||
BITLK_ENTRY_VALUE_OFFSET_SIZE = 0x000f,
|
||||
BITLK_ENTRY_VALUE_RECOVERY_TIME = 0x015,
|
||||
BITLK_ENTRY_VALUE_GUID = 0x0017,
|
||||
} BITLKFVEEntryValue;
|
||||
|
||||
struct bitlk_vmk {
|
||||
@@ -120,25 +117,12 @@ 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_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);
|
||||
int BITLK_activate(struct crypt_device *cd,
|
||||
const char *name,
|
||||
const char *password,
|
||||
size_t passwordLen,
|
||||
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);
|
||||
|
||||
@@ -450,8 +450,6 @@ 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;
|
||||
|
||||
@@ -120,24 +120,18 @@ void free_memory(const argon2_context *context, uint8_t *memory,
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(_MSC_VER) && VC_GE_2005(_MSC_VER)
|
||||
void secure_wipe_memory(void *v, size_t n) {
|
||||
SecureZeroMemory(v, n);
|
||||
}
|
||||
#elif defined memset_s
|
||||
void secure_wipe_memory(void *v, size_t n) {
|
||||
memset_s(v, n, 0, n);
|
||||
}
|
||||
#elif defined(HAVE_EXPLICIT_BZERO)
|
||||
void secure_wipe_memory(void *v, size_t n) {
|
||||
explicit_bzero(v, n);
|
||||
}
|
||||
#else
|
||||
void NOT_OPTIMIZED secure_wipe_memory(void *v, size_t n) {
|
||||
#if defined(_MSC_VER) && VC_GE_2005(_MSC_VER)
|
||||
SecureZeroMemory(v, n);
|
||||
#elif defined memset_s
|
||||
memset_s(v, n, 0, n);
|
||||
#elif defined(HAVE_EXPLICIT_BZERO)
|
||||
explicit_bzero(v, n);
|
||||
#else
|
||||
static void *(*const volatile memset_sec)(void *, int, size_t) = &memset;
|
||||
memset_sec(v, 0, n);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Memory clear flag defaults to true. */
|
||||
int FLAG_clear_internal_memory = 1;
|
||||
|
||||
@@ -31,6 +31,7 @@ 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 },
|
||||
|
||||
@@ -31,7 +31,7 @@ struct crypt_hmac;
|
||||
struct crypt_cipher;
|
||||
struct crypt_storage;
|
||||
|
||||
int crypt_backend_init(bool fips);
|
||||
int crypt_backend_init(void);
|
||||
void crypt_backend_destroy(void);
|
||||
|
||||
#define CRYPT_BACKEND_KERNEL (1 << 0) /* Crypto uses kernel part, for benchmark */
|
||||
@@ -62,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, min_bench_memory;
|
||||
uint32_t min_memory, max_memory;
|
||||
uint32_t min_parallel, max_parallel;
|
||||
};
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
|
||||
#include "crypto_backend.h"
|
||||
|
||||
#if USE_INTERNAL_PBKDF2
|
||||
/* internal PBKDF2 implementation */
|
||||
int pkcs5_pbkdf2(const char *hash,
|
||||
const char *P, size_t Plen,
|
||||
@@ -30,6 +31,7 @@ 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,
|
||||
|
||||
@@ -96,14 +96,11 @@ 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;
|
||||
|
||||
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;
|
||||
snprintf((char *)sa.salg_name, sizeof(sa.salg_name), "%s(%s)", mode, name);
|
||||
|
||||
return _crypt_cipher_init(ctx, key, key_length, 0, &sa);
|
||||
}
|
||||
@@ -167,14 +164,15 @@ 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;
|
||||
else {
|
||||
len = read(ctx->opfd, out, out_length);
|
||||
if (len != (ssize_t)out_length)
|
||||
r = -EIO;
|
||||
goto bad;
|
||||
}
|
||||
|
||||
len = read(ctx->opfd, out, out_length);
|
||||
if (len != (ssize_t)out_length)
|
||||
r = -EIO;
|
||||
bad:
|
||||
crypt_backend_memzero(buffer, sizeof(buffer));
|
||||
return r;
|
||||
}
|
||||
@@ -232,10 +230,7 @@ int crypt_cipher_check_kernel(const char *name, const char *mode,
|
||||
}
|
||||
|
||||
salg_type = aead ? "aead" : "skcipher";
|
||||
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;
|
||||
|
||||
snprintf((char *)sa.salg_type, sizeof(sa.salg_type), "%s", salg_type);
|
||||
memset(tmp_salg_name, 0, sizeof(tmp_salg_name));
|
||||
|
||||
/* FIXME: this is duplicating a part of devmapper backend */
|
||||
@@ -248,7 +243,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 || (size_t)r >= sizeof(tmp_salg_name))
|
||||
if (r <= 0 || r > (int)(sizeof(sa.salg_name) - 1))
|
||||
return -EINVAL;
|
||||
|
||||
memcpy(sa.salg_name, tmp_salg_name, sizeof(sa.salg_name));
|
||||
|
||||
@@ -51,11 +51,6 @@ struct crypt_cipher {
|
||||
} u;
|
||||
};
|
||||
|
||||
struct hash_alg {
|
||||
const char *name;
|
||||
const char *gcrypt_name;
|
||||
};
|
||||
|
||||
/*
|
||||
* Test for wrong Whirlpool variant,
|
||||
* Ref: https://lists.gnupg.org/pipermail/gcrypt-devel/2014-January/002889.html
|
||||
@@ -94,10 +89,8 @@ static void crypt_hash_test_whirlpool_bug(void)
|
||||
crypto_backend_whirlpool_bug = 1;
|
||||
}
|
||||
|
||||
int crypt_backend_init(bool fips __attribute__((unused)))
|
||||
int crypt_backend_init(void)
|
||||
{
|
||||
int r;
|
||||
|
||||
if (crypto_backend_initialised)
|
||||
return 0;
|
||||
|
||||
@@ -106,7 +99,7 @@ int crypt_backend_init(bool fips __attribute__((unused)))
|
||||
return -ENOSYS;
|
||||
}
|
||||
|
||||
/* If gcrypt compiled to support POSIX 1003.1e capabilities,
|
||||
/* FIXME: 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
|
||||
@@ -127,12 +120,11 @@ int crypt_backend_init(bool fips __attribute__((unused)))
|
||||
crypto_backend_initialised = 1;
|
||||
crypt_hash_test_whirlpool_bug();
|
||||
|
||||
r = snprintf(version, sizeof(version), "gcrypt %s%s%s",
|
||||
snprintf(version, 64, "gcrypt %s%s%s",
|
||||
gcry_check_version(NULL),
|
||||
crypto_backend_secmem ? "" : ", secmem disabled",
|
||||
crypto_backend_whirlpool_bug > 0 ? ", flawed whirlpool" : "");
|
||||
if (r < 0 || (size_t)r >= sizeof(version))
|
||||
return -EINVAL;
|
||||
crypto_backend_whirlpool_bug > 0 ? ", flawed whirlpool" : ""
|
||||
);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -158,24 +150,10 @@ 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 (!strcasecmp(name, "whirlpool_gcryptbug")) {
|
||||
if (name && !strcasecmp(name, "whirlpool_gcryptbug")) {
|
||||
#if GCRYPT_VERSION_NUMBER >= 0x010601
|
||||
if (flags)
|
||||
*flags |= GCRY_MD_FLAG_BUGEMU1;
|
||||
@@ -183,15 +161,6 @@ 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;
|
||||
}
|
||||
|
||||
@@ -347,7 +316,7 @@ void crypt_hmac_destroy(struct crypt_hmac *ctx)
|
||||
}
|
||||
|
||||
/* RNG */
|
||||
int crypt_backend_rng(char *buffer, size_t length, int quality, int fips __attribute__((unused)))
|
||||
int crypt_backend_rng(char *buffer, size_t length, int quality, int fips)
|
||||
{
|
||||
switch(quality) {
|
||||
case CRYPT_RND_NORMAL:
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
#include <linux/if_alg.h>
|
||||
#include "crypto_backend_internal.h"
|
||||
|
||||
/* FIXME: remove later */
|
||||
#ifndef AF_ALG
|
||||
#define AF_ALG 38
|
||||
#endif
|
||||
@@ -61,14 +62,6 @@ 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 }
|
||||
};
|
||||
|
||||
@@ -117,7 +110,7 @@ static int crypt_kernel_socket_init(struct sockaddr_alg *sa, int *tfmfd, int *op
|
||||
return 0;
|
||||
}
|
||||
|
||||
int crypt_backend_init(bool fips __attribute__((unused)))
|
||||
int crypt_backend_init(void)
|
||||
{
|
||||
struct utsname uts;
|
||||
struct sockaddr_alg sa = {
|
||||
@@ -125,7 +118,7 @@ int crypt_backend_init(bool fips __attribute__((unused)))
|
||||
.salg_type = "hash",
|
||||
.salg_name = "sha256",
|
||||
};
|
||||
int r, tfmfd = -1, opfd = -1;
|
||||
int tfmfd = -1, opfd = -1;
|
||||
|
||||
if (crypto_backend_initialised)
|
||||
return 0;
|
||||
@@ -133,17 +126,15 @@ int crypt_backend_init(bool fips __attribute__((unused)))
|
||||
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;
|
||||
}
|
||||
@@ -264,7 +255,6 @@ 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)
|
||||
@@ -277,12 +267,8 @@ int crypt_hmac_init(struct crypt_hmac **ctx, const char *name,
|
||||
}
|
||||
h->hash_len = ha->length;
|
||||
|
||||
r = snprintf((char *)sa.salg_name, sizeof(sa.salg_name),
|
||||
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);
|
||||
@@ -329,8 +315,7 @@ void crypt_hmac_destroy(struct crypt_hmac *ctx)
|
||||
}
|
||||
|
||||
/* RNG - N/A */
|
||||
int crypt_backend_rng(char *buffer __attribute__((unused)), size_t length __attribute__((unused)),
|
||||
int quality __attribute__((unused)), int fips __attribute__((unused)))
|
||||
int crypt_backend_rng(char *buffer, size_t length, int quality, int fips)
|
||||
{
|
||||
return -EINVAL;
|
||||
}
|
||||
@@ -403,7 +388,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 __attribute__((unused)))
|
||||
bool crypt_cipher_kernel_only(struct crypt_cipher *ctx)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -213,7 +213,7 @@ static struct hash_alg *_get_alg(const char *name)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int crypt_backend_init(bool fips __attribute__((unused)))
|
||||
int crypt_backend_init(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@@ -301,16 +301,12 @@ int crypt_hmac_init(struct crypt_hmac **ctx, const char *name,
|
||||
|
||||
|
||||
h->hash = _get_alg(name);
|
||||
if (!h->hash) {
|
||||
free(h);
|
||||
return -EINVAL;
|
||||
}
|
||||
if (!h->hash)
|
||||
goto bad;
|
||||
|
||||
h->key = malloc(key_length);
|
||||
if (!h->key) {
|
||||
free(h);
|
||||
return -ENOMEM;
|
||||
}
|
||||
if (!h->key)
|
||||
goto bad;
|
||||
|
||||
memcpy(h->key, key, key_length);
|
||||
h->key_length = key_length;
|
||||
@@ -320,6 +316,9 @@ 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)
|
||||
@@ -352,10 +351,7 @@ void crypt_hmac_destroy(struct crypt_hmac *ctx)
|
||||
}
|
||||
|
||||
/* RNG - N/A */
|
||||
int crypt_backend_rng(char *buffer __attribute__((unused)),
|
||||
size_t length __attribute__((unused)),
|
||||
int quality __attribute__((unused)),
|
||||
int fips __attribute__((unused)))
|
||||
int crypt_backend_rng(char *buffer, size_t length, int quality, int fips)
|
||||
{
|
||||
return -EINVAL;
|
||||
}
|
||||
@@ -433,7 +429,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 __attribute__((unused)))
|
||||
bool crypt_cipher_kernel_only(struct crypt_cipher *ctx)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -75,10 +75,8 @@ static struct hash_alg *_get_alg(const char *name)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int crypt_backend_init(bool fips __attribute__((unused)))
|
||||
int crypt_backend_init(void)
|
||||
{
|
||||
int r;
|
||||
|
||||
if (crypto_backend_initialised)
|
||||
return 0;
|
||||
|
||||
@@ -86,13 +84,10 @@ int crypt_backend_init(bool fips __attribute__((unused)))
|
||||
return -EINVAL;
|
||||
|
||||
#if HAVE_DECL_NSS_GETVERSION
|
||||
r = snprintf(version, sizeof(version), "NSS %s", NSS_GetVersion());
|
||||
snprintf(version, 64, "NSS %s", NSS_GetVersion());
|
||||
#else
|
||||
r = snprintf(version, sizeof(version), "NSS");
|
||||
snprintf(version, 64, "NSS");
|
||||
#endif
|
||||
if (r < 0 || (size_t)r >= sizeof(version))
|
||||
return -EINVAL;
|
||||
|
||||
crypto_backend_initialised = 1;
|
||||
return 0;
|
||||
}
|
||||
@@ -225,28 +220,28 @@ int crypt_hmac_init(struct crypt_hmac **ctx, const char *name,
|
||||
|
||||
h->hash = _get_alg(name);
|
||||
if (!h->hash)
|
||||
goto err;
|
||||
goto bad;
|
||||
|
||||
h->slot = PK11_GetInternalKeySlot();
|
||||
if (!h->slot)
|
||||
goto err;
|
||||
goto bad;
|
||||
|
||||
h->key = PK11_ImportSymKey(h->slot, h->hash->ck_type, PK11_OriginUnwrap,
|
||||
CKA_SIGN, &keyItem, NULL);
|
||||
if (!h->key)
|
||||
goto err;
|
||||
goto bad;
|
||||
|
||||
h->md = PK11_CreateContextBySymKey(h->hash->ck_type, CKA_SIGN, h->key,
|
||||
&noParams);
|
||||
if (!h->md)
|
||||
goto err;
|
||||
goto bad;
|
||||
|
||||
if (PK11_DigestBegin(h->md) != SECSuccess)
|
||||
goto err;
|
||||
goto bad;
|
||||
|
||||
*ctx = h;
|
||||
return 0;
|
||||
err:
|
||||
bad:
|
||||
crypt_hmac_destroy(h);
|
||||
return -EINVAL;
|
||||
}
|
||||
@@ -303,7 +298,7 @@ void crypt_hmac_destroy(struct crypt_hmac *ctx)
|
||||
}
|
||||
|
||||
/* RNG */
|
||||
int crypt_backend_rng(char *buffer, size_t length, int quality __attribute__((unused)), int fips)
|
||||
int crypt_backend_rng(char *buffer, size_t length, int quality, int fips)
|
||||
{
|
||||
if (fips)
|
||||
return -EINVAL;
|
||||
@@ -382,7 +377,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 __attribute__((unused)))
|
||||
bool crypt_cipher_kernel_only(struct crypt_cipher *ctx)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -34,15 +34,6 @@
|
||||
#include <openssl/hmac.h>
|
||||
#include <openssl/rand.h>
|
||||
#include "crypto_backend_internal.h"
|
||||
#if OPENSSL_VERSION_MAJOR >= 3
|
||||
#include <openssl/provider.h>
|
||||
#include <openssl/kdf.h>
|
||||
#include <openssl/core_names.h>
|
||||
static OSSL_PROVIDER *ossl_legacy = NULL;
|
||||
static OSSL_PROVIDER *ossl_default = NULL;
|
||||
static OSSL_LIB_CTX *ossl_ctx = NULL;
|
||||
static char backend_version[256] = "OpenSSL";
|
||||
#endif
|
||||
|
||||
#define CONST_CAST(x) (x)(uintptr_t)
|
||||
|
||||
@@ -55,14 +46,8 @@ struct crypt_hash {
|
||||
};
|
||||
|
||||
struct crypt_hmac {
|
||||
#if OPENSSL_VERSION_MAJOR >= 3
|
||||
EVP_MAC *mac;
|
||||
EVP_MAC_CTX *md;
|
||||
EVP_MAC_CTX *md_org;
|
||||
#else
|
||||
HMAC_CTX *md;
|
||||
const EVP_MD *hash_id;
|
||||
#endif
|
||||
int hash_len;
|
||||
};
|
||||
|
||||
@@ -73,31 +58,20 @@ struct crypt_cipher {
|
||||
struct {
|
||||
EVP_CIPHER_CTX *hd_enc;
|
||||
EVP_CIPHER_CTX *hd_dec;
|
||||
const EVP_CIPHER *cipher_type;
|
||||
size_t iv_length;
|
||||
} lib;
|
||||
} u;
|
||||
};
|
||||
|
||||
struct hash_alg {
|
||||
const char *name;
|
||||
const char *openssl_name;
|
||||
};
|
||||
|
||||
/*
|
||||
* Compatible wrappers for OpenSSL < 1.1.0 and LibreSSL < 2.7.0
|
||||
*/
|
||||
#if OPENSSL_VERSION_NUMBER < 0x10100000L || \
|
||||
(defined(LIBRESSL_VERSION_NUMBER) && LIBRESSL_VERSION_NUMBER < 0x2070000fL)
|
||||
|
||||
static int openssl_backend_init(bool fips __attribute__((unused)))
|
||||
static void openssl_backend_init(void)
|
||||
{
|
||||
OpenSSL_add_all_algorithms();
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void openssl_backend_exit(void)
|
||||
{
|
||||
}
|
||||
|
||||
static const char *openssl_backend_version(void)
|
||||
@@ -137,79 +111,22 @@ static void HMAC_CTX_free(HMAC_CTX *md)
|
||||
free(md);
|
||||
}
|
||||
#else
|
||||
static void openssl_backend_exit(void)
|
||||
static void openssl_backend_init(void)
|
||||
{
|
||||
#if OPENSSL_VERSION_MAJOR >= 3
|
||||
if (ossl_legacy)
|
||||
OSSL_PROVIDER_unload(ossl_legacy);
|
||||
if (ossl_default)
|
||||
OSSL_PROVIDER_unload(ossl_default);
|
||||
if (ossl_ctx)
|
||||
OSSL_LIB_CTX_free(ossl_ctx);
|
||||
|
||||
ossl_legacy = NULL;
|
||||
ossl_default = NULL;
|
||||
ossl_ctx = NULL;
|
||||
#endif
|
||||
}
|
||||
|
||||
static int openssl_backend_init(bool fips)
|
||||
{
|
||||
/*
|
||||
* OpenSSL >= 3.0.0 provides some algorithms in legacy provider
|
||||
*/
|
||||
#if OPENSSL_VERSION_MAJOR >= 3
|
||||
int r;
|
||||
|
||||
/*
|
||||
* In FIPS mode we keep default OpenSSL context & global config
|
||||
*/
|
||||
if (!fips) {
|
||||
ossl_ctx = OSSL_LIB_CTX_new();
|
||||
if (!ossl_ctx)
|
||||
return -EINVAL;
|
||||
|
||||
ossl_default = OSSL_PROVIDER_try_load(ossl_ctx, "default", 0);
|
||||
if (!ossl_default) {
|
||||
OSSL_LIB_CTX_free(ossl_ctx);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
/* Optional */
|
||||
ossl_legacy = OSSL_PROVIDER_try_load(ossl_ctx, "legacy", 0);
|
||||
}
|
||||
|
||||
r = snprintf(backend_version, sizeof(backend_version), "%s %s%s%s",
|
||||
OpenSSL_version(OPENSSL_VERSION),
|
||||
ossl_default ? "[default]" : "",
|
||||
ossl_legacy ? "[legacy]" : "",
|
||||
fips ? "[fips]" : "");
|
||||
|
||||
if (r < 0 || (size_t)r >= sizeof(backend_version)) {
|
||||
openssl_backend_exit();
|
||||
return -EINVAL;
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const char *openssl_backend_version(void)
|
||||
{
|
||||
#if OPENSSL_VERSION_MAJOR >= 3
|
||||
return backend_version;
|
||||
#else
|
||||
return OpenSSL_version(OPENSSL_VERSION);
|
||||
#endif
|
||||
return OpenSSL_version(OPENSSL_VERSION);
|
||||
}
|
||||
#endif
|
||||
|
||||
int crypt_backend_init(bool fips)
|
||||
int crypt_backend_init(void)
|
||||
{
|
||||
if (crypto_backend_initialised)
|
||||
return 0;
|
||||
|
||||
if (openssl_backend_init(fips))
|
||||
return -EINVAL;
|
||||
openssl_backend_init();
|
||||
|
||||
crypto_backend_initialised = 1;
|
||||
return 0;
|
||||
@@ -217,15 +134,7 @@ int crypt_backend_init(bool fips)
|
||||
|
||||
void crypt_backend_destroy(void)
|
||||
{
|
||||
/*
|
||||
* If Destructor was already called, we must not call it again
|
||||
*/
|
||||
if (!crypto_backend_initialised)
|
||||
return;
|
||||
|
||||
crypto_backend_initialised = 0;
|
||||
|
||||
openssl_backend_exit();
|
||||
}
|
||||
|
||||
uint32_t crypt_backend_flags(void)
|
||||
@@ -238,75 +147,15 @@ 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;
|
||||
}
|
||||
|
||||
static const EVP_MD *hash_id_get(const char *name)
|
||||
{
|
||||
#if OPENSSL_VERSION_MAJOR >= 3
|
||||
return EVP_MD_fetch(ossl_ctx, crypt_hash_compat_name(name), NULL);
|
||||
#else
|
||||
return EVP_get_digestbyname(crypt_hash_compat_name(name));
|
||||
#endif
|
||||
}
|
||||
|
||||
static void hash_id_free(const EVP_MD *hash_id)
|
||||
{
|
||||
#if OPENSSL_VERSION_MAJOR >= 3
|
||||
EVP_MD_free(CONST_CAST(EVP_MD*)hash_id);
|
||||
#endif
|
||||
}
|
||||
|
||||
static const EVP_CIPHER *cipher_type_get(const char *name)
|
||||
{
|
||||
#if OPENSSL_VERSION_MAJOR >= 3
|
||||
return EVP_CIPHER_fetch(ossl_ctx, name, NULL);
|
||||
#else
|
||||
return EVP_get_cipherbyname(name);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void cipher_type_free(const EVP_CIPHER *cipher_type)
|
||||
{
|
||||
#if OPENSSL_VERSION_MAJOR >= 3
|
||||
EVP_CIPHER_free(CONST_CAST(EVP_CIPHER*)cipher_type);
|
||||
#endif
|
||||
}
|
||||
|
||||
/* HASH */
|
||||
int crypt_hash_size(const char *name)
|
||||
{
|
||||
int size;
|
||||
const EVP_MD *hash_id;
|
||||
const EVP_MD *hash_id = EVP_get_digestbyname(name);
|
||||
|
||||
hash_id = hash_id_get(name);
|
||||
if (!hash_id)
|
||||
return -EINVAL;
|
||||
|
||||
size = EVP_MD_size(hash_id);
|
||||
hash_id_free(hash_id);
|
||||
return size;
|
||||
return EVP_MD_size(hash_id);
|
||||
}
|
||||
|
||||
int crypt_hash_init(struct crypt_hash **ctx, const char *name)
|
||||
@@ -323,7 +172,7 @@ int crypt_hash_init(struct crypt_hash **ctx, const char *name)
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
h->hash_id = hash_id_get(name);
|
||||
h->hash_id = EVP_get_digestbyname(name);
|
||||
if (!h->hash_id) {
|
||||
EVP_MD_CTX_free(h->md);
|
||||
free(h);
|
||||
@@ -331,7 +180,6 @@ int crypt_hash_init(struct crypt_hash **ctx, const char *name)
|
||||
}
|
||||
|
||||
if (EVP_DigestInit_ex(h->md, h->hash_id, NULL) != 1) {
|
||||
hash_id_free(h->hash_id);
|
||||
EVP_MD_CTX_free(h->md);
|
||||
free(h);
|
||||
return -EINVAL;
|
||||
@@ -383,7 +231,6 @@ int crypt_hash_final(struct crypt_hash *ctx, char *buffer, size_t length)
|
||||
|
||||
void crypt_hash_destroy(struct crypt_hash *ctx)
|
||||
{
|
||||
hash_id_free(ctx->hash_id);
|
||||
EVP_MD_CTX_free(ctx->md);
|
||||
memset(ctx, 0, sizeof(*ctx));
|
||||
free(ctx);
|
||||
@@ -399,39 +246,7 @@ int crypt_hmac_init(struct crypt_hmac **ctx, const char *name,
|
||||
const void *key, size_t key_length)
|
||||
{
|
||||
struct crypt_hmac *h;
|
||||
#if OPENSSL_VERSION_MAJOR >= 3
|
||||
OSSL_PARAM params[] = {
|
||||
OSSL_PARAM_utf8_string(OSSL_MAC_PARAM_DIGEST, CONST_CAST(void*)name, 0),
|
||||
OSSL_PARAM_END
|
||||
};
|
||||
|
||||
h = malloc(sizeof(*h));
|
||||
if (!h)
|
||||
return -ENOMEM;
|
||||
|
||||
h->mac = EVP_MAC_fetch(ossl_ctx, OSSL_MAC_NAME_HMAC, NULL);
|
||||
if (!h->mac) {
|
||||
free(h);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
h->md = EVP_MAC_CTX_new(h->mac);
|
||||
if (!h->md) {
|
||||
EVP_MAC_free(h->mac);
|
||||
free(h);
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
if (EVP_MAC_init(h->md, key, key_length, params) != 1) {
|
||||
EVP_MAC_CTX_free(h->md);
|
||||
EVP_MAC_free(h->mac);
|
||||
free(h);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
h->hash_len = EVP_MAC_CTX_get_mac_size(h->md);
|
||||
h->md_org = EVP_MAC_CTX_dup(h->md);
|
||||
#else
|
||||
h = malloc(sizeof(*h));
|
||||
if (!h)
|
||||
return -ENOMEM;
|
||||
@@ -442,7 +257,7 @@ int crypt_hmac_init(struct crypt_hmac **ctx, const char *name,
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
h->hash_id = hash_id_get(name);
|
||||
h->hash_id = EVP_get_digestbyname(name);
|
||||
if (!h->hash_id) {
|
||||
HMAC_CTX_free(h->md);
|
||||
free(h);
|
||||
@@ -452,82 +267,51 @@ int crypt_hmac_init(struct crypt_hmac **ctx, const char *name,
|
||||
HMAC_Init_ex(h->md, key, key_length, h->hash_id, NULL);
|
||||
|
||||
h->hash_len = EVP_MD_size(h->hash_id);
|
||||
#endif
|
||||
*ctx = h;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int crypt_hmac_restart(struct crypt_hmac *ctx)
|
||||
static void crypt_hmac_restart(struct crypt_hmac *ctx)
|
||||
{
|
||||
#if OPENSSL_VERSION_MAJOR >= 3
|
||||
EVP_MAC_CTX_free(ctx->md);
|
||||
ctx->md = EVP_MAC_CTX_dup(ctx->md_org);
|
||||
if (!ctx->md)
|
||||
return -EINVAL;
|
||||
#else
|
||||
HMAC_Init_ex(ctx->md, NULL, 0, ctx->hash_id, NULL);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
int crypt_hmac_write(struct crypt_hmac *ctx, const char *buffer, size_t length)
|
||||
{
|
||||
#if OPENSSL_VERSION_MAJOR >= 3
|
||||
return EVP_MAC_update(ctx->md, (const unsigned char *)buffer, length) == 1 ? 0 : -EINVAL;
|
||||
#else
|
||||
HMAC_Update(ctx->md, (const unsigned char *)buffer, length);
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
int crypt_hmac_final(struct crypt_hmac *ctx, char *buffer, size_t length)
|
||||
{
|
||||
unsigned char tmp[EVP_MAX_MD_SIZE];
|
||||
#if OPENSSL_VERSION_MAJOR >= 3
|
||||
size_t tmp_len = 0;
|
||||
|
||||
if (length > (size_t)ctx->hash_len)
|
||||
return -EINVAL;
|
||||
|
||||
if (EVP_MAC_final(ctx->md, tmp, &tmp_len, sizeof(tmp)) != 1)
|
||||
return -EINVAL;
|
||||
#else
|
||||
unsigned int tmp_len = 0;
|
||||
|
||||
if (length > (size_t)ctx->hash_len)
|
||||
return -EINVAL;
|
||||
|
||||
HMAC_Final(ctx->md, tmp, &tmp_len);
|
||||
#endif
|
||||
|
||||
memcpy(buffer, tmp, length);
|
||||
crypt_backend_memzero(tmp, sizeof(tmp));
|
||||
|
||||
if (tmp_len < length)
|
||||
return -EINVAL;
|
||||
|
||||
if (crypt_hmac_restart(ctx))
|
||||
return -EINVAL;
|
||||
crypt_hmac_restart(ctx);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void crypt_hmac_destroy(struct crypt_hmac *ctx)
|
||||
{
|
||||
#if OPENSSL_VERSION_MAJOR >= 3
|
||||
EVP_MAC_CTX_free(ctx->md);
|
||||
EVP_MAC_CTX_free(ctx->md_org);
|
||||
EVP_MAC_free(ctx->mac);
|
||||
#else
|
||||
hash_id_free(ctx->hash_id);
|
||||
HMAC_CTX_free(ctx->md);
|
||||
#endif
|
||||
memset(ctx, 0, sizeof(*ctx));
|
||||
free(ctx);
|
||||
}
|
||||
|
||||
/* RNG */
|
||||
int crypt_backend_rng(char *buffer, size_t length,
|
||||
int quality __attribute__((unused)), int fips __attribute__((unused)))
|
||||
int crypt_backend_rng(char *buffer, size_t length, int quality, int fips)
|
||||
{
|
||||
if (RAND_bytes((unsigned char *)buffer, length) != 1)
|
||||
return -EINVAL;
|
||||
@@ -535,91 +319,48 @@ int crypt_backend_rng(char *buffer, size_t length,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int openssl_pbkdf2(const char *password, size_t password_length,
|
||||
const char *salt, size_t salt_length, uint32_t iterations,
|
||||
const char *hash, char *key, size_t key_length)
|
||||
{
|
||||
int r;
|
||||
#if OPENSSL_VERSION_MAJOR >= 3
|
||||
EVP_KDF_CTX *ctx;
|
||||
EVP_KDF *pbkdf2;
|
||||
OSSL_PARAM params[] = {
|
||||
OSSL_PARAM_octet_string(OSSL_KDF_PARAM_PASSWORD,
|
||||
CONST_CAST(void*)password, password_length),
|
||||
OSSL_PARAM_octet_string(OSSL_KDF_PARAM_SALT,
|
||||
CONST_CAST(void*)salt, salt_length),
|
||||
OSSL_PARAM_uint32(OSSL_KDF_PARAM_ITER, &iterations),
|
||||
OSSL_PARAM_utf8_string(OSSL_KDF_PARAM_DIGEST,
|
||||
CONST_CAST(void*)hash, 0),
|
||||
OSSL_PARAM_END
|
||||
};
|
||||
|
||||
pbkdf2 = EVP_KDF_fetch(ossl_ctx, "pbkdf2", NULL);
|
||||
if (!pbkdf2)
|
||||
return -EINVAL;
|
||||
|
||||
ctx = EVP_KDF_CTX_new(pbkdf2);
|
||||
if (!ctx) {
|
||||
EVP_KDF_free(pbkdf2);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
r = EVP_KDF_derive(ctx, (unsigned char*)key, key_length, params);
|
||||
|
||||
EVP_KDF_CTX_free(ctx);
|
||||
EVP_KDF_free(pbkdf2);
|
||||
#else
|
||||
const EVP_MD *hash_id = EVP_get_digestbyname(crypt_hash_compat_name(hash));
|
||||
if (!hash_id)
|
||||
return -EINVAL;
|
||||
|
||||
r = PKCS5_PBKDF2_HMAC(password, (int)password_length, (const unsigned char *)salt,
|
||||
(int)salt_length, iterations, hash_id, (int)key_length, (unsigned char*) key);
|
||||
#endif
|
||||
return r == 1 ? 0 : -EINVAL;
|
||||
}
|
||||
|
||||
static int openssl_argon2(const char *type, const char *password, size_t password_length,
|
||||
const char *salt, size_t salt_length, char *key, size_t key_length,
|
||||
uint32_t iterations, uint32_t memory, uint32_t parallel)
|
||||
{
|
||||
return argon2(type, password, password_length, salt, salt_length,
|
||||
key, key_length, iterations, memory, parallel);
|
||||
}
|
||||
|
||||
/* PBKDF */
|
||||
int crypt_pbkdf(const char *kdf, const char *hash,
|
||||
const char *password, size_t password_length,
|
||||
const char *salt, size_t salt_length,
|
||||
char *key, size_t key_length,
|
||||
uint32_t iterations, uint32_t memory, uint32_t parallel)
|
||||
|
||||
{
|
||||
const EVP_MD *hash_id;
|
||||
|
||||
if (!kdf)
|
||||
return -EINVAL;
|
||||
|
||||
if (!strcmp(kdf, "pbkdf2"))
|
||||
return openssl_pbkdf2(password, password_length, salt, salt_length,
|
||||
iterations, hash, key, key_length);
|
||||
if (!strncmp(kdf, "argon2", 6))
|
||||
return openssl_argon2(kdf, password, password_length, salt, salt_length,
|
||||
key, key_length, iterations, memory, parallel);
|
||||
if (!strcmp(kdf, "pbkdf2")) {
|
||||
hash_id = EVP_get_digestbyname(hash);
|
||||
if (!hash_id)
|
||||
return -EINVAL;
|
||||
|
||||
if (!PKCS5_PBKDF2_HMAC(password, (int)password_length,
|
||||
(const unsigned char *)salt, (int)salt_length,
|
||||
(int)iterations, hash_id, (int)key_length, (unsigned char *)key))
|
||||
return -EINVAL;
|
||||
return 0;
|
||||
} else if (!strncmp(kdf, "argon2", 6)) {
|
||||
return argon2(kdf, password, password_length, salt, salt_length,
|
||||
key, key_length, iterations, memory, parallel);
|
||||
}
|
||||
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
/* Block ciphers */
|
||||
static void _cipher_destroy(EVP_CIPHER_CTX **hd_enc, EVP_CIPHER_CTX **hd_dec, const EVP_CIPHER **cipher_type)
|
||||
static void _cipher_destroy(EVP_CIPHER_CTX **hd_enc, EVP_CIPHER_CTX **hd_dec)
|
||||
{
|
||||
EVP_CIPHER_CTX_free(*hd_enc);
|
||||
*hd_enc = NULL;
|
||||
|
||||
EVP_CIPHER_CTX_free(*hd_dec);
|
||||
*hd_dec = NULL;
|
||||
|
||||
cipher_type_free(*cipher_type);
|
||||
*cipher_type = NULL;
|
||||
}
|
||||
|
||||
static int _cipher_init(EVP_CIPHER_CTX **hd_enc, EVP_CIPHER_CTX **hd_dec, const EVP_CIPHER **cipher_type, const char *name,
|
||||
static int _cipher_init(EVP_CIPHER_CTX **hd_enc, EVP_CIPHER_CTX **hd_dec, const char *name,
|
||||
const char *mode, const void *key, size_t key_length, size_t *iv_length)
|
||||
{
|
||||
char cipher_name[256];
|
||||
@@ -631,41 +372,35 @@ 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 || (size_t)r >= sizeof(cipher_name))
|
||||
if (r < 0 || r >= (int)sizeof(cipher_name))
|
||||
return -EINVAL;
|
||||
|
||||
type = cipher_type_get(cipher_name);
|
||||
type = EVP_get_cipherbyname(cipher_name);
|
||||
if (!type)
|
||||
return -ENOENT;
|
||||
|
||||
if (EVP_CIPHER_key_length(type) != (int)key_length) {
|
||||
cipher_type_free(type);
|
||||
if (EVP_CIPHER_key_length(type) != (int)key_length)
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
*hd_enc = EVP_CIPHER_CTX_new();
|
||||
*hd_dec = EVP_CIPHER_CTX_new();
|
||||
*iv_length = EVP_CIPHER_iv_length(type);
|
||||
|
||||
if (!*hd_enc || !*hd_dec) {
|
||||
cipher_type_free(type);
|
||||
if (!*hd_enc || !*hd_dec)
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (EVP_EncryptInit_ex(*hd_enc, type, NULL, key, NULL) != 1 ||
|
||||
EVP_DecryptInit_ex(*hd_dec, type, NULL, key, NULL) != 1) {
|
||||
_cipher_destroy(hd_enc, hd_dec, &type);
|
||||
_cipher_destroy(hd_enc, hd_dec);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (EVP_CIPHER_CTX_set_padding(*hd_enc, 0) != 1 ||
|
||||
EVP_CIPHER_CTX_set_padding(*hd_dec, 0) != 1) {
|
||||
_cipher_destroy(hd_enc, hd_dec, &type);
|
||||
_cipher_destroy(hd_enc, hd_dec);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
*cipher_type = type;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -679,7 +414,7 @@ int crypt_cipher_init(struct crypt_cipher **ctx, const char *name,
|
||||
if (!h)
|
||||
return -ENOMEM;
|
||||
|
||||
if (!_cipher_init(&h->u.lib.hd_enc, &h->u.lib.hd_dec, &h->u.lib.cipher_type, name, mode, key,
|
||||
if (!_cipher_init(&h->u.lib.hd_enc, &h->u.lib.hd_dec, name, mode, key,
|
||||
key_length, &h->u.lib.iv_length)) {
|
||||
h->use_kernel = false;
|
||||
*ctx = h;
|
||||
@@ -702,7 +437,7 @@ void crypt_cipher_destroy(struct crypt_cipher *ctx)
|
||||
if (ctx->use_kernel)
|
||||
crypt_cipher_destroy_kernel(&ctx->u.kernel);
|
||||
else
|
||||
_cipher_destroy(&ctx->u.lib.hd_enc, &ctx->u.lib.hd_dec, &ctx->u.lib.cipher_type);
|
||||
_cipher_destroy(&ctx->u.lib.hd_enc, &ctx->u.lib.hd_dec);
|
||||
free(ctx);
|
||||
}
|
||||
|
||||
@@ -773,7 +508,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 __attribute__((unused)),
|
||||
int crypt_bitlk_decrypt_key(const void *key, size_t key_length,
|
||||
const char *in, char *out, size_t length,
|
||||
const char *iv, size_t iv_length,
|
||||
const char *tag, size_t tag_length)
|
||||
|
||||
@@ -21,7 +21,6 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <strings.h>
|
||||
#include "bitops.h"
|
||||
#include "crypto_backend.h"
|
||||
|
||||
|
||||
@@ -48,7 +48,6 @@ 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 */
|
||||
@@ -56,8 +55,7 @@ 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; /* hard limit */
|
||||
limits->min_bench_memory=64*1024; /* 64 MiB minimum for benchmark */
|
||||
limits->min_memory = 32;
|
||||
limits->max_memory = 4*1024*1024; /* 4GiB */
|
||||
limits->min_parallel = 1;
|
||||
limits->max_parallel = 4;
|
||||
@@ -76,7 +74,7 @@ static long time_ms(struct rusage *start, struct rusage *end)
|
||||
count_kernel_time = 1;
|
||||
|
||||
/*
|
||||
* If there is no self usage info, count system time.
|
||||
* FIXME: 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 &&
|
||||
@@ -410,19 +408,15 @@ 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;
|
||||
|
||||
@@ -435,7 +429,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,
|
||||
min_memory,
|
||||
pbkdf_limits.min_memory,
|
||||
max_memory_kb,
|
||||
parallel_threads, time_ms, iterations_out,
|
||||
memory_out, progress, usrptr);
|
||||
|
||||
@@ -120,7 +120,7 @@ int INTEGRITY_data_sectors(struct crypt_device *cd,
|
||||
return 0;
|
||||
}
|
||||
|
||||
int INTEGRITY_key_size(struct crypt_device *cd __attribute__((unused)), const char *integrity)
|
||||
int INTEGRITY_key_size(struct crypt_device *cd, 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 __attribute__((unused)),
|
||||
int INTEGRITY_tag_size(struct crypt_device *cd,
|
||||
const char *integrity,
|
||||
const char *cipher,
|
||||
const char *cipher_mode)
|
||||
@@ -189,7 +189,7 @@ int INTEGRITY_tag_size(struct crypt_device *cd __attribute__((unused)),
|
||||
if (!integrity || !strcmp(integrity, "none"))
|
||||
auth_tag_size = 0;
|
||||
else if (!strcmp(integrity, "aead"))
|
||||
auth_tag_size = 16; /* gcm- mode only */
|
||||
auth_tag_size = 16; //FIXME gcm- mode only
|
||||
else if (!strcmp(integrity, "cmac(aes)"))
|
||||
auth_tag_size = 16;
|
||||
else if (!strcmp(integrity, "hmac(sha1)"))
|
||||
@@ -330,9 +330,7 @@ int INTEGRITY_format(struct crypt_device *cd,
|
||||
uuid_generate(tmp_uuid_bin);
|
||||
uuid_unparse(tmp_uuid_bin, 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;
|
||||
snprintf(tmp_name, sizeof(tmp_name), "temporary-cryptsetup-%s", tmp_uuid);
|
||||
|
||||
/* There is no data area, we can actually use fake zeroed key */
|
||||
if (params && params->integrity_key_size)
|
||||
|
||||
@@ -66,7 +66,8 @@ 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,
|
||||
|
||||
@@ -41,25 +41,49 @@
|
||||
#include "utils_fips.h"
|
||||
#include "utils_keyring.h"
|
||||
#include "utils_io.h"
|
||||
#include "crypto_backend/crypto_backend.h"
|
||||
#include "crypto_backend.h"
|
||||
#include "utils_storage_wrappers.h"
|
||||
|
||||
#include "libcryptsetup.h"
|
||||
|
||||
#include "libcryptsetup_macros.h"
|
||||
#include "libcryptsetup_symver.h"
|
||||
/* to silent gcc -Wcast-qual for const cast */
|
||||
#define CONST_CAST(x) (x)(uintptr_t)
|
||||
|
||||
#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]))
|
||||
#endif
|
||||
|
||||
#define MOVE_REF(x, y) \
|
||||
do { \
|
||||
typeof (x) *_px = &(x), *_py = &(y); \
|
||||
*_px = *_py; \
|
||||
*_py = NULL; \
|
||||
} while (0)
|
||||
|
||||
#ifndef O_CLOEXEC
|
||||
#define O_CLOEXEC 0
|
||||
#endif
|
||||
|
||||
struct crypt_device;
|
||||
struct luks2_reencrypt;
|
||||
struct luks2_reenc_context;
|
||||
|
||||
struct volume_key {
|
||||
int id;
|
||||
@@ -120,8 +144,6 @@ 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);
|
||||
@@ -162,7 +184,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);
|
||||
int lookup_by_sysfs_uuid_field(const char *dm_uuid, size_t max_len);
|
||||
int crypt_uuid_cmp(const char *dm_uuid, const char *hdr_uuid);
|
||||
|
||||
size_t crypt_getpagesize(void);
|
||||
@@ -171,10 +193,11 @@ uint64_t crypt_getphysmemory_kb(void);
|
||||
|
||||
int init_crypto(struct crypt_device *ctx);
|
||||
|
||||
#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)
|
||||
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)
|
||||
|
||||
int crypt_get_debug_level(void);
|
||||
|
||||
@@ -199,8 +222,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_luks2_reencrypt(struct crypt_device *cd, struct luks2_reencrypt *rh);
|
||||
struct luks2_reencrypt *crypt_get_luks2_reencrypt(struct crypt_device *cd);
|
||||
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);
|
||||
|
||||
int onlyLUKS2(struct crypt_device *cd);
|
||||
int onlyLUKS2mask(struct crypt_device *cd, uint32_t mask);
|
||||
@@ -226,7 +249,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 compact_version(uint16_t major, uint16_t minor, uint16_t patch, uint16_t release)
|
||||
static inline uint64_t 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);
|
||||
}
|
||||
|
||||
@@ -129,10 +129,9 @@ void crypt_free(struct crypt_device *cd);
|
||||
* other values mean accepted.
|
||||
*
|
||||
* @param cd crypt device handle
|
||||
* @param confirm user defined confirm callback reference; use
|
||||
* @p msg for message for user to confirm and
|
||||
* @p usrptr for identification in callback
|
||||
* @param confirm user defined confirm callback reference
|
||||
* @param usrptr provided identification in callback
|
||||
* @param msg Message for user to confirm
|
||||
*
|
||||
* @note Current version of cryptsetup API requires confirmation for UUID change and
|
||||
* LUKS header restore only.
|
||||
@@ -197,11 +196,10 @@ int crypt_set_data_offset(struct crypt_device *cd, uint64_t data_offset);
|
||||
* Set log function.
|
||||
*
|
||||
* @param cd crypt device handle (can be @e NULL to set default log function)
|
||||
* @param log user defined log function reference; use
|
||||
* @p level for log level,
|
||||
* @p msg for message, and
|
||||
* @p usrptr for identification in callback
|
||||
* @param log user defined log function reference
|
||||
* @param usrptr provided identification in callback
|
||||
* @param level log level below (debug messages can uses other levels)
|
||||
* @param msg log message
|
||||
*/
|
||||
void crypt_set_log_callback(struct crypt_device *cd,
|
||||
void (*log)(int level, const char *msg, void *usrptr),
|
||||
@@ -217,15 +215,6 @@ 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, ...);
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
@@ -601,7 +590,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, 0 triggers auto-detection for optimal encryption sector size */
|
||||
uint32_t sector_size; /**< encryption sector size */
|
||||
const char *label; /**< header label or @e NULL*/
|
||||
const char *subsystem; /**< header subsystem label or @e NULL*/
|
||||
};
|
||||
@@ -1124,8 +1113,6 @@ int crypt_keyslot_destroy(struct crypt_device *cd, int keyslot);
|
||||
#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
|
||||
@@ -1368,8 +1355,6 @@ 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
|
||||
@@ -1473,17 +1458,6 @@ 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.
|
||||
*
|
||||
@@ -1576,21 +1550,6 @@ 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.
|
||||
*
|
||||
@@ -1988,19 +1947,6 @@ 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
|
||||
|
||||
@@ -2158,15 +2104,6 @@ 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,
|
||||
@@ -2175,38 +2112,6 @@ 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
|
||||
@@ -2244,16 +2149,6 @@ 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
|
||||
*/
|
||||
@@ -2274,35 +2169,6 @@ 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"
|
||||
|
||||
/** open by token - ABI exported symbol for external token (mandatory) */
|
||||
#define CRYPT_TOKEN_ABI_OPEN "cryptsetup_token_open"
|
||||
/** open by token with PIN - ABI exported symbol for external token */
|
||||
#define CRYPT_TOKEN_ABI_OPEN_PIN "cryptsetup_token_open_pin"
|
||||
/** deallocate callback - ABI exported symbol for external token */
|
||||
#define CRYPT_TOKEN_ABI_BUFFER_FREE "cryptsetup_token_buffer_free"
|
||||
/** validate token metadata - ABI exported symbol for external token */
|
||||
#define CRYPT_TOKEN_ABI_VALIDATE "cryptsetup_token_validate"
|
||||
/** dump token metadata - ABI exported symbol for external token */
|
||||
#define CRYPT_TOKEN_ABI_DUMP "cryptsetup_token_dump"
|
||||
/** token version - ABI exported symbol for external token */
|
||||
#define CRYPT_TOKEN_ABI_VERSION "cryptsetup_token_version"
|
||||
|
||||
/**
|
||||
* Activate device or check key using a token.
|
||||
*
|
||||
@@ -2313,71 +2179,12 @@ void crypt_token_external_disable(void);
|
||||
* @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 @e 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 @e 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);
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
@@ -2397,8 +2204,6 @@ int crypt_activate_by_token_pin(struct crypt_device *cd,
|
||||
#define CRYPT_REENCRYPT_RESUME_ONLY (1 << 2)
|
||||
/** Run reencryption recovery only. (in) */
|
||||
#define CRYPT_REENCRYPT_RECOVERY (1 << 3)
|
||||
/** Reencryption requires metadata protection. (in/out) */
|
||||
#define CRYPT_REENCRYPT_REPAIR_NEEDED (1 << 4)
|
||||
|
||||
/**
|
||||
* Reencryption direction
|
||||
@@ -2490,34 +2295,17 @@ int crypt_reencrypt_init_by_keyring(struct crypt_device *cd,
|
||||
const char *cipher_mode,
|
||||
const struct crypt_params_reencrypt *params);
|
||||
|
||||
/**
|
||||
* Legacy data reencryption function.
|
||||
*
|
||||
* @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
|
||||
*
|
||||
* @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))
|
||||
__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);
|
||||
int crypt_reencrypt(struct crypt_device *cd,
|
||||
int (*progress)(uint64_t size, uint64_t offset, void *usrptr));
|
||||
|
||||
/**
|
||||
* Reencryption status info
|
||||
|
||||
@@ -131,16 +131,3 @@ 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;
|
||||
|
||||
@@ -1,67 +0,0 @@
|
||||
/*
|
||||
* 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 */
|
||||
@@ -1,105 +0,0 @@
|
||||
/*
|
||||
* 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 */
|
||||
@@ -24,16 +24,23 @@
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
#include <ctype.h>
|
||||
#include <dirent.h>
|
||||
#include <errno.h>
|
||||
#include <libdevmapper.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"
|
||||
@@ -235,9 +242,6 @@ static void _dm_set_integrity_compat(struct crypt_device *cd,
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -261,12 +265,16 @@ static void _dm_check_target(dm_target_type target_type)
|
||||
return;
|
||||
|
||||
if (!(dmt = dm_task_create(DM_DEVICE_GET_TARGET_VERSION)))
|
||||
return;
|
||||
goto out;
|
||||
|
||||
if (dm_task_set_name(dmt, target_name))
|
||||
dm_task_run(dmt);
|
||||
if (!dm_task_set_name(dmt, target_name))
|
||||
goto out;
|
||||
|
||||
dm_task_destroy(dmt);
|
||||
if (!dm_task_run(dmt))
|
||||
goto out;
|
||||
out:
|
||||
if (dmt)
|
||||
dm_task_destroy(dmt);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -290,6 +298,7 @@ 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;
|
||||
|
||||
@@ -387,7 +396,10 @@ void dm_backend_exit(struct crypt_device *cd)
|
||||
}
|
||||
}
|
||||
|
||||
/* libdevmapper is not context friendly, switch context on every DM call. */
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
static int dm_init_context(struct crypt_device *cd, dm_target_type target)
|
||||
{
|
||||
_context = cd;
|
||||
@@ -578,14 +590,9 @@ 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)
|
||||
i = snprintf(dmcrypt_tmp, sizeof(dmcrypt_tmp), "%s-%s-%s", cipher, mode, iv);
|
||||
snprintf(dmcrypt_tmp, sizeof(dmcrypt_tmp), "%s-%s-%s", cipher, mode, iv);
|
||||
else
|
||||
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;
|
||||
}
|
||||
snprintf(dmcrypt_tmp, sizeof(dmcrypt_tmp), "%s-%s", capi, iv);
|
||||
|
||||
if (!(*org_c = strdup(dmcrypt_tmp))) {
|
||||
free(*org_i);
|
||||
@@ -596,18 +603,11 @@ 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 = NULL, *hexkey = NULL;
|
||||
char *params, *hexkey;
|
||||
char sector_feature[32], features[512], integrity_dm[256], cipher_dm[256];
|
||||
|
||||
if (!tgt)
|
||||
@@ -632,22 +632,22 @@ static char *get_dm_crypt_params(const struct dm_target *tgt, uint32_t flags)
|
||||
num_options++;
|
||||
if (tgt->u.crypt.integrity)
|
||||
num_options++;
|
||||
if (tgt->u.crypt.sector_size != SECTOR_SIZE)
|
||||
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,
|
||||
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%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" : "",
|
||||
(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;
|
||||
sector_feature, integrity_dm);
|
||||
} else
|
||||
*features = '\0';
|
||||
|
||||
@@ -663,14 +663,16 @@ static char *get_dm_crypt_params(const struct dm_target *tgt, uint32_t flags)
|
||||
hexkey = crypt_safe_alloc(tgt->u.crypt.vk->keylength * 2 + 1);
|
||||
|
||||
if (!hexkey)
|
||||
goto out;
|
||||
return NULL;
|
||||
|
||||
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)
|
||||
if (r < 0 || r >= keystr_len) {
|
||||
params = NULL;
|
||||
goto out;
|
||||
}
|
||||
} else
|
||||
hex_key(hexkey, tgt->u.crypt.vk->keylength, tgt->u.crypt.vk->key);
|
||||
|
||||
@@ -697,10 +699,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, max_fec_size, max_verify_size, r, num_options = 0;
|
||||
int max_size, r, num_options = 0;
|
||||
struct crypt_params_verity *vp;
|
||||
char *params = NULL, *hexroot = NULL, *hexsalt = NULL;
|
||||
char features[256], *fec_features = NULL, *verity_verify_args = NULL;
|
||||
char features[256], fec_features[256], verity_verify_args[512+32];
|
||||
|
||||
if (!tgt || !tgt->u.verity.vp)
|
||||
return NULL;
|
||||
@@ -726,45 +728,30 @@ static char *get_dm_verity_params(const struct dm_target *tgt, uint32_t flags)
|
||||
if (flags & CRYPT_ACTIVATE_CHECK_AT_MOST_ONCE)
|
||||
num_options++;
|
||||
|
||||
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 */
|
||||
if (tgt->u.verity.fec_device) {
|
||||
num_options += 8;
|
||||
r = snprintf(fec_features, max_fec_size,
|
||||
snprintf(fec_features, sizeof(fec_features)-1,
|
||||
" 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,
|
||||
tgt->u.verity.fec_blocks, vp->fec_roots);
|
||||
if (r < 0 || r >= max_fec_size)
|
||||
goto out;
|
||||
} else
|
||||
*fec_features = '\0';
|
||||
|
||||
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 */
|
||||
if (tgt->u.verity.root_hash_sig_key_desc) {
|
||||
num_options += 2;
|
||||
r = snprintf(verity_verify_args, max_verify_size,
|
||||
snprintf(verity_verify_args, sizeof(verity_verify_args)-1,
|
||||
" 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) { /* MAX length int32 + 18 + 22 + 20 + 19 + 19 */
|
||||
r = snprintf(features, sizeof(features), " %d%s%s%s%s%s", num_options,
|
||||
if (num_options)
|
||||
snprintf(features, sizeof(features)-1, " %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" : "");
|
||||
if (r < 0 || (size_t)r >= sizeof(features))
|
||||
goto out;
|
||||
} else
|
||||
else
|
||||
*features = '\0';
|
||||
|
||||
hexroot = crypt_safe_alloc(tgt->u.verity.root_hash_size * 2 + 1);
|
||||
@@ -798,13 +785,12 @@ 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;
|
||||
@@ -812,146 +798,162 @@ out:
|
||||
|
||||
static char *get_dm_integrity_params(const struct dm_target *tgt, uint32_t flags)
|
||||
{
|
||||
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;
|
||||
int r, max_size, num_options = 0;
|
||||
char *params, *hexkey, mode;
|
||||
char features[512], feature[256];
|
||||
|
||||
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) +
|
||||
max_integrity + max_journal_integrity + max_journal_crypt + 512;
|
||||
(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;
|
||||
|
||||
params = crypt_safe_alloc(max_size);
|
||||
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;
|
||||
if (!params)
|
||||
return NULL;
|
||||
|
||||
if (tgt->u.integrity.integrity) { /* MAX length 16 + str_integrity + str_key */
|
||||
*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) {
|
||||
num_options++;
|
||||
|
||||
if (tgt->u.integrity.vk) {
|
||||
hexkey = crypt_safe_alloc(tgt->u.integrity.vk->keylength * 2 + 1);
|
||||
if (!hexkey)
|
||||
goto out;
|
||||
if (!hexkey) {
|
||||
crypt_safe_free(params);
|
||||
return NULL;
|
||||
}
|
||||
hex_key(hexkey, tgt->u.integrity.vk->keylength, tgt->u.integrity.vk->key);
|
||||
} else
|
||||
hexkey = NULL;
|
||||
|
||||
r = snprintf(integrity, max_integrity, " internal_hash:%s%s%s",
|
||||
snprintf(feature, sizeof(feature), "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) { /* MAX length 14 + str_journal_integrity + str_key */
|
||||
if (tgt->u.integrity.journal_integrity) {
|
||||
num_options++;
|
||||
|
||||
if (tgt->u.integrity.journal_integrity_key) {
|
||||
hexkey = crypt_safe_alloc(tgt->u.integrity.journal_integrity_key->keylength * 2 + 1);
|
||||
if (!hexkey)
|
||||
goto out;
|
||||
if (!hexkey) {
|
||||
crypt_safe_free(params);
|
||||
return NULL;
|
||||
}
|
||||
hex_key(hexkey, tgt->u.integrity.journal_integrity_key->keylength,
|
||||
tgt->u.integrity.journal_integrity_key->key);
|
||||
} else
|
||||
hexkey = NULL;
|
||||
|
||||
r = snprintf(journal_integrity, max_journal_integrity, " journal_mac:%s%s%s",
|
||||
snprintf(feature, sizeof(feature), "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) { /* MAX length 15 + str_journal_crypt + str_key */
|
||||
if (tgt->u.integrity.journal_crypt) {
|
||||
num_options++;
|
||||
|
||||
if (tgt->u.integrity.journal_crypt_key) {
|
||||
hexkey = crypt_safe_alloc(tgt->u.integrity.journal_crypt_key->keylength * 2 + 1);
|
||||
if (!hexkey)
|
||||
goto out;
|
||||
if (!hexkey) {
|
||||
crypt_safe_free(params);
|
||||
return NULL;
|
||||
}
|
||||
hex_key(hexkey, tgt->u.integrity.journal_crypt_key->keylength,
|
||||
tgt->u.integrity.journal_crypt_key->key);
|
||||
} else
|
||||
hexkey = NULL;
|
||||
|
||||
r = snprintf(journal_crypt, max_journal_crypt, " journal_crypt:%s%s%s",
|
||||
snprintf(feature, sizeof(feature), "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 (r < 0 || r >= max_journal_crypt)
|
||||
goto out;
|
||||
}
|
||||
|
||||
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)
|
||||
if (tgt->u.integrity.fix_padding) {
|
||||
num_options++;
|
||||
snprintf(feature, sizeof(feature), "fix_padding ");
|
||||
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 (tgt->u.integrity.fix_hmac) {
|
||||
num_options++;
|
||||
snprintf(feature, sizeof(feature), "fix_hmac ");
|
||||
strncat(features, feature, sizeof(features) - strlen(features) - 1);
|
||||
}
|
||||
|
||||
if (tgt->u.integrity.legacy_recalc) {
|
||||
num_options++;
|
||||
snprintf(feature, sizeof(feature), "legacy_recalculate ");
|
||||
strncat(features, feature, sizeof(features) - strlen(features) - 1);
|
||||
}
|
||||
|
||||
if (flags & CRYPT_ACTIVATE_RECALCULATE) {
|
||||
num_options++;
|
||||
snprintf(feature, sizeof(feature), "recalculate ");
|
||||
strncat(features, feature, sizeof(features) - strlen(features) - 1);
|
||||
}
|
||||
|
||||
if (flags & CRYPT_ACTIVATE_ALLOW_DISCARDS) {
|
||||
num_options++;
|
||||
snprintf(feature, sizeof(feature), "allow_discards ");
|
||||
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);
|
||||
}
|
||||
|
||||
if (flags & CRYPT_ACTIVATE_NO_JOURNAL_BITMAP)
|
||||
mode = 'B';
|
||||
@@ -962,25 +964,19 @@ 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 %s",
|
||||
r = snprintf(params, max_size, "%s %" PRIu64 " %d %c %d %s",
|
||||
device_block_path(tgt->data_device), tgt->u.integrity.offset,
|
||||
tgt->u.integrity.tag_size, mode, features);
|
||||
if (r < 0 || r >= max_size)
|
||||
goto out;
|
||||
|
||||
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)
|
||||
tgt->u.integrity.tag_size, mode,
|
||||
num_options, *features ? features : "");
|
||||
if (r < 0 || r >= max_size) {
|
||||
crypt_safe_free(params);
|
||||
params = NULL;
|
||||
}
|
||||
|
||||
return params_out;
|
||||
return params;
|
||||
}
|
||||
|
||||
static char *get_dm_linear_params(const struct dm_target *tgt, uint32_t flags __attribute__((unused)))
|
||||
static char *get_dm_linear_params(const struct dm_target *tgt, uint32_t flags)
|
||||
{
|
||||
char *params;
|
||||
int r;
|
||||
@@ -1001,7 +997,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 __attribute__((unused)), uint32_t flags __attribute__((unused)))
|
||||
static char *get_dm_zero_params(const struct dm_target *tgt, uint32_t flags)
|
||||
{
|
||||
char *params = crypt_safe_alloc(1);
|
||||
if (!params)
|
||||
@@ -1083,27 +1079,28 @@ static int _error_device(const char *name, size_t size)
|
||||
return 0;
|
||||
|
||||
if (!dm_task_set_name(dmt, name))
|
||||
goto out;
|
||||
goto error;
|
||||
|
||||
if (!dm_task_add_target(dmt, UINT64_C(0), size, "error", ""))
|
||||
goto out;
|
||||
goto error;
|
||||
|
||||
if (!dm_task_set_ro(dmt))
|
||||
goto out;
|
||||
goto error;
|
||||
|
||||
if (!dm_task_no_open_count(dmt))
|
||||
goto out;
|
||||
goto error;
|
||||
|
||||
if (!dm_task_run(dmt))
|
||||
goto out;
|
||||
goto error;
|
||||
|
||||
if (_dm_resume_device(name, 0)) {
|
||||
_dm_simple(DM_DEVICE_CLEAR, name, 0);
|
||||
goto out;
|
||||
goto error;
|
||||
}
|
||||
|
||||
r = 1;
|
||||
out:
|
||||
|
||||
error:
|
||||
dm_task_destroy(dmt);
|
||||
return r;
|
||||
}
|
||||
@@ -1211,7 +1208,7 @@ static int dm_prepare_uuid(struct crypt_device *cd, const char *name, const char
|
||||
{
|
||||
char *ptr, uuid2[UUID_LEN] = {0};
|
||||
uuid_t uu;
|
||||
int i = 0;
|
||||
unsigned i = 0;
|
||||
|
||||
/* Remove '-' chars */
|
||||
if (uuid) {
|
||||
@@ -1231,11 +1228,9 @@ 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 ((size_t)i >= buflen)
|
||||
if (i >= buflen)
|
||||
log_err(cd, _("DM-UUID for device %s was truncated."), name);
|
||||
|
||||
return 1;
|
||||
@@ -1243,7 +1238,7 @@ static int dm_prepare_uuid(struct crypt_device *cd, const char *name, const char
|
||||
|
||||
int lookup_dm_dev_by_uuid(struct crypt_device *cd, const char *uuid, const char *type)
|
||||
{
|
||||
int r_udev, r;
|
||||
int r;
|
||||
char *c;
|
||||
char dev_uuid[DM_UUID_LEN + DM_BY_ID_PREFIX_LEN] = DM_BY_ID_PREFIX;
|
||||
|
||||
@@ -1257,16 +1252,13 @@ int lookup_dm_dev_by_uuid(struct crypt_device *cd, const char *uuid, const char
|
||||
/* cut of dm name */
|
||||
*c = '\0';
|
||||
|
||||
/* Either udev or sysfs can report that device is active. */
|
||||
r = lookup_by_disk_id(dev_uuid);
|
||||
if (r > 0)
|
||||
return r;
|
||||
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_udev = r;
|
||||
if (r_udev <= 0)
|
||||
r = lookup_by_sysfs_uuid_field(dev_uuid + DM_BY_ID_PREFIX_LEN);
|
||||
|
||||
return r == -ENOENT ? r_udev : r;
|
||||
return r;
|
||||
}
|
||||
|
||||
static int _add_dm_targets(struct dm_task *dmt, struct crypt_dm_active_device *dmd)
|
||||
@@ -1349,8 +1341,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,
|
||||
struct crypt_dm_active_device *dmd)
|
||||
const char *uuid, struct crypt_dm_active_device *dmd)
|
||||
{
|
||||
struct dm_task *dmt = NULL;
|
||||
struct dm_info dmi;
|
||||
@@ -1399,11 +1397,8 @@ static int _dm_create_device(struct crypt_device *cd, const char *name, const ch
|
||||
goto out;
|
||||
|
||||
if (!dm_task_run(dmt)) {
|
||||
r = dm_status_device(cd, name);;
|
||||
if (r >= 0)
|
||||
if (dm_device_exists(cd, name))
|
||||
r = -EEXIST;
|
||||
if (r != -EEXIST && r != -ENODEV)
|
||||
r = -EINVAL;
|
||||
goto out;
|
||||
}
|
||||
|
||||
@@ -1666,7 +1661,7 @@ 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);
|
||||
r = _dm_create_device(cd, name, type, dmd->uuid, dmd);
|
||||
|
||||
if (r < 0 && dm_flags(cd, dmd->segment.type, &dmt_flags))
|
||||
goto out;
|
||||
@@ -1674,7 +1669,7 @@ int dm_create_device(struct crypt_device *cd, const char *name,
|
||||
if (r && (dmd->segment.type == DM_CRYPT || dmd->segment.type == DM_LINEAR || dmd->segment.type == DM_ZERO) &&
|
||||
check_retry(cd, &dmd->flags, dmt_flags)) {
|
||||
log_dbg(cd, "Retrying open without incompatible options.");
|
||||
r = _dm_create_device(cd, name, type, dmd);
|
||||
r = _dm_create_device(cd, name, type, dmd->uuid, dmd);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1721,10 +1716,6 @@ 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."));
|
||||
@@ -1785,7 +1776,7 @@ static int dm_status_dmi(const char *name, struct dm_info *dmi,
|
||||
int r = -EINVAL;
|
||||
|
||||
if (!(dmt = dm_task_create(DM_DEVICE_STATUS)))
|
||||
return r;
|
||||
goto out;
|
||||
|
||||
if (!dm_task_no_flush(dmt))
|
||||
goto out;
|
||||
@@ -1827,7 +1818,8 @@ out:
|
||||
if (!r && status_line && !(*status_line = strdup(params)))
|
||||
r = -ENOMEM;
|
||||
|
||||
dm_task_destroy(dmt);
|
||||
if (dmt)
|
||||
dm_task_destroy(dmt);
|
||||
|
||||
return r;
|
||||
}
|
||||
@@ -2303,16 +2295,11 @@ static int _dm_target_query_verity(struct crypt_device *cd,
|
||||
str = strsep(¶ms, " ");
|
||||
if (!str)
|
||||
goto err;
|
||||
if (vp && !root_hash_sig_key_desc) {
|
||||
if (!root_hash_sig_key_desc)
|
||||
root_hash_sig_key_desc = strdup(str);
|
||||
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++;
|
||||
if (vp)
|
||||
vp->flags |= CRYPT_VERITY_ROOT_HASH_SIGNATURE;
|
||||
} else /* unknown option */
|
||||
goto err;
|
||||
}
|
||||
@@ -2511,8 +2498,6 @@ 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")) {
|
||||
@@ -2595,7 +2580,7 @@ err:
|
||||
return r;
|
||||
}
|
||||
|
||||
static int _dm_target_query_error(struct crypt_device *cd __attribute__((unused)), struct dm_target *tgt)
|
||||
static int _dm_target_query_error(struct crypt_device *cd, struct dm_target *tgt)
|
||||
{
|
||||
tgt->type = DM_ERROR;
|
||||
tgt->direction = TARGET_QUERY;
|
||||
@@ -2603,7 +2588,7 @@ static int _dm_target_query_error(struct crypt_device *cd __attribute__((unused)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int _dm_target_query_zero(struct crypt_device *cd __attribute__((unused)), struct dm_target *tgt)
|
||||
static int _dm_target_query_zero(struct crypt_device *cd, struct dm_target *tgt)
|
||||
{
|
||||
tgt->type = DM_ZERO;
|
||||
tgt->direction = TARGET_QUERY;
|
||||
@@ -2736,7 +2721,8 @@ static int _dm_query_device(struct crypt_device *cd, const char *name,
|
||||
|
||||
r = (dmi.open_count > 0);
|
||||
out:
|
||||
dm_task_destroy(dmt);
|
||||
if (dmt)
|
||||
dm_task_destroy(dmt);
|
||||
|
||||
if (r < 0)
|
||||
dm_targets_free(cd, dmd);
|
||||
@@ -2990,11 +2976,6 @@ 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();
|
||||
@@ -3015,13 +2996,18 @@ 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)
|
||||
return -ENOMEM;
|
||||
if (!dm_integrity) {
|
||||
r = -ENOMEM;
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
|
||||
tgt->data_device = data_device;
|
||||
@@ -3040,6 +3026,10 @@ 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,
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
#define _LOOPAES_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include <unistd.h>
|
||||
|
||||
struct crypt_device;
|
||||
struct volume_key;
|
||||
|
||||
@@ -26,9 +26,6 @@
|
||||
|
||||
#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
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <netinet/in.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
@@ -65,27 +66,6 @@ static void LUKS_sort_keyslots(const struct luks_phdr *hdr, int *array)
|
||||
}
|
||||
}
|
||||
|
||||
static int _is_not_lower(char *str, unsigned max_len)
|
||||
{
|
||||
for(; *str && max_len; str++, max_len--)
|
||||
if (isupper(*str))
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int _to_lower(char *str, unsigned max_len)
|
||||
{
|
||||
int r = 0;
|
||||
|
||||
for(; *str && max_len; str++, max_len--)
|
||||
if (isupper(*str)) {
|
||||
*str = tolower(*str);
|
||||
r = 1;
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
size_t LUKS_device_sectors(const struct luks_phdr *hdr)
|
||||
{
|
||||
int sorted_areas[LUKS_NUMKEYS] = { 0, 1, 2, 3, 4, 5, 6, 7 };
|
||||
@@ -406,30 +386,6 @@ static int _keyslot_repair(struct luks_phdr *phdr, struct crypt_device *ctx)
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
/*
|
||||
* ECB mode does not use IV but legacy dmcrypt silently allows it.
|
||||
* Today device cannot be activated anyway, so we need to fix it here.
|
||||
*/
|
||||
if (!strncmp(phdr->cipherMode, "ecb-", 4)) {
|
||||
log_err(ctx, _("Cipher mode repaired (%s -> %s)."), phdr->cipherMode, "ecb");
|
||||
memset(phdr->cipherMode, 0, LUKS_CIPHERMODE_L);
|
||||
strcpy(phdr->cipherMode, "ecb");
|
||||
need_write = 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Old cryptsetup expects "sha1", gcrypt allows case insensitive names,
|
||||
* so always convert hash to lower case in header
|
||||
*/
|
||||
if (_to_lower(phdr->hashSpec, LUKS_HASHSPEC_L)) {
|
||||
log_err(ctx, _("Cipher hash repaired to lowercase (%s)."), phdr->hashSpec);
|
||||
if (crypt_hmac_size(phdr->hashSpec) < LUKS_DIGESTSIZE) {
|
||||
log_err(ctx, _("Requested LUKS hash %s is not supported."), phdr->hashSpec);
|
||||
return -EINVAL;
|
||||
}
|
||||
need_write = 1;
|
||||
}
|
||||
|
||||
r = LUKS_check_cipher(ctx, phdr->keyBytes, phdr->cipherName, phdr->cipherMode);
|
||||
if (r < 0)
|
||||
return -EINVAL;
|
||||
@@ -517,13 +473,12 @@ static int _check_and_convert_hdr(const char *device,
|
||||
unsigned int i;
|
||||
char luksMagic[] = LUKS_MAGIC;
|
||||
|
||||
hdr->version = be16_to_cpu(hdr->version);
|
||||
if (memcmp(hdr->magic, luksMagic, LUKS_MAGIC_L)) { /* Check magic */
|
||||
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 != 1) {
|
||||
} else if((hdr->version = ntohs(hdr->version)) != 1) { /* Convert every uint16/32_t item from network byte order */
|
||||
log_err(ctx, _("Unsupported LUKS version %d."), hdr->version);
|
||||
return -EINVAL;
|
||||
}
|
||||
@@ -531,19 +486,19 @@ static int _check_and_convert_hdr(const char *device,
|
||||
hdr->hashSpec[LUKS_HASHSPEC_L - 1] = '\0';
|
||||
if (crypt_hmac_size(hdr->hashSpec) < LUKS_DIGESTSIZE) {
|
||||
log_err(ctx, _("Requested LUKS hash %s is not supported."), hdr->hashSpec);
|
||||
r = -EINVAL;
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
/* Header detected */
|
||||
hdr->payloadOffset = be32_to_cpu(hdr->payloadOffset);
|
||||
hdr->keyBytes = be32_to_cpu(hdr->keyBytes);
|
||||
hdr->mkDigestIterations = be32_to_cpu(hdr->mkDigestIterations);
|
||||
hdr->payloadOffset = ntohl(hdr->payloadOffset);
|
||||
hdr->keyBytes = ntohl(hdr->keyBytes);
|
||||
hdr->mkDigestIterations = ntohl(hdr->mkDigestIterations);
|
||||
|
||||
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);
|
||||
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);
|
||||
}
|
||||
|
||||
if (LUKS_check_keyslots(ctx, hdr))
|
||||
@@ -555,16 +510,6 @@ static int _check_and_convert_hdr(const char *device,
|
||||
hdr->uuid[UUID_STRING_L - 1] = '\0';
|
||||
|
||||
if (repair) {
|
||||
if (!strncmp(hdr->cipherMode, "ecb-", 4)) {
|
||||
log_err(ctx, _("LUKS cipher mode %s is invalid."), hdr->cipherMode);
|
||||
r = -EINVAL;
|
||||
}
|
||||
|
||||
if (_is_not_lower(hdr->hashSpec, LUKS_HASHSPEC_L)) {
|
||||
log_err(ctx, _("LUKS hash %s is invalid."), hdr->hashSpec);
|
||||
r = -EINVAL;
|
||||
}
|
||||
|
||||
if (r == -EINVAL)
|
||||
r = _keyslot_repair(hdr, ctx);
|
||||
else
|
||||
@@ -574,6 +519,27 @@ static int _check_and_convert_hdr(const char *device,
|
||||
return r;
|
||||
}
|
||||
|
||||
static void _to_lower(char *str, unsigned max_len)
|
||||
{
|
||||
for(; *str && max_len; str++, max_len--)
|
||||
if (isupper(*str))
|
||||
*str = tolower(*str);
|
||||
}
|
||||
|
||||
static void LUKS_fix_header_compatible(struct luks_phdr *header)
|
||||
{
|
||||
/* Old cryptsetup expects "sha1", gcrypt allows case insensitive names,
|
||||
* so always convert hash to lower case in header */
|
||||
_to_lower(header->hashSpec, LUKS_HASHSPEC_L);
|
||||
|
||||
/* ECB mode does not use IV but dmcrypt silently allows it.
|
||||
* Drop any IV here if ECB is used (that is not secure anyway).*/
|
||||
if (!strncmp(header->cipherMode, "ecb-", 4)) {
|
||||
memset(header->cipherMode, 0, LUKS_CIPHERMODE_L);
|
||||
strcpy(header->cipherMode, "ecb");
|
||||
}
|
||||
}
|
||||
|
||||
int LUKS_read_phdr_backup(const char *backup_file,
|
||||
struct luks_phdr *hdr,
|
||||
int require_luks_device,
|
||||
@@ -593,9 +559,11 @@ int LUKS_read_phdr_backup(const char *backup_file,
|
||||
|
||||
if (read_buffer(devfd, hdr, hdr_size) < hdr_size)
|
||||
r = -EIO;
|
||||
else
|
||||
else {
|
||||
LUKS_fix_header_compatible(hdr);
|
||||
r = _check_and_convert_hdr(backup_file, hdr,
|
||||
require_luks_device, 0, ctx);
|
||||
}
|
||||
|
||||
close(devfd);
|
||||
return r;
|
||||
@@ -682,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 = 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);
|
||||
convHdr.version = htons(hdr->version);
|
||||
convHdr.payloadOffset = htonl(hdr->payloadOffset);
|
||||
convHdr.keyBytes = htonl(hdr->keyBytes);
|
||||
convHdr.mkDigestIterations = htonl(hdr->mkDigestIterations);
|
||||
for(i = 0; i < LUKS_NUMKEYS; ++i) {
|
||||
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);
|
||||
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);
|
||||
}
|
||||
|
||||
r = write_lseek_blockwise(devfd, device_block_size(ctx, device), device_alignment(device),
|
||||
@@ -803,10 +771,11 @@ int LUKS_generate_phdr(struct luks_phdr *header,
|
||||
strncpy(header->cipherName,cipherName,LUKS_CIPHERNAME_L-1);
|
||||
strncpy(header->cipherMode,cipherMode,LUKS_CIPHERMODE_L-1);
|
||||
strncpy(header->hashSpec,hashSpec,LUKS_HASHSPEC_L-1);
|
||||
_to_lower(header->hashSpec, LUKS_HASHSPEC_L);
|
||||
|
||||
header->keyBytes=vk->keylength;
|
||||
|
||||
LUKS_fix_header_compatible(header);
|
||||
|
||||
log_dbg(ctx, "Generating LUKS header version %d using hash %s, %s, %s, MK %d bytes",
|
||||
header->version, header->hashSpec ,header->cipherName, header->cipherMode,
|
||||
header->keyBytes);
|
||||
@@ -831,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,
|
||||
@@ -905,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);
|
||||
|
||||
|
||||
@@ -44,8 +44,6 @@
|
||||
#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
|
||||
@@ -63,10 +61,6 @@
|
||||
#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.
|
||||
@@ -102,6 +96,7 @@ struct luks2_hdr_disk {
|
||||
/*
|
||||
* LUKS2 header in-memory.
|
||||
*/
|
||||
typedef struct json_object json_object;
|
||||
struct luks2_hdr {
|
||||
size_t hdr_size;
|
||||
uint64_t seqid;
|
||||
@@ -112,7 +107,7 @@ struct luks2_hdr {
|
||||
uint8_t salt1[LUKS2_SALT_L];
|
||||
uint8_t salt2[LUKS2_SALT_L];
|
||||
char uuid[LUKS2_UUID_L];
|
||||
void *jobj;
|
||||
json_object *jobj;
|
||||
};
|
||||
|
||||
struct luks2_keyslot_params {
|
||||
@@ -134,6 +129,77 @@ 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.
|
||||
@@ -156,11 +222,13 @@ struct luks2_keyslot_params {
|
||||
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,
|
||||
@@ -181,9 +249,9 @@ int LUKS2_hdr_restore(struct crypt_device *cd,
|
||||
struct luks2_hdr *hdr,
|
||||
const char *backup_file);
|
||||
|
||||
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);
|
||||
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);
|
||||
|
||||
int LUKS2_keyslot_cipher_incompatible(struct crypt_device *cd, const char *cipher_spec);
|
||||
|
||||
@@ -212,11 +280,28 @@ 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);
|
||||
@@ -227,11 +312,6 @@ 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
|
||||
*/
|
||||
@@ -269,25 +349,89 @@ crypt_token_info LUKS2_token_status(struct crypt_device *cd,
|
||||
int token,
|
||||
const char **type);
|
||||
|
||||
int LUKS2_token_open_and_activate(struct crypt_device *cd,
|
||||
int LUKS2_builtin_token_get(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);
|
||||
void *params);
|
||||
|
||||
int LUKS2_token_keyring_get(struct crypt_device *cd,
|
||||
int LUKS2_builtin_token_create(struct crypt_device *cd,
|
||||
struct luks2_hdr *hdr,
|
||||
int token,
|
||||
struct crypt_token_params_luks2_keyring *keyring_params);
|
||||
const char *type,
|
||||
const void *params,
|
||||
int commit);
|
||||
|
||||
int LUKS2_token_keyring_json(char *buffer, size_t buffer_size,
|
||||
const struct crypt_token_params_luks2_keyring *keyring_params);
|
||||
int LUKS2_token_open_and_activate(struct crypt_device *cd,
|
||||
struct luks2_hdr *hdr,
|
||||
int token,
|
||||
const char *name,
|
||||
uint32_t flags,
|
||||
void *usrptr);
|
||||
|
||||
void crypt_token_unload_external_all(struct crypt_device *cd);
|
||||
int LUKS2_token_open_and_activate_any(struct crypt_device *cd,
|
||||
struct luks2_hdr *hdr,
|
||||
const char *name,
|
||||
uint32_t flags);
|
||||
|
||||
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,
|
||||
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
|
||||
@@ -296,16 +440,29 @@ 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,
|
||||
@@ -322,8 +479,6 @@ 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,
|
||||
@@ -343,12 +498,20 @@ 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,
|
||||
@@ -380,14 +543,19 @@ 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 crypt_device *cd, struct luks2_hdr *hdr, size_t keylength);
|
||||
int LUKS2_keyslot_find_empty(struct luks2_hdr *hdr);
|
||||
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
|
||||
@@ -401,8 +569,6 @@ int LUKS2_config_set_flags(struct crypt_device *cd, struct luks2_hdr *hdr, uint3
|
||||
int LUKS2_config_get_requirements(struct crypt_device *cd, struct luks2_hdr *hdr, uint32_t *reqs);
|
||||
int LUKS2_config_set_requirements(struct crypt_device *cd, struct luks2_hdr *hdr, uint32_t reqs, bool commit);
|
||||
|
||||
int LUKS2_config_get_reencrypt_version(struct luks2_hdr *hdr, uint32_t *version);
|
||||
|
||||
int LUKS2_unmet_requirements(struct crypt_device *cd, struct luks2_hdr *hdr, uint32_t reqs_mask, int quiet);
|
||||
|
||||
int LUKS2_key_description_by_segment(struct crypt_device *cd,
|
||||
@@ -412,6 +578,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 luks_phdr;
|
||||
int LUKS2_luks1_to_luks2(struct crypt_device *cd,
|
||||
struct luks_phdr *hdr1,
|
||||
struct luks2_hdr *hdr2);
|
||||
@@ -430,33 +597,21 @@ int LUKS2_reencrypt_locked_recovery_by_passphrase(struct crypt_device *cd,
|
||||
uint32_t flags,
|
||||
struct volume_key **vks);
|
||||
|
||||
void LUKS2_reencrypt_free(struct crypt_device *cd,
|
||||
struct luks2_reencrypt *rh);
|
||||
void LUKS2_reenc_context_free(struct crypt_device *cd, struct luks2_reenc_context *rh);
|
||||
|
||||
crypt_reencrypt_info LUKS2_reencrypt_status(struct luks2_hdr *hdr);
|
||||
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_get_params(struct luks2_hdr *hdr,
|
||||
crypt_reencrypt_info LUKS2_reencrypt_status(struct crypt_device *cd,
|
||||
struct crypt_params_reencrypt *params);
|
||||
|
||||
int LUKS2_reencrypt_lock(struct crypt_device *cd,
|
||||
struct crypt_lock_handle **reencrypt_lock);
|
||||
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_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);
|
||||
|
||||
int LUKS2_reencrypt_digest_verify(struct crypt_device *cd,
|
||||
struct luks2_hdr *hdr,
|
||||
struct volume_key *vks);
|
||||
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);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -28,7 +28,7 @@ static const digest_handler *digest_handlers[LUKS2_DIGEST_MAX] = {
|
||||
NULL
|
||||
};
|
||||
|
||||
static const digest_handler *LUKS2_digest_handler_type(const char *type)
|
||||
static const digest_handler *LUKS2_digest_handler_type(struct crypt_device *cd, 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(json_object_get_string(jobj2));
|
||||
return LUKS2_digest_handler_type(cd, json_object_get_string(jobj2));
|
||||
}
|
||||
|
||||
static int LUKS2_digest_find_free(struct luks2_hdr *hdr)
|
||||
static int LUKS2_digest_find_free(struct crypt_device *cd, 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(type);
|
||||
dh = LUKS2_digest_handler_type(cd, type);
|
||||
if (!dh)
|
||||
return -EINVAL;
|
||||
|
||||
digest = LUKS2_digest_find_free(hdr);
|
||||
digest = LUKS2_digest_find_free(cd, 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 __attribute__((unused)),
|
||||
struct luks2_hdr *hdr,
|
||||
int digest,
|
||||
const struct volume_key *vk)
|
||||
{
|
||||
@@ -219,9 +219,7 @@ static int assign_one_digest(struct crypt_device *cd, struct luks2_hdr *hdr,
|
||||
if (!jobj_digest_keyslots)
|
||||
return -EINVAL;
|
||||
|
||||
if (snprintf(num, sizeof(num), "%d", keyslot) < 0)
|
||||
return -EINVAL;
|
||||
|
||||
snprintf(num, sizeof(num), "%d", keyslot);
|
||||
if (assign) {
|
||||
jobj1 = LUKS2_array_jobj(jobj_digest_keyslots, num);
|
||||
if (!jobj1)
|
||||
@@ -256,11 +254,12 @@ 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 __attribute__((unused)),
|
||||
struct luks2_hdr *hdr, int digest, int assign)
|
||||
static int assign_all_segments(struct crypt_device *cd, struct luks2_hdr *hdr,
|
||||
int digest, int assign)
|
||||
{
|
||||
json_object *jobj1, *jobj_digest, *jobj_digest_segments;
|
||||
|
||||
@@ -305,9 +304,7 @@ static int assign_one_segment(struct crypt_device *cd, struct luks2_hdr *hdr,
|
||||
if (!jobj_digest_segments)
|
||||
return -EINVAL;
|
||||
|
||||
if (snprintf(num, sizeof(num), "%d", segment) < 0)
|
||||
return -EINVAL;
|
||||
|
||||
snprintf(num, sizeof(num), "%d", segment);
|
||||
if (assign) {
|
||||
jobj1 = LUKS2_array_jobj(jobj_digest_segments, num);
|
||||
if (!jobj1)
|
||||
@@ -352,6 +349,7 @@ 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;
|
||||
}
|
||||
|
||||
@@ -443,7 +441,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 __attribute__((unused)), struct volume_key *vk, int digest)
|
||||
struct luks2_hdr *hdr, struct volume_key *vk, int digest)
|
||||
{
|
||||
char *desc = get_key_description_by_digest(cd, digest);
|
||||
int r;
|
||||
|
||||
@@ -62,8 +62,8 @@ static void log_dbg_checksum(struct crypt_device *cd,
|
||||
int i;
|
||||
|
||||
for (i = 0; i < crypt_hash_size(csum_alg); i++)
|
||||
if (snprintf(&csum_txt[i*2], 3, "%02hhx", (const char)csum[i]) != 2)
|
||||
return;
|
||||
snprintf(&csum_txt[i*2], 3, "%02hhx", (const char)csum[i]);
|
||||
csum_txt[i*2+1] = '\0'; /* Just to be safe, sprintf should write \0 there. */
|
||||
|
||||
log_dbg(cd, "Checksum:%s (%s)", &csum_txt[0], info);
|
||||
}
|
||||
@@ -195,8 +195,6 @@ static int hdr_disk_sanity_check_pre(struct crypt_device *cd,
|
||||
size_t *hdr_json_size, int secondary,
|
||||
uint64_t offset)
|
||||
{
|
||||
uint64_t hdr_size;
|
||||
|
||||
if (memcmp(hdr->magic, secondary ? LUKS2_MAGIC_2ND : LUKS2_MAGIC_1ST, LUKS2_MAGIC_L))
|
||||
return -EINVAL;
|
||||
|
||||
@@ -206,31 +204,24 @@ static int hdr_disk_sanity_check_pre(struct crypt_device *cd,
|
||||
}
|
||||
|
||||
if (offset != be64_to_cpu(hdr->hdr_offset)) {
|
||||
log_dbg(cd, "LUKS2 offset 0x%04" PRIx64 " on device differs to expected offset 0x%04" PRIx64 ".",
|
||||
be64_to_cpu(hdr->hdr_offset), offset);
|
||||
log_dbg(cd, "LUKS2 offset 0x%04x on device differs to expected offset 0x%04x.",
|
||||
(unsigned)be64_to_cpu(hdr->hdr_offset), (unsigned)offset);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
hdr_size = be64_to_cpu(hdr->hdr_size);
|
||||
|
||||
if (hdr_size < LUKS2_HDR_16K_LEN || hdr_size > LUKS2_HDR_OFFSET_MAX) {
|
||||
log_dbg(cd, "LUKS2 header has bogus size 0x%04" PRIx64 ".", hdr_size);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (secondary && (offset != hdr_size)) {
|
||||
log_dbg(cd, "LUKS2 offset 0x%04" PRIx64 " in secondary header does not match size 0x%04" PRIx64 ".",
|
||||
offset, hdr_size);
|
||||
if (secondary && (offset != be64_to_cpu(hdr->hdr_size))) {
|
||||
log_dbg(cd, "LUKS2 offset 0x%04x in secondary header does not match size 0x%04x.",
|
||||
(unsigned)offset, (unsigned)be64_to_cpu(hdr->hdr_size));
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
/* FIXME: sanity check checksum alg. */
|
||||
|
||||
log_dbg(cd, "LUKS2 header version %u of size %" PRIu64 " bytes, checksum %s.",
|
||||
be16_to_cpu(hdr->version), hdr_size,
|
||||
log_dbg(cd, "LUKS2 header version %u of size %u bytes, checksum %s.",
|
||||
(unsigned)be16_to_cpu(hdr->version), (unsigned)be64_to_cpu(hdr->hdr_size),
|
||||
hdr->checksum_alg);
|
||||
|
||||
*hdr_json_size = hdr_size - LUKS2_HDR_BIN_LEN;
|
||||
*hdr_json_size = be64_to_cpu(hdr->hdr_size) - LUKS2_HDR_BIN_LEN;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -261,19 +252,18 @@ static int hdr_read_disk(struct crypt_device *cd,
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
/*
|
||||
* hdr_json_size is validated if this call succeeds
|
||||
*/
|
||||
r = hdr_disk_sanity_check_pre(cd, hdr_disk, &hdr_json_size, secondary, offset);
|
||||
if (r < 0)
|
||||
if (r < 0) {
|
||||
return r;
|
||||
}
|
||||
|
||||
/*
|
||||
* Allocate and read JSON area. Always the whole area must be read.
|
||||
*/
|
||||
*json_area = malloc(hdr_json_size);
|
||||
if (!*json_area)
|
||||
if (!*json_area) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
if (read_lseek_blockwise(devfd, device_block_size(cd, device),
|
||||
device_alignment(device), *json_area, hdr_json_size,
|
||||
@@ -289,8 +279,6 @@ static int hdr_read_disk(struct crypt_device *cd,
|
||||
if (hdr_checksum_check(cd, hdr_disk->checksum_alg, hdr_disk,
|
||||
*json_area, hdr_json_size)) {
|
||||
log_dbg(cd, "LUKS2 header checksum error (offset %" PRIu64 ").", offset);
|
||||
free(*json_area);
|
||||
*json_area = NULL;
|
||||
r = -EINVAL;
|
||||
}
|
||||
memset(hdr_disk->csum, 0, LUKS2_CHECKSUM_L);
|
||||
@@ -313,6 +301,8 @@ 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;
|
||||
@@ -395,7 +385,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_luks2_reencrypt(cd)) {
|
||||
if (r == 1 && !crypt_get_reenc_context(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);
|
||||
@@ -423,7 +413,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), 1);
|
||||
r = device_check_size(cd, crypt_metadata_device(cd), LUKS2_hdr_and_areas_size(hdr->jobj), 1);
|
||||
if (r)
|
||||
return r;
|
||||
|
||||
@@ -679,9 +669,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(jobj_hdr1);
|
||||
hdr_size = LUKS2_hdr_and_areas_size(jobj_hdr1);
|
||||
else if (state_hdr2 == HDR_OK)
|
||||
hdr_size = LUKS2_hdr_and_areas_size_jobj(jobj_hdr2);
|
||||
hdr_size = LUKS2_hdr_and_areas_size(jobj_hdr2);
|
||||
else {
|
||||
r = (state_hdr1 == HDR_FAIL_IO && state_hdr2 == HDR_FAIL_IO) ? -EIO : -EINVAL;
|
||||
goto err;
|
||||
@@ -798,11 +788,14 @@ int LUKS2_hdr_version_unlocked(struct crypt_device *cd, const char *backup_file)
|
||||
flags |= O_DIRECT;
|
||||
|
||||
devfd = open(device_path(device), flags);
|
||||
if (devfd != -1 && (read_lseek_blockwise(devfd, device_block_size(cd, device),
|
||||
if (devfd < 0)
|
||||
goto err;
|
||||
|
||||
if ((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);
|
||||
|
||||
|
||||
@@ -30,6 +30,8 @@
|
||||
#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
|
||||
@@ -42,8 +44,6 @@ 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
|
||||
@@ -92,8 +92,8 @@ void LUKS2_keyslots_repair(struct crypt_device *cd, json_object *jobj_hdr);
|
||||
/*
|
||||
* JSON array helpers
|
||||
*/
|
||||
json_object *LUKS2_array_jobj(json_object *array, const char *num);
|
||||
json_object *LUKS2_array_remove(json_object *array, const char *num);
|
||||
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);
|
||||
|
||||
/*
|
||||
* Plugins API
|
||||
@@ -162,53 +162,28 @@ typedef struct {
|
||||
digest_dump_func dump;
|
||||
} digest_handler;
|
||||
|
||||
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.
|
||||
/**
|
||||
* LUKS2 token handlers (internal use only)
|
||||
*/
|
||||
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;
|
||||
};
|
||||
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 *);
|
||||
|
||||
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,
|
||||
@@ -225,127 +200,4 @@ 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_allocate(struct crypt_device *cd,
|
||||
struct luks2_hdr *hdr,
|
||||
int keyslot,
|
||||
const struct crypt_params_reencrypt *params);
|
||||
|
||||
int LUKS2_keyslot_reencrypt_digest_create(struct crypt_device *cd,
|
||||
struct luks2_hdr *hdr,
|
||||
struct volume_key *vks);
|
||||
|
||||
int LUKS2_keyslot_dump(struct crypt_device *cd,
|
||||
int keyslot);
|
||||
|
||||
int LUKS2_keyslot_jobj_area(json_object *jobj_keyslot, uint64_t *offset, uint64_t *length);
|
||||
|
||||
/* 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);
|
||||
bool json_segment_cmp(json_object *jobj_segment_1, json_object *jobj_segment_2);
|
||||
bool json_segment_contains_flag(json_object *jobj_segment, const char *flag_str, size_t len);
|
||||
|
||||
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
|
||||
|
||||
@@ -30,7 +30,7 @@ struct area {
|
||||
|
||||
static size_t get_area_size(size_t keylength)
|
||||
{
|
||||
/* for now it is AF_split_sectors */
|
||||
//FIXME: calculate this properly, 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);
|
||||
return LUKS2_hdr_and_areas_size(hdr->jobj);
|
||||
}
|
||||
|
||||
int LUKS2_find_area_max_gap(struct crypt_device *cd, struct luks2_hdr *hdr,
|
||||
@@ -177,11 +177,8 @@ int LUKS2_find_area_gap(struct crypt_device *cd, struct luks2_hdr *hdr,
|
||||
|
||||
log_dbg(cd, "Found area %zu -> %zu", offset, length + offset);
|
||||
|
||||
if (area_offset)
|
||||
*area_offset = offset;
|
||||
if (area_length)
|
||||
*area_length = length;
|
||||
|
||||
*area_offset = offset;
|
||||
*area_length = length;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -219,7 +216,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 r, digest;
|
||||
int digest;
|
||||
uint64_t mdev_size;
|
||||
|
||||
if (!metadata_size)
|
||||
@@ -293,11 +290,9 @@ int LUKS2_generate_hdr(
|
||||
uuid_unparse(partitionUuid, hdr->uuid);
|
||||
|
||||
if (*cipherMode != '\0')
|
||||
r = snprintf(cipher, sizeof(cipher), "%s-%s", cipherName, cipherMode);
|
||||
snprintf(cipher, sizeof(cipher), "%s-%s", cipherName, cipherMode);
|
||||
else
|
||||
r = snprintf(cipher, sizeof(cipher), "%s", cipherName);
|
||||
if (r < 0 || (size_t)r >= sizeof(cipher))
|
||||
return -EINVAL;
|
||||
snprintf(cipher, sizeof(cipher), "%s", cipherName);
|
||||
|
||||
hdr->jobj = json_object_new_object();
|
||||
|
||||
@@ -374,7 +369,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);
|
||||
length = LUKS2_keyslots_size(hdr->jobj);
|
||||
|
||||
log_dbg(cd, "Wiping keyslots area (0x%06" PRIx64 " - 0x%06" PRIx64") with random data.",
|
||||
offset, length + offset);
|
||||
@@ -383,7 +378,8 @@ int LUKS2_wipe_header_areas(struct crypt_device *cd,
|
||||
offset, length, wipe_block, NULL, NULL);
|
||||
}
|
||||
|
||||
int LUKS2_set_keyslots_size(struct crypt_device *cd __attribute__((unused)),
|
||||
/* FIXME: what if user wanted to keep original keyslots size? */
|
||||
int LUKS2_set_keyslots_size(struct crypt_device *cd,
|
||||
struct luks2_hdr *hdr,
|
||||
uint64_t data_offset)
|
||||
{
|
||||
|
||||
@@ -403,8 +403,7 @@ static json_bool validate_intervals(struct crypt_device *cd,
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int LUKS2_keyslot_validate(struct crypt_device *cd, json_object *hdr_jobj __attribute__((unused)),
|
||||
json_object *hdr_keyslot, const char *key)
|
||||
static int LUKS2_keyslot_validate(struct crypt_device *cd, json_object *hdr_jobj, json_object *hdr_keyslot, const char *key)
|
||||
{
|
||||
json_object *jobj_key_size;
|
||||
|
||||
@@ -517,7 +516,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 __attribute__((unused)), uint64_t size)
|
||||
uint64_t offset, uint64_t size)
|
||||
{
|
||||
json_object *jobj_ivoffset, *jobj_sector_size, *jobj_integrity;
|
||||
uint32_t sector_size;
|
||||
@@ -592,78 +591,6 @@ static bool validate_segment_intervals(struct crypt_device *cd,
|
||||
return true;
|
||||
}
|
||||
|
||||
static int reqs_unknown(uint32_t reqs)
|
||||
{
|
||||
return reqs & CRYPT_REQUIREMENT_UNKNOWN;
|
||||
}
|
||||
|
||||
static int reqs_reencrypt(uint32_t reqs)
|
||||
{
|
||||
return reqs & CRYPT_REQUIREMENT_OFFLINE_REENCRYPT;
|
||||
}
|
||||
|
||||
static int reqs_reencrypt_online(uint32_t reqs)
|
||||
{
|
||||
return reqs & CRYPT_REQUIREMENT_ONLINE_REENCRYPT;
|
||||
}
|
||||
|
||||
/*
|
||||
* Config section requirements object must be valid.
|
||||
* Also general segments section must be validated first.
|
||||
*/
|
||||
static int validate_reencrypt_segments(struct crypt_device *cd, json_object *hdr_jobj, json_object *jobj_segments, int first_backup, int segments_count)
|
||||
{
|
||||
json_object *jobj, *jobj_backup_previous = NULL, *jobj_backup_final = NULL;
|
||||
uint32_t reqs;
|
||||
int i, r;
|
||||
struct luks2_hdr dummy = {
|
||||
.jobj = hdr_jobj
|
||||
};
|
||||
|
||||
r = LUKS2_config_get_requirements(cd, &dummy, &reqs);
|
||||
if (r)
|
||||
return 1;
|
||||
|
||||
if (reqs_reencrypt_online(reqs)) {
|
||||
for (i = first_backup; i < segments_count; i++) {
|
||||
jobj = json_segments_get_segment(jobj_segments, i);
|
||||
if (!jobj)
|
||||
return 1;
|
||||
if (json_segment_contains_flag(jobj, "backup-final", 0))
|
||||
jobj_backup_final = jobj;
|
||||
else if (json_segment_contains_flag(jobj, "backup-previous", 0))
|
||||
jobj_backup_previous = jobj;
|
||||
}
|
||||
|
||||
if (!jobj_backup_final || !jobj_backup_previous) {
|
||||
log_dbg(cd, "Backup segment is missing.");
|
||||
return 1;
|
||||
}
|
||||
|
||||
for (i = 0; i < first_backup; i++) {
|
||||
jobj = json_segments_get_segment(jobj_segments, i);
|
||||
if (!jobj)
|
||||
return 1;
|
||||
|
||||
if (json_segment_contains_flag(jobj, "in-reencryption", 0)) {
|
||||
if (!json_segment_cmp(jobj, jobj_backup_final)) {
|
||||
log_dbg(cd, "Segment in reencryption does not match backup final segment.");
|
||||
return 1;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!json_segment_cmp(jobj, jobj_backup_final) &&
|
||||
!json_segment_cmp(jobj, jobj_backup_previous)) {
|
||||
log_dbg(cd, "Segment does not match neither backup final or backup previous segment.");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
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;
|
||||
@@ -790,10 +717,10 @@ static int hdr_validate_segments(struct crypt_device *cd, json_object *hdr_jobj)
|
||||
}
|
||||
}
|
||||
|
||||
return validate_reencrypt_segments(cd, hdr_jobj, jobj_segments, first_backup, count);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static uint64_t LUKS2_metadata_size_jobj(json_object *jobj)
|
||||
uint64_t LUKS2_metadata_size(json_object *jobj)
|
||||
{
|
||||
json_object *jobj1, *jobj2;
|
||||
uint64_t json_size;
|
||||
@@ -805,11 +732,6 @@ static uint64_t LUKS2_metadata_size_jobj(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;
|
||||
@@ -825,7 +747,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_jobj(hdr_jobj);
|
||||
metadata_size = LUKS2_metadata_size(hdr_jobj);
|
||||
|
||||
length = json_object_object_length(jobj_keyslots);
|
||||
|
||||
@@ -871,7 +793,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_jobj(hdr_jobj)) ? 0 : 1;
|
||||
ret = validate_intervals(cd, length, intervals, metadata_size, LUKS2_hdr_and_areas_size(hdr_jobj)) ? 0 : 1;
|
||||
|
||||
free(intervals);
|
||||
|
||||
@@ -913,10 +835,9 @@ static int hdr_validate_digests(struct crypt_device *cd, json_object *hdr_jobj)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* requirements being validated in stand-alone routine */
|
||||
static int hdr_validate_config(struct crypt_device *cd, json_object *hdr_jobj)
|
||||
{
|
||||
json_object *jobj_config, *jobj;
|
||||
json_object *jobj_config, *jobj, *jobj1;
|
||||
int i;
|
||||
uint64_t keyslots_size, metadata_size, segment_offset;
|
||||
|
||||
@@ -971,19 +892,6 @@ static int hdr_validate_config(struct crypt_device *cd, json_object *hdr_jobj)
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int hdr_validate_requirements(struct crypt_device *cd, json_object *hdr_jobj)
|
||||
{
|
||||
int i;
|
||||
json_object *jobj_config, *jobj, *jobj1;
|
||||
|
||||
if (!json_object_object_get_ex(hdr_jobj, "config", &jobj_config)) {
|
||||
log_dbg(cd, "Missing config section.");
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Requirements object is optional */
|
||||
if (json_object_object_get_ex(jobj_config, "requirements", &jobj)) {
|
||||
if (!json_contains(cd, jobj_config, "section", "Config", "requirements", json_type_object))
|
||||
@@ -1009,7 +917,6 @@ int LUKS2_hdr_validate(struct crypt_device *cd, json_object *hdr_jobj, uint64_t
|
||||
struct {
|
||||
int (*validate)(struct crypt_device *, json_object *);
|
||||
} checks[] = {
|
||||
{ hdr_validate_requirements },
|
||||
{ hdr_validate_tokens },
|
||||
{ hdr_validate_digests },
|
||||
{ hdr_validate_segments },
|
||||
@@ -1134,7 +1041,7 @@ void LUKS2_hdr_free(struct crypt_device *cd, struct luks2_hdr *hdr)
|
||||
log_dbg(cd, "LUKS2 header still in use");
|
||||
}
|
||||
|
||||
static uint64_t LUKS2_keyslots_size_jobj(json_object *jobj)
|
||||
uint64_t LUKS2_keyslots_size(json_object *jobj)
|
||||
{
|
||||
json_object *jobj1, *jobj2;
|
||||
uint64_t keyslots_size;
|
||||
@@ -1146,19 +1053,9 @@ static uint64_t LUKS2_keyslots_size_jobj(json_object *jobj)
|
||||
return keyslots_size;
|
||||
}
|
||||
|
||||
uint64_t LUKS2_keyslots_size(struct luks2_hdr *hdr)
|
||||
uint64_t LUKS2_hdr_and_areas_size(json_object *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);
|
||||
return 2 * LUKS2_metadata_size(jobj) + LUKS2_keyslots_size(jobj);
|
||||
}
|
||||
|
||||
int LUKS2_hdr_backup(struct crypt_device *cd, struct luks2_hdr *hdr,
|
||||
@@ -1170,7 +1067,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);
|
||||
hdr_size = LUKS2_hdr_and_areas_size(hdr->jobj);
|
||||
buffer_size = size_round_up(hdr_size, crypt_getpagesize());
|
||||
|
||||
buffer = crypt_safe_alloc(buffer_size);
|
||||
@@ -1226,6 +1123,21 @@ int LUKS2_hdr_backup(struct crypt_device *cd, struct luks2_hdr *hdr,
|
||||
return r;
|
||||
}
|
||||
|
||||
static int reqs_unknown(uint32_t reqs)
|
||||
{
|
||||
return reqs & CRYPT_REQUIREMENT_UNKNOWN;
|
||||
}
|
||||
|
||||
static int reqs_reencrypt(uint32_t reqs)
|
||||
{
|
||||
return reqs & CRYPT_REQUIREMENT_OFFLINE_REENCRYPT;
|
||||
}
|
||||
|
||||
static int reqs_reencrypt_online(uint32_t reqs)
|
||||
{
|
||||
return reqs & CRYPT_REQUIREMENT_ONLINE_REENCRYPT;
|
||||
}
|
||||
|
||||
int LUKS2_hdr_restore(struct crypt_device *cd, struct luks2_hdr *hdr,
|
||||
const char *backup_file)
|
||||
{
|
||||
@@ -1266,7 +1178,7 @@ int LUKS2_hdr_restore(struct crypt_device *cd, struct luks2_hdr *hdr,
|
||||
goto out;
|
||||
}
|
||||
|
||||
buffer_size = LUKS2_hdr_and_areas_size(&hdr_file);
|
||||
buffer_size = LUKS2_hdr_and_areas_size(hdr_file.jobj);
|
||||
buffer = crypt_safe_alloc(buffer_size);
|
||||
if (!buffer) {
|
||||
r = -ENOMEM;
|
||||
@@ -1306,7 +1218,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)) {
|
||||
if (buffer_size != (ssize_t) LUKS2_hdr_and_areas_size(tmp_hdr.jobj)) {
|
||||
log_err(cd, _("Binary header with keyslot areas size differ on device and backup, restore failed."));
|
||||
r = -EINVAL;
|
||||
goto out;
|
||||
@@ -1461,106 +1373,24 @@ int LUKS2_config_set_flags(struct crypt_device *cd, struct luks2_hdr *hdr, uint3
|
||||
*/
|
||||
|
||||
/* LUKS2 library requirements */
|
||||
struct requirement_flag {
|
||||
static const struct {
|
||||
uint32_t flag;
|
||||
uint32_t version;
|
||||
const char *description;
|
||||
} requirements_flags[] = {
|
||||
{ CRYPT_REQUIREMENT_OFFLINE_REENCRYPT, "offline-reencrypt" },
|
||||
{ CRYPT_REQUIREMENT_ONLINE_REENCRYPT, "online-reencrypt" },
|
||||
{ 0, NULL }
|
||||
};
|
||||
|
||||
static const struct requirement_flag unknown_requirement_flag = { CRYPT_REQUIREMENT_UNKNOWN, 0, NULL };
|
||||
|
||||
static const struct requirement_flag requirements_flags[] = {
|
||||
{ CRYPT_REQUIREMENT_OFFLINE_REENCRYPT,1, "offline-reencrypt" },
|
||||
{ CRYPT_REQUIREMENT_ONLINE_REENCRYPT, 2, "online-reencrypt-v2" },
|
||||
{ CRYPT_REQUIREMENT_ONLINE_REENCRYPT, 1, "online-reencrypt" },
|
||||
{ 0, 0, NULL }
|
||||
};
|
||||
|
||||
static const struct requirement_flag *get_requirement_by_name(const char *requirement)
|
||||
static uint32_t get_requirement_by_name(const char *requirement)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; requirements_flags[i].description; i++)
|
||||
if (!strcmp(requirement, requirements_flags[i].description))
|
||||
return requirements_flags + i;
|
||||
return requirements_flags[i].flag;
|
||||
|
||||
return &unknown_requirement_flag;
|
||||
}
|
||||
|
||||
int LUKS2_config_get_reencrypt_version(struct luks2_hdr *hdr, uint32_t *version)
|
||||
{
|
||||
json_object *jobj_config, *jobj_requirements, *jobj_mandatory, *jobj;
|
||||
int i, len;
|
||||
const struct requirement_flag *req;
|
||||
|
||||
assert(hdr && version);
|
||||
if (!hdr || !version)
|
||||
return -EINVAL;
|
||||
|
||||
if (!json_object_object_get_ex(hdr->jobj, "config", &jobj_config))
|
||||
return -EINVAL;
|
||||
|
||||
if (!json_object_object_get_ex(jobj_config, "requirements", &jobj_requirements))
|
||||
return -ENOENT;
|
||||
|
||||
if (!json_object_object_get_ex(jobj_requirements, "mandatory", &jobj_mandatory))
|
||||
return -ENOENT;
|
||||
|
||||
len = (int) json_object_array_length(jobj_mandatory);
|
||||
if (len <= 0)
|
||||
return -ENOENT;
|
||||
|
||||
for (i = 0; i < len; i++) {
|
||||
jobj = json_object_array_get_idx(jobj_mandatory, i);
|
||||
|
||||
/* search for requirements prefixed with "online-reencrypt" */
|
||||
if (strncmp(json_object_get_string(jobj), "online-reencrypt", 16))
|
||||
continue;
|
||||
|
||||
/* check current library is aware of the requirement */
|
||||
req = get_requirement_by_name(json_object_get_string(jobj));
|
||||
if (req->flag == (uint32_t)CRYPT_REQUIREMENT_UNKNOWN)
|
||||
continue;
|
||||
|
||||
*version = req->version;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
static const struct requirement_flag *stored_requirement_name_by_id(struct crypt_device *cd, struct luks2_hdr *hdr, uint32_t req_id)
|
||||
{
|
||||
json_object *jobj_config, *jobj_requirements, *jobj_mandatory, *jobj;
|
||||
int i, len;
|
||||
const struct requirement_flag *req;
|
||||
|
||||
assert(hdr);
|
||||
if (!hdr)
|
||||
return NULL;
|
||||
|
||||
if (!json_object_object_get_ex(hdr->jobj, "config", &jobj_config))
|
||||
return NULL;
|
||||
|
||||
if (!json_object_object_get_ex(jobj_config, "requirements", &jobj_requirements))
|
||||
return NULL;
|
||||
|
||||
if (!json_object_object_get_ex(jobj_requirements, "mandatory", &jobj_mandatory))
|
||||
return NULL;
|
||||
|
||||
len = (int) json_object_array_length(jobj_mandatory);
|
||||
if (len <= 0)
|
||||
return 0;
|
||||
|
||||
for (i = 0; i < len; i++) {
|
||||
jobj = json_object_array_get_idx(jobj_mandatory, i);
|
||||
req = get_requirement_by_name(json_object_get_string(jobj));
|
||||
if (req->flag == req_id)
|
||||
return req;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
return CRYPT_REQUIREMENT_UNKNOWN;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1570,7 +1400,7 @@ int LUKS2_config_get_requirements(struct crypt_device *cd, struct luks2_hdr *hdr
|
||||
{
|
||||
json_object *jobj_config, *jobj_requirements, *jobj_mandatory, *jobj;
|
||||
int i, len;
|
||||
const struct requirement_flag *req;
|
||||
uint32_t req;
|
||||
|
||||
assert(hdr);
|
||||
if (!hdr || !reqs)
|
||||
@@ -1597,8 +1427,8 @@ int LUKS2_config_get_requirements(struct crypt_device *cd, struct luks2_hdr *hdr
|
||||
jobj = json_object_array_get_idx(jobj_mandatory, i);
|
||||
req = get_requirement_by_name(json_object_get_string(jobj));
|
||||
log_dbg(cd, "%s - %sknown", json_object_get_string(jobj),
|
||||
reqs_unknown(req->flag) ? "un" : "");
|
||||
*reqs |= req->flag;
|
||||
reqs_unknown(req) ? "un" : "");
|
||||
*reqs |= req;
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -1608,8 +1438,6 @@ int LUKS2_config_set_requirements(struct crypt_device *cd, struct luks2_hdr *hdr
|
||||
{
|
||||
json_object *jobj_config, *jobj_requirements, *jobj_mandatory, *jobj;
|
||||
int i, r = -EINVAL;
|
||||
const struct requirement_flag *req;
|
||||
uint32_t req_id;
|
||||
|
||||
if (!hdr)
|
||||
return -EINVAL;
|
||||
@@ -1619,14 +1447,8 @@ int LUKS2_config_set_requirements(struct crypt_device *cd, struct luks2_hdr *hdr
|
||||
return -ENOMEM;
|
||||
|
||||
for (i = 0; requirements_flags[i].description; i++) {
|
||||
req_id = reqs & requirements_flags[i].flag;
|
||||
if (req_id) {
|
||||
/* retain already stored version of requirement flag */
|
||||
req = stored_requirement_name_by_id(cd, hdr, req_id);
|
||||
if (req)
|
||||
jobj = json_object_new_string(req->description);
|
||||
else
|
||||
jobj = json_object_new_string(requirements_flags[i].description);
|
||||
if (reqs & requirements_flags[i].flag) {
|
||||
jobj = json_object_new_string(requirements_flags[i].description);
|
||||
if (!jobj) {
|
||||
r = -ENOMEM;
|
||||
goto err;
|
||||
@@ -1798,7 +1620,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));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1892,8 +1714,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));
|
||||
log_std(cd, "Keyslots area: \t%" PRIu64 " [bytes]\n", LUKS2_keyslots_size(hdr));
|
||||
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, "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)");
|
||||
@@ -1907,24 +1729,6 @@ 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;
|
||||
@@ -1970,7 +1774,7 @@ uint64_t LUKS2_get_data_offset(struct luks2_hdr *hdr)
|
||||
crypt_reencrypt_info ri;
|
||||
json_object *jobj;
|
||||
|
||||
ri = LUKS2_reencrypt_status(hdr);
|
||||
ri = LUKS2_reenc_status(hdr);
|
||||
if (ri == CRYPT_REENCRYPT_CLEAN || ri == CRYPT_REENCRYPT_CRASH) {
|
||||
jobj = LUKS2_get_segment_by_flag(hdr, "backup-final");
|
||||
if (jobj)
|
||||
@@ -1998,7 +1802,7 @@ const char *LUKS2_get_cipher(struct luks2_hdr *hdr, int segment)
|
||||
return json_segment_get_cipher(jobj_segment) ?: "null";
|
||||
}
|
||||
|
||||
crypt_reencrypt_info LUKS2_reencrypt_status(struct luks2_hdr *hdr)
|
||||
crypt_reencrypt_info LUKS2_reenc_status(struct luks2_hdr *hdr)
|
||||
{
|
||||
uint32_t reqs;
|
||||
|
||||
@@ -2441,7 +2245,7 @@ int LUKS2_deactivate(struct crypt_device *cd, const char *name, struct luks2_hdr
|
||||
goto out;
|
||||
|
||||
if (contains_reencryption_helper(deps)) {
|
||||
r = LUKS2_reencrypt_lock_by_dm_uuid(cd, dmd->uuid, &reencrypt_lock);
|
||||
r = crypt_reencrypt_lock_by_dm_uuid(cd, dmd->uuid, &reencrypt_lock);
|
||||
if (r) {
|
||||
if (r == -EBUSY)
|
||||
log_err(cd, _("Reencryption in-progress. Cannot deactivate device."));
|
||||
@@ -2520,7 +2324,7 @@ int LUKS2_deactivate(struct crypt_device *cd, const char *name, struct luks2_hdr
|
||||
}
|
||||
|
||||
out:
|
||||
LUKS2_reencrypt_unlock(cd, reencrypt_lock);
|
||||
crypt_reencrypt_unlock(cd, reencrypt_lock);
|
||||
dep = deps;
|
||||
while (*dep)
|
||||
free(*dep++);
|
||||
|
||||
@@ -27,14 +27,12 @@ extern const keyslot_handler reenc_keyslot;
|
||||
|
||||
static const keyslot_handler *keyslot_handlers[LUKS2_KEYSLOTS_MAX] = {
|
||||
&luks2_keyslot,
|
||||
#if USE_LUKS2_REENCRYPTION
|
||||
&reenc_keyslot,
|
||||
#endif
|
||||
NULL
|
||||
};
|
||||
|
||||
static const keyslot_handler
|
||||
*LUKS2_keyslot_handler_type(struct crypt_device *cd __attribute__((unused)), const char *type)
|
||||
*LUKS2_keyslot_handler_type(struct crypt_device *cd, const char *type)
|
||||
{
|
||||
int i;
|
||||
|
||||
@@ -67,22 +65,15 @@ static const keyslot_handler
|
||||
return LUKS2_keyslot_handler_type(cd, json_object_get_string(jobj2));
|
||||
}
|
||||
|
||||
int LUKS2_keyslot_find_empty(struct crypt_device *cd, struct luks2_hdr *hdr, size_t keylength)
|
||||
int LUKS2_keyslot_find_empty(struct luks2_hdr *hdr)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < LUKS2_KEYSLOTS_MAX; i++)
|
||||
if (!LUKS2_get_keyslot_jobj(hdr, i))
|
||||
break;
|
||||
return i;
|
||||
|
||||
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;
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
/* Check if a keyslot is assigned to specific segment */
|
||||
@@ -290,9 +281,19 @@ crypt_keyslot_info LUKS2_keyslot_info(struct luks2_hdr *hdr, int keyslot)
|
||||
return CRYPT_SLOT_ACTIVE;
|
||||
}
|
||||
|
||||
int LUKS2_keyslot_jobj_area(json_object *jobj_keyslot, uint64_t *offset, uint64_t *length)
|
||||
int LUKS2_keyslot_area(struct luks2_hdr *hdr,
|
||||
int keyslot,
|
||||
uint64_t *offset,
|
||||
uint64_t *length)
|
||||
{
|
||||
json_object *jobj_area, *jobj;
|
||||
json_object *jobj_keyslot, *jobj_area, *jobj;
|
||||
|
||||
if(LUKS2_keyslot_info(hdr, keyslot) == CRYPT_SLOT_INVALID)
|
||||
return -EINVAL;
|
||||
|
||||
jobj_keyslot = LUKS2_get_keyslot_jobj(hdr, keyslot);
|
||||
if (!jobj_keyslot)
|
||||
return -ENOENT;
|
||||
|
||||
if (!json_object_object_get_ex(jobj_keyslot, "area", &jobj_area))
|
||||
return -EINVAL;
|
||||
@@ -308,23 +309,6 @@ int LUKS2_keyslot_jobj_area(json_object *jobj_keyslot, uint64_t *offset, uint64_
|
||||
return 0;
|
||||
}
|
||||
|
||||
int LUKS2_keyslot_area(struct luks2_hdr *hdr,
|
||||
int keyslot,
|
||||
uint64_t *offset,
|
||||
uint64_t *length)
|
||||
{
|
||||
json_object *jobj_keyslot;
|
||||
|
||||
if (LUKS2_keyslot_info(hdr, keyslot) == CRYPT_SLOT_INVALID)
|
||||
return -EINVAL;
|
||||
|
||||
jobj_keyslot = LUKS2_get_keyslot_jobj(hdr, keyslot);
|
||||
if (!jobj_keyslot)
|
||||
return -ENOENT;
|
||||
|
||||
return LUKS2_keyslot_jobj_area(jobj_keyslot, offset, length);
|
||||
}
|
||||
|
||||
static int _open_and_verify(struct crypt_device *cd,
|
||||
struct luks2_hdr *hdr,
|
||||
const keyslot_handler *h,
|
||||
@@ -561,7 +545,7 @@ out:
|
||||
|
||||
if (r == -ENOMEM)
|
||||
log_err(cd, _("Not enough available memory to open a keyslot."));
|
||||
else if (r != -EPERM && r != -ENOENT)
|
||||
else if (r != -EPERM)
|
||||
log_err(cd, _("Keyslot open failed."));
|
||||
}
|
||||
return r;
|
||||
@@ -598,14 +582,14 @@ 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 && r != -ENOENT)
|
||||
else if (r != -EPERM)
|
||||
log_err(cd, _("Keyslot open failed."));
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
int LUKS2_keyslot_reencrypt_allocate(struct crypt_device *cd,
|
||||
int LUKS2_keyslot_reencrypt_create(struct crypt_device *cd,
|
||||
struct luks2_hdr *hdr,
|
||||
int keyslot,
|
||||
const struct crypt_params_reencrypt *params)
|
||||
@@ -616,6 +600,7 @@ int LUKS2_keyslot_reencrypt_allocate(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;
|
||||
@@ -634,6 +619,9 @@ int LUKS2_keyslot_reencrypt_allocate(struct crypt_device *cd,
|
||||
return r;
|
||||
}
|
||||
|
||||
if (LUKS2_hdr_validate(cd, hdr->jobj, hdr->hdr_size - LUKS2_HDR_BIN_LEN))
|
||||
return -EINVAL;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -781,7 +769,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 __attribute__((unused)),
|
||||
crypt_keyslot_priority LUKS2_keyslot_priority_get(struct crypt_device *cd,
|
||||
struct luks2_hdr *hdr, int keyslot)
|
||||
{
|
||||
json_object *jobj_keyslot, *jobj_priority;
|
||||
@@ -817,7 +805,7 @@ int placeholder_keyslot_alloc(struct crypt_device *cd,
|
||||
int keyslot,
|
||||
uint64_t area_offset,
|
||||
uint64_t area_length,
|
||||
size_t volume_key_len __attribute__((unused)))
|
||||
size_t volume_key_len)
|
||||
{
|
||||
struct luks2_hdr *hdr;
|
||||
json_object *jobj_keyslots, *jobj_keyslot, *jobj_area;
|
||||
@@ -884,17 +872,10 @@ int LUKS2_keyslots_validate(struct crypt_device *cd, json_object *hdr_jobj)
|
||||
const keyslot_handler *h;
|
||||
int keyslot;
|
||||
json_object *jobj_keyslots, *jobj_type;
|
||||
uint32_t reqs, reencrypt_count = 0;
|
||||
struct luks2_hdr dummy = {
|
||||
.jobj = hdr_jobj
|
||||
};
|
||||
|
||||
if (!json_object_object_get_ex(hdr_jobj, "keyslots", &jobj_keyslots))
|
||||
return -EINVAL;
|
||||
|
||||
if (LUKS2_config_get_requirements(cd, &dummy, &reqs))
|
||||
return -EINVAL;
|
||||
|
||||
json_object_object_foreach(jobj_keyslots, slot, val) {
|
||||
keyslot = atoi(slot);
|
||||
json_object_object_get_ex(val, "type", &jobj_type);
|
||||
@@ -910,24 +891,6 @@ int LUKS2_keyslots_validate(struct crypt_device *cd, json_object *hdr_jobj)
|
||||
log_dbg(cd, "Keyslot %d is not assigned to exactly 1 digest.", keyslot);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (!strcmp(h->name, "reencrypt"))
|
||||
reencrypt_count++;
|
||||
}
|
||||
|
||||
if ((reqs & CRYPT_REQUIREMENT_ONLINE_REENCRYPT) && reencrypt_count == 0) {
|
||||
log_dbg(cd, "Missing reencryption keyslot.");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (!(reqs & CRYPT_REQUIREMENT_ONLINE_REENCRYPT) && reencrypt_count) {
|
||||
log_dbg(cd, "Missing reencryption requirement flag.");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (reencrypt_count > 1) {
|
||||
log_dbg(cd, "Too many reencryption keyslots.");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -972,40 +935,3 @@ 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;
|
||||
}
|
||||
|
||||
@@ -248,7 +248,6 @@ static int luks2_keyslot_set_key(struct crypt_device *cd,
|
||||
/*
|
||||
* Calculate keyslot content, split and store it to keyslot area.
|
||||
*/
|
||||
log_dbg(cd, "Running keyslot key derivation.");
|
||||
r = crypt_pbkdf(pbkdf.type, pbkdf.hash, password, passwordLen,
|
||||
salt, LUKS_SALTSIZE,
|
||||
derived_key->key, derived_key->keylength,
|
||||
@@ -270,7 +269,7 @@ static int luks2_keyslot_set_key(struct crypt_device *cd,
|
||||
r = AF_split(cd, volume_key, AfKey, volume_key_len, LUKS_STRIPES, af_hash);
|
||||
|
||||
if (r == 0) {
|
||||
log_dbg(cd, "Updating keyslot area [0x%04" PRIx64 "].", area_offset);
|
||||
log_dbg(cd, "Updating keyslot area [0x%04x].", (unsigned)area_offset);
|
||||
/* FIXME: sector_offset should be size_t, fix LUKS_encrypt... accordingly */
|
||||
r = luks2_encrypt_to_storage(AfKey, AFEKSize, cipher, cipher_mode,
|
||||
derived_key, (unsigned)(area_offset / SECTOR_SIZE), cd);
|
||||
@@ -326,6 +325,13 @@ 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.
|
||||
*/
|
||||
@@ -336,22 +342,12 @@ 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) {
|
||||
r = -ENOMEM;
|
||||
goto out;
|
||||
crypt_free_volume_key(derived_key);
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
log_dbg(cd, "Running keyslot key derivation.");
|
||||
r = crypt_pbkdf(pbkdf.type, pbkdf.hash, password, passwordLen,
|
||||
salt, LUKS_SALTSIZE,
|
||||
derived_key->key, derived_key->keylength,
|
||||
@@ -362,7 +358,7 @@ static int luks2_keyslot_get_key(struct crypt_device *cd,
|
||||
crypt_serialize_unlock(cd);
|
||||
|
||||
if (r == 0) {
|
||||
log_dbg(cd, "Reading keyslot area [0x%04" PRIx64 "].", area_offset);
|
||||
log_dbg(cd, "Reading keyslot area [0x%04x].", (unsigned)area_offset);
|
||||
/* FIXME: sector_offset should be size_t, fix LUKS_decrypt... accordingly */
|
||||
r = luks2_decrypt_from_storage(AfKey, AFEKSize, cipher, cipher_mode,
|
||||
derived_key, (unsigned)(area_offset / SECTOR_SIZE), cd);
|
||||
@@ -371,7 +367,6 @@ 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);
|
||||
|
||||
@@ -467,7 +462,7 @@ static int luks2_keyslot_alloc(struct crypt_device *cd,
|
||||
return -EINVAL;
|
||||
|
||||
if (keyslot == CRYPT_ANY_SLOT)
|
||||
keyslot = LUKS2_keyslot_find_empty(cd, hdr, 0);
|
||||
keyslot = LUKS2_keyslot_find_empty(hdr);
|
||||
|
||||
if (keyslot < 0 || keyslot >= LUKS2_KEYSLOTS_MAX)
|
||||
return -ENOMEM;
|
||||
@@ -740,7 +735,7 @@ static int luks2_keyslot_update(struct crypt_device *cd,
|
||||
return r;
|
||||
}
|
||||
|
||||
static void luks2_keyslot_repair(struct crypt_device *cd __attribute__((unused)), json_object *jobj_keyslot)
|
||||
static void luks2_keyslot_repair(struct crypt_device *cd, json_object *jobj_keyslot)
|
||||
{
|
||||
const char *type;
|
||||
json_object *jobj_kdf, *jobj_type;
|
||||
|
||||
@@ -21,12 +21,12 @@
|
||||
|
||||
#include "luks2_internal.h"
|
||||
|
||||
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)))
|
||||
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)
|
||||
{
|
||||
return -ENOENT;
|
||||
}
|
||||
@@ -176,17 +176,43 @@ static int reenc_keyslot_store(struct crypt_device *cd,
|
||||
return r < 0 ? r : keyslot;
|
||||
}
|
||||
|
||||
static int reenc_keyslot_wipe(struct crypt_device *cd,
|
||||
int 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;
|
||||
|
||||
/* remove reencryption verification data */
|
||||
LUKS2_digest_assign(cd, hdr, keyslot, CRYPT_ANY_DIGEST, 0, 0);
|
||||
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)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -230,7 +256,7 @@ static int reenc_keyslot_dump(struct crypt_device *cd, int keyslot)
|
||||
|
||||
static int reenc_keyslot_validate(struct crypt_device *cd, json_object *jobj_keyslot)
|
||||
{
|
||||
json_object *jobj_mode, *jobj_area, *jobj_type, *jobj_shift_size, *jobj_hash, *jobj_sector_size, *jobj_direction, *jobj_key_size;
|
||||
json_object *jobj_mode, *jobj_area, *jobj_type, *jobj_shift_size, *jobj_hash, *jobj_sector_size, *jobj_direction;
|
||||
const char *mode, *type, *direction;
|
||||
uint32_t sector_size;
|
||||
uint64_t shift_size;
|
||||
@@ -250,18 +276,12 @@ static int reenc_keyslot_validate(struct crypt_device *cd, json_object *jobj_key
|
||||
!json_object_object_get_ex(jobj_area, "type", &jobj_type))
|
||||
return -EINVAL;
|
||||
|
||||
jobj_key_size = json_contains(cd, jobj_keyslot, "", "reencrypt keyslot", "key_size", json_type_int);
|
||||
jobj_mode = json_contains(cd, jobj_keyslot, "", "reencrypt keyslot", "mode", json_type_string);
|
||||
jobj_direction = json_contains(cd, jobj_keyslot, "", "reencrypt keyslot", "direction", json_type_string);
|
||||
|
||||
if (!jobj_mode || !jobj_direction || !jobj_key_size)
|
||||
if (!jobj_mode || !jobj_direction)
|
||||
return -EINVAL;
|
||||
|
||||
if (!validate_json_uint32(jobj_key_size) || crypt_jobj_get_uint32(jobj_key_size) != 1) {
|
||||
log_dbg(cd, "Illegal reencrypt key size.");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
mode = json_object_get_string(jobj_mode);
|
||||
type = json_object_get_string(jobj_type);
|
||||
direction = json_object_get_string(jobj_direction);
|
||||
|
||||
@@ -573,7 +573,7 @@ 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)) {
|
||||
if (max_size < LUKS2_hdr_and_areas_size(hdr2->jobj)) {
|
||||
r = -EINVAL;
|
||||
goto out;
|
||||
}
|
||||
@@ -595,7 +595,7 @@ int LUKS2_luks1_to_luks2(struct crypt_device *cd, struct luks_phdr *hdr1, struct
|
||||
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)) {
|
||||
if (buf_size > LUKS2_keyslots_size(hdr2->jobj)) {
|
||||
log_err(cd, _("Unable to move keyslot area. LUKS2 keyslots area too small."));
|
||||
r = -EINVAL;
|
||||
goto out;
|
||||
@@ -883,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);
|
||||
buf_size = LUKS2_keyslots_size(hdr2->jobj);
|
||||
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,381 +0,0 @@
|
||||
/*
|
||||
* LUKS - Linux Unified Key Setup v2, reencryption digest helpers
|
||||
*
|
||||
* Copyright (C) 2022, Red Hat, Inc. All rights reserved.
|
||||
* Copyright (C) 2022, Ondrej Kozina
|
||||
* Copyright (C) 2022, 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.
|
||||
*/
|
||||
|
||||
#include "luks2_internal.h"
|
||||
#include <assert.h>
|
||||
|
||||
#define MAX_STR 64
|
||||
|
||||
struct jtype {
|
||||
enum { JNONE = 0, JSTR, JU64, JX64, JU32 } type;
|
||||
json_object *jobj;
|
||||
const char *id;
|
||||
};
|
||||
|
||||
static size_t sr(struct jtype *j, uint8_t *ptr)
|
||||
{
|
||||
json_object *jobj;
|
||||
size_t len = 0;
|
||||
uint64_t u64;
|
||||
uint32_t u32;
|
||||
|
||||
if (!json_object_is_type(j->jobj, json_type_object))
|
||||
return 0;
|
||||
|
||||
if (!json_object_object_get_ex(j->jobj, j->id, &jobj))
|
||||
return 0;
|
||||
|
||||
switch(j->type) {
|
||||
case JSTR: /* JSON string */
|
||||
if (!json_object_is_type(jobj, json_type_string))
|
||||
return 0;
|
||||
len = strlen(json_object_get_string(jobj));
|
||||
if (len > MAX_STR)
|
||||
return 0;
|
||||
if (ptr)
|
||||
memcpy(ptr, json_object_get_string(jobj), len);
|
||||
break;
|
||||
case JU64: /* Unsigned 64bit integer stored as string */
|
||||
if (!json_object_is_type(jobj, json_type_string))
|
||||
break;
|
||||
len = sizeof(u64);
|
||||
if (ptr) {
|
||||
u64 = cpu_to_be64(crypt_jobj_get_uint64(jobj));
|
||||
memcpy(ptr, &u64, len);
|
||||
}
|
||||
break;
|
||||
case JX64: /* Unsigned 64bit segment size (allows "dynamic") */
|
||||
if (!json_object_is_type(jobj, json_type_string))
|
||||
break;
|
||||
if (!strcmp(json_object_get_string(jobj), "dynamic")) {
|
||||
len = strlen("dynamic");
|
||||
if (ptr)
|
||||
memcpy(ptr, json_object_get_string(jobj), len);
|
||||
} else {
|
||||
len = sizeof(u64);
|
||||
u64 = cpu_to_be64(crypt_jobj_get_uint64(jobj));
|
||||
if (ptr)
|
||||
memcpy(ptr, &u64, len);
|
||||
}
|
||||
break;
|
||||
case JU32: /* Unsigned 32bit integer, stored as JSON int */
|
||||
if (!json_object_is_type(jobj, json_type_int))
|
||||
return 0;
|
||||
len = sizeof(u32);
|
||||
if (ptr) {
|
||||
u32 = cpu_to_be32(crypt_jobj_get_uint32(jobj));
|
||||
memcpy(ptr, &u32, len);
|
||||
}
|
||||
break;
|
||||
case JNONE:
|
||||
return 0;
|
||||
};
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
static size_t srs(struct jtype j[], uint8_t *ptr)
|
||||
{
|
||||
size_t l, len = 0;
|
||||
|
||||
while(j->jobj) {
|
||||
l = sr(j, ptr);
|
||||
if (!l)
|
||||
return 0;
|
||||
len += l;
|
||||
if (ptr)
|
||||
ptr += l;
|
||||
j++;
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
static size_t segment_linear_serialize(json_object *jobj_segment, uint8_t *buffer)
|
||||
{
|
||||
struct jtype j[] = {
|
||||
{ JSTR, jobj_segment, "type" },
|
||||
{ JU64, jobj_segment, "offset" },
|
||||
{ JX64, jobj_segment, "size" },
|
||||
{}
|
||||
};
|
||||
return srs(j, buffer);
|
||||
}
|
||||
|
||||
static size_t segment_crypt_serialize(json_object *jobj_segment, uint8_t *buffer)
|
||||
{
|
||||
struct jtype j[] = {
|
||||
{ JSTR, jobj_segment, "type" },
|
||||
{ JU64, jobj_segment, "offset" },
|
||||
{ JX64, jobj_segment, "size" },
|
||||
{ JU64, jobj_segment, "iv_tweak" },
|
||||
{ JSTR, jobj_segment, "encryption" },
|
||||
{ JU32, jobj_segment, "sector_size" },
|
||||
{}
|
||||
};
|
||||
return srs(j, buffer);
|
||||
}
|
||||
|
||||
static size_t segment_serialize(json_object *jobj_segment, uint8_t *buffer)
|
||||
{
|
||||
json_object *jobj_type;
|
||||
const char *segment_type;
|
||||
|
||||
if (!json_object_object_get_ex(jobj_segment, "type", &jobj_type))
|
||||
return 0;
|
||||
|
||||
if (!(segment_type = json_object_get_string(jobj_type)))
|
||||
return 0;
|
||||
|
||||
if (!strcmp(segment_type, "crypt"))
|
||||
return segment_crypt_serialize(jobj_segment, buffer);
|
||||
else if (!strcmp(segment_type, "linear"))
|
||||
return segment_linear_serialize(jobj_segment, buffer);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static size_t backup_segments_serialize(struct luks2_hdr *hdr, uint8_t *buffer)
|
||||
{
|
||||
json_object *jobj_segment;
|
||||
size_t l, len = 0;
|
||||
|
||||
jobj_segment = LUKS2_get_segment_by_flag(hdr, "backup-previous");
|
||||
if (!jobj_segment || !(l = segment_serialize(jobj_segment, buffer)))
|
||||
return 0;
|
||||
len += l;
|
||||
if (buffer)
|
||||
buffer += l;
|
||||
|
||||
jobj_segment = LUKS2_get_segment_by_flag(hdr, "backup-final");
|
||||
if (!jobj_segment || !(l = segment_serialize(jobj_segment, buffer)))
|
||||
return 0;
|
||||
len += l;
|
||||
if (buffer)
|
||||
buffer += l;
|
||||
|
||||
jobj_segment = LUKS2_get_segment_by_flag(hdr, "backup-moved-segment");
|
||||
if (jobj_segment) {
|
||||
if (!(l = segment_serialize(jobj_segment, buffer)))
|
||||
return 0;
|
||||
len += l;
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
static size_t reenc_keyslot_serialize(struct luks2_hdr *hdr, uint8_t *buffer)
|
||||
{
|
||||
json_object *jobj_keyslot, *jobj_area, *jobj_type;
|
||||
const char *area_type;
|
||||
int keyslot_reencrypt;
|
||||
|
||||
keyslot_reencrypt = LUKS2_find_keyslot(hdr, "reencrypt");
|
||||
if (keyslot_reencrypt < 0)
|
||||
return 0;
|
||||
|
||||
if (!(jobj_keyslot = LUKS2_get_keyslot_jobj(hdr, keyslot_reencrypt)))
|
||||
return 0;
|
||||
|
||||
if (!json_object_object_get_ex(jobj_keyslot, "area", &jobj_area))
|
||||
return 0;
|
||||
|
||||
if (!json_object_object_get_ex(jobj_area, "type", &jobj_type))
|
||||
return 0;
|
||||
|
||||
if (!(area_type = json_object_get_string(jobj_type)))
|
||||
return 0;
|
||||
|
||||
struct jtype j[] = {
|
||||
{ JSTR, jobj_keyslot, "mode" },
|
||||
{ JSTR, jobj_keyslot, "direction" },
|
||||
{ JSTR, jobj_area, "type" },
|
||||
{ JU64, jobj_area, "offset" },
|
||||
{ JU64, jobj_area, "size" },
|
||||
{}
|
||||
};
|
||||
struct jtype j_datashift[] = {
|
||||
{ JSTR, jobj_keyslot, "mode" },
|
||||
{ JSTR, jobj_keyslot, "direction" },
|
||||
{ JSTR, jobj_area, "type" },
|
||||
{ JU64, jobj_area, "offset" },
|
||||
{ JU64, jobj_area, "size" },
|
||||
{ JU64, jobj_area, "shift_size" },
|
||||
{}
|
||||
};
|
||||
struct jtype j_checksum[] = {
|
||||
{ JSTR, jobj_keyslot, "mode" },
|
||||
{ JSTR, jobj_keyslot, "direction" },
|
||||
{ JSTR, jobj_area, "type" },
|
||||
{ JU64, jobj_area, "offset" },
|
||||
{ JU64, jobj_area, "size" },
|
||||
{ JSTR, jobj_area, "hash" },
|
||||
{ JU32, jobj_area, "sector_size" },
|
||||
{}
|
||||
};
|
||||
|
||||
if (!strcmp(area_type, "datashift"))
|
||||
return srs(j_datashift, buffer);
|
||||
else if (!strcmp(area_type, "checksum"))
|
||||
return srs(j_checksum, buffer);
|
||||
|
||||
return srs(j, buffer);
|
||||
}
|
||||
|
||||
static size_t blob_serialize(void *blob, size_t length, uint8_t *buffer)
|
||||
{
|
||||
if (buffer)
|
||||
memcpy(buffer, blob, length);
|
||||
|
||||
return length;
|
||||
}
|
||||
|
||||
static int reencrypt_assembly_verification_data(struct crypt_device *cd,
|
||||
struct luks2_hdr *hdr,
|
||||
struct volume_key *vks,
|
||||
struct volume_key **verification_data)
|
||||
{
|
||||
uint8_t *ptr;
|
||||
int digest_new, digest_old;
|
||||
struct volume_key *data = NULL, *vk_old = NULL, *vk_new = NULL;
|
||||
size_t keyslot_data_len, segments_data_len, data_len = 2;
|
||||
|
||||
/* Keys - calculate length */
|
||||
digest_new = LUKS2_reencrypt_digest_new(hdr);
|
||||
digest_old = LUKS2_reencrypt_digest_old(hdr);
|
||||
|
||||
if (digest_old >= 0) {
|
||||
vk_old = crypt_volume_key_by_id(vks, digest_old);
|
||||
if (!vk_old)
|
||||
return -EINVAL;
|
||||
data_len += blob_serialize(vk_old->key, vk_old->keylength, NULL);
|
||||
}
|
||||
|
||||
if (digest_new >= 0 && digest_old != digest_new) {
|
||||
vk_new = crypt_volume_key_by_id(vks, digest_new);
|
||||
if (!vk_new)
|
||||
return -EINVAL;
|
||||
data_len += blob_serialize(vk_new->key, vk_new->keylength, NULL);
|
||||
}
|
||||
|
||||
if (data_len == 2)
|
||||
return -EINVAL;
|
||||
|
||||
/* Metadata - calculate length */
|
||||
if (!(keyslot_data_len = reenc_keyslot_serialize(hdr, NULL)))
|
||||
return -EINVAL;
|
||||
data_len += keyslot_data_len;
|
||||
|
||||
if (!(segments_data_len = backup_segments_serialize(hdr, NULL)))
|
||||
return -EINVAL;
|
||||
data_len += segments_data_len;
|
||||
|
||||
/* Alloc and fill serialization data */
|
||||
data = crypt_alloc_volume_key(data_len, NULL);
|
||||
if (!data)
|
||||
return -ENOMEM;
|
||||
|
||||
ptr = (uint8_t*)data->key;
|
||||
|
||||
/* v2 */
|
||||
*ptr++ = 0x76;
|
||||
*ptr++ = 0x32;
|
||||
|
||||
if (vk_old)
|
||||
ptr += blob_serialize(vk_old->key, vk_old->keylength, ptr);
|
||||
|
||||
if (vk_new)
|
||||
ptr += blob_serialize(vk_new->key, vk_new->keylength, ptr);
|
||||
|
||||
if (!reenc_keyslot_serialize(hdr, ptr))
|
||||
goto bad;
|
||||
ptr += keyslot_data_len;
|
||||
|
||||
if (!backup_segments_serialize(hdr, ptr))
|
||||
goto bad;
|
||||
ptr += segments_data_len;
|
||||
|
||||
assert((size_t)(ptr - (uint8_t*)data->key) == data_len);
|
||||
|
||||
*verification_data = data;
|
||||
|
||||
return 0;
|
||||
bad:
|
||||
crypt_free_volume_key(data);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
int LUKS2_keyslot_reencrypt_digest_create(struct crypt_device *cd,
|
||||
struct luks2_hdr *hdr,
|
||||
struct volume_key *vks)
|
||||
{
|
||||
int digest_reencrypt, keyslot_reencrypt, r;
|
||||
struct volume_key *data;
|
||||
|
||||
keyslot_reencrypt = LUKS2_find_keyslot(hdr, "reencrypt");
|
||||
if (keyslot_reencrypt < 0)
|
||||
return keyslot_reencrypt;
|
||||
|
||||
r = reencrypt_assembly_verification_data(cd, hdr, vks, &data);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = LUKS2_digest_create(cd, "pbkdf2", hdr, data);
|
||||
crypt_free_volume_key(data);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
digest_reencrypt = r;
|
||||
|
||||
r = LUKS2_digest_assign(cd, hdr, keyslot_reencrypt, CRYPT_ANY_DIGEST, 0, 0);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
return LUKS2_digest_assign(cd, hdr, keyslot_reencrypt, digest_reencrypt, 1, 0);
|
||||
}
|
||||
|
||||
int LUKS2_reencrypt_digest_verify(struct crypt_device *cd,
|
||||
struct luks2_hdr *hdr,
|
||||
struct volume_key *vks)
|
||||
{
|
||||
int r, keyslot_reencrypt;
|
||||
struct volume_key *data;
|
||||
|
||||
keyslot_reencrypt = LUKS2_find_keyslot(hdr, "reencrypt");
|
||||
if (keyslot_reencrypt < 0)
|
||||
return keyslot_reencrypt;
|
||||
|
||||
r = reencrypt_assembly_verification_data(cd, hdr, vks, &data);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = LUKS2_digest_verify(cd, hdr, data, keyslot_reencrypt);
|
||||
crypt_free_volume_key(data);
|
||||
|
||||
if (r < 0) {
|
||||
if (r == -ENOENT)
|
||||
log_dbg(cd, "Reencryption digest is missing.");
|
||||
log_err(cd, _("Reencryption metadata is invalid."));
|
||||
} else
|
||||
log_dbg(cd, "Reencryption metadata verified.");
|
||||
|
||||
return r;
|
||||
}
|
||||
@@ -123,7 +123,7 @@ static json_object *json_segment_get_flags(json_object *jobj_segment)
|
||||
return jobj;
|
||||
}
|
||||
|
||||
bool json_segment_contains_flag(json_object *jobj_segment, const char *flag_str, size_t len)
|
||||
static bool json_segment_contains_flag(json_object *jobj_segment, const char *flag_str, size_t len)
|
||||
{
|
||||
int r, i;
|
||||
json_object *jobj, *jobj_flags = json_segment_get_flags(jobj_segment);
|
||||
@@ -410,23 +410,3 @@ json_object *LUKS2_get_segment_by_flag(struct luks2_hdr *hdr, const char *flag)
|
||||
|
||||
return jobj_segment;
|
||||
}
|
||||
|
||||
/* compares key characteristics of both segments */
|
||||
bool json_segment_cmp(json_object *jobj_segment_1, json_object *jobj_segment_2)
|
||||
{
|
||||
const char *type = json_segment_type(jobj_segment_1);
|
||||
const char *type2 = json_segment_type(jobj_segment_2);
|
||||
|
||||
if (!type || !type2)
|
||||
return false;
|
||||
|
||||
if (strcmp(type, type2))
|
||||
return false;
|
||||
|
||||
if (!strcmp(type, "crypt"))
|
||||
return (json_segment_get_sector_size(jobj_segment_1) == json_segment_get_sector_size(jobj_segment_2) &&
|
||||
!strcmp(json_segment_get_cipher(jobj_segment_1),
|
||||
json_segment_get_cipher(jobj_segment_2)));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -19,201 +19,39 @@
|
||||
* 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"
|
||||
|
||||
#if USE_EXTERNAL_TOKENS
|
||||
static bool external_tokens_enabled = true;
|
||||
#else
|
||||
static bool external_tokens_enabled = false;
|
||||
#endif
|
||||
/* Builtin tokens */
|
||||
extern const crypt_token_handler keyring_handler;
|
||||
|
||||
static struct crypt_token_handler_internal token_handlers[LUKS2_TOKENS_MAX] = {
|
||||
static token_handler token_handlers[LUKS2_TOKENS_MAX] = {
|
||||
/* keyring builtin token */
|
||||
{
|
||||
.version = 1,
|
||||
.u = {
|
||||
.v1 = { .name = LUKS2_TOKEN_KEYRING,
|
||||
.open = keyring_open,
|
||||
.validate = keyring_validate,
|
||||
.dump = keyring_dump }
|
||||
}
|
||||
}
|
||||
.get = token_keyring_get,
|
||||
.set = token_keyring_set,
|
||||
.h = &keyring_handler
|
||||
},
|
||||
};
|
||||
|
||||
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;
|
||||
|
||||
#ifdef HAVE_DLVSYM
|
||||
log_dbg(cd, "Loading symbol %s@%s.", symbol, version);
|
||||
sym = dlvsym(handle, symbol, version);
|
||||
#else
|
||||
log_dbg(cd, "Loading default version of symbol %s.", symbol);
|
||||
sym = dlsym(handle, symbol);
|
||||
#endif
|
||||
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);
|
||||
}
|
||||
|
||||
static int crypt_token_find_free(struct crypt_device *cd, const char *name, int *index)
|
||||
int crypt_token_register(const crypt_token_handler *handler)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (is_builtin_candidate(name)) {
|
||||
log_dbg(cd, "'" LUKS2_BUILTIN_TOKEN_PREFIX "' is reserved prefix for builtin tokens.");
|
||||
if (is_builtin_candidate(handler->name)) {
|
||||
log_dbg(NULL, "'" LUKS2_BUILTIN_TOKEN_PREFIX "' is reserved prefix for builtin tokens.");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
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);
|
||||
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);
|
||||
return -EINVAL;
|
||||
}
|
||||
}
|
||||
@@ -221,70 +59,32 @@ static int crypt_token_find_free(struct crypt_device *cd, const char *name, int
|
||||
if (i == LUKS2_TOKENS_MAX)
|
||||
return -EINVAL;
|
||||
|
||||
if (index)
|
||||
*index = i;
|
||||
|
||||
token_handlers[i].h = handler;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int crypt_token_register(const crypt_token_handler *handler)
|
||||
static const token_handler
|
||||
*LUKS2_token_handler_type_internal(struct crypt_device *cd, const char *type)
|
||||
{
|
||||
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)
|
||||
{
|
||||
#if USE_EXTERNAL_TOKENS
|
||||
int i;
|
||||
|
||||
for (i = LUKS2_TOKENS_MAX - 1; i >= 0; i--) {
|
||||
if (token_handlers[i].version < 2)
|
||||
continue;
|
||||
for (i = 0; i < LUKS2_TOKENS_MAX && token_handlers[i].h; i++)
|
||||
if (!strcmp(token_handlers[i].h->name, type))
|
||||
return token_handlers + i;
|
||||
|
||||
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());
|
||||
}
|
||||
#endif
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static const void
|
||||
static const crypt_token_handler
|
||||
*LUKS2_token_handler_type(struct crypt_device *cd, const char *type)
|
||||
{
|
||||
int i;
|
||||
const token_handler *th = LUKS2_token_handler_type_internal(cd, type);
|
||||
|
||||
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;
|
||||
return th ? th->h : NULL;
|
||||
}
|
||||
|
||||
static const void
|
||||
*LUKS2_token_handler(struct crypt_device *cd, int token)
|
||||
static const token_handler
|
||||
*LUKS2_token_handler_internal(struct crypt_device *cd, int token)
|
||||
{
|
||||
struct luks2_hdr *hdr;
|
||||
json_object *jobj1, *jobj2;
|
||||
@@ -301,7 +101,15 @@ static const void
|
||||
if (!json_object_object_get_ex(jobj1, "type", &jobj2))
|
||||
return NULL;
|
||||
|
||||
return LUKS2_token_handler_type(cd, json_object_get_string(jobj2));
|
||||
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;
|
||||
}
|
||||
|
||||
static int LUKS2_token_find_free(struct luks2_hdr *hdr)
|
||||
@@ -322,6 +130,7 @@ 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];
|
||||
@@ -338,8 +147,7 @@ int LUKS2_token_create(struct crypt_device *cd,
|
||||
if (!json_object_object_get_ex(hdr->jobj, "tokens", &jobj_tokens))
|
||||
return -EINVAL;
|
||||
|
||||
if (snprintf(num, sizeof(num), "%d", token) < 0)
|
||||
return -EINVAL;
|
||||
snprintf(num, sizeof(num), "%d", token);
|
||||
|
||||
/* Remove token */
|
||||
if (!json)
|
||||
@@ -358,14 +166,16 @@ int LUKS2_token_create(struct crypt_device *cd,
|
||||
}
|
||||
|
||||
json_object_object_get_ex(jobj, "type", &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 (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));
|
||||
|
||||
if (h && h->validate && h->validate(cd, json)) {
|
||||
json_object_put(jobj);
|
||||
@@ -393,7 +203,7 @@ crypt_token_info LUKS2_token_status(struct crypt_device *cd,
|
||||
const char **type)
|
||||
{
|
||||
const char *tmp;
|
||||
const crypt_token_handler *th;
|
||||
const token_handler *th;
|
||||
json_object *jobj_type, *jobj_token;
|
||||
|
||||
if (token < 0 || token >= LUKS2_TOKENS_MAX)
|
||||
@@ -405,10 +215,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(cd, tmp))) {
|
||||
if ((th = LUKS2_token_handler_type_internal(cd, tmp))) {
|
||||
if (type)
|
||||
*type = th->name;
|
||||
return is_builtin_candidate(tmp) ? CRYPT_TOKEN_INTERNAL : CRYPT_TOKEN_EXTERNAL;
|
||||
*type = th->h->name;
|
||||
return th->set ? CRYPT_TOKEN_INTERNAL : CRYPT_TOKEN_EXTERNAL;
|
||||
}
|
||||
|
||||
if (type)
|
||||
@@ -417,109 +227,95 @@ crypt_token_info LUKS2_token_status(struct crypt_device *cd,
|
||||
return is_builtin_candidate(tmp) ? CRYPT_TOKEN_INTERNAL_UNKNOWN : CRYPT_TOKEN_EXTERNAL_UNKNOWN;
|
||||
}
|
||||
|
||||
static const char *token_json_to_string(json_object *jobj_token)
|
||||
int LUKS2_builtin_token_get(struct crypt_device *cd,
|
||||
struct luks2_hdr *hdr,
|
||||
int token,
|
||||
const char *type,
|
||||
void *params)
|
||||
{
|
||||
return json_object_to_json_string_ext(jobj_token,
|
||||
JSON_C_TO_STRING_PLAIN | JSON_C_TO_STRING_NOSLASHESCAPE);
|
||||
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;
|
||||
}
|
||||
|
||||
static int token_is_usable(struct luks2_hdr *hdr, json_object *jobj_token, int segment, crypt_keyslot_priority minimal_priority)
|
||||
int LUKS2_builtin_token_create(struct crypt_device *cd,
|
||||
struct luks2_hdr *hdr,
|
||||
int token,
|
||||
const char *type,
|
||||
const void *params,
|
||||
int commit)
|
||||
{
|
||||
crypt_keyslot_priority keyslot_priority;
|
||||
json_object *jobj_array;
|
||||
int i, keyslot, len, r = -ENOENT;
|
||||
const token_handler *th;
|
||||
int r;
|
||||
json_object *jobj_token, *jobj_tokens;
|
||||
|
||||
if (!jobj_token)
|
||||
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)
|
||||
return -EINVAL;
|
||||
|
||||
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;
|
||||
r = th->set(&jobj_token, params);
|
||||
if (r) {
|
||||
log_err(cd, _("Failed to create builtin token %s."), type);
|
||||
return r;
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
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;
|
||||
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;
|
||||
}
|
||||
|
||||
return ret_val;
|
||||
if (commit)
|
||||
return LUKS2_hdr_write(cd, hdr) ?: token;
|
||||
|
||||
return token;
|
||||
}
|
||||
|
||||
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 struct crypt_token_handler_v2 *h;
|
||||
json_object *jobj_type;
|
||||
const char *json;
|
||||
const crypt_token_handler *h;
|
||||
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 && h->validate(cd, token_json_to_string(jobj_token))) {
|
||||
log_dbg(cd, "Token %d (%s) validation failed.", token, h->name);
|
||||
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 (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);
|
||||
r = h->open(cd, token, buffer, buffer_len, usrptr);
|
||||
if (r < 0)
|
||||
log_dbg(cd, "Token %d (%s) open failed with %d.", token, h->name, r);
|
||||
|
||||
@@ -541,206 +337,71 @@ 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)
|
||||
{
|
||||
crypt_keyslot_priority keyslot_priority;
|
||||
json_object *jobj_token, *jobj_token_keyslots, *jobj_type, *jobj;
|
||||
const crypt_token_handler *h;
|
||||
json_object *jobj_token, *jobj_token_keyslots, *jobj;
|
||||
unsigned int num = 0;
|
||||
int i, r = -ENOENT, stored_retval = -ENOENT;
|
||||
int i, r;
|
||||
|
||||
if (!(h = LUKS2_token_handler(cd, token)))
|
||||
return -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));
|
||||
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));
|
||||
log_dbg(cd, "Trying to open keyslot %u with token %d (type %s).", num, token, h->name);
|
||||
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 stored_retval;
|
||||
return r;
|
||||
|
||||
return num;
|
||||
}
|
||||
|
||||
static bool token_is_blocked(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));
|
||||
|
||||
return (*block_list & (1 << token));
|
||||
}
|
||||
|
||||
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,
|
||||
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;
|
||||
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)
|
||||
struct luks2_hdr *hdr,
|
||||
int token,
|
||||
const char *name,
|
||||
uint32_t flags,
|
||||
void *usrptr)
|
||||
{
|
||||
bool use_keyring;
|
||||
int keyslot, r;
|
||||
char *buffer;
|
||||
size_t buffer_size;
|
||||
json_object *jobj_token;
|
||||
int keyslot, segment, r = -ENOENT;
|
||||
size_t buffer_len;
|
||||
struct volume_key *vk = NULL;
|
||||
|
||||
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;
|
||||
|
||||
r = LUKS2_token_open(cd, hdr, token, &buffer, &buffer_len, usrptr);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
assert(vk);
|
||||
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;
|
||||
|
||||
@@ -765,6 +426,53 @@ int LUKS2_token_open_and_activate(struct crypt_device *cd,
|
||||
return r < 0 ? r : keyslot;
|
||||
}
|
||||
|
||||
int LUKS2_token_open_and_activate_any(struct crypt_device *cd,
|
||||
struct luks2_hdr *hdr,
|
||||
const char *name,
|
||||
uint32_t flags)
|
||||
{
|
||||
char *buffer;
|
||||
json_object *tokens_jobj;
|
||||
size_t buffer_len;
|
||||
int keyslot, token, r = -EINVAL;
|
||||
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;
|
||||
}
|
||||
|
||||
keyslot = r;
|
||||
|
||||
if (r >= 0 && (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;
|
||||
}
|
||||
|
||||
void LUKS2_token_dump(struct crypt_device *cd, int token)
|
||||
{
|
||||
const crypt_token_handler *h;
|
||||
@@ -779,7 +487,7 @@ void LUKS2_token_dump(struct crypt_device *cd, int token)
|
||||
}
|
||||
}
|
||||
|
||||
int LUKS2_token_json_get(struct crypt_device *cd __attribute__((unused)), struct luks2_hdr *hdr,
|
||||
int LUKS2_token_json_get(struct crypt_device *cd, struct luks2_hdr *hdr,
|
||||
int token, const char **json)
|
||||
{
|
||||
json_object *jobj_token;
|
||||
@@ -788,7 +496,8 @@ int LUKS2_token_json_get(struct crypt_device *cd __attribute__((unused)), struct
|
||||
if (!jobj_token)
|
||||
return -EINVAL;
|
||||
|
||||
*json = token_json_to_string(jobj_token);
|
||||
*json = json_object_to_json_string_ext(jobj_token,
|
||||
JSON_C_TO_STRING_PLAIN | JSON_C_TO_STRING_NOSLASHESCAPE);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -808,9 +517,7 @@ static int assign_one_keyslot(struct crypt_device *cd, struct luks2_hdr *hdr,
|
||||
if (!jobj_token_keyslots)
|
||||
return -EINVAL;
|
||||
|
||||
if (snprintf(num, sizeof(num), "%d", keyslot) < 0)
|
||||
return -EINVAL;
|
||||
|
||||
snprintf(num, sizeof(num), "%d", keyslot);
|
||||
if (assign) {
|
||||
jobj1 = LUKS2_array_jobj(jobj_token_keyslots, num);
|
||||
if (!jobj1)
|
||||
@@ -869,6 +576,7 @@ 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;
|
||||
|
||||
@@ -895,7 +603,7 @@ static int token_is_assigned(struct luks2_hdr *hdr, int keyslot, int token)
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
int LUKS2_token_is_assigned(struct crypt_device *cd __attribute__((unused)), struct luks2_hdr *hdr,
|
||||
int LUKS2_token_is_assigned(struct crypt_device *cd, struct luks2_hdr *hdr,
|
||||
int keyslot, int token)
|
||||
{
|
||||
if (keyslot < 0 || keyslot >= LUKS2_KEYSLOTS_MAX || token < 0 || token >= LUKS2_TOKENS_MAX)
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
|
||||
#include "luks2_internal.h"
|
||||
|
||||
int keyring_open(struct crypt_device *cd,
|
||||
static int keyring_open(struct crypt_device *cd,
|
||||
int token,
|
||||
char **buffer,
|
||||
size_t *buffer_len,
|
||||
@@ -45,16 +45,16 @@ 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 -ENOENT;
|
||||
return -EINVAL;
|
||||
} else if (r < 0) {
|
||||
log_dbg(cd, "keyring_get_passphrase failed (error %d)", r);
|
||||
return -EPERM;
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int keyring_validate(struct crypt_device *cd __attribute__((unused)),
|
||||
static int keyring_validate(struct crypt_device *cd __attribute__((unused)),
|
||||
const char *json)
|
||||
{
|
||||
enum json_tokener_error jerr;
|
||||
@@ -92,7 +92,7 @@ out:
|
||||
return r;
|
||||
}
|
||||
|
||||
void keyring_dump(struct crypt_device *cd, const char *json)
|
||||
static void keyring_dump(struct crypt_device *cd, const char *json)
|
||||
{
|
||||
enum json_tokener_error jerr;
|
||||
json_object *jobj_token, *jobj_key;
|
||||
@@ -111,25 +111,47 @@ void keyring_dump(struct crypt_device *cd, const char *json)
|
||||
json_object_put(jobj_token);
|
||||
}
|
||||
|
||||
int LUKS2_token_keyring_json(char *buffer, size_t buffer_size,
|
||||
const struct crypt_token_params_luks2_keyring *keyring_params)
|
||||
int token_keyring_set(json_object **jobj_builtin_token,
|
||||
const void *params)
|
||||
{
|
||||
int r;
|
||||
json_object *jobj_token, *jobj;
|
||||
const struct crypt_token_params_luks2_keyring *keyring_params = (const struct crypt_token_params_luks2_keyring *) params;
|
||||
|
||||
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_token = json_object_new_object();
|
||||
if (!jobj_token)
|
||||
return -ENOMEM;
|
||||
|
||||
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 LUKS2_token_keyring_get(struct crypt_device *cd __attribute__((unused)), struct luks2_hdr *hdr,
|
||||
int token, struct crypt_token_params_luks2_keyring *keyring_params)
|
||||
int token_keyring_get(json_object *jobj_token,
|
||||
void *params)
|
||||
{
|
||||
json_object *jobj_token, *jobj;
|
||||
json_object *jobj;
|
||||
struct crypt_token_params_luks2_keyring *keyring_params = (struct crypt_token_params_luks2_keyring *) params;
|
||||
|
||||
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));
|
||||
|
||||
@@ -137,5 +159,12 @@ int LUKS2_token_keyring_get(struct crypt_device *cd __attribute__((unused)), str
|
||||
|
||||
keyring_params->key_description = json_object_get_string(jobj);
|
||||
|
||||
return token;
|
||||
return 0;
|
||||
}
|
||||
|
||||
const crypt_token_handler keyring_handler = {
|
||||
.name = LUKS2_TOKEN_KEYRING,
|
||||
.open = keyring_open,
|
||||
.validate = keyring_validate,
|
||||
.dump = keyring_dump
|
||||
};
|
||||
|
||||
@@ -153,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 err;
|
||||
goto fail;
|
||||
|
||||
/* 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 err;
|
||||
goto fail;
|
||||
|
||||
if (crypt_fips_mode())
|
||||
log_verbose(ctx, _("Running in FIPS mode."));
|
||||
|
||||
random_initialised = 1;
|
||||
return 0;
|
||||
err:
|
||||
fail:
|
||||
crypt_random_exit();
|
||||
log_err(ctx, _("Fatal error during RNG initialisation."));
|
||||
return -ENOSYS;
|
||||
|
||||
483
lib/setup.c
483
lib/setup.c
File diff suppressed because it is too large
Load Diff
@@ -274,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[8], iv_old[8];
|
||||
char iv[bs], iv_old[bs];
|
||||
struct crypt_cipher *cipher = NULL;
|
||||
int i, j, r;
|
||||
|
||||
assert(bs == 8);
|
||||
assert(bs == 2*sizeof(uint32_t));
|
||||
|
||||
r = crypt_cipher_init(&cipher, "blowfish", "ecb",
|
||||
&key[alg->key_offset], alg->key_size);
|
||||
@@ -380,15 +380,12 @@ 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[3];
|
||||
struct crypt_cipher *cipher[ciphers->chain_count];
|
||||
unsigned int bs = ciphers->cipher[0].iv_size;
|
||||
char *buf = (char*)&hdr->e, iv[16], iv_old[16];
|
||||
char *buf = (char*)&hdr->e, iv[bs], iv_old[bs];
|
||||
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);
|
||||
@@ -428,15 +425,13 @@ out:
|
||||
}
|
||||
|
||||
static int TCRYPT_decrypt_hdr(struct crypt_device *cd, struct tcrypt_phdr *hdr,
|
||||
const char *key, struct crypt_params_tcrypt *params)
|
||||
const char *key, uint32_t flags)
|
||||
{
|
||||
struct tcrypt_phdr hdr2;
|
||||
int i, j, r = -EINVAL;
|
||||
|
||||
for (i = 0; tcrypt_cipher[i].chain_count; i++) {
|
||||
if (params->cipher && !strstr(tcrypt_cipher[i].long_name, params->cipher))
|
||||
continue;
|
||||
if (!(params->flags & CRYPT_TCRYPT_LEGACY_MODES) && tcrypt_cipher[i].legacy)
|
||||
if (!(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);
|
||||
@@ -468,7 +463,7 @@ static int TCRYPT_decrypt_hdr(struct crypt_device *cd, struct tcrypt_phdr *hdr,
|
||||
r = i;
|
||||
break;
|
||||
}
|
||||
if ((params->flags & CRYPT_TCRYPT_VERA_MODES) &&
|
||||
if ((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);
|
||||
@@ -573,8 +568,6 @@ 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)
|
||||
@@ -605,7 +598,7 @@ static int TCRYPT_init_hdr(struct crypt_device *cd,
|
||||
}
|
||||
|
||||
/* Decrypt header */
|
||||
r = TCRYPT_decrypt_hdr(cd, hdr, key, params);
|
||||
r = TCRYPT_decrypt_hdr(cd, hdr, key, params->flags);
|
||||
if (r == -ENOENT) {
|
||||
skipped++;
|
||||
r = -EPERM;
|
||||
@@ -1029,13 +1022,18 @@ uint64_t TCRYPT_get_data_offset(struct crypt_device *cd,
|
||||
{
|
||||
uint64_t size;
|
||||
|
||||
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))))
|
||||
/* 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))))
|
||||
return 0;
|
||||
} else if (params->mode && !strncmp(params->mode, "xts", 3)) {
|
||||
goto hdr_offset;
|
||||
}
|
||||
|
||||
if (params->mode && !strncmp(params->mode, "xts", 3)) {
|
||||
if (hdr->d.version < 3)
|
||||
return 1;
|
||||
|
||||
@@ -1047,13 +1045,17 @@ uint64_t TCRYPT_get_data_offset(struct crypt_device *cd,
|
||||
return (size - hdr->d.hidden_volume_size +
|
||||
(TCRYPT_HDR_HIDDEN_OFFSET_OLD)) / SECTOR_SIZE;
|
||||
}
|
||||
} else if (params->flags & CRYPT_TCRYPT_HIDDEN_HEADER) {
|
||||
goto hdr_offset;
|
||||
}
|
||||
|
||||
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)) / SECTOR_SIZE;
|
||||
}
|
||||
|
||||
hdr_offset:
|
||||
return hdr->d.mk_offset / SECTOR_SIZE;
|
||||
}
|
||||
|
||||
@@ -1071,7 +1073,7 @@ uint64_t TCRYPT_get_iv_offset(struct crypt_device *cd,
|
||||
iv_offset = hdr->d.mk_offset / SECTOR_SIZE;
|
||||
|
||||
if (params->flags & CRYPT_TCRYPT_SYSTEM_HEADER)
|
||||
iv_offset += crypt_dev_partition_offset(device_path(crypt_data_device(cd)));
|
||||
iv_offset += crypt_dev_partition_offset(device_path(crypt_metadata_device(cd)));
|
||||
|
||||
return iv_offset;
|
||||
}
|
||||
|
||||
@@ -75,6 +75,7 @@ struct tcrypt_phdr {
|
||||
|
||||
struct crypt_device;
|
||||
struct crypt_params_tcrypt;
|
||||
struct crypt_dm_active_device;
|
||||
struct dm_target;
|
||||
struct volume_key;
|
||||
struct device;
|
||||
|
||||
25
lib/utils.c
25
lib/utils.c
@@ -171,7 +171,8 @@ int crypt_keyfile_device_read(struct crypt_device *cd, const char *keyfile,
|
||||
|
||||
if (isatty(fd)) {
|
||||
log_err(cd, _("Cannot read keyfile from a terminal."));
|
||||
goto out;
|
||||
r = -EINVAL;
|
||||
goto out_err;
|
||||
}
|
||||
|
||||
/* If not requested otherwise, we limit input to prevent memory exhaustion */
|
||||
@@ -187,7 +188,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;
|
||||
goto out_err;
|
||||
}
|
||||
if (S_ISREG(st.st_mode)) {
|
||||
regular_file = 1;
|
||||
@@ -195,7 +196,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;
|
||||
goto out_err;
|
||||
}
|
||||
file_read_size -= keyfile_offset;
|
||||
|
||||
@@ -210,13 +211,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;
|
||||
goto out_err;
|
||||
}
|
||||
|
||||
/* 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;
|
||||
goto out_err;
|
||||
}
|
||||
|
||||
for (i = 0, newline = 0; i < key_size; i += char_read) {
|
||||
@@ -226,7 +227,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;
|
||||
goto out_err;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -246,7 +247,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;
|
||||
goto out_err;
|
||||
}
|
||||
|
||||
if (char_read == 0)
|
||||
@@ -263,24 +264,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;
|
||||
goto out_err;
|
||||
}
|
||||
|
||||
/* Fail if we exceeded internal default (no specified size) */
|
||||
if (unlimited_read && i == key_size) {
|
||||
log_err(cd, _("Maximum keyfile size exceeded."));
|
||||
goto out;
|
||||
goto out_err;
|
||||
}
|
||||
|
||||
if (!unlimited_read && i != key_size) {
|
||||
log_err(cd, _("Cannot read requested amount of data."));
|
||||
goto out;
|
||||
goto out_err;
|
||||
}
|
||||
|
||||
*key = pass;
|
||||
*key_size_read = i;
|
||||
r = 0;
|
||||
out:
|
||||
out_err:
|
||||
if (fd != STDIN_FILENO)
|
||||
close(fd);
|
||||
|
||||
@@ -317,7 +318,7 @@ int kernel_version(uint64_t *kversion)
|
||||
}
|
||||
|
||||
if (!r)
|
||||
*kversion = compact_version(maj, min, patch, rel);
|
||||
*kversion = version(maj, min, patch, rel);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
@@ -196,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) {
|
||||
|
||||
@@ -23,8 +23,6 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <strings.h>
|
||||
#include <unistd.h>
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
|
||||
@@ -88,7 +86,7 @@ int crypt_parse_hash_integrity_mode(const char *s, char *integrity)
|
||||
else
|
||||
return -EINVAL;
|
||||
|
||||
if (r < 0 || r >= MAX_CIPHER_LEN)
|
||||
if (r < 0 || r == MAX_CIPHER_LEN)
|
||||
return -EINVAL;
|
||||
|
||||
return 0;
|
||||
@@ -102,6 +100,8 @@ int crypt_parse_integrity_mode(const char *s, char *integrity,
|
||||
if (!s || !integrity)
|
||||
return -EINVAL;
|
||||
|
||||
// FIXME: do not hardcode it here
|
||||
|
||||
/* AEAD modes */
|
||||
if (!strcmp(s, "aead") ||
|
||||
!strcmp(s, "poly1305") ||
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
#define _UTILS_CRYPT_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define MAX_CIPHER_LEN 32
|
||||
#define MAX_CIPHER_LEN_STR "31"
|
||||
|
||||
@@ -57,7 +57,6 @@ struct device {
|
||||
/* cached values */
|
||||
size_t alignment;
|
||||
size_t block_size;
|
||||
size_t loop_block_size;
|
||||
};
|
||||
|
||||
static size_t device_fs_block_size_fd(int fd)
|
||||
@@ -112,23 +111,6 @@ static size_t device_block_size_fd(int fd, size_t *min_size)
|
||||
return bsize;
|
||||
}
|
||||
|
||||
static size_t device_block_phys_size_fd(int fd)
|
||||
{
|
||||
struct stat st;
|
||||
int arg;
|
||||
size_t bsize = SECTOR_SIZE;
|
||||
|
||||
if (fstat(fd, &st) < 0)
|
||||
return bsize;
|
||||
|
||||
if (S_ISREG(st.st_mode))
|
||||
bsize = MAX_SECTOR_SIZE;
|
||||
else if (ioctl(fd, BLKPBSZGET, &arg) >= 0)
|
||||
bsize = (size_t)arg;
|
||||
|
||||
return bsize;
|
||||
}
|
||||
|
||||
static size_t device_alignment_fd(int devfd)
|
||||
{
|
||||
long alignment = DEFAULT_MEM_ALIGNMENT;
|
||||
@@ -180,9 +162,6 @@ static int device_ready(struct crypt_device *cd, struct device *device)
|
||||
struct stat st;
|
||||
size_t tmp_size;
|
||||
|
||||
if (!device)
|
||||
return -EINVAL;
|
||||
|
||||
if (device->o_direct) {
|
||||
log_dbg(cd, "Trying to open and read device %s with direct-io.",
|
||||
device_path(device));
|
||||
@@ -238,9 +217,6 @@ static int _open_locked(struct crypt_device *cd, struct device *device, int flag
|
||||
{
|
||||
int fd;
|
||||
|
||||
if (!device)
|
||||
return -EINVAL;
|
||||
|
||||
log_dbg(cd, "Opening locked device %s", device_path(device));
|
||||
|
||||
if ((flags & O_ACCMODE) != O_RDONLY && device_locked_readonly(device->lh)) {
|
||||
@@ -593,42 +569,6 @@ size_t device_block_size(struct crypt_device *cd, struct device *device)
|
||||
return device->block_size;
|
||||
}
|
||||
|
||||
size_t device_optimal_encryption_sector_size(struct crypt_device *cd, struct device *device)
|
||||
{
|
||||
int fd;
|
||||
size_t phys_block_size;
|
||||
|
||||
if (!device)
|
||||
return SECTOR_SIZE;
|
||||
|
||||
fd = open(device->file_path ?: device->path, O_RDONLY);
|
||||
if (fd < 0) {
|
||||
log_dbg(cd, "Cannot get optimal encryption sector size for device %s.", device_path(device));
|
||||
return SECTOR_SIZE;
|
||||
}
|
||||
|
||||
/* cache device block size */
|
||||
device->block_size = device_block_size_fd(fd, NULL);
|
||||
if (!device->block_size) {
|
||||
close(fd);
|
||||
log_dbg(cd, "Cannot get block size for device %s.", device_path(device));
|
||||
return SECTOR_SIZE;
|
||||
}
|
||||
|
||||
if (device->block_size >= MAX_SECTOR_SIZE) {
|
||||
close(fd);
|
||||
return MISALIGNED(device->block_size, MAX_SECTOR_SIZE) ? SECTOR_SIZE : MAX_SECTOR_SIZE;
|
||||
}
|
||||
|
||||
phys_block_size = device_block_phys_size_fd(fd);
|
||||
close(fd);
|
||||
|
||||
if (device->block_size >= phys_block_size || phys_block_size <= SECTOR_SIZE || phys_block_size > MAX_SECTOR_SIZE || MISALIGNED(phys_block_size, device->block_size))
|
||||
return device->block_size;
|
||||
|
||||
return phys_block_size;
|
||||
}
|
||||
|
||||
int device_read_ahead(struct device *device, uint32_t *read_ahead)
|
||||
{
|
||||
int fd, r = 0;
|
||||
@@ -833,11 +773,10 @@ static int device_internal_prepare(struct crypt_device *cd, struct device *devic
|
||||
return -ENOTSUP;
|
||||
}
|
||||
|
||||
log_dbg(cd, "Allocating a free loop device (block size: %zu).",
|
||||
device->loop_block_size ?: SECTOR_SIZE);
|
||||
log_dbg(cd, "Allocating a free loop device.");
|
||||
|
||||
/* Keep the loop open, detached on last close. */
|
||||
loop_fd = crypt_loop_attach(&loop_device, device->path, 0, 1, &readonly, device->loop_block_size);
|
||||
loop_fd = crypt_loop_attach(&loop_device, device->path, 0, 1, &readonly);
|
||||
if (loop_fd == -1) {
|
||||
log_err(cd, _("Attaching loopback device failed "
|
||||
"(loop device with autoclear flag is required)."));
|
||||
@@ -856,8 +795,6 @@ static int device_internal_prepare(struct crypt_device *cd, struct device *devic
|
||||
return r;
|
||||
}
|
||||
|
||||
log_dbg(cd, "Attached loop device block size is %zu bytes.", device_block_size_fd(loop_fd, NULL));
|
||||
|
||||
device->loop_fd = loop_fd;
|
||||
device->file_path = file_path;
|
||||
device->init_done = 1;
|
||||
@@ -1077,11 +1014,3 @@ void device_close(struct crypt_device *cd, struct device *device)
|
||||
device->dev_fd = -1;
|
||||
}
|
||||
}
|
||||
|
||||
void device_set_block_size(struct device *device, size_t size)
|
||||
{
|
||||
if (!device)
|
||||
return;
|
||||
|
||||
device->loop_block_size = size;
|
||||
}
|
||||
|
||||
@@ -173,7 +173,7 @@ static int acquire_lock_handle(struct crypt_device *cd, struct device *device, s
|
||||
h->u.bdev.devno = st.st_rdev;
|
||||
h->mode = DEV_LOCK_BDEV;
|
||||
} else if (S_ISREG(st.st_mode)) {
|
||||
/* workaround for nfsv4 */
|
||||
// FIXME: workaround for nfsv4
|
||||
fd = open(device_path(device), O_RDWR | O_NONBLOCK | O_CLOEXEC);
|
||||
if (fd < 0)
|
||||
h->flock_fd = dev_fd;
|
||||
@@ -261,7 +261,7 @@ int device_locked_readonly(struct crypt_lock_handle *h)
|
||||
return (h && h->type == DEV_LOCK_READ);
|
||||
}
|
||||
|
||||
static int verify_lock_handle(struct crypt_lock_handle *h)
|
||||
static int verify_lock_handle(const char *device_path, struct crypt_lock_handle *h)
|
||||
{
|
||||
char res[PATH_MAX];
|
||||
struct stat lck_st, res_st;
|
||||
@@ -326,7 +326,7 @@ static int acquire_and_verify(struct crypt_device *cd, struct device *device, co
|
||||
* check whether another libcryptsetup process removed resource file before this
|
||||
* one managed to flock() it. See release_lock_handle() for details
|
||||
*/
|
||||
r = verify_lock_handle(h);
|
||||
r = verify_lock_handle(device_path(device), h);
|
||||
if (r < 0) {
|
||||
if (flock(h->flock_fd, LOCK_UN))
|
||||
log_dbg(cd, "flock on fd %d failed.", h->flock_fd);
|
||||
@@ -505,11 +505,11 @@ int device_locked_verify(struct crypt_device *cd, int dev_fd, struct crypt_lock_
|
||||
|
||||
/* if device handle is regular file the handle must match the lock handle */
|
||||
if (S_ISREG(dev_st.st_mode)) {
|
||||
log_dbg(cd, "Verifying locked device handle (regular file)");
|
||||
log_dbg(cd, "Veryfing locked device handle (regular file)");
|
||||
if (!same_inode(dev_st, lck_st))
|
||||
return 1;
|
||||
} else if (S_ISBLK(dev_st.st_mode)) {
|
||||
log_dbg(cd, "Verifying locked device handle (bdev)");
|
||||
log_dbg(cd, "Veryfing locked device handle (bdev)");
|
||||
if (resource_by_devno(res, sizeof(res), dev_st.st_rdev, 1) ||
|
||||
stat(res, &st) ||
|
||||
!same_inode(lck_st, st))
|
||||
|
||||
@@ -367,9 +367,7 @@ char *crypt_get_base_device(const char *dev_path)
|
||||
if (dm_is_dm_kernel_name(devname))
|
||||
return NULL;
|
||||
|
||||
if (snprintf(part_path, sizeof(part_path), "/dev/%s", devname) < 0)
|
||||
return NULL;
|
||||
|
||||
snprintf(part_path, sizeof(part_path), "/dev/%s", devname);
|
||||
return strdup(part_path);
|
||||
}
|
||||
|
||||
@@ -408,10 +406,10 @@ int lookup_by_disk_id(const char *dm_uuid)
|
||||
return r;
|
||||
}
|
||||
|
||||
int lookup_by_sysfs_uuid_field(const char *dm_uuid)
|
||||
int lookup_by_sysfs_uuid_field(const char *dm_uuid, size_t max_len)
|
||||
{
|
||||
struct dirent *entry;
|
||||
char subpath[PATH_MAX], uuid[DM_UUID_LEN];
|
||||
char subpath[PATH_MAX], uuid[max_len];
|
||||
ssize_t s;
|
||||
struct stat st;
|
||||
int fd, len, r = 0; /* not found */
|
||||
@@ -443,7 +441,7 @@ int lookup_by_sysfs_uuid_field(const char *dm_uuid)
|
||||
}
|
||||
|
||||
/* reads binary data */
|
||||
s = read_buffer(fd, uuid, sizeof(uuid) - 1);
|
||||
s = read_buffer(fd, uuid, max_len - 1);
|
||||
if (s > 0) {
|
||||
uuid[s] = '\0';
|
||||
if (!strncmp(uuid, dm_uuid, strlen(dm_uuid)))
|
||||
|
||||
@@ -73,7 +73,6 @@ static inline uint32_t act2dmflags(uint32_t act_flags)
|
||||
#define DM_VERITY_PANIC_CORRUPTION_SUPPORTED (1 << 24) /* dm-verity panic on corruption */
|
||||
#define DM_CRYPT_NO_WORKQUEUE_SUPPORTED (1 << 25) /* dm-crypt suppot for bypassing workqueues */
|
||||
#define DM_INTEGRITY_FIX_HMAC_SUPPORTED (1 << 26) /* hmac covers also superblock */
|
||||
#define DM_INTEGRITY_RESET_RECALC_SUPPORTED (1 << 27) /* dm-integrity automatic recalculation supported */
|
||||
|
||||
typedef enum { DM_CRYPT = 0, DM_VERITY, DM_INTEGRITY, DM_LINEAR, DM_ERROR, DM_ZERO, DM_UNKNOWN } dm_target_type;
|
||||
enum tdirection { TARGET_SET = 1, TARGET_QUERY };
|
||||
@@ -223,7 +222,6 @@ int dm_resume_and_reinstate_key(struct crypt_device *cd, const char *name,
|
||||
const struct volume_key *vk);
|
||||
int dm_error_device(struct crypt_device *cd, const char *name);
|
||||
int dm_clear_device(struct crypt_device *cd, const char *name);
|
||||
int dm_cancel_deferred_removal(const char *name);
|
||||
|
||||
const char *dm_get_dir(void);
|
||||
|
||||
|
||||
@@ -24,12 +24,9 @@
|
||||
#include "utils_fips.h"
|
||||
|
||||
#if !ENABLE_FIPS
|
||||
bool crypt_fips_mode(void) { return false; }
|
||||
int crypt_fips_mode(void) { return 0; }
|
||||
#else
|
||||
static bool fips_checked = false;
|
||||
static bool fips_mode = false;
|
||||
|
||||
static bool kernel_fips_mode(void)
|
||||
static int kernel_fips_mode(void)
|
||||
{
|
||||
int fd;
|
||||
char buf[1] = "";
|
||||
@@ -39,17 +36,11 @@ static bool kernel_fips_mode(void)
|
||||
close(fd);
|
||||
}
|
||||
|
||||
return (buf[0] == '1');
|
||||
return (buf[0] == '1') ? 1 : 0;
|
||||
}
|
||||
|
||||
bool crypt_fips_mode(void)
|
||||
int crypt_fips_mode(void)
|
||||
{
|
||||
if (fips_checked)
|
||||
return fips_mode;
|
||||
|
||||
fips_mode = kernel_fips_mode() && !access("/etc/system-fips", F_OK);
|
||||
fips_checked = true;
|
||||
|
||||
return fips_mode;
|
||||
return kernel_fips_mode() && !access("/etc/system-fips", F_OK);
|
||||
}
|
||||
#endif /* ENABLE_FIPS */
|
||||
|
||||
@@ -21,8 +21,6 @@
|
||||
#ifndef _UTILS_FIPS_H
|
||||
#define _UTILS_FIPS_H
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
bool crypt_fips_mode(void);
|
||||
int crypt_fips_mode(void);
|
||||
|
||||
#endif /* _UTILS_FIPS_H */
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "utils_io.h"
|
||||
|
||||
|
||||
@@ -24,7 +24,6 @@
|
||||
#ifndef _CRYPTSETUP_UTILS_IO_H
|
||||
#define _CRYPTSETUP_UTILS_IO_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
ssize_t read_buffer(int fd, void *buf, size_t length);
|
||||
|
||||
@@ -26,7 +26,6 @@
|
||||
#include <sys/syscall.h>
|
||||
|
||||
#include "libcryptsetup.h"
|
||||
#include "libcryptsetup_macros.h"
|
||||
#include "utils_keyring.h"
|
||||
|
||||
#ifndef HAVE_KEY_SERIAL_T
|
||||
@@ -34,6 +33,10 @@
|
||||
typedef int32_t key_serial_t;
|
||||
#endif
|
||||
|
||||
#ifndef ARRAY_SIZE
|
||||
# define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
|
||||
#endif
|
||||
|
||||
#ifdef KERNEL_KEYRING
|
||||
|
||||
static const struct {
|
||||
|
||||
@@ -28,14 +28,13 @@
|
||||
#include <limits.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#ifdef HAVE_SYS_SYSMACROS_H
|
||||
# include <sys/sysmacros.h> /* for major, minor */
|
||||
#endif
|
||||
#include <linux/types.h>
|
||||
#include <linux/loop.h>
|
||||
|
||||
#include "utils_loop.h"
|
||||
#include "libcryptsetup_macros.h"
|
||||
|
||||
#define LOOP_DEV_MAJOR 7
|
||||
|
||||
@@ -51,20 +50,6 @@
|
||||
#define LOOP_SET_CAPACITY 0x4C07
|
||||
#endif
|
||||
|
||||
#ifndef LOOP_SET_BLOCK_SIZE
|
||||
#define LOOP_SET_BLOCK_SIZE 0x4C09
|
||||
#endif
|
||||
|
||||
#ifndef LOOP_CONFIGURE
|
||||
#define LOOP_CONFIGURE 0x4C0A
|
||||
struct loop_config {
|
||||
__u32 fd;
|
||||
__u32 block_size;
|
||||
struct loop_info64 info;
|
||||
__u64 __reserved[8];
|
||||
};
|
||||
#endif
|
||||
|
||||
static char *crypt_loop_get_device_old(void)
|
||||
{
|
||||
char dev[20];
|
||||
@@ -116,12 +101,11 @@ static char *crypt_loop_get_device(void)
|
||||
}
|
||||
|
||||
int crypt_loop_attach(char **loop, const char *file, int offset,
|
||||
int autoclear, int *readonly, size_t blocksize)
|
||||
int autoclear, int *readonly)
|
||||
{
|
||||
struct loop_config config = {0};
|
||||
struct loop_info64 lo64 = {0};
|
||||
char *lo_file_name;
|
||||
int loop_fd = -1, file_fd = -1, r = 1;
|
||||
int fallback = 0;
|
||||
|
||||
*loop = NULL;
|
||||
|
||||
@@ -133,18 +117,7 @@ int crypt_loop_attach(char **loop, const char *file, int offset,
|
||||
if (file_fd < 0)
|
||||
goto out;
|
||||
|
||||
config.fd = file_fd;
|
||||
|
||||
lo_file_name = (char*)config.info.lo_file_name;
|
||||
lo_file_name[LO_NAME_SIZE-1] = '\0';
|
||||
strncpy(lo_file_name, file, LO_NAME_SIZE-1);
|
||||
config.info.lo_offset = offset;
|
||||
if (autoclear)
|
||||
config.info.lo_flags |= LO_FLAGS_AUTOCLEAR;
|
||||
if (blocksize > SECTOR_SIZE)
|
||||
config.block_size = blocksize;
|
||||
|
||||
while (loop_fd < 0) {
|
||||
while (loop_fd < 0) {
|
||||
*loop = crypt_loop_get_device();
|
||||
if (!*loop)
|
||||
goto out;
|
||||
@@ -152,18 +125,8 @@ int crypt_loop_attach(char **loop, const char *file, int offset,
|
||||
loop_fd = open(*loop, *readonly ? O_RDONLY : O_RDWR);
|
||||
if (loop_fd < 0)
|
||||
goto out;
|
||||
if (ioctl(loop_fd, LOOP_CONFIGURE, &config) < 0) {
|
||||
if (errno == EINVAL || errno == ENOTTY) {
|
||||
free(*loop);
|
||||
*loop = NULL;
|
||||
|
||||
close(loop_fd);
|
||||
loop_fd = -1;
|
||||
|
||||
/* kernel doesn't support LOOP_CONFIGURE */
|
||||
fallback = 1;
|
||||
break;
|
||||
}
|
||||
if (ioctl(loop_fd, LOOP_SET_FD, file_fd) < 0) {
|
||||
if (errno != EBUSY)
|
||||
goto out;
|
||||
free(*loop);
|
||||
@@ -174,40 +137,23 @@ int crypt_loop_attach(char **loop, const char *file, int offset,
|
||||
}
|
||||
}
|
||||
|
||||
if (fallback) {
|
||||
while (loop_fd < 0) {
|
||||
*loop = crypt_loop_get_device();
|
||||
if (!*loop)
|
||||
goto out;
|
||||
lo_file_name = (char*)lo64.lo_file_name;
|
||||
lo_file_name[LO_NAME_SIZE-1] = '\0';
|
||||
strncpy(lo_file_name, file, LO_NAME_SIZE-1);
|
||||
lo64.lo_offset = offset;
|
||||
if (autoclear)
|
||||
lo64.lo_flags |= LO_FLAGS_AUTOCLEAR;
|
||||
|
||||
loop_fd = open(*loop, *readonly ? O_RDONLY : O_RDWR);
|
||||
if (loop_fd < 0)
|
||||
goto out;
|
||||
if (ioctl(loop_fd, LOOP_SET_FD, file_fd) < 0) {
|
||||
if (errno != EBUSY)
|
||||
goto out;
|
||||
free(*loop);
|
||||
*loop = NULL;
|
||||
|
||||
close(loop_fd);
|
||||
loop_fd = -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (blocksize > SECTOR_SIZE)
|
||||
(void)ioctl(loop_fd, LOOP_SET_BLOCK_SIZE, (unsigned long)blocksize);
|
||||
|
||||
if (ioctl(loop_fd, LOOP_SET_STATUS64, &config.info) < 0) {
|
||||
(void)ioctl(loop_fd, LOOP_CLR_FD, 0);
|
||||
goto out;
|
||||
}
|
||||
if (ioctl(loop_fd, LOOP_SET_STATUS64, &lo64) < 0) {
|
||||
(void)ioctl(loop_fd, LOOP_CLR_FD, 0);
|
||||
goto out;
|
||||
}
|
||||
|
||||
/* Verify that autoclear is really set */
|
||||
if (autoclear) {
|
||||
memset(&config.info, 0, sizeof(config.info));
|
||||
if (ioctl(loop_fd, LOOP_GET_STATUS64, &config.info) < 0 ||
|
||||
!(config.info.lo_flags & LO_FLAGS_AUTOCLEAR)) {
|
||||
memset(&lo64, 0, sizeof(lo64));
|
||||
if (ioctl(loop_fd, LOOP_GET_STATUS64, &lo64) < 0 ||
|
||||
!(lo64.lo_flags & LO_FLAGS_AUTOCLEAR)) {
|
||||
(void)ioctl(loop_fd, LOOP_CLR_FD, 0);
|
||||
goto out;
|
||||
}
|
||||
@@ -288,9 +234,8 @@ static char *_sysfs_backing_file(const char *loop)
|
||||
if (stat(loop, &st) || !S_ISBLK(st.st_mode))
|
||||
return NULL;
|
||||
|
||||
if (snprintf(buf, sizeof(buf), "/sys/dev/block/%d:%d/loop/backing_file",
|
||||
major(st.st_rdev), minor(st.st_rdev)) < 0)
|
||||
return NULL;
|
||||
snprintf(buf, sizeof(buf), "/sys/dev/block/%d:%d/loop/backing_file",
|
||||
major(st.st_rdev), minor(st.st_rdev));
|
||||
|
||||
fd = open(buf, O_RDONLY);
|
||||
if (fd < 0)
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
char *crypt_loop_backing_file(const char *loop);
|
||||
int crypt_loop_device(const char *loop);
|
||||
int crypt_loop_attach(char **loop, const char *file, int offset,
|
||||
int autoclear, int *readonly, size_t blocksize);
|
||||
int autoclear, int *readonly);
|
||||
int crypt_loop_detach(const char *loop);
|
||||
int crypt_loop_resize(const char *loop);
|
||||
|
||||
|
||||
@@ -92,7 +92,7 @@ int verify_pbkdf_params(struct crypt_device *cd,
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
if (!pbkdf || !pbkdf->type ||
|
||||
if (!pbkdf->type ||
|
||||
(!pbkdf->hash && !strcmp(pbkdf->type, "pbkdf2")))
|
||||
return -EINVAL;
|
||||
|
||||
|
||||
@@ -150,7 +150,7 @@ int crypt_wipe_device(struct crypt_device *cd,
|
||||
if (!bsize || !alignment || !wipe_block_size)
|
||||
return -EINVAL;
|
||||
|
||||
/* if wipe_block_size < bsize, then a wipe is highly ineffective */
|
||||
/* FIXME: if wipe_block_size < bsize, then a wipe is highly ineffective */
|
||||
|
||||
/* Everything must be aligned to SECTOR_SIZE */
|
||||
if (MISALIGNED_512(offset) || MISALIGNED_512(length) || MISALIGNED_512(wipe_block_size))
|
||||
|
||||
@@ -25,19 +25,15 @@
|
||||
|
||||
#include "rs.h"
|
||||
|
||||
#define MAX_NR_BUF 256
|
||||
|
||||
int decode_rs_char(struct rs* rs, data_t* data)
|
||||
{
|
||||
int deg_lambda, el, deg_omega, syn_error, count;
|
||||
int i, j, r, k;
|
||||
data_t q, tmp, num1, num2, den, discr_r;
|
||||
data_t lambda[MAX_NR_BUF], s[MAX_NR_BUF]; /* Err+Eras Locator poly and syndrome poly */
|
||||
data_t b[MAX_NR_BUF], t[MAX_NR_BUF], omega[MAX_NR_BUF];
|
||||
data_t root[MAX_NR_BUF], reg[MAX_NR_BUF], loc[MAX_NR_BUF];
|
||||
|
||||
if (rs->nroots >= MAX_NR_BUF)
|
||||
return -1;
|
||||
/* FIXME: remove VLAs here */
|
||||
data_t lambda[rs->nroots + 1], s[rs->nroots]; /* Err+Eras Locator poly and syndrome poly */
|
||||
data_t b[rs->nroots + 1], t[rs->nroots + 1], omega[rs->nroots + 1];
|
||||
data_t root[rs->nroots], reg[rs->nroots + 1], loc[rs->nroots];
|
||||
|
||||
memset(s, 0, rs->nroots * sizeof(data_t));
|
||||
memset(b, 0, (rs->nroots + 1) * sizeof(data_t));
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
#include <ctype.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <netinet/in.h>
|
||||
#include <uuid/uuid.h>
|
||||
|
||||
#include "libcryptsetup.h"
|
||||
@@ -236,7 +237,7 @@ uint64_t VERITY_hash_offset_block(struct crypt_params_verity *params)
|
||||
return hash_offset / params->hash_block_size;
|
||||
}
|
||||
|
||||
int VERITY_UUID_generate(struct crypt_device *cd __attribute__((unused)), char **uuid_string)
|
||||
int VERITY_UUID_generate(struct crypt_device *cd, char **uuid_string)
|
||||
{
|
||||
uuid_t uuid;
|
||||
|
||||
|
||||
@@ -178,7 +178,6 @@ static int FEC_process_inputs(struct crypt_device *cd,
|
||||
r = decode_rs_char(rs, rs_block);
|
||||
if (r < 0) {
|
||||
log_err(cd, _("Failed to repair parity for block %" PRIu64 "."), n);
|
||||
r = -EPERM;
|
||||
goto out;
|
||||
}
|
||||
/* return number of detected errors */
|
||||
|
||||
@@ -28,7 +28,6 @@
|
||||
#include "internal.h"
|
||||
|
||||
#define VERITY_MAX_LEVELS 63
|
||||
#define VERITY_MAX_DIGEST_SIZE 1024
|
||||
|
||||
static unsigned get_bits_up(size_t u)
|
||||
{
|
||||
@@ -48,30 +47,20 @@ static unsigned get_bits_down(size_t u)
|
||||
|
||||
static int verify_zero(struct crypt_device *cd, FILE *wr, size_t bytes)
|
||||
{
|
||||
char *block = NULL;
|
||||
char block[bytes];
|
||||
size_t i;
|
||||
int r;
|
||||
|
||||
block = malloc(bytes);
|
||||
if (!block)
|
||||
return -ENOMEM;
|
||||
|
||||
if (fread(block, bytes, 1, wr) != 1) {
|
||||
log_dbg(cd, "EIO while reading spare area.");
|
||||
r = -EIO;
|
||||
goto out;
|
||||
return -EIO;
|
||||
}
|
||||
for (i = 0; i < bytes; i++)
|
||||
if (block[i]) {
|
||||
log_err(cd, _("Spare area is not zeroed at position %" PRIu64 "."),
|
||||
ftello(wr) - bytes);
|
||||
r = -EPERM;
|
||||
goto out;
|
||||
return -EPERM;
|
||||
}
|
||||
r = 0;
|
||||
out:
|
||||
free(block);
|
||||
return r;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int verify_hash_block(const char *hash_name, int version,
|
||||
@@ -149,8 +138,9 @@ static int create_or_verify(struct crypt_device *cd, FILE *rd, FILE *wr,
|
||||
char *calculated_digest, size_t digest_size,
|
||||
const char *salt, size_t salt_size)
|
||||
{
|
||||
char *left_block, *data_buffer;
|
||||
char read_digest[VERITY_MAX_DIGEST_SIZE];
|
||||
char left_block[hash_block_size];
|
||||
char data_buffer[data_block_size];
|
||||
char read_digest[digest_size];
|
||||
size_t hash_per_block = 1 << get_bits_down(hash_block_size / digest_size);
|
||||
size_t digest_size_full = 1 << get_bits_up(digest_size);
|
||||
uint64_t blocks_to_write = (blocks + hash_per_block - 1) / hash_per_block;
|
||||
@@ -159,9 +149,6 @@ static int create_or_verify(struct crypt_device *cd, FILE *rd, FILE *wr,
|
||||
unsigned i;
|
||||
int r;
|
||||
|
||||
if (digest_size > sizeof(read_digest))
|
||||
return -EINVAL;
|
||||
|
||||
if (uint64_mult_overflow(&seek_rd, data_block, data_block_size) ||
|
||||
uint64_mult_overflow(&seek_wr, hash_block, hash_block_size)) {
|
||||
log_err(cd, _("Device offset overflow."));
|
||||
@@ -178,13 +165,6 @@ static int create_or_verify(struct crypt_device *cd, FILE *rd, FILE *wr,
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
left_block = malloc(hash_block_size);
|
||||
data_buffer = malloc(data_block_size);
|
||||
if (!left_block || !data_buffer) {
|
||||
r = -ENOMEM;
|
||||
goto out;
|
||||
}
|
||||
|
||||
memset(left_block, 0, hash_block_size);
|
||||
while (blocks_to_write--) {
|
||||
left_bytes = hash_block_size;
|
||||
@@ -194,37 +174,31 @@ static int create_or_verify(struct crypt_device *cd, FILE *rd, FILE *wr,
|
||||
blocks--;
|
||||
if (fread(data_buffer, data_block_size, 1, rd) != 1) {
|
||||
log_dbg(cd, "Cannot read data device block.");
|
||||
r = -EIO;
|
||||
goto out;
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
if (verify_hash_block(hash_name, version,
|
||||
calculated_digest, digest_size,
|
||||
data_buffer, data_block_size,
|
||||
salt, salt_size)) {
|
||||
r = -EINVAL;
|
||||
goto out;
|
||||
}
|
||||
salt, salt_size))
|
||||
return -EINVAL;
|
||||
|
||||
if (!wr)
|
||||
break;
|
||||
if (verify) {
|
||||
if (fread(read_digest, digest_size, 1, wr) != 1) {
|
||||
log_dbg(cd, "Cannot read digest form hash device.");
|
||||
r = -EIO;
|
||||
goto out;
|
||||
return -EIO;
|
||||
}
|
||||
if (memcmp(read_digest, calculated_digest, digest_size)) {
|
||||
log_err(cd, _("Verification failed at position %" PRIu64 "."),
|
||||
ftello(rd) - data_block_size);
|
||||
r = -EPERM;
|
||||
goto out;
|
||||
return -EPERM;
|
||||
}
|
||||
} else {
|
||||
if (fwrite(calculated_digest, digest_size, 1, wr) != 1) {
|
||||
log_dbg(cd, "Cannot write digest to hash device.");
|
||||
r = -EIO;
|
||||
goto out;
|
||||
return -EIO;
|
||||
}
|
||||
}
|
||||
if (version == 0) {
|
||||
@@ -234,11 +208,10 @@ static int create_or_verify(struct crypt_device *cd, FILE *rd, FILE *wr,
|
||||
if (verify) {
|
||||
r = verify_zero(cd, wr, digest_size_full - digest_size);
|
||||
if (r)
|
||||
goto out;
|
||||
return r;
|
||||
} else if (fwrite(left_block, digest_size_full - digest_size, 1, wr) != 1) {
|
||||
log_dbg(cd, "Cannot write spare area to hash device.");
|
||||
r = -EIO;
|
||||
goto out;
|
||||
return -EIO;
|
||||
}
|
||||
}
|
||||
left_bytes -= digest_size_full;
|
||||
@@ -248,26 +221,22 @@ static int create_or_verify(struct crypt_device *cd, FILE *rd, FILE *wr,
|
||||
if (verify) {
|
||||
r = verify_zero(cd , wr, left_bytes);
|
||||
if (r)
|
||||
goto out;
|
||||
return r;
|
||||
} else if (fwrite(left_block, left_bytes, 1, wr) != 1) {
|
||||
log_dbg(cd, "Cannot write remaining spare area to hash device.");
|
||||
r = -EIO;
|
||||
goto out;
|
||||
return -EIO;
|
||||
}
|
||||
}
|
||||
}
|
||||
r = 0;
|
||||
out:
|
||||
free(left_block);
|
||||
free(data_buffer);
|
||||
return r;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int VERITY_create_or_verify_hash(struct crypt_device *cd, bool verify,
|
||||
struct crypt_params_verity *params,
|
||||
char *root_hash, size_t digest_size)
|
||||
{
|
||||
char calculated_digest[VERITY_MAX_DIGEST_SIZE];
|
||||
char calculated_digest[digest_size];
|
||||
FILE *data_file = NULL;
|
||||
FILE *hash_file = NULL, *hash_file_2;
|
||||
uint64_t hash_level_block[VERITY_MAX_LEVELS];
|
||||
@@ -284,9 +253,6 @@ static int VERITY_create_or_verify_hash(struct crypt_device *cd, bool verify,
|
||||
device_path(crypt_data_device(cd)), params->data_size,
|
||||
device_path(crypt_metadata_device(cd)), hash_position);
|
||||
|
||||
if (digest_size > sizeof(calculated_digest))
|
||||
return -EINVAL;
|
||||
|
||||
if (!params->data_size) {
|
||||
r = device_size(crypt_data_device(cd), &dev_size);
|
||||
if (r < 0)
|
||||
|
||||
@@ -13,8 +13,3 @@ endif
|
||||
if INTEGRITYSETUP
|
||||
man8_MANS += man/integritysetup.8
|
||||
endif
|
||||
|
||||
if SSHPLUGIN_TOKEN
|
||||
EXTRA_DIST += man/cryptsetup-ssh.8
|
||||
man8_MANS += man/cryptsetup-ssh.8
|
||||
endif
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user