0005-Cryptomount-support-for-hyphens-in-UUID.patch 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. From 047a5b323de2a0c45a6fe2b6854106830da5f3ae Mon Sep 17 00:00:00 2001
  2. From: John Lane <john@lane.uk.net>
  3. Date: Fri, 26 Jun 2015 22:48:03 +0100
  4. Subject: [PATCH 06/10] Cryptomount support for hyphens in UUID
  5. ---
  6. grub-core/disk/cryptodisk.c | 20 +++++++++++++++++---
  7. grub-core/disk/luks.c | 26 ++++++++------------------
  8. include/grub/cryptodisk.h | 2 ++
  9. 3 files changed, 27 insertions(+), 21 deletions(-)
  10. diff --git a/grub-core/disk/cryptodisk.c b/grub-core/disk/cryptodisk.c
  11. index 57fb904..5430b2e 100644
  12. --- a/grub-core/disk/cryptodisk.c
  13. +++ b/grub-core/disk/cryptodisk.c
  14. @@ -114,6 +114,20 @@ gf_mul_be (grub_uint8_t *o, const grub_uint8_t *a, const grub_uint8_t *b)
  15. }
  16. }
  17. +int
  18. +grub_cryptodisk_uuidcmp(char *uuid_a, char *uuid_b)
  19. +{
  20. + while ((*uuid_a != '\0') && (*uuid_b != '\0'))
  21. + {
  22. + while (*uuid_a == '-') uuid_a++;
  23. + while (*uuid_b == '-') uuid_b++;
  24. + if (grub_toupper(*uuid_a) != grub_toupper(*uuid_b)) break;
  25. + uuid_a++;
  26. + uuid_b++;
  27. + }
  28. + return (*uuid_a == '\0') && (*uuid_b == '\0');
  29. +}
  30. +
  31. static gcry_err_code_t
  32. grub_crypto_pcbc_decrypt (grub_crypto_cipher_handle_t cipher,
  33. void *out, void *in, grub_size_t size,
  34. @@ -508,8 +522,8 @@ grub_cryptodisk_open (const char *name, grub_disk_t disk)
  35. if (grub_memcmp (name, "cryptouuid/", sizeof ("cryptouuid/") - 1) == 0)
  36. {
  37. for (dev = cryptodisk_list; dev != NULL; dev = dev->next)
  38. - if (grub_strcasecmp (name + sizeof ("cryptouuid/") - 1, dev->uuid) == 0)
  39. - break;
  40. + if (grub_cryptodisk_uuidcmp(name + sizeof ("cryptouuid/") - 1, dev->uuid))
  41. + break;
  42. }
  43. else
  44. {
  45. @@ -741,7 +755,7 @@ grub_cryptodisk_get_by_uuid (const char *uuid)
  46. {
  47. grub_cryptodisk_t dev;
  48. for (dev = cryptodisk_list; dev != NULL; dev = dev->next)
  49. - if (grub_strcasecmp (dev->uuid, uuid) == 0)
  50. + if (grub_cryptodisk_uuidcmp(dev->uuid, uuid))
  51. return dev;
  52. return NULL;
  53. }
  54. diff --git a/grub-core/disk/luks.c b/grub-core/disk/luks.c
  55. index 4ebe21b..80a7606 100644
  56. --- a/grub-core/disk/luks.c
  57. +++ b/grub-core/disk/luks.c
  58. @@ -68,9 +68,7 @@ configure_ciphers (grub_disk_t disk, const char *check_uuid,
  59. int check_boot, grub_file_t hdr)
  60. {
  61. grub_cryptodisk_t newdev;
  62. - const char *iptr;
  63. struct grub_luks_phdr header;
  64. - char *optr;
  65. char uuid[sizeof (header.uuid) + 1];
  66. char ciphername[sizeof (header.cipherName) + 1];
  67. char ciphermode[sizeof (header.cipherMode) + 1];
  68. @@ -104,22 +102,6 @@ configure_ciphers (grub_disk_t disk, const char *check_uuid,
  69. || grub_be_to_cpu16 (header.version) != 1)
  70. return NULL;
  71. - optr = uuid;
  72. - for (iptr = header.uuid; iptr < &header.uuid[ARRAY_SIZE (header.uuid)];
  73. - iptr++)
  74. - {
  75. - if (*iptr != '-')
  76. - *optr++ = *iptr;
  77. - }
  78. - *optr = 0;
  79. -
  80. - if (check_uuid && grub_strcasecmp (check_uuid, uuid) != 0)
  81. - {
  82. - grub_dprintf ("luks", "%s != %s\n", uuid, check_uuid);
  83. - return NULL;
  84. - }
  85. -
  86. -
  87. /* Make sure that strings are null terminated. */
  88. grub_memcpy (ciphername, header.cipherName, sizeof (header.cipherName));
  89. ciphername[sizeof (header.cipherName)] = 0;
  90. @@ -127,6 +109,14 @@ configure_ciphers (grub_disk_t disk, const char *check_uuid,
  91. ciphermode[sizeof (header.cipherMode)] = 0;
  92. grub_memcpy (hashspec, header.hashSpec, sizeof (header.hashSpec));
  93. hashspec[sizeof (header.hashSpec)] = 0;
  94. + grub_memcpy (uuid, header.uuid, sizeof (header.uuid));
  95. + uuid[sizeof (header.uuid)] = 0;
  96. +
  97. + if ( check_uuid && ! grub_cryptodisk_uuidcmp(check_uuid, uuid))
  98. + {
  99. + grub_dprintf ("luks", "%s != %s\n", uuid, check_uuid);
  100. + return NULL;
  101. + }
  102. newdev = grub_cryptodisk_create (disk, uuid, ciphername, ciphermode, hashspec);
  103. diff --git a/include/grub/cryptodisk.h b/include/grub/cryptodisk.h
  104. index bb25ab7..01c0269 100644
  105. --- a/include/grub/cryptodisk.h
  106. +++ b/include/grub/cryptodisk.h
  107. @@ -168,4 +168,6 @@ grub_cryptodisk_t grub_cryptodisk_get_by_source_disk (grub_disk_t disk);
  108. grub_cryptodisk_t grub_cryptodisk_create (grub_disk_t disk, char *uuid,
  109. char *ciphername, char *ciphermode, char *digest);
  110. +int
  111. +grub_cryptodisk_uuidcmp(char *uuid_a, char *uuid_b);
  112. #endif
  113. --
  114. 1.9.1