Add a 'fsverity dump_metadata' subcommand which calls
FS_IOC_READ_VERITY_METADATA on a file and prints the returned metadata
to stdout. There are three subsubcommands, one for each type of
metadata that can be read using the ioctl:
fsverity dump_metadata merkle_tree FILE
fsverity dump_metadata descriptor FILE
fsverity dump_metadata signature FILE
By default the whole metadata item is dumped. --length and --offset can
be specified to dump only a particular range of the item.
This subcommand will be used by xfstests to test the
FS_IOC_READ_VERITY_METADATA ioctl.
Link: https://lore.kernel.org/r/20210115182402.35691-3-ebiggers@kernel.org
Signed-off-by: Eric Biggers <ebiggers@google.com>
Make any user-specified CFLAGS only replace flags that affect the
resulting binary. Currently that means just "-O2". Always add the
warning flags, although they can still be disabled by -Wno-*. This
seems to be closer to what people want; see the discussion at
https://lkml.kernel.org/linux-fscrypt/20201026204831.3337360-1-luca.boccassi@gmail.com/T/#u
Also fix up scripts/run-tests.sh to use appropriate CFLAGS. That is,
don't specify -Wall since the Makefile now adds it, always specify
-Werror, and usually specify an optimization level too.
Acked-by: Luca Boccassi <bluca@debian.org>
Signed-off-by: Eric Biggers <ebiggers@google.com>
The current approach doesn't really work as expected because 'make &&
make PREFIX=/usr install' causes a rebuild due to PREFIX changing.
Avoid this for now by generating libfsverity.pc during 'make install'.
Signed-off-by: Eric Biggers <ebiggers@google.com>
Add a 'fsverity digest' subcommand that prints the hex-encoded digest of
the specified file(s), ready to be signed offline. By default the
output is like 'fsverity measure', but if the --for-builtin-sig option
is given, the output is the hex-encoded "struct fsverity_signed_digest"
that the kernel expects to be signed for builtin signatures.
This subcommand is useful in case the integrated signing mechanism with
local cert/key cannot be used.
Signed-off-by: Luca Boccassi <luca.boccassi@microsoft.com>
Link: https://lore.kernel.org/r/20201026191839.3329948-1-luca.boccassi@gmail.com
[EB: commit message, comment, and whitespace tweaks]
Signed-off-by: Eric Biggers <ebiggers@google.com>
pkg-config is commonly used by libraries to convey information about
compiler flags and dependencies.
As packagers, we heavily rely on it so that all our tools do the right
thing by default regardless of the environment.
Signed-off-by: Luca Boccassi <luca.boccassi@microsoft.com>
Link: https://lore.kernel.org/r/20201026111506.3215328-2-luca.boccassi@gmail.com
[EB: added leading slash to .gitignore entry]
[EB: added dependency on .build-config]
Signed-off-by: Eric Biggers <ebiggers@google.com>
libfsverity.h is the public API, but the other headers in common/ are
private headers for fsverity-utils. Move libfsverity.h to its own
directory to make this clear. This is also needed for Android's build
system in order to restrict the exported headers to libfsverity.h.
This doesn't affect users who are using 'make install', since
'make install' still installs libfsverity.h to the same place,
and it doesn't install any private headers.
Link: https://lore.kernel.org/r/20200923202328.16310-1-ebiggers@kernel.org
Signed-off-by: Eric Biggers <ebiggers@google.com>
The build on Ubuntu Xenial with GCC 5.4.0 will fail with:
cc: error: unrecognized command line option ‘-Wimplicit-fallthrough’
This unsupported flag is not skipped as expected.
It is because of the /bin/sh shell on Ubuntu, DASH, which does not
support this &> redirection. Use 2>&1 to solve this problem.
Signed-off-by: Po-Hsu Lin <po-hsu.lin@canonical.com>
Link: https://lore.kernel.org/r/20200803030736.6364-1-po-hsu.lin@canonical.com
Signed-off-by: Eric Biggers <ebiggers@google.com>
Add a script that automatically runs 'make check' in lots of
configurations, runs static analysis, and does a few other tests.
Signed-off-by: Eric Biggers <ebiggers@google.com>
- Support $(TEST_WRAPPER_PROG), for valgrind.
- Run a few 'fsverity' commands that don't require kernel support.
Signed-off-by: Eric Biggers <ebiggers@google.com>
From the 'fsverity' program, split out a library 'libfsverity'.
Currently it supports computing file measurements ("digests"), and
signing those file measurements for use with the fs-verity builtin
signature verification feature.
Rewritten from patches by Jes Sorensen <jsorensen@fb.com>.
I made a lot of improvements, e.g.:
- Separated library and program source into different directories.
- Drastically improved the Makefile.
- Added 'make check' target and rules to build test programs.
- In the shared lib, only export the functions intended to be public.
- Prefixed global functions with "libfsverity_" so that they don't cause
conflicts when the library is built as a static library.
- Made library error messages be sent to a user-specified callback
rather than always be printed to stderr.
- Keep showing OpenSSL error messages.
- Stopped abort()ing in library code, when possible.
- Made libfsverity_digest use native endianness.
- Moved file_size into the merkle_tree_params.
- Made libfsverity_get_hash_name() just return the static strings.
- Made some variables in the API uint32_t instead of uint16_t.
- Shared parse_hash_alg_option() between cmd_enable and cmd_sign.
- Lots of other fixes.
(Folded in a couple Makefile fixes from Jes.)
Reviewed-by: Jes Sorensen <jsorensen@fb.com>
Signed-off-by: Eric Biggers <ebiggers@google.com>
In preparation for moving most of the functionality of 'fsverity sign'
into a shared library, split up cmd_sign.c into three files:
- cmd_sign.c: the actual command
- compute_digest.c: compute the file measurement
- sign_digest.c: sign the file measurement
No "real" changes; this is just moving code around.
Reviewed-by: Jes Sorensen <jsorensen@fb.com>
Signed-off-by: Eric Biggers <ebiggers@google.com>
- Root hash is now stored in authenticated extensions
- Magic number is now at the very end of the file too
- 'set_measurement' is replaced with 'measure'
- UAPI header now declares on-disk format
- log_tree_blocksize is stored instead of log_arity
- CRC-32 is changed to CRC-32C
- SHA-512 is now supported too
Signed-off-by: Eric Biggers <ebiggers@google.com>
Make fsveritysetup a subcommand 'setup' of the 'fsverity' program which
previously had just the 'enable' and 'set_measurement' commands.
When signing the file measurement, use libcrypto directly instead of
invoking the 'openssl' binary.
Similarly, build the Merkle tree in C code (using libcrypto for SHA-256,
or zlib for CRC-32) rather than invoking the 'veritysetup' binary.
Other improvements over the original Python script are included as well.
Signed-off-by: Eric Biggers <ebiggers@google.com>