1 # --- T2-COPYRIGHT-NOTE-BEGIN ---
2 # This copyright note is auto-generated by scripts/Create-CopyPatch.
4 # T2 SDE: package/*/grub2/uuid-hyphens.patch
5 # Copyright (C) 2017 - 2021 The T2 SDE Project
7 # More information can be found in the files COPYING and README.
9 # This patch file is dual-licensed. It is available under the license the
10 # patched project is licensed under, as long as it is an OpenSource license
11 # as defined at http://www.opensource.org/ (e.g. BSD, X11) or under the terms
12 # of the GNU General Public License as published by the Free Software
13 # Foundation; either version 2 of the License, or (at your option) any later
15 # --- T2-COPYRIGHT-NOTE-END ---
17 From f723c22cb7d8a5a6633eaa0682e024e667fb581a Mon Sep 17 00:00:00 2001
18 From: John Lane <john@lane.uk.net>
19 Date: Fri, 26 Jun 2015 22:48:03 +0100
20 Subject: [PATCH 5/5] Cryptomount support for hyphens in UUID
22 Rebased and added luks2 support:
24 - René Rebe <rene@exactcode.de>
27 grub-core/disk/cryptodisk.c | 20 +++++++++++++++++---
28 grub-core/disk/luks.c | 26 ++++++++------------------
29 include/grub/cryptodisk.h | 2 ++
30 3 files changed, 27 insertions(+), 21 deletions(-)
32 diff --git a/grub-core/disk/cryptodisk.c b/grub-core/disk/cryptodisk.c
33 index cd5cfc9..d36d16b 100644
34 --- a/grub-core/disk/cryptodisk.c
35 +++ b/grub-core/disk/cryptodisk.c
36 @@ -113,6 +113,20 @@ gf_mul_be (grub_uint8_t *o, const grub_uint8_t *a, const grub_uint8_t *b)
41 +grub_cryptodisk_uuidcmp(const char *uuid_a, const char *uuid_b)
43 + while ((*uuid_a != '\0') && (*uuid_b != '\0'))
45 + while (*uuid_a == '-') uuid_a++;
46 + while (*uuid_b == '-') uuid_b++;
47 + if (grub_toupper(*uuid_a) != grub_toupper(*uuid_b)) break;
51 + return (*uuid_a == '\0') && (*uuid_b == '\0');
54 static gcry_err_code_t
55 grub_crypto_pcbc_decrypt (grub_crypto_cipher_handle_t cipher,
56 void *out, void *in, grub_size_t size,
57 @@ -507,8 +521,8 @@ grub_cryptodisk_open (const char *name, grub_disk_t disk)
58 if (grub_memcmp (name, "cryptouuid/", sizeof ("cryptouuid/") - 1) == 0)
60 for (dev = cryptodisk_list; dev != NULL; dev = dev->next)
61 - if (grub_strcasecmp (name + sizeof ("cryptouuid/") - 1, dev->uuid) == 0)
63 + if (grub_cryptodisk_uuidcmp(name + sizeof ("cryptouuid/") - 1, dev->uuid))
68 @@ -739,7 +753,7 @@ grub_cryptodisk_get_by_uuid (const char *uuid)
70 grub_cryptodisk_t dev;
71 for (dev = cryptodisk_list; dev != NULL; dev = dev->next)
72 - if (grub_strcasecmp (dev->uuid, uuid) == 0)
73 + if (grub_cryptodisk_uuidcmp(dev->uuid, uuid))
77 --- grub-2.02/grub-core/disk/luks.c.orig 2015-09-02 22:10:53.000000000 +0200
78 +++ grub-2.02/grub-core/disk/luks.c 2017-12-03 18:02:29.093945562 +0100
82 grub_cryptodisk_t newdev;
84 struct grub_luks_phdr header;
86 char uuid[sizeof (header.uuid) + 1];
87 char ciphername[sizeof (header.cipherName) + 1];
88 char ciphermode[sizeof (header.cipherMode) + 1];
92 grub_memset (uuid, 0, sizeof (uuid));
94 - for (iptr = header.uuid; iptr < &header.uuid[ARRAY_SIZE (header.uuid)];
102 - if (check_uuid && grub_strcasecmp (check_uuid, uuid) != 0)
104 - grub_dprintf ("luks", "%s != %s\n", uuid, check_uuid);
108 /* Make sure that strings are null terminated. */
109 grub_memcpy (ciphername, header.cipherName, sizeof (header.cipherName));
111 ciphermode[sizeof (header.cipherMode)] = 0;
112 grub_memcpy (hashspec, header.hashSpec, sizeof (header.hashSpec));
113 hashspec[sizeof (header.hashSpec)] = 0;
114 + grub_memcpy (uuid, header.uuid, sizeof (header.uuid));
115 + uuid[sizeof (header.uuid)] = 0;
117 + if ( check_uuid && ! grub_cryptodisk_uuidcmp(check_uuid, uuid))
119 + grub_dprintf ("luks", "%s != %s\n", uuid, check_uuid);
123 ciph = grub_crypto_lookup_cipher_by_name (ciphername);
125 diff --git a/include/grub/cryptodisk.h b/include/grub/cryptodisk.h
126 index 4076412..a564f2c 100644
127 --- a/include/grub/cryptodisk.h
128 +++ b/include/grub/cryptodisk.h
129 @@ -167,4 +167,6 @@ grub_cryptodisk_t grub_cryptodisk_get_by_source_disk (grub_disk_t disk);
130 grub_cryptodisk_t grub_cryptodisk_create (grub_disk_t disk, char *uuid,
131 char *ciphername, char *ciphermode, char *digest);
134 +grub_cryptodisk_uuidcmp(const char *uuid_a, const char *uuid_b);
139 --- grub-2.06~rc1/grub-core/disk/luks2.c.vanilla 2021-03-13 13:33:43.247134523 +0100
140 +++ grub-2.06~rc1/grub-core/disk/luks2.c 2021-03-13 13:39:37.093113432 +0100
142 grub_cryptodisk_t cryptodisk;
143 grub_luks2_header_t header;
144 char uuid[sizeof (header.uuid) + 1];
149 @@ -364,13 +363,14 @@
153 - for (i = 0, j = 0; i < sizeof (header.uuid); i++)
154 - if (header.uuid[i] != '-')
155 - uuid[j++] = header.uuid[i];
157 + grub_memcpy (uuid, header.uuid, sizeof (header.uuid));
158 + uuid[sizeof (header.uuid)] = 0;
160 - if (check_uuid && grub_strcasecmp (check_uuid, uuid) != 0)
162 + if ( check_uuid && ! grub_cryptodisk_uuidcmp(check_uuid, uuid))
164 + grub_dprintf ("luks", "%s != %s\n", uuid, check_uuid);
168 cryptodisk = grub_zalloc (sizeof (*cryptodisk));