From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1kOqRk-0007YV-3R for mharc-grub-devel@gnu.org; Sat, 03 Oct 2020 18:56:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54702) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kOqRi-0007XE-OT for grub-devel@gnu.org; Sat, 03 Oct 2020 18:56:06 -0400 Received: from mail-oi1-x244.google.com ([2607:f8b0:4864:20::244]:40331) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kOqRg-0000FE-QI for grub-devel@gnu.org; Sat, 03 Oct 2020 18:56:06 -0400 Received: by mail-oi1-x244.google.com with SMTP id m128so5040022oig.7 for ; Sat, 03 Oct 2020 15:56:04 -0700 (PDT) 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=Kecwsj6jQ7A/h9t+kVdj81/3KkAbY1dYOwJtl7LvM0Q=; b=uTx3MBObYY4qwcQoShyiidmKFQdnpYQFx1kIF3tvv+0ZfRBGmMpgUPD9ZgnmEgzuhc 4+Dl33w8RPK2Mb1zn9cvk39ftYYGySG2F6iX28z55kz5UfDzPn18Lto2gUWrrlnhrhQu 6ZcNz3FF2a5dwDCg/gP/s1LPtADO7pQmxEc8swZuwOGwLzdNUFB46qyOcRBS0+Sf6FGL abPEB78CcVrDZaRsxC1DX+PIzeM07c8xH0PA4eIUIsjWWwNZOP9GP2CFbmtunhx8FpJa 9E8mJMfpwgmecMJWiBJbQ4Of1N5rb7kI+/IKBiGIRKbRTMFRs7e8l3Vg3YXpptTchd21 ZBKg== 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=Kecwsj6jQ7A/h9t+kVdj81/3KkAbY1dYOwJtl7LvM0Q=; b=TGyRvRROXAVbAUT3LUG/HIdyOzGYBo/+KyaGGmhQITT00FU9TdWksWZuMTj1mh6KcX 9219bmJtpwNwVwMg+GoySN7nnZG+pv+KAITWv8O5Tqor5x7Q8DWPrYYkE2dh2C1kua0O wXDKVP0LEPvSUUdNH0zWfQuWUe2ROLmjd98GLGRXX3JQnGxwmGssDSXPCsT1vt9wmxdg HvRGgk12ZR5wgQfTuYnPgn95RTsczuozik6ZBKBADI7Ams2zsAQUWY8UvhL0OUPjrWKf jpdq7PviOWOvooPsS++6i6JiSVRS4tmDrYqnckv8Q0w2fTIKpvDgTuo2SaaGgkNPfq8b ocaw== X-Gm-Message-State: AOAM533/4UCXMTj4Fsj72lL5LESLkB0+rZVQ9yVKeovGPX8KBB42cQO1 bUFh1qdS3jUQtAVB0xK3hM+KGuzuuktCwA== X-Google-Smtp-Source: ABdhPJxfkduB+HVv5ngyP0KdBGJTEa7JYzPZG6BSRF36sldf/4OZ7Dugok6CKhnzchArL0jKMI7Eyw== X-Received: by 2002:aca:c546:: with SMTP id v67mr1448001oif.24.1601765763403; Sat, 03 Oct 2020 15:56:03 -0700 (PDT) Received: from crass-HP-ZBook-15-G2.lan ([136.49.44.103]) by smtp.gmail.com with ESMTPSA id d17sm1524580oth.73.2020.10.03.15.56.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 03 Oct 2020 15:56:03 -0700 (PDT) From: Glenn Washburn To: grub-devel@gnu.org Cc: Daniel Kiper , Patrick Steinhardt , Glenn Washburn Subject: [PATCH v2 03/10] luks2: Use more intuitive keyslot key instead of index when naming keyslot. Date: Sat, 3 Oct 2020 17:55:27 -0500 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::244; envelope-from=development@efficientek.com; helo=mail-oi1-x244.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. 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=ham 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: Sat, 03 Oct 2020 22:56:07 -0000 Use the keyslot key value in the keyslot json array rather than the index of the keyslot in the json array. 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 | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/grub-core/disk/luks2.c b/grub-core/disk/luks2.c index c3cd63606..db251cce0 100644 --- a/grub-core/disk/luks2.c +++ b/grub-core/disk/luks2.c @@ -255,16 +255,16 @@ luks2_parse_digest (grub_luks2_digest_t *out, const grub_json_t *digest) static grub_err_t luks2_get_keyslot (grub_luks2_keyslot_t *k, grub_luks2_digest_t *d, grub_luks2_segment_t *s, - const grub_json_t *root, grub_size_t keyslot_idx) + grub_uint64_t *keyslot_key, const grub_json_t *root, grub_size_t keyslot_idx) { grub_json_t keyslots, keyslot, digests, digest, segments, segment; grub_size_t i, size; - grub_uint64_t keyslot_key, digest_key, segment_key; + grub_uint64_t digest_key, segment_key; /* Get nth keyslot */ if (grub_json_getvalue (&keyslots, root, "keyslots") || grub_json_getchild (&keyslot, &keyslots, keyslot_idx) || - grub_json_getuint64 (&keyslot_key, &keyslot, NULL) || + grub_json_getuint64 (keyslot_key, &keyslot, NULL) || grub_json_getchild (&keyslot, &keyslot, 0) || luks2_parse_keyslot (k, &keyslot)) return grub_error (GRUB_ERR_BAD_ARGUMENT, "Could not parse keyslot index %"PRIuGRUB_SIZE, keyslot_idx); @@ -281,11 +281,11 @@ luks2_get_keyslot (grub_luks2_keyslot_t *k, grub_luks2_digest_t *d, grub_luks2_s luks2_parse_digest (d, &digest)) return grub_error (GRUB_ERR_BAD_ARGUMENT, "Could not parse digest index %"PRIuGRUB_SIZE, i); - if ((d->keyslots & (1 << keyslot_key))) + if ((d->keyslots & (1 << *keyslot_key))) break; } if (i == size) - return grub_error (GRUB_ERR_FILE_NOT_FOUND, "No digest for keyslot \"%"PRIuGRUB_UINT64_T"\"", keyslot_key); + return grub_error (GRUB_ERR_FILE_NOT_FOUND, "No digest for keyslot \"%"PRIuGRUB_UINT64_T"\"", *keyslot_key); /* Get segment that matches the digest. */ if (grub_json_getvalue (&segments, root, "segments") || @@ -593,17 +593,18 @@ luks2_recover_key (grub_disk_t disk, /* Try all keyslot */ for (i = 0; i < size; i++) { - ret = luks2_get_keyslot (&keyslot, &digest, &segment, json, i); + grub_uint64_t keyslot_key; + ret = luks2_get_keyslot (&keyslot, &digest, &segment, &keyslot_key, json, i); if (ret) goto err; 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_key); continue; } - grub_dprintf ("luks2", "Trying keyslot %"PRIuGRUB_SIZE"\n", i); + grub_dprintf ("luks2", "Trying keyslot %"PRIuGRUB_UINT64_T"\n", keyslot_key); /* Set up disk according to keyslot's segment. */ crypt->offset = grub_divmod64 (segment.offset, segment.sector_size, NULL); @@ -618,16 +619,16 @@ luks2_recover_key (grub_disk_t disk, (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_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_key, grub_errmsg); continue; } @@ -635,7 +636,7 @@ luks2_recover_key (grub_disk_t disk, * 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_key); candidate_key_len = keyslot.key_size; break; -- 2.27.0