From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D383BC433E0 for ; Fri, 15 Jan 2021 18:30:29 +0000 (UTC) Received: from lists.sourceforge.net (lists.sourceforge.net [216.105.38.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 9319723A9C; Fri, 15 Jan 2021 18:30:29 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9319723A9C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=linux-f2fs-devel-bounces@lists.sourceforge.net Received: from [127.0.0.1] (helo=sfs-ml-1.v29.lw.sourceforge.com) by sfs-ml-1.v29.lw.sourceforge.com with esmtp (Exim 4.90_1) (envelope-from ) id 1l0Trg-0005QU-BS; Fri, 15 Jan 2021 18:30:28 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-1.v29.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l0Trf-0005QE-IV for linux-f2fs-devel@lists.sourceforge.net; Fri, 15 Jan 2021 18:30:27 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=J1+IlV+unHHEqbbLStNxswQ0Zurf8oJp/kBe1W+rdik=; b=Ndog3VKZnln+Zt9AJQJcHNJ/YR Qqg1xyI9NNHLoN1Yln9ffS8bOS6ZUGJAolSR3yA8RXZScqd411PL4NryibVv3l5QNgrwwOK6Tvu83 sMhzmhp5wQLLLinWn9DihUayz1B2AX5QnacCEgAHooZ4ucDLr/l2fCb9K4+mN6gQ9D4E=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=J1+IlV+unHHEqbbLStNxswQ0Zurf8oJp/kBe1W+rdik=; b=OAb38phLMpGf5IXWjjZ4M6Zq32 nk2UPI1vZ5m3hyn5Gh/prlBM+nVbsz8/XdlFopiDLbgX8z3ft8BzwCBZGZH88aSTSmioXFmbdvmd0 T5D4n2GAoikKJ/gu1G5T1gIaziCsB6JdDcJwv+NgpNxhMxqB0PP8RhT836QP7sfxxJDI=; Received: from mail.kernel.org ([198.145.29.99]) by sfi-mx-3.v28.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.92.2) id 1l0Trd-005QcV-Hc for linux-f2fs-devel@lists.sourceforge.net; Fri, 15 Jan 2021 18:30:27 +0000 Received: by mail.kernel.org (Postfix) with ESMTPSA id E6BF823A59; Fri, 15 Jan 2021 18:30:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1610735420; bh=TyRLY9HOrw4FJ9cPyh5lToCNCoiKY1YY9L+hh8t7VKw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nqQdPkPoV2mj5m0otY41WNCWvsiLgZz7MBYQpxNhHdCJoOO6mD7OqYW5GvM/RqWmE cPoDBYi7yrsycvgzC2ZIj1m+7nOfcIwWvi/i/6HGElGqpkJVj5TkxLMyBk73Lx3DO1 5iwLuXxxRzGa7JH1w/u7/XOS+OekMO3SEXuf/Pe8zo1KO4bBCcV91go6K/x8Xovgli gBaXkB3RzvCG1IAzfOmk3gGft3hC+9fPsouRQK1d4onid+y2fMorlpyA11LpB1PZMq n6N74gjuxMhWtw9MOPU4O4uAwFNL6w225KknoAKE26qtLju9ltei1A+liSWdsVl/Wg nV9CaMSg2poZw== From: Eric Biggers To: fstests@vger.kernel.org Date: Fri, 15 Jan 2021 10:28:34 -0800 Message-Id: <20210115182837.36333-2-ebiggers@kernel.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210115182837.36333-1-ebiggers@kernel.org> References: <20210115182837.36333-1-ebiggers@kernel.org> MIME-Version: 1.0 X-Headers-End: 1l0Trd-005QcV-Hc Subject: [f2fs-dev] [xfstests RFC PATCH 1/4] generic: factor out helpers for fs-verity built-in signatures X-BeenThere: linux-f2fs-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Theodore Ts'o , linux-f2fs-devel@lists.sourceforge.net, linux-fscrypt@vger.kernel.org, Jaegeuk Kim , linux-ext4@vger.kernel.org, Victor Hsieh Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net From: Eric Biggers The test for retrieving a verity file's built-in signature using FS_IOC_READ_VERITY_METADATA will need to set up a file with a built-in signature, which requires the same commands that generic/577 does. Factor this out into helper functions in common/verity. Signed-off-by: Eric Biggers --- common/verity | 37 ++++++++++++++++++++++++++++++++++++- tests/generic/577 | 15 +++------------ 2 files changed, 39 insertions(+), 13 deletions(-) diff --git a/common/verity b/common/verity index a8d3de06..9a182240 100644 --- a/common/verity +++ b/common/verity @@ -48,12 +48,47 @@ _require_scratch_verity() FSV_BLOCK_SIZE=$(get_page_size) } -# Check for CONFIG_FS_VERITY_BUILTIN_SIGNATURES=y. +# Check for CONFIG_FS_VERITY_BUILTIN_SIGNATURES=y, as well as the userspace +# commands needed to generate certificates and add them to the kernel. _require_fsverity_builtin_signatures() { if [ ! -e /proc/sys/fs/verity/require_signatures ]; then _notrun "kernel doesn't support fs-verity builtin signatures" fi + _require_command "$OPENSSL_PROG" openssl + _require_command "$KEYCTL_PROG" keyctl +} + +# Use the openssl program to generate a private key and a X.509 certificate for +# use with fs-verity built-in signature verification, and convert the +# certificate to DER format. +_fsv_generate_cert() +{ + local keyfile=$1 + local certfile=$2 + local certfileder=$3 + + if ! $OPENSSL_PROG req -newkey rsa:4096 -nodes -batch -x509 \ + -keyout $keyfile -out $certfile &>> $seqres.full; then + _fail "Failed to generate certificate and private key (see $seqres.full)" + fi + $OPENSSL_PROG x509 -in $certfile -out $certfileder -outform der +} + +# Clear the .fs-verity keyring. +_fsv_clear_keyring() +{ + $KEYCTL_PROG clear %keyring:.fs-verity +} + +# Load the given X.509 certificate in DER format into the .fs-verity keyring so +# that the kernel can use it to verify built-in signatures. +_fsv_load_cert() +{ + local certfileder=$1 + + $KEYCTL_PROG padd asymmetric '' %keyring:.fs-verity \ + < $certfileder >> $seqres.full } # Disable mandatory signatures for fs-verity files, if they are supported. diff --git a/tests/generic/577 b/tests/generic/577 index 0e945942..114463be 100755 --- a/tests/generic/577 +++ b/tests/generic/577 @@ -34,8 +34,6 @@ rm -f $seqres.full _supported_fs generic _require_scratch_verity _require_fsverity_builtin_signatures -_require_command "$OPENSSL_PROG" openssl -_require_command "$KEYCTL_PROG" keyctl _scratch_mkfs_verity &>> $seqres.full _scratch_mount @@ -53,21 +51,14 @@ othersigfile=$tmp.othersig echo -e "\n# Generating certificates and private keys" for suffix in '' '.2'; do - if ! $OPENSSL_PROG req -newkey rsa:4096 -nodes -batch -x509 \ - -keyout $keyfile$suffix -out $certfile$suffix \ - &>> $seqres.full; then - _fail "Failed to generate certificate and private key (see $seqres.full)" - fi - $OPENSSL_PROG x509 -in $certfile$suffix -out $certfileder$suffix \ - -outform der + _fsv_generate_cert $keyfile$suffix $certfile$suffix $certfileder$suffix done echo -e "\n# Clearing fs-verity keyring" -$KEYCTL_PROG clear %keyring:.fs-verity +_fsv_clear_keyring echo -e "\n# Loading first certificate into fs-verity keyring" -$KEYCTL_PROG padd asymmetric '' %keyring:.fs-verity \ - < $certfileder >> $seqres.full +_fsv_load_cert $certfileder echo -e "\n# Enabling fs.verity.require_signatures" _enable_fsverity_signatures -- 2.30.0 _______________________________________________ Linux-f2fs-devel mailing list Linux-f2fs-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel