Skip to contentSkip to conversation

fsverity-utils: introduce libfsverity

PATCH In review Eric Biggers 3 participants 10 messages May 25, 2020 – Jun 6, 2020

Subsystems (3)
lore
Share & tools
lore

Eric Biggers

author maintainer
#0 lore raw

v2 cover fsverity-utils: introduce libfsverity

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 <[email protected]>. I made a lot of improvements; see patch 2 for details.

This patchset can also be found at branch "libfsverity" of
https://git.kernel.org/pub/scm/linux/kernel/git/ebiggers/fsverity-utils.git/

Changes v1 => v2:
- Fold in the Makefile fixes from Jes
- Rename libfsverity_digest_size() and libfsverity_hash_name()
- Improve the documentation slightly
- If a memory allocation fails, print the allocation size
- Use EBADMSG for invalid cert or keyfile, not EINVAL
- Make libfsverity_find_hash_alg_by_name() handle NULL
- Avoid introducing compiler warnings with AOSP's default cflags
- Don't assume that BIO_new_file() sets errno
- Other small cleanups

Eric Biggers (3):
Split up cmd_sign.c
Introduce libfsverity
Add some basic test programs for libfsverity

 .gitignore                                |  10 +-
 Makefile                                  | 191 ++++++-
 cmd_sign.c                                | 633 ----------------------
 commands.h                                |  24 -
 util.h => common/common_defs.h            |  47 +-
 fsverity_uapi.h => common/fsverity_uapi.h |   0
 common/libfsverity.h                      | 132 +++++
 hash_algs.h                               |  68 ---
 lib/compute_digest.c                      | 240 ++++++++
 hash_algs.c => lib/hash_algs.c            | 129 +++--
 lib/lib_private.h                         |  83 +++
 lib/sign_digest.c                         | 399 ++++++++++++++
 lib/utils.c                               | 109 ++++
 cmd_enable.c => programs/cmd_enable.c     |  32 +-
 cmd_measure.c => programs/cmd_measure.c   |  12 +-
 programs/cmd_sign.c                       | 163 ++++++
 fsverity.c => programs/fsverity.c         |  52 +-
 programs/fsverity.h                       |  43 ++
 programs/test_compute_digest.c            |  61 +++
 programs/test_hash_algs.c                 |  38 ++
 programs/test_sign_digest.c               |  50 ++
 util.c => programs/utils.c                |   7 +-
 programs/utils.h                          |  44 ++
 testdata/cert.pem                         |  31 ++
 testdata/file.sig                         | Bin 0 -> 708 bytes
 testdata/key.pem                          |  52 ++
 26 files changed, 1770 insertions(+), 880 deletions(-)
 delete mode 100644 cmd_sign.c
 delete mode 100644 commands.h
 rename util.h => common/common_defs.h (56%)
 rename fsverity_uapi.h => common/fsverity_uapi.h (100%)
 create mode 100644 common/libfsverity.h
 delete mode 100644 hash_algs.h
 create mode 100644 lib/compute_digest.c
 rename hash_algs.c => lib/hash_algs.c (53%)
 create mode 100644 lib/lib_private.h
 create mode 100644 lib/sign_digest.c
 create mode 100644 lib/utils.c
 rename cmd_enable.c => programs/cmd_enable.c (81%)
 rename cmd_measure.c => programs/cmd_measure.c (83%)
 create mode 100644 programs/cmd_sign.c
 rename fsverity.c => programs/fsverity.c (82%)
 create mode 100644 programs/fsverity.h
 create mode 100644 programs/test_compute_digest.c
 create mode 100644 programs/test_hash_algs.c
 create mode 100644 programs/test_sign_digest.c
 rename util.c => programs/utils.c (96%)
 create mode 100644 programs/utils.h
 create mode 100644 testdata/cert.pem
 create mode 100644 testdata/file.sig
 create mode 100644 testdata/key.pem
Signature · 1 line
2.26.2
author maintainer
#1 lore raw

PATCH v2 1/3 Split up cmd_sign.c

From: Eric Biggers <[email protected]>

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.

---
 Makefile             |   4 +-
 cmd_sign.c           | 481 +------------------------------------------
 lib/compute_digest.c | 184 +++++++++++++++++
 lib/sign_digest.c    | 304 +++++++++++++++++++++++++++
 sign.h               |  32 +++
 5 files changed, 523 insertions(+), 482 deletions(-)
 create mode 100644 lib/compute_digest.c
 create mode 100644 lib/sign_digest.c
 create mode 100644 sign.h
Makefile +2 -2
index b9c09b9..c3b14a3 100644
@@ -1,9 +1,9 @@
 EXE := fsverity
 CFLAGS := -O2 -Wall
-CPPFLAGS := -D_FILE_OFFSET_BITS=64
+CPPFLAGS := -D_FILE_OFFSET_BITS=64 -I.
 LDLIBS := -lcrypto
 DESTDIR := /usr/local
-SRC := $(wildcard *.c)
+SRC := $(wildcard *.c) $(wildcard lib/*.c)
 OBJ := $(SRC:.c=.o)
 HDRS := $(wildcard *.h)
 
cmd_sign.c +1 -480

499 lines not on this page · raw message

lib/compute_digest.c new file +184 -0

184 lines not on this page · raw message

lib/sign_digest.c new file +304 -0

304 lines not on this page · raw message

sign.h new file +32 -0
new file mode 100644
index 0000000..55c8be8
@@ -0,0 +1,32 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+#ifndef SIGN_H
+#define SIGN_H
+
+#include "hash_algs.h"
+
+#include <linux/types.h>
+
+/*
+ * Format in which verity file measurements are signed.  This is the same as
+ * 'struct fsverity_digest', except here some magic bytes are prepended to
+ * provide some context about what is being signed in case the same key is used
+ * for non-fsverity purposes, and here the fields have fixed endianness.
+ */
+struct fsverity_signed_digest {
+	char magic[8];			/* must be "FSVerity" */
+	__le16 digest_algorithm;
+	__le16 digest_size;
+	__u8 digest[];
+};
+
+bool compute_file_measurement(const char *filename,
+			      const struct fsverity_hash_alg *hash_alg,
+			      u32 block_size, const u8 *salt,
+			      u32 salt_size, u8 *measurement);
+
+bool sign_data(const void *data_to_sign, size_t data_size,
+	       const char *keyfile, const char *certfile,
+	       const struct fsverity_hash_alg *hash_alg,
+	       u8 **sig_ret, u32 *sig_size_ret);
+
+#endif /* SIGN_H */
Signature · 1 line
2.26.2
author maintainer
#2 lore raw

PATCH v2 2/3 Introduce libfsverity

In reply to Eric Biggers

From: Eric Biggers <[email protected]>

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 <[email protected]>. 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.)

---
 .gitignore                                |  10 +-
 Makefile                                  | 191 ++++++++++++++++++--
 commands.h                                |  24 ---
 util.h => common/common_defs.h            |  47 +----
 fsverity_uapi.h => common/fsverity_uapi.h |   0
 common/libfsverity.h                      | 132 ++++++++++++++
 hash_algs.h                               |  68 -------
 lib/compute_digest.c                      | 182 ++++++++++++-------
 hash_algs.c => lib/hash_algs.c            | 129 +++++++++-----
 lib/lib_private.h                         |  83 +++++++++
 lib/sign_digest.c                         | 205 ++++++++++++++++------
 lib/utils.c                               | 109 ++++++++++++
 cmd_enable.c => programs/cmd_enable.c     |  32 +---
 cmd_measure.c => programs/cmd_measure.c   |  12 +-
 cmd_sign.c => programs/cmd_sign.c         |  91 +++++-----
 fsverity.c => programs/fsverity.c         |  52 +++++-
 programs/fsverity.h                       |  43 +++++
 util.c => programs/utils.c                |   7 +-
 programs/utils.h                          |  44 +++++
 sign.h                                    |  32 ----
 20 files changed, 1055 insertions(+), 438 deletions(-)
 delete mode 100644 commands.h
 rename util.h => common/common_defs.h (56%)
 rename fsverity_uapi.h => common/fsverity_uapi.h (100%)
 create mode 100644 common/libfsverity.h
 delete mode 100644 hash_algs.h
 rename hash_algs.c => lib/hash_algs.c (53%)
 create mode 100644 lib/lib_private.h
 create mode 100644 lib/utils.c
 rename cmd_enable.c => programs/cmd_enable.c (81%)
 rename cmd_measure.c => programs/cmd_measure.c (83%)
 rename cmd_sign.c => programs/cmd_sign.c (53%)
 rename fsverity.c => programs/fsverity.c (82%)
 create mode 100644 programs/fsverity.h
 rename util.c => programs/utils.c (96%)
 create mode 100644 programs/utils.h
 delete mode 100644 sign.h
.gitignore +8 -2
index 95457ca..d3109a8 100644
@@ -1,5 +1,11 @@
-fsverity
+*.a
 *.o
-tags
+*.patch
+*.so
+*.so.*
+/.build-config
+/fsverity
+/test_*
 cscope.*
 ncscope.*
+tags
Makefile +176 -15

198 lines not on this page · raw message

commands.h deleted +0 -24
deleted file mode 100644
index d96f580..0000000
@@ -1,24 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0-or-later */
-#ifndef COMMANDS_H
-#define COMMANDS_H
-
-#include "util.h"
-
-#include <stdio.h>
-
-struct fsverity_command;
-
-void usage(const struct fsverity_command *cmd, FILE *fp);
-
-int fsverity_cmd_enable(const struct fsverity_command *cmd,
-			int argc, char *argv[]);
-int fsverity_cmd_measure(const struct fsverity_command *cmd,
-			 int argc, char *argv[]);
-int fsverity_cmd_sign(const struct fsverity_command *cmd,
-		      int argc, char *argv[]);
-
-bool parse_block_size_option(const char *arg, u32 *size_ptr);
-u32 get_default_block_size(void);
-bool parse_salt_option(const char *arg, u8 **salt_ptr, u32 *salt_size_ptr);
-
-#endif /* COMMANDS_H */
common/common_defs.h renamed from util.h +5 -42

61 lines not on this page · raw message

common/fsverity_uapi.h renamed from fsverity_uapi.h +0 -0
similarity index 100%
rename from fsverity_uapi.h
rename to common/fsverity_uapi.h
common/libfsverity.h new file +132 -0

132 lines not on this page · raw message

hash_algs.h deleted +0 -68

68 lines not on this page · raw message

lib/compute_digest.c +119 -63

259 lines not on this page · raw message

lib/hash_algs.c renamed from hash_algs.c +85 -44

199 lines not on this page · raw message

lib/lib_private.h new file +83 -0

83 lines not on this page · raw message

lib/sign_digest.c +150 -55

388 lines not on this page · raw message

lib/utils.c new file +109 -0

109 lines not on this page · raw message

programs/cmd_enable.c renamed from cmd_enable.c +1 -31
similarity index 81%
rename from cmd_enable.c
rename to programs/cmd_enable.c
index 38e7d65..f1c0806 100644
@@ -5,43 +5,13 @@
  * Copyright 2018 Google LLC
  */
 
-#include "commands.h"
-#include "fsverity_uapi.h"
-#include "hash_algs.h"
+#include "fsverity.h"
 
 #include <fcntl.h>
 #include <getopt.h>
 #include <limits.h>
-#include <stdlib.h>
-#include <string.h>
 #include <sys/ioctl.h>
 
-static bool parse_hash_alg_option(const char *arg, u32 *alg_ptr)
-{
-	char *end;
-	unsigned long n = strtoul(arg, &end, 10);
-	const struct fsverity_hash_alg *alg;
-
-	if (*alg_ptr != 0) {
-		error_msg("--hash-alg can only be specified once");
-		return false;
-	}
-
-	/* Specified by number? */
-	if (n > 0 && n < INT32_MAX && *end == '\0') {
-		*alg_ptr = n;
-		return true;
-	}
-
-	/* Specified by name? */
-	alg = find_hash_alg_by_name(arg);
-	if (alg != NULL) {
-		*alg_ptr = alg - fsverity_hash_algs;
-		return true;
-	}
-	return false;
-}
-
 static bool read_signature(const char *filename, u8 **sig_ret,
 			   u32 *sig_size_ret)
 {
programs/cmd_measure.c renamed from cmd_measure.c +3 -9
similarity index 83%
rename from cmd_measure.c
rename to programs/cmd_measure.c
index 1b2fc7b..4e6cb2b 100644
@@ -5,12 +5,9 @@
  * Copyright 2018 Google LLC
  */
 
-#include "commands.h"
-#include "fsverity_uapi.h"
-#include "hash_algs.h"
+#include "fsverity.h"
 
 #include <fcntl.h>
-#include <stdlib.h>
 #include <sys/ioctl.h>
 
 /* Display the measurement of the given verity file(s). */
@@ -20,7 +17,6 @@ int fsverity_cmd_measure(const struct fsverity_command *cmd,
 	struct fsverity_digest *d = NULL;
 	struct filedes file;
 	char digest_hex[FS_VERITY_MAX_DIGEST_SIZE * 2 + 1];
-	const struct fsverity_hash_alg *hash_alg;
 	char _hash_alg_name[32];
 	const char *hash_alg_name;
 	int status;
@@ -46,10 +42,8 @@ int fsverity_cmd_measure(const struct fsverity_command *cmd,
 
 		ASSERT(d->digest_size <= FS_VERITY_MAX_DIGEST_SIZE);
 		bin2hex(d->digest, d->digest_size, digest_hex);
-		hash_alg = find_hash_alg_by_num(d->digest_algorithm);
-		if (hash_alg) {
-			hash_alg_name = hash_alg->name;
-		} else {
+		hash_alg_name = libfsverity_get_hash_name(d->digest_algorithm);
+		if (!hash_alg_name) {
 			sprintf(_hash_alg_name, "ALG_%u", d->digest_algorithm);
 			hash_alg_name = _hash_alg_name;
 		}
programs/cmd_sign.c renamed from cmd_sign.c +50 -41

159 lines not on this page · raw message

programs/fsverity.c renamed from fsverity.c +45 -7

89 lines not on this page · raw message

programs/fsverity.h new file +43 -0

43 lines not on this page · raw message

programs/utils.c renamed from util.c +2 -5
similarity index 96%
rename from util.c
rename to programs/utils.c
index fcab635..02b6dab 100644
@@ -5,15 +5,12 @@
  * Copyright 2018 Google LLC
  */
 
-#include "util.h"
+#include "utils.h"
 
 #include <errno.h>
 #include <fcntl.h>
 #include <limits.h>
 #include <stdarg.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
 #include <sys/stat.h>
 #include <unistd.h>
 
@@ -45,7 +42,7 @@ char *xstrdup(const char *s)
 
 /* ========== Error messages and assertions ========== */
 
-void do_error_msg(const char *format, va_list va, int err)
+static void do_error_msg(const char *format, va_list va, int err)
 {
 	fputs("ERROR: ", stderr);
 	vfprintf(stderr, format, va);
programs/utils.h new file +44 -0

44 lines not on this page · raw message

sign.h deleted +0 -32
deleted file mode 100644
index 55c8be8..0000000
@@ -1,32 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0-or-later */
-#ifndef SIGN_H
-#define SIGN_H
-
-#include "hash_algs.h"
-
-#include <linux/types.h>
-
-/*
- * Format in which verity file measurements are signed.  This is the same as
- * 'struct fsverity_digest', except here some magic bytes are prepended to
- * provide some context about what is being signed in case the same key is used
- * for non-fsverity purposes, and here the fields have fixed endianness.
- */
-struct fsverity_signed_digest {
-	char magic[8];			/* must be "FSVerity" */
-	__le16 digest_algorithm;
-	__le16 digest_size;
-	__u8 digest[];
-};
-
-bool compute_file_measurement(const char *filename,
-			      const struct fsverity_hash_alg *hash_alg,
-			      u32 block_size, const u8 *salt,
-			      u32 salt_size, u8 *measurement);
-
-bool sign_data(const void *data_to_sign, size_t data_size,
-	       const char *keyfile, const char *certfile,
-	       const struct fsverity_hash_alg *hash_alg,
-	       u8 **sig_ret, u32 *sig_size_ret);
-
-#endif /* SIGN_H */
Signature · 1 line
2.26.2
author maintainer
#3 lore raw

PATCH v2 3/3 Add some basic test programs for libfsverity

In reply to Eric Biggers

From: Eric Biggers <[email protected]>

Add three test programs: 'test_hash_algs', 'test_compute_digest', and 'test_sign_digest'. Nothing fancy yet, just some basic tests to test each library function.

With the new Makefile, these get run by 'make check'.

---
 programs/test_compute_digest.c |  61 +++++++++++++++++++++++++++++++++
 programs/test_hash_algs.c      |  38 ++++++++++++++++++++
 programs/test_sign_digest.c    |  50 +++++++++++++++++++++++++++
 testdata/cert.pem              |  31 +++++++++++++++++
 testdata/file.sig              | Bin 0 -> 708 bytes
 testdata/key.pem               |  52 ++++++++++++++++++++++++++++
 6 files changed, 232 insertions(+)
 create mode 100644 programs/test_compute_digest.c
 create mode 100644 programs/test_hash_algs.c
 create mode 100644 programs/test_sign_digest.c
 create mode 100644 testdata/cert.pem
 create mode 100644 testdata/file.sig
 create mode 100644 testdata/key.pem
programs/test_compute_digest.c new file +61 -0
new file mode 100644
index 0000000..fab64a4
@@ -0,0 +1,61 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Test libfsverity_compute_digest().
+ *
+ * Copyright 2020 Google LLC
+ */
+#include "utils.h"
+
+#define SHA256_DIGEST_SIZE 32
+
+struct mem_file {
+	u8 *data;
+	size_t size;
+	size_t offset;
+};
+
+static int read_fn(void *fd, void *buf, size_t count)
+{
+	struct mem_file *f = fd;
+
+	ASSERT(count <= f->size - f->offset);
+	memcpy(buf, &f->data[f->offset], count);
+	f->offset += count;
+	return 0;
+}
+
+int main(void)
+{
+	struct mem_file f = { .size = 1000000 };
+	size_t i;
+	const struct libfsverity_merkle_tree_params params = {
+		.version = 1,
+		.hash_algorithm = FS_VERITY_HASH_ALG_SHA256,
+		.block_size = 4096,
+		.salt_size = 4,
+		.salt = (u8 *)"abcd",
+		.file_size = f.size,
+	};
+	struct libfsverity_digest *d;
+	static const u8 expected_digest[SHA256_DIGEST_SIZE] =
+		"\x91\x79\x00\xb0\xd2\x99\x45\x4a\xa3\x04\xd5\xde\xbc\x6f\x39"
+		"\xe4\xaf\x7b\x5a\xbe\x33\xbd\xbc\x56\x8d\x5d\x8f\x1e\x5c\x4d"
+		"\x86\x52";
+	int err;
+
+	f.data = xmalloc(f.size);
+	for (i = 0; i < f.size; i++)
+		f.data[i] = (i % 11) + (i % 439) + (i % 1103);
+
+	err = libfsverity_compute_digest(&f, read_fn, &params, &d);
+	ASSERT(err == 0);
+
+	ASSERT(d->digest_algorithm == FS_VERITY_HASH_ALG_SHA256);
+	ASSERT(d->digest_size == SHA256_DIGEST_SIZE);
+	ASSERT(!memcmp(d->digest, expected_digest, SHA256_DIGEST_SIZE));
+
+	free(f.data);
+	free(d);
+	printf("test_compute_digest passed\n");
+	return 0;
+}
programs/test_hash_algs.c new file +38 -0
new file mode 100644
index 0000000..80d7a07
@@ -0,0 +1,38 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Test the hash algorithm-related libfsverity APIs.
+ *
+ * Copyright 2020 Google LLC
+ */
+#include "utils.h"
+
+#define SHA256_DIGEST_SIZE 32
+#define SHA512_DIGEST_SIZE 64
+
+int main(void)
+{
+	ASSERT(libfsverity_get_digest_size(0) == -1);
+	ASSERT(libfsverity_get_hash_name(0) == NULL);
+	ASSERT(libfsverity_find_hash_alg_by_name("bad") == 0);
+	ASSERT(libfsverity_find_hash_alg_by_name(NULL) == 0);
+
+	ASSERT(libfsverity_get_digest_size(100) == -1);
+	ASSERT(libfsverity_get_hash_name(100) == NULL);
+
+	ASSERT(libfsverity_get_digest_size(FS_VERITY_HASH_ALG_SHA256) ==
+	       SHA256_DIGEST_SIZE);
+	ASSERT(!strcmp("sha256",
+		       libfsverity_get_hash_name(FS_VERITY_HASH_ALG_SHA256)));
+	ASSERT(libfsverity_find_hash_alg_by_name("sha256") ==
+	       FS_VERITY_HASH_ALG_SHA256);
+
+	ASSERT(libfsverity_get_digest_size(FS_VERITY_HASH_ALG_SHA512) ==
+	       SHA512_DIGEST_SIZE);
+	ASSERT(!strcmp("sha512",
+		       libfsverity_get_hash_name(FS_VERITY_HASH_ALG_SHA512)));
+	ASSERT(libfsverity_find_hash_alg_by_name("sha512") ==
+	       FS_VERITY_HASH_ALG_SHA512);
+
+	printf("test_hash_algs passed\n");
+	return 0;
+}
programs/test_sign_digest.c new file +50 -0

50 lines not on this page · raw message

testdata/cert.pem new file +31 -0
new file mode 100644
index 0000000..c63b965
@@ -0,0 +1,31 @@
+-----BEGIN CERTIFICATE-----
+MIIFazCCA1OgAwIBAgIUYaRYcyZGDIv9fIxx/RoJwQu23+owDQYJKoZIhvcNAQEL
+BQAwRTELMAkGA1UEBhMCQVUxEzARBgNVBAgMClNvbWUtU3RhdGUxITAfBgNVBAoM
+GEludGVybmV0IFdpZGdpdHMgUHR5IEx0ZDAeFw0yMDA1MTUwMjUyMzFaFw0yMDA2
+MTQwMjUyMzFaMEUxCzAJBgNVBAYTAkFVMRMwEQYDVQQIDApTb21lLVN0YXRlMSEw
+HwYDVQQKDBhJbnRlcm5ldCBXaWRnaXRzIFB0eSBMdGQwggIiMA0GCSqGSIb3DQEB
+AQUAA4ICDwAwggIKAoICAQC5lXk9otBz/VM/tbvBBK6sK//HE+q3ctY4+fPVv3Ob
+D1YNYuWRD59U+7K8fVUfZlXyjgxt3n4VPzkLgRSr/w5YUTa5NEOVJIltKT4ugswL
+5oY8eRVSuIr1O+vTbu+EpUk3DhTaFkalVzwspwipBeiVTDO9kh0NAueRk2HyLJte
+IoPyfzSCKxg9sED6/WtLFqrhDb5+1qeGoMNGM66ueWXKX0QjomMEODGXC04ypIY3
+sTwB+sYhZUe3YRpY0HyaVNh/6cxCxSiKr2jkC5UL+ry+46EJerNZbKmeqqyqmhXh
+P2cHv8MO91zdH1xbXUUenLcdpK/0oq+/sTAVV1/qPvnAofpN8tdZdrH65JD753jt
+s+lH/f0iGuKAb9ZpLOTM2d3wjY13OcHElj0zu2Usw9PXQpTK/DYlbcapOI4NTVyU
+NpK3yP4i5dPnkHoxpjLWz75Eq6gP9ZXohGq3YG0LxtvELWfaFmpzEUTlD59hJJOZ
+ELGxAXzsxLbelX/EmpX+GIqnFBpdMIuPO4HEfJwD5IcdeHqGl2iH9LIqsY5DcGj4
+hnqYplIYYk5mWgbhkexRbJIGNdn8WyXlraVp2MoSr3p7xJbmo0qYRRtt3kQShzDG
+0FrZX7wqxemc/g/hr+g2xqMQj0nYLehDeodqxA2n9grDUr4AdgQyxXDMUkGZdrg3
+cwIDAQABo1MwUTAdBgNVHQ4EFgQUxpaj6YjgLFyh9UVM71hf18cb/hkwHwYDVR0j
+BBgwFoAUxpaj6YjgLFyh9UVM71hf18cb/hkwDwYDVR0TAQH/BAUwAwEB/zANBgkq
+hkiG9w0BAQsFAAOCAgEAQnXMCgI+eSjK+l3nrpE+TRrXZhHeB0aT3gilVtBqFM95
+GxkLzOgJnW4SU+BCKTiGjwhCEXQiFj6UNDrI7vaNzmurI370uqmC9/pwKn4/L27V
+ToqLHk5d8kmvjSJyfgY/9H73srzHjNcqLG3uy+JP3/fIzaUzy7x9OUJtzdH19zic
+b61kCbqe6TJrlpL0Y50FY91QTzupsIS9IsAAeYXrJiEwpkXv/O9c51swtGZmQhVD
+TDn4B2aKOHecR+gKZQbPcuwTCbNLDRRPT4q0IM9yKjUxIM8vkAaxlrW3O7fgqUV0
+GU3/i0zZugq2XEludF3VelrqMUhSMqaREAtRUe3ufipwEsovDa43Hr9P6bINAfU3
+92Kv6adgeKZc4DmuEg6sFje/ET85teioHtwmjviJu6vnkbZg7x+IU01Y6YHboz/z
+hTAjz9g6owgdsbTG9nptvgJllY83zBtnAGOqhJLNVZ+TC3pbbKht/7sT+s+WP2+K
+81oZ3gmxIr6myMVyR5CCt+FNJ1hFxYNBJDao35iiZLxDe2s5nMJKHYezUY60ujqT
+Ljv3Ku4uAk5PgXltZnWGz152ntjopA0gbnlU4f+SgnmPoBFcvn36BcUQWQbTDqmh
+h+Y0OaXR3x/27M/qkPBov4IAfoCkWeF7i02wxwtdTLiSF7OjTDkQXtZemUzN5+w=
+-----END CERTIFICATE-----
testdata/file.sig new file binary +0 -0
new file mode 100644
index 0000000000000000000000000000000000000000..1ba61f8c939c8d2616953f4ac8681f9f5988cd0c
GIT binary patch
testdata/key.pem new file +52 -0

52 lines not on this page · raw message

Signature · 1 line
2.26.2
#4 lore raw
In reply to Eric Biggers
Quoted 22 lines · Eric Biggers

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 <[email protected]>. I made a lot of improvements; see patch 2 for details.

This patchset can also be found at branch "libfsverity" of
https://git.kernel.org/pub/scm/linux/kernel/git/ebiggers/fsverity-utils.git/

Changes v1 => v2:
- Fold in the Makefile fixes from Jes
- Rename libfsverity_digest_size() and libfsverity_hash_name()
- Improve the documentation slightly
- If a memory allocation fails, print the allocation size
- Use EBADMSG for invalid cert or keyfile, not EINVAL
- Make libfsverity_find_hash_alg_by_name() handle NULL
- Avoid introducing compiler warnings with AOSP's default cflags
- Don't assume that BIO_new_file() sets errno
- Other small cleanups

Quoted 4 lines

Eric Biggers (3):
Split up cmd_sign.c
Introduce libfsverity
Add some basic test programs for libfsverity

Hi Eric,

Assuming you didn't make any big changes since the previous rev. I have tested this here, and I can build an fsverity-utils RPM from it, and build my RPM support with this version, so looks all good from my side.

One feature I would like to have, and this is what I confused in my previous comments. In addition to a get_digset_size() function, it would be really useful to also have a get_signature_size() function. This would be really useful when trying to pre-allocate space for an array of signatures, or is there no way to get that info from openssl without creating an actual signature?

Cheers,
Jes

author maintainer
#5 lore raw
Quoted 8 lines · Jes Sorensen

One feature I would like to have, and this is what I confused in my previous comments. In addition to a get_digset_size() function, it would be really useful to also have a get_signature_size() function. This would be really useful when trying to pre-allocate space for an array of signatures, or is there no way to get that info from openssl without creating an actual signature?

I don't think that's possible.

It's also not fixed for each hash algorithm, but rather it depends on the key and certificate used.

- Eric

author maintainer
#6 lore raw
In reply to Eric Biggers
Quoted 22 lines · Eric Biggers

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 <[email protected]>. I made a lot of improvements; see patch 2 for details.

This patchset can also be found at branch "libfsverity" of
https://git.kernel.org/pub/scm/linux/kernel/git/ebiggers/fsverity-utils.git/

Changes v1 => v2:
- Fold in the Makefile fixes from Jes
- Rename libfsverity_digest_size() and libfsverity_hash_name()
- Improve the documentation slightly
- If a memory allocation fails, print the allocation size
- Use EBADMSG for invalid cert or keyfile, not EINVAL
- Make libfsverity_find_hash_alg_by_name() handle NULL
- Avoid introducing compiler warnings with AOSP's default cflags
- Don't assume that BIO_new_file() sets errno
- Other small cleanups

Quoted 5 lines

Eric Biggers (3):
Split up cmd_sign.c
Introduce libfsverity
Add some basic test programs for libfsverity

Applied and pushed out to the 'master' branch.

- Eric

#7 lore raw
Quoted 23 lines · Eric Biggers
Quoted 22 lines · Eric Biggers

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 <[email protected]>. I made a lot of improvements; see patch 2 for details.

This patchset can also be found at branch "libfsverity" of
https://git.kernel.org/pub/scm/linux/kernel/git/ebiggers/fsverity-utils.git/

Changes v1 => v2:
- Fold in the Makefile fixes from Jes
- Rename libfsverity_digest_size() and libfsverity_hash_name()
- Improve the documentation slightly
- If a memory allocation fails, print the allocation size
- Use EBADMSG for invalid cert or keyfile, not EINVAL
- Make libfsverity_find_hash_alg_by_name() handle NULL
- Avoid introducing compiler warnings with AOSP's default cflags
- Don't assume that BIO_new_file() sets errno
- Other small cleanups

Quoted 7 lines
Quoted 5 lines

Eric Biggers (3):
Split up cmd_sign.c
Introduce libfsverity
Add some basic test programs for libfsverity

Applied and pushed out to the 'master' branch.

Awesome, any idea when you'll be able to tag a new official release?

Thanks,
Jes

#8 lore raw
Quoted 30 lines · Jes Sorensen
Quoted 29 lines · Eric Biggers
Quoted 27 lines · Eric Biggers

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 <[email protected]>. I made a lot of improvements; see patch 2 for details.

This patchset can also be found at branch "libfsverity" of
https://git.kernel.org/pub/scm/linux/kernel/git/ebiggers/fsverity-utils.git/

Changes v1 => v2:
- Fold in the Makefile fixes from Jes
- Rename libfsverity_digest_size() and libfsverity_hash_name()
- Improve the documentation slightly
- If a memory allocation fails, print the allocation size
- Use EBADMSG for invalid cert or keyfile, not EINVAL
- Make libfsverity_find_hash_alg_by_name() handle NULL
- Avoid introducing compiler warnings with AOSP's default cflags
- Don't assume that BIO_new_file() sets errno
- Other small cleanups

Eric Biggers (3):
Split up cmd_sign.c
Introduce libfsverity
Add some basic test programs for libfsverity

Quoted 3 lines
Quoted 1 line

Applied and pushed out to the 'master' branch.

Awesome, any idea when you'll be able to tag a new official release?

Hi Eric,

Ping, anything holding up the release at this point?

Sorry for nagging, I would really like to push an updated version to Rawhide that can be distributed as a prerequisite for the RPM changes.

Thanks,
Jes

author maintainer
#9 lore raw
Quoted 33 lines · Jes Sorensen
Quoted 32 lines · Jes Sorensen
Quoted 30 lines · Eric Biggers
Quoted 22 lines · Eric Biggers

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 <[email protected]>. I made a lot of improvements; see patch 2 for details.

This patchset can also be found at branch "libfsverity" of
https://git.kernel.org/pub/scm/linux/kernel/git/ebiggers/fsverity-utils.git/

Changes v1 => v2:
- Fold in the Makefile fixes from Jes
- Rename libfsverity_digest_size() and libfsverity_hash_name()
- Improve the documentation slightly
- If a memory allocation fails, print the allocation size
- Use EBADMSG for invalid cert or keyfile, not EINVAL
- Make libfsverity_find_hash_alg_by_name() handle NULL
- Avoid introducing compiler warnings with AOSP's default cflags
- Don't assume that BIO_new_file() sets errno
- Other small cleanups

Quoted 5 lines

Eric Biggers (3):
Split up cmd_sign.c
Introduce libfsverity
Add some basic test programs for libfsverity

Applied and pushed out to the 'master' branch.

Quoted 9 lines
Quoted 1 line

Awesome, any idea when you'll be able to tag a new official release?

Hi Eric,

Ping, anything holding up the release at this point?

Sorry for nagging, I would really like to push an updated version to Rawhide that can be distributed as a prerequisite for the RPM changes.

I might do it this weekend, but I've been working on a test script and some other improvements first.

Also, please feel free to contribute more test programs or extend the existing ones. We could use more test coverage of the library.

- Eric