cryptodisk: Add infrastructure to pass data from cryptomount to cryptodisk modules
RFC PATCH 1/1 cryptodisk: Add infrastructure to pass data from cryptomount to cryptodisk modules
As an example, passing a password as a cryptomount argument is implemented. However, the backends are not implemented, so testing this will return a not implemented error.
Signed-off-by Glenn Washburn <[email protected]>
---
This is a proof of concept of how I think the data passing from cryptomount to the crypto module backends should be done. Currently global variables and added parameters to recover_key are being used to do this in submitted patches. We want to avoid both of these. I've tested this patch with the rebased and reworked cryptodisk v7 patches sucessfully. Suggestions welcome.
Glenn
--- grub-core/disk/cryptodisk.c | 29 ++++++++++++++++++++--------- grub-core/disk/geli.c | 4 ++++ grub-core/disk/luks.c | 4 ++++ grub-core/disk/luks2.c | 4 ++++ include/grub/cryptodisk.h | 8 ++++++++ 5 files changed, 40 insertions(+), 9 deletions(-)
grub-core/disk/cryptodisk.c +20 -9
@@ -41,6 +41,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}, + {"password", 'p', 0, N_("Password to open volumes."), 0, ARG_TYPE_STRING}, {0, 0, 0, 0, 0, 0} };
@@ -992,7 +993,9 @@ cryptodisk_close (grub_cryptodisk_t dev) }static grub_err_t -grub_cryptodisk_scan_device_real (const char *name,grub_disk_t source) +grub_cryptodisk_scan_device_real (const char *name, +grub_disk_t source, +grub_cryptomount_args_t cargs) {grub_err_t err;grub_cryptodisk_t dev;
@@ -1011,6 +1014,7 @@ grub_cryptodisk_scan_device_real (const char *name, grub_disk_t source)if (!dev)continue ; + *dev->cargs = *cargs; err = cr->recover_key (source, dev);if (err) {
@@ -1076,7 +1080,7 @@ grub_cryptodisk_cheat_mount (const char *sourcedev, const char *cheat)static int grub_cryptodisk_scan_device (const char *name, -void *data __attribute__ ((unused))) +void *cargs) {grub_err_t err;grub_disk_t source;
@@ -1089,7 +1093,7 @@ grub_cryptodisk_scan_device (const char *name,return 0 ; } - err =grub_cryptodisk_scan_device_real (name, source); + err =grub_cryptodisk_scan_device_real (name, source, (grub_cryptomount_args_t ) cargs);grub_disk_close (source);
@@ -1102,12 +1106,19 @@ static grub_err_t grub_cmd_cryptomount (grub_extcmd_context_t ctxt, int argc, char **args) { struct grub_arg_list *state = ctxt->state; +struct grub_cryptomount_args cargs = {0 };if (argc <1 && !state[1 ].set && !state[2 ].set)return grub_error (GRUB_ERR_BAD_ARGUMENT ,"device name required" ); +if (state[3 ].set)/* password */ + { + cargs.key_data = (grub_uint8_t *) state[3 ].arg; + cargs.key_len =grub_strlen (state[3 ].arg); + } + have_it =0 ; -if (state[0 ].set) +if (state[0 ].set)/* uuid */ {grub_cryptodisk_t dev;
@@ -1121,18 +1132,18 @@ grub_cmd_cryptomount (grub_extcmd_context_t ctxt, int argc, char **args) check_boot = state[2 ].set; search_uuid = args[0 ]; -grub_device_iterate (&grub_cryptodisk_scan_device,NULL ); +grub_device_iterate (&grub_cryptodisk_scan_device, &cargs); search_uuid =NULL ;if (!have_it)return grub_error (GRUB_ERR_BAD_ARGUMENT ,"no such cryptodisk found" );return GRUB_ERR_NONE ; } -else if (state[1 ].set || (argc ==0 && state[2 ].set)) +else if (state[1 ].set || (argc ==0 && state[2 ].set))/* -a|-b */ { search_uuid =NULL ; check_boot = state[2 ].set; -grub_device_iterate (&grub_cryptodisk_scan_device,NULL ); +grub_device_iterate (&grub_cryptodisk_scan_device, &cargs); search_uuid =NULL ;return GRUB_ERR_NONE ; }
@@ -1174,7 +1185,7 @@ grub_cmd_cryptomount (grub_extcmd_context_t ctxt, int argc, char **args)return GRUB_ERR_NONE ; } - err =grub_cryptodisk_scan_device_real (diskname, disk); + err =grub_cryptodisk_scan_device_real (diskname, disk, &cargs);grub_disk_close (disk);if (disklast)
@@ -1313,7 +1324,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_ ("[-p password] <SOURCE|-u UUID|-a|-b>" ),N_ ("Mount a crypto device." ), options);grub_procfs_register ("luks_script" , &luks_script); }
grub-core/disk/geli.c +4 -0
@@ -414,6 +414,10 @@ recover_key (grub_disk_t source, grub_cryptodisk_t dev)grub_disk_addr_t sector;grub_err_t err; +/* Keyfiles are not implemented yet */ +if (dev->cargs->key_data || dev->cargs->key_len) +return GRUB_ERR_NOT_IMPLEMENTED_YET ; +if (dev->cipher->cipher->blocksize >GRUB_CRYPTO_MAX_CIPHER_BLOCKSIZE )return grub_error (GRUB_ERR_BUG ,"cipher block is too long" );
grub-core/disk/luks.c +4 -0
@@ -165,6 +165,10 @@ luks_recover_key (grub_disk_t source,grub_size_t max_stripes =1 ;char *tmp; +/* Keyfiles are not implemented yet */ +if (dev->cargs->key_data || dev->cargs->key_len) +return GRUB_ERR_NOT_IMPLEMENTED_YET ; + err =grub_disk_read (source,0 ,0 ,sizeof (header), &header);if (err)return err;
grub-core/disk/luks2.c +4 -0
@@ -556,6 +556,10 @@ luks2_recover_key (grub_disk_t source,grub_json_t *json =NULL , keyslots;grub_err_t ret; +/* Keyfiles are not implemented yet */ +if (crypt->cargs->key_data || crypt->cargs->key_len) +return GRUB_ERR_NOT_IMPLEMENTED_YET ; + ret =luks2_read_header (source, &header);if (ret)return ret;
include/grub/cryptodisk.h +8 -0
@@ -66,6 +66,13 @@ typedef gcry_err_code_t (*grub_cryptodisk_rekey_func_t) (struct grub_cryptodisk *dev, grub_uint64_t zoneno); +struct grub_cryptomount_args +{ +grub_uint8_t *key_data; +grub_size_t key_len; +}; +typedef struct grub_cryptomount_args *grub_cryptomount_args_t ; +struct grub_cryptodisk {struct grub_cryptodisk *next;
@@ -109,6 +116,7 @@ struct grub_cryptodiskgrub_uint64_t last_rekey;int rekey_derived_size;grub_disk_addr_t partition_start; +grub_cryptomount_args_t cargs; };typedef struct grub_cryptodisk *grub_cryptodisk_t ;
Signature · 1 line
2.27.0