From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1klEmI-0000X5-Bw for mharc-grub-devel@gnu.org; Fri, 04 Dec 2020 12:22:01 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:40008) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1klEhm-0008NJ-8y for grub-devel@gnu.org; Fri, 04 Dec 2020 12:17:33 -0500 Received: from mail-il1-x144.google.com ([2607:f8b0:4864:20::144]:46465) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1klEfK-0008Er-JW for grub-devel@gnu.org; Fri, 04 Dec 2020 12:16:45 -0500 Received: by mail-il1-x144.google.com with SMTP id b8so5823895ila.13 for ; Fri, 04 Dec 2020 09:13:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=efficientek-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=RMMDprkvs1Hl/JFbDXc7df/t+rGE8qnAHfhZdkTMvJM=; b=RjraaGqI4Rofnm2mJfs6NSavlrF6KlPUdHK3CYTMTYgpQf9Q2LioJaKSkI+AQ+CTYU JPBAmFoKIYN7HlJ5sTf48/jwRdWGK+YSJJofNTzG9PvlTeYwjclpcfGc9JCutAB6lZNa FAtacxaHQ2UIeELfaACxRKSt7ssyhwoDVJJ/dKfm2N8fnv+5SH581GofTu/kGV4QnF76 i78+VsB1MByoYG4gx93GxFJ++wWEqUbCevk4GRBTACNwSpoY4LoOcVRv745IBjF0lE/r hWhVrH64RM6iA+/7n1H98ImvhizKsAYOuX4vErMGO1HHo3yEVtXROJYzTcFRRzbae4rl 8ngw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=RMMDprkvs1Hl/JFbDXc7df/t+rGE8qnAHfhZdkTMvJM=; b=QC38UBuaTqIcdRSWYTFUmYpJZ6DsLa/3QMiThS6MJT6C8yKcoAKGBzDSq6h6pBc9G2 RpCh411WrPwnU9ADRXR0uEt/f5JIje6LSp30WQ5KN3gFGRS2sHO52H7vnblDiRgKxOIh DLbHwb7ui6OLtIMCkdi3TK5+7Hn7c/jjwDCkVqKhWLmv27HUQdMUGah8hDIk5miIItMc yKQ6PNlXDtZJ/EF+s8APyRyO6ToLPtVRfsp/o8EEhUSrplu4hq2yt00+JzcbfQOw1zOK jcpt/nsoVT9CXJ9XCssKWRSS/uXIe5ew4t1yVSy5zze0HHK3K3dOYJJnX8IRl2cN9k6W Mo4Q== X-Gm-Message-State: AOAM53340rpi0E9Q+UqcTqs/GDaaPhtSMZJu3fc7V3Ytz1iGGVwu/yEl X7wx4neM+3/LcnHqc659+l1UFSNi7xM/Mw== X-Google-Smtp-Source: ABdhPJxTYIfENLhpRfD14c0+T36uvgNFQeIyn+juEvg1IiG0hxHB9lyZB9atuAmyztgS7gA5AwNj9g== X-Received: by 2002:a5d:9a8e:: with SMTP id c14mr7909534iom.178.1607100258893; Fri, 04 Dec 2020 08:44:18 -0800 (PST) Received: from localhost.localdomain ([136.49.211.192]) by smtp.gmail.com with ESMTPSA id w3sm1754909iol.9.2020.12.04.08.44.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Dec 2020 08:44:18 -0800 (PST) From: Glenn Washburn To: grub-devel@gnu.org Cc: Patrick Steinhardt , Daniel Kiper , Glenn Washburn Subject: [PATCH v7 06/17] luks2: Use more intuitive slot key instead of index in user messages Date: Fri, 4 Dec 2020 10:43:35 -0600 Message-Id: X-Mailer: git-send-email 2.27.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2607:f8b0:4864:20::144; envelope-from=development@efficientek.com; helo=mail-il1-x144.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 04 Dec 2020 17:18:00 -0000 Use the slot key name in the json array rather than the 0 based index in the json array for keyslots, segments, and digests. This is less confusing for the end user. For example, say you have a LUKS2 device with a key in slot 1 and slot 4. When using the password for slot 4 to unlock the device, the messages using the index of the keyslot will mention keyslot 1 (its a zero-based index). Furthermore, with this change the keyslot number will align with the number used to reference the keyslot when using the --key-slot argument to cryptsetup. Signed-off-by: Glenn Washburn --- grub-core/disk/luks2.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/grub-core/disk/luks2.c b/grub-core/disk/luks2.c index 437c1da07..ea1065bcf 100644 --- a/grub-core/disk/luks2.c +++ b/grub-core/disk/luks2.c @@ -284,13 +284,13 @@ luks2_get_keyslot (grub_luks2_keyslot_t *k, grub_luks2_digest_t *d, grub_luks2_s grub_json_getuint64 (&d->json_slot_key, &digest, NULL) || grub_json_getchild (&digest, &digest, 0) || luks2_parse_digest (d, &digest)) - return grub_error (GRUB_ERR_BAD_ARGUMENT, "Could not parse digest %"PRIuGRUB_SIZE, i); + return grub_error (GRUB_ERR_BAD_ARGUMENT, "Could not parse digest index %"PRIuGRUB_SIZE, i); if ((d->keyslots & (1 << k->json_slot_key))) break; } if (i == size) - return grub_error (GRUB_ERR_FILE_NOT_FOUND, "No digest for keyslot %"PRIuGRUB_SIZE, keyslot_idx); + return grub_error (GRUB_ERR_FILE_NOT_FOUND, "No digest for keyslot \"%"PRIuGRUB_UINT64_T"\"", k->slot_key); /* Get segment that matches the digest. */ if (grub_json_getvalue (&segments, root, "segments") || @@ -308,7 +308,7 @@ luks2_get_keyslot (grub_luks2_keyslot_t *k, grub_luks2_digest_t *d, grub_luks2_s break; } if (i == size) - return grub_error (GRUB_ERR_FILE_NOT_FOUND, "No segment for digest %"PRIuGRUB_SIZE); + return grub_error (GRUB_ERR_FILE_NOT_FOUND, "No segment for digest \"%"PRIuGRUB_UINT64_T"\"", d->slot_key); return GRUB_ERR_NONE; } @@ -604,11 +604,11 @@ luks2_recover_key (grub_disk_t source, if (keyslot.priority == 0) { - grub_dprintf ("luks2", "Ignoring keyslot %"PRIuGRUB_SIZE" due to priority\n", i); + grub_dprintf ("luks2", "Ignoring keyslot \"%"PRIuGRUB_UINT64_T"\" due to priority\n", keyslot.slot_key); continue; } - grub_dprintf ("luks2", "Trying keyslot %"PRIuGRUB_SIZE"\n", i); + grub_dprintf ("luks2", "Trying keyslot \"%"PRIuGRUB_UINT64_T"\"\n", keyslot.slot_key); /* Set up disk according to keyslot's segment. */ crypt->offset_sectors = grub_divmod64 (segment.offset, segment.sector_size, NULL); @@ -623,16 +623,16 @@ luks2_recover_key (grub_disk_t source, (const grub_uint8_t *) passphrase, grub_strlen (passphrase)); if (ret) { - grub_dprintf ("luks2", "Decryption with keyslot %"PRIuGRUB_SIZE" failed: %s\n", - i, grub_errmsg); + grub_dprintf ("luks2", "Decryption with keyslot \"%"PRIuGRUB_UINT64_T"\" failed: %s\n", + keyslot.slot_key, grub_errmsg); continue; } ret = luks2_verify_key (&digest, candidate_key, keyslot.key_size); if (ret) { - grub_dprintf ("luks2", "Could not open keyslot %"PRIuGRUB_SIZE": %s\n", - i, grub_errmsg); + grub_dprintf ("luks2", "Could not open keyslot \"%"PRIuGRUB_UINT64_T"\": %s\n", + keyslot.slot_key, grub_errmsg); continue; } @@ -640,7 +640,7 @@ luks2_recover_key (grub_disk_t source, * TRANSLATORS: It's a cryptographic key slot: one element of an array * where each element is either empty or holds a key. */ - grub_printf_ (N_("Slot %"PRIuGRUB_SIZE" opened\n"), i); + grub_printf_ (N_("Slot \"%"PRIuGRUB_UINT64_T"\" opened\n"), keyslot.slot_key); candidate_key_len = keyslot.key_size; break; -- 2.27.0