Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1nC0VY-0001ZR-IH for mharc-grub-devel@gnu.org; Mon, 24 Jan 2022 09:39:48 -0500 Received: from eggs.gnu.org ([209.51.188.92]:40494) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nC058-0003Pm-QV for grub-devel@gnu.org; Mon, 24 Jan 2022 09:12:30 -0500 Received: from linux.microsoft.com ([13.77.154.182]:40426) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nC054-0004CP-MR for grub-devel@gnu.org; Mon, 24 Jan 2022 09:12:30 -0500 Received: from linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net (linux.microsoft.com [13.77.154.182]) by linux.microsoft.com (Postfix) with ESMTPSA id CB16A20B8013 for ; Mon, 24 Jan 2022 06:12:24 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com CB16A20B8013 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1643033544; bh=Kb9WbDC9SOmYMp3siUSmdqLinwcdtfZcPuUZc+S5UUI=; h=From:To:Subject:Date:In-Reply-To:References:From; b=jVWHSfeY7Vgk5ZlfXZvrxuMnaWU/yZYaJxvfHmLiWeC1qHDj8eUumd/Vic3PeR1ip BBlGop9IDkt806JALcRykYLwws42zvf3ShwiWWVngzn8sxTTcDVH1y8pu1Yt7c3Mep QdiLkNgq8xyEkQvBbxqQGGpMQagxL+dcwBA4pBZY= From: Hernan Gatta To: grub-devel@gnu.org Subject: [PATCH 4/5] cryptodisk: Support key protectors Date: Mon, 24 Jan 2022 06:12:17 -0800 Message-Id: <1643033538-19024-5-git-send-email-hegatta@linux.microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1643033538-19024-1-git-send-email-hegatta@linux.microsoft.com> References: <1643033538-19024-1-git-send-email-hegatta@linux.microsoft.com> Received-SPF: pass client-ip=13.77.154.182; envelope-from=hegatta@linux.microsoft.com; helo=linux.microsoft.com X-Spam_score_int: -197 X-Spam_score: -19.8 X-Spam_bar: ------------------- X-Spam_report: (-19.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, ENV_AND_HDR_SPF_MATCH=-0.5, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, USER_IN_DEF_DKIM_WL=-7.5, USER_IN_DEF_SPF_WL=-7.5 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Mon, 24 Jan 2022 09:39:47 -0500 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 24 Jan 2022 14:12:31 -0000 From: Hernan Gatta Add a new parameter to cryptomount to support the key protectors framework: -k. This parameter is accepted whenever the cryptomount command is used to mount a specific disk either via a disk specification (e.g., (hd0,gpt1)) or by UUID, but not when disks are mounted in bulk (i.e., via -a or -b). The parameter is used to automatically retrieve a key from the specified key protector. Signed-off-by: --- Makefile.util.def | 1 + grub-core/disk/cryptodisk.c | 21 ++++++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/Makefile.util.def b/Makefile.util.def index f8b356c..39b53b3 100644 --- a/Makefile.util.def +++ b/Makefile.util.def @@ -35,6 +35,7 @@ library = { common = grub-core/kern/list.c; common = grub-core/kern/misc.c; common = grub-core/kern/partition.c; + common = grub-core/kern/protectors.c; common = grub-core/lib/crypto.c; common = grub-core/lib/json/json.c; common = grub-core/disk/luks.c; diff --git a/grub-core/disk/cryptodisk.c b/grub-core/disk/cryptodisk.c index 4970973..176dd56 100644 --- a/grub-core/disk/cryptodisk.c +++ b/grub-core/disk/cryptodisk.c @@ -26,6 +26,7 @@ #include #include #include +#include #ifdef GRUB_UTIL #include @@ -42,6 +43,7 @@ static const struct grub_arg_option options[] = {"all", 'a', 0, N_("Mount all."), 0, 0}, {"boot", 'b', 0, N_("Mount all volumes with `boot' flag set."), 0, 0}, {"password", 'p', 0, N_("Password to open volumes."), 0, ARG_TYPE_STRING}, + {"protector", 'k', 0, N_("Unlock disk using the specified key protector."), 0, ARG_TYPE_STRING}, {0, 0, 0, 0, 0, 0} }; @@ -1160,6 +1162,7 @@ grub_cmd_cryptomount (grub_extcmd_context_t ctxt, int argc, char **args) { struct grub_arg_list *state = ctxt->state; struct grub_cryptomount_args cargs = {0}; + grub_err_t err; if (argc < 1 && !state[1].set && !state[2].set) return grub_error (GRUB_ERR_BAD_ARGUMENT, "device name required"); @@ -1167,12 +1170,28 @@ grub_cmd_cryptomount (grub_extcmd_context_t ctxt, int argc, char **args) if (grub_cryptodisk_list == NULL) return grub_error (GRUB_ERR_BAD_MODULE, "no cryptodisk modules loaded"); + if (state[3].set && state[4].set) /* password and key protector */ + return grub_error (GRUB_ERR_BAD_ARGUMENT, + "a password and a key protector cannot both be set"); + + if (state[4].set && argc < 1) /* key protector */ + return grub_error (GRUB_ERR_BAD_ARGUMENT, + "key protectors require a device name or UUID"); + if (state[3].set) /* password */ { cargs.key_data = (grub_uint8_t *) state[3].arg; cargs.key_len = grub_strlen (state[3].arg); } + if (state[4].set) /* key protector */ + { + err = grub_key_protector_recover_key (state[4].arg, &cargs.key_data, + &cargs.key_len); + if (err) + grub_printf_ (N_("Could not recover key from key protector.\n")); + } + if (state[0].set) /* uuid */ { int found_uuid; @@ -1385,7 +1404,7 @@ GRUB_MOD_INIT (cryptodisk) { grub_disk_dev_register (&grub_cryptodisk_dev); cmd = grub_register_extcmd ("cryptomount", grub_cmd_cryptomount, 0, - N_("[-p password] "), + N_("[-p password] [-k protector[:args]] "), N_("Mount a crypto device."), options); grub_procfs_register ("luks_script", &luks_script); } -- 1.8.3.1