Patches to cryptomount (plain support, keyfiles and LUKS detached headers)
Hello, I've been working over the past couple of weeks on adding some functionality to the "cryptomount" command to support plain-mode dm-crypt, keyfiles and LUKS detached headers. I've put my work on GitHub and written a few notes on http://grub.johnlane.ie, along with my patches. I believe this is the right list to post this kind of thing on.
I can explain in detail what I did if there's interest in what I've done. I haven't added much code - I mostly made use of what was already there, using it in different ways to support some additional use-cases that I needed.
Best,
John Lane
Quoted 6 lines · John Lane
Hello, I've been working over the past couple of weeks on adding some functionality to the "cryptomount" command to support plain-mode dm-crypt, keyfiles and LUKS detached headers. I've put my work on GitHub and written a few notes on http://grub.johnlane.ie, along with my patches. I believe this is the right list to post this kind of thing on.
Sorry, we cannot accept patches which aren't sent to this ml by author. I'm not sure that all features are good. For starters plain mode is just difficult to setup and use. Please provide usecases not already covered by current features.
Quoted 18 lines
I can explain in detail what I did if there's interest in what I've done. I haven't added much code - I mostly made use of what was already there, using it in different ways to support some additional use-cases that I needed.
Best,
John Lane_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
I did some work a while ago to update the crypto routines to support LUKS detached headers.
I've been busy on other things but just found some time to update to the current master head.
Quoted 8 lines · Vladimir 'φ-coder/phcoder' Serbinenko
Quoted 6 lines · John Lane
Hello, I've been working over the past couple of weeks on adding some functionality to the "cryptomount" command to support plain-mode dm-crypt, keyfiles and LUKS detached headers. I've put my work on GitHub and written a few notes on http://grub.johnlane.ie, along with my patches. I believe this is the right list to post this kind of thing on.
Sorry, we cannot accept patches which aren't sent to this ml by author.
I've attached the patches here. They apply clean to c945ca75.
Quoted 3 lines
I'm not sure that all features are good. For starters plain mode is just difficult to setup and use. Please provide usecases not already covered by current features.
My target was to establish LUKS volumes with detached headers and key files and this is not already covered by current features.
My specific use-case is booting secured systems where the boot environment (Grub, LUKS headers and keys) is contained on removable media such as a USB key. The non-removable hard-drive has no boot code on it; it just appears as an unformatted disk unless the removable key is used.
To support this, it was necessary to add support to Grub for detached LUKS headers and keys.
I am aware of a number of other people enquiring about this specific functionality so I am not alone in thinking it's a valid use-case.
Regarding plain mode, I don't understand why plain mode is "difficult to setup and use". I did the work on plain mode at the same time because one of the disks that I needed to work with was a plain mode disk. I asked about the existing but non-functioning "peter/devmapper" branch and spent some time trying to get that to work. In the end, and as I understand how LUKS uses dm-crypt, it seemed better to re-use the existing code base in the cryptodisk routines because this is more current, used and tested. By doing that I was able to get it to work very quickly.
I've been using my changes in daily use since my original postings last December. I've just updated to the latest head and the patches still merge cleanly.
I'd appreciate it if these changes could be considered. If any more information would be useful please let me know.
Quoted 21 lines
Quoted 13 lines
I can explain in detail what I did if there's interest in what I've done. I haven't added much code - I mostly made use of what was already there, using it in different ways to support some additional use-cases that I needed.
Best,
John LaneQuoted 5 lines
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
Quoted 4 lines
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
From be5328baa13459fddcef2e55fde398eb6932ebf5 Mon Sep 17 00:00:00 2001
From: John Lane <[email protected]>
Date: Sat, 29 Nov 2014 18:59:43 +0000
Subject: [PATCH 1/1] Cryptomount support for hyphens in UUID
--- grub-core/disk/cryptodisk.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
grub-core/disk/cryptodisk.c +10 -0
@@ -103,6 +103,14 @@ gf_mul_be (grub_uint8_t *o, const grub_uint8_t *a, const grub_uint8_t *b) } } +void +grub_crypto_uuid_dehyphenate (char *uuid) +{ +char *s, *d; +for (s=d=uuid;(*d=*s);d+=(*s++!='-' )); +} + + static gcry_err_code_t grub_crypto_pcbc_decrypt (grub_crypto_cipher_handle_t cipher, void *out, void *in, grub_size_t size,
@@ -488,6 +496,7 @@ grub_cryptodisk_open (const char *name, grub_disk_t disk)if (grub_memcmp (name,"cryptouuid/" ,sizeof ("cryptouuid/" ) -1 ) ==0 ) { +grub_crypto_uuid_dehyphenate ((char *)name +sizeof ("cryptouuid/" ));for (dev = cryptodisk_list; dev !=NULL ; dev = dev->next)if (grub_strcasecmp (name +sizeof ("cryptouuid/" ) -1 , dev->uuid) ==0 )break ;
@@ -925,6 +934,7 @@ grub_cmd_cryptomount (grub_extcmd_context_t ctxt, int argc, char **args) {grub_cryptodisk_t dev; +grub_crypto_uuid_dehyphenate (args[0 ]); dev =grub_cryptodisk_get_by_uuid (args[0 ]);if (dev) {
Signature · 1 line
2.1.2
From b6bc9bb59d1245a8510948cc5bf51112aa005506 Mon Sep 17 00:00:00 2001
From: John Lane <[email protected]>
Date: Sun, 30 Nov 2014 19:47:49 +0000
Subject: [PATCH 1/1] Cryptomount support LUKS detached header
--- grub-core/disk/cryptodisk.c | 20 ++++++++++++++++---- grub-core/disk/geli.c | 7 +++++-- grub-core/disk/luks.c | 45 +++++++++++++++++++++++++++++++++++++-------- include/grub/cryptodisk.h | 5 +++-- 4 files changed, 61 insertions(+), 16 deletions(-)
grub-core/disk/cryptodisk.c +16 -4
@@ -40,6 +40,7 @@ static const struct grub_arg_option options[] =/* TRANSLATORS: It's still restricted to cryptodisks only. */ {"all", 'a', 0, N_("Mount all."), 0, 0}, {"boot", 'b', 0, N_("Mount all volumes with `boot' flag set."), 0, 0}, + {"header", 'H', 0, N_("Read LUKS header from file"), 0, ARG_TYPE_STRING}, {0, 0, 0, 0, 0, 0} };
@@ -804,6 +805,7 @@ grub_util_cryptodisk_get_uuid (grub_disk_t disk)static int check_boot, have_it;static char *search_uuid; +static grub_file_t hdr;static void cryptodisk_close (grub_cryptodisk_t dev)
@@ -828,13 +830,13 @@ grub_cryptodisk_scan_device_real (const char *name, grub_disk_t source)FOR_CRYPTODISK_DEVS (cr) { - dev = cr->scan (source, search_uuid, check_boot); + dev = cr->scan (source, search_uuid, check_boot, hdr);if (grub_errno)return grub_errno;if (!dev)continue ; - err = cr->recover_key (source, dev); + err = cr->recover_key (source, dev, hdr);if (err) {cryptodisk_close (dev);
@@ -875,7 +877,7 @@ grub_cryptodisk_cheat_mount (const char *sourcedev, const char *cheat)FOR_CRYPTODISK_DEVS (cr) { - dev = cr->scan (source, search_uuid, check_boot); + dev = cr->scan (source, search_uuid, check_boot,0 );if (grub_errno)return grub_errno;if (!dev)
@@ -929,6 +931,16 @@ grub_cmd_cryptomount (grub_extcmd_context_t ctxt, int argc, char **args)if (argc <1 && !state[1 ].set && !state[2 ].set)return grub_error (GRUB_ERR_BAD_ARGUMENT ,"device name required" ); +if (state[3 ].set) + { + hdr =grub_file_open (state[3 ].arg); +if (!hdr) +return grub_errno; +grub_printf ("\nUsing detached header %s\n" , state[3 ].arg); + } +else + hdr =NULL ; + have_it =0 ;if (state[0 ].set) {
@@ -1127,7 +1139,7 @@ GRUB_MOD_INIT (cryptodisk) {grub_disk_dev_register (&grub_cryptodisk_dev); cmd =grub_register_extcmd ("cryptomount" , grub_cmd_cryptomount,0 , -N_ ("SOURCE|-u UUID|-a|-b" ), +N_ ("SOURCE|-u UUID|-a|-b|-H file" ),N_ ("Mount a crypto device." ), options);grub_procfs_register ("luks_script" , &luks_script); }
grub-core/disk/geli.c +5 -2
@@ -52,6 +52,7 @@#include <grub/dl.h> #include <grub/err.h> #include <grub/disk.h> +#include <grub/file.h> #include <grub/crypto.h> #include <grub/partition.h> #include <grub/i18n.h>
@@ -239,7 +240,8 @@ grub_util_get_geli_uuid (const char *dev)static grub_cryptodisk_t configure_ciphers (grub_disk_t disk,const char *check_uuid, -int boot_only) +int boot_only, +grub_file_t hdr __attribute__ ((unused)) ) {grub_cryptodisk_t newdev;struct grub_geli_phdr header;
@@ -394,7 +396,8 @@ configure_ciphers (grub_disk_t disk, const char *check_uuid, }static grub_err_t -recover_key (grub_disk_t source,grub_cryptodisk_t dev) +recover_key (grub_disk_t source,grub_cryptodisk_t dev, +grub_file_t hdr __attribute__ ((unused)) ) {grub_size_t keysize;grub_uint8_t digest[GRUB_CRYPTO_MAX_MDLEN ];
grub-core/disk/luks.c +37 -8
94 lines not on this page · raw message
include/grub/cryptodisk.h +3 -2
@@ -20,6 +20,7 @@#define GRUB_CRYPTODISK_HEADER 1#include <grub/disk.h> +#include <grub/file.h> #include <grub/crypto.h> #include <grub/list.h> #ifdef GRUB_UTIL
@@ -106,8 +107,8 @@ struct grub_cryptodisk_devstruct grub_cryptodisk_dev **prev;grub_cryptodisk_t (*scan) (grub_disk_t disk,const char *check_uuid, -int boot_only); -grub_err_t (*recover_key) (grub_disk_t disk,grub_cryptodisk_t dev); +int boot_only,grub_file_t hdr); +grub_err_t (*recover_key) (grub_disk_t disk,grub_cryptodisk_t dev,grub_file_t hdr); };typedef struct grub_cryptodisk_dev *grub_cryptodisk_dev_t ;
Signature · 1 line
2.1.2
From 3a50cd9b4cb7b9e00df60edb480896bd24471511 Mon Sep 17 00:00:00 2001
From: John Lane <[email protected]>
Date: Tue, 9 Dec 2014 17:17:16 +0000
Subject: [PATCH 1/1] Cryptomount support plain dm-crypt and key files
--- grub-core/disk/cryptodisk.c | 338 +++++++++++++++++++++++++++++++++++++++++++- grub-core/disk/geli.c | 4 +- grub-core/disk/luks.c | 248 +++++--------------------------- include/grub/cryptodisk.h | 17 ++- 4 files changed, 388 insertions(+), 219 deletions(-)
grub-core/disk/cryptodisk.c +333 -5
395 lines not on this page · raw message
grub-core/disk/geli.c +3 -1
@@ -397,7 +397,9 @@ configure_ciphers (grub_disk_t disk, const char *check_uuid,static grub_err_t recover_key (grub_disk_t source,grub_cryptodisk_t dev, -grub_file_t hdr __attribute__ ((unused)) ) +grub_file_t hdr __attribute__ ((unused)), +grub_uint8_t *key __attribute__ ((unused)), +grub_size_t keyfile_size __attribute__ ((unused)) ) {grub_size_t keysize;grub_uint8_t digest[GRUB_CRYPTO_MAX_MDLEN ];
grub-core/disk/luks.c +36 -212
308 lines not on this page · raw message
include/grub/cryptodisk.h +16 -1
@@ -54,6 +54,13 @@ typedef enum#define GRUB_CRYPTODISK_GF_LOG_BYTES (GRUB_CRYPTODISK_GF_LOG_SIZE - 3)#define GRUB_CRYPTODISK_GF_BYTES (1U << GRUB_CRYPTODISK_GF_LOG_BYTES)#define GRUB_CRYPTODISK_MAX_KEYLEN 128 +#define GRUB_CRYPTODISK_MAX_PASSPHRASE 512 + +#define GRUB_CRYPTODISK_MAX_KEYFILE_SIZE 8192 + +#define GRUB_CRYPTODISK_PLAIN_CIPHER "aes-cbc-essiv:sha256" +#define GRUB_CRYPTODISK_PLAIN_DIGEST "ripemd160" +#define GRUB_CRYPTODISK_PLAIN_KEYSIZE 256struct grub_cryptodisk ;
@@ -108,7 +115,8 @@ struct grub_cryptodisk_devgrub_cryptodisk_t (*scan) (grub_disk_t disk,const char *check_uuid,int boot_only,grub_file_t hdr); -grub_err_t (*recover_key) (grub_disk_t disk,grub_cryptodisk_t dev,grub_file_t hdr); +grub_err_t (*recover_key) (grub_disk_t disk,grub_cryptodisk_t dev, +grub_file_t hdr,grub_uint8_t *key,grub_size_t keyfile_size); };typedef struct grub_cryptodisk_dev *grub_cryptodisk_dev_t ;
@@ -156,4 +164,11 @@ grub_util_get_geli_uuid (const char *dev);grub_cryptodisk_t grub_cryptodisk_get_by_uuid (const char *uuid);grub_cryptodisk_t grub_cryptodisk_get_by_source_disk (grub_disk_t disk); +void +grub_crypto_uuid_dehyphenate (char *uuid); + +grub_cryptodisk_t +grub_cryptodisk_create (grub_disk_t disk,char *uuid, +char *ciphername,char *ciphermode,char *digest); +#endif
Signature · 1 line
2.1.2
В Fri, 12 Jun 2015 20:15:32 +0100
John Lane <[email protected]> пишет:
Quoted 2 lines
Quoted 1 line
Sorry, we cannot accept patches which aren't sent to this ml by author.
I've attached the patches here. They apply clean to
c945ca75.
Sending them as patch series in mail body would make it easier to review and comment on them.
Quoted 19 lines
Quoted 3 lines
I'm not sure that all features are good. For starters plain mode is just difficult to setup and use. Please provide usecases not already covered by current features.
My target was to establish LUKS volumes with detached headers and key files and this is not already covered by current features.
My specific use-case is booting secured systems where the boot environment (Grub, LUKS headers and keys) is contained on removable media such as a USB key. The non-removable hard-drive has no boot code on it; it just appears as an unformatted disk unless the removable key is used.
To support this, it was necessary to add support to Grub for detached LUKS headers and keys.
I am aware of a number of other people enquiring about this specific functionality so I am not alone in thinking it's a valid use-case.
Quoted 10 lines
Regarding plain mode, I don't understand why plain mode is "difficult to setup and use". I did the work on plain mode at the same time because one of the disks that I needed to work with was a plain mode disk. I asked about the existing but non-functioning "peter/devmapper" branch and spent some time trying to get that to work. In the end, and as I understand how LUKS uses dm-crypt, it seemed better to re-use the existing code base in the cryptodisk routines because this is more current, used and tested. By doing that I was able to get it to work very quickly.
The problem is not coding it. It is impossible to identify plain mode crypto-containers at run time. So it depends on user knowing (or guessing) which of disks to use. It is pure manual stuff which cannot be integrated in GRUB grub-install or grub-mkconfig.
You have 5 disks each encrypted with different key that are plain/use detached header. How can you setup GRUB to automatically find out the right key/header for each disk?
I personally would appreciate keyfile support as separate patch, not buried in plain mode support. Especially if it would be accompanied by grub-mkconfig changes to automate generation of grub.cfg to use it.
Quoted 10 lines
I've been using my changes in daily use since my original postings last December. I've just updated to the latest head and the patches still merge cleanly.
I'd appreciate it if these changes could be considered. If any more information would be useful please let me know.
grub-core/disk/cryptodisk.c grub_cryptodisk_open (const char *name, grub_disk_t disk) · line 499
Quoted 4 lines
grub-core/disk/cryptodisk.c +1
-0@@ -488,6 +496,7 @@ grub_cryptodisk_open (const char *name, grub_disk_t disk)if (grub_memcmp (name,"cryptouuid/" ,sizeof ("cryptouuid/" ) -1 ) ==0 ) { +grub_crypto_uuid_dehyphenate ((char *)name +sizeof ("cryptouuid/" ));
This alters original name passed to grub_disk_open. As already mentioned it is better to use comparison function that ignores hyphens.
Quoted 7 lines · Andrei Borzenkov
В Fri, 12 Jun 2015 20:15:32 +0100
John Lane <[email protected]> пишет:Quoted 2 lines
Quoted 1 line
Sorry, we cannot accept patches which aren't sent to this ml by author.
I've attached the patches here. They apply clean to
c945ca75.Sending them as patch series in mail body would make it easier to review and comment on them.
Ok, sure I'll do that. please bear with me...
I'll re-jig the patches so that the plain-mode stuff is separated. May be a delay as I'll need to find the time to do it.
Quoted 34 lines
Quoted 19 lines
Quoted 4 lines
I'm not sure that all features are good. For starters plain mode is just difficult to setup and use. Please provide usecases not already covered by current features.
My target was to establish LUKS volumes with detached headers and key files and this is not already covered by current features.
My specific use-case is booting secured systems where the boot environment (Grub, LUKS headers and keys) is contained on removable media such as a USB key. The non-removable hard-drive has no boot code on it; it just appears as an unformatted disk unless the removable key is used.
To support this, it was necessary to add support to Grub for detached LUKS headers and keys.
I am aware of a number of other people enquiring about this specific functionality so I am not alone in thinking it's a valid use-case.
Quoted 10 lines
Regarding plain mode, I don't understand why plain mode is "difficult to setup and use". I did the work on plain mode at the same time because one of the disks that I needed to work with was a plain mode disk. I asked about the existing but non-functioning "peter/devmapper" branch and spent some time trying to get that to work. In the end, and as I understand how LUKS uses dm-crypt, it seemed better to re-use the existing code base in the cryptodisk routines because this is more current, used and tested. By doing that I was able to get it to work very quickly.
The problem is not coding it. It is impossible to identify plain mode crypto-containers at run time. So it depends on user knowing (or guessing) which of disks to use. It is pure manual stuff which cannot be integrated in GRUB grub-install or grub-mkconfig.
Quoted 7 lines
You have 5 disks each encrypted with different key that are plain/use detached header. How can you setup GRUB to automatically find out the right key/header for each disk?
I personally would appreciate keyfile support as separate patch, not buried in plain mode support. Especially if it would be accompanied by grub-mkconfig changes to automate generation of grub.cfg to use it.
I'll separate the plain from LUKS stuff as said above... might take a little while to find some time though...
Quoted 8 lines
Quoted 7 lines
I've been using my changes in daily use since my original postings last December. I've just updated to the latest head and the patches still merge cleanly.
I'd appreciate it if these changes could be considered. If any more information would be useful please let me know.
Quoted 7 lines
grub-core/disk/cryptodisk.c grub_cryptodisk_open (const char *name, grub_disk_t disk) · line 499
Quoted 5 lines
grub-core/disk/cryptodisk.c +1
-0@@ -488,6 +496,7 @@ grub_cryptodisk_open (const char *name, grub_disk_t disk)if (grub_memcmp (name,"cryptouuid/" ,sizeof ("cryptouuid/" ) -1 ) ==0 ) { +grub_crypto_uuid_dehyphenate ((char *)name +sizeof ("cryptouuid/" ));This alters original name passed to
grub_disk_open. As already mentioned it is better to use comparison function that ignores hyphens.
The reason I did it that way was because it was easy, coming from the point of view that I was only getting to know the code-base. I simply converted the uuid at the first opportunity into the format that the existing code base expects. That way the rest of the code can carry on as if a uuid without hyphens was presented. I thought that was pretty harmless given that the dehyphenate function does nothing to a uuid that has no hyphens in it. Anyway, I will resubmit the patch by email as described above - we can discuss it further under that...