Add cryptsetup options for LUKS2 header size settings.

Also print these area sizes in dump command.

NOTE: since now, the metadata area size in dump command contains
mandatory 4k binary section (to be aligned with API definition).
This commit is contained in:
Milan Broz
2018-11-18 21:13:52 +01:00
parent 41c7e4fe87
commit ec07927b55
4 changed files with 66 additions and 2 deletions

View File

@@ -90,6 +90,11 @@ static const char *opt_label = NULL;
static const char *opt_subsystem = NULL;
static int opt_unbound = 0;
static const char *opt_luks2_metadata_size_str = NULL;
static uint64_t opt_luks2_metadata_size = 0;
static const char *opt_luks2_keyslots_size_str = NULL;
static uint64_t opt_luks2_keyslots_size = 0;
static const char **action_argv;
static int action_argc;
static const char *null_action_argv[] = {NULL, NULL};
@@ -989,6 +994,11 @@ static int action_luksFormat(void)
log_err(_("Integrity option can be used only for LUKS2 format."));
return -EINVAL;
}
if (opt_luks2_keyslots_size || opt_luks2_metadata_size) {
log_err(_("Unsupported LUKS2 metadata size options."));
return -EINVAL;
}
} else
return -EINVAL;
@@ -1043,6 +1053,14 @@ static int action_luksFormat(void)
return r;
}
if (opt_luks2_keyslots_size || opt_luks2_metadata_size) {
r = crypt_set_metadata_size(cd, opt_luks2_metadata_size, opt_luks2_keyslots_size);
if (r < 0) {
log_err(_("Unsupported LUKS2 metadata size options."));
goto out;
}
}
if (opt_offset) {
r = crypt_set_data_offset(cd, opt_offset);
if (r < 0)
@@ -2406,6 +2424,8 @@ int main(int argc, const char **argv)
{ "subsystem", '\0', POPT_ARG_STRING, &opt_subsystem, 0, N_("Set subsystem label for the LUKS2 device"), NULL },
{ "unbound", '\0', POPT_ARG_NONE, &opt_unbound, 0, N_("Create unbound (no assigned data segment) LUKS2 keyslot"), NULL },
{ "json-file", '\0', POPT_ARG_STRING, &opt_json_file, 0, N_("Read or write the json from or to a file"), NULL },
{ "luks2-metadata-size",'\0',POPT_ARG_STRING,&opt_luks2_metadata_size_str,0,N_("LUKS2 header metadata area size"), N_("bytes") },
{ "luks2-keyslots-size",'\0',POPT_ARG_STRING,&opt_luks2_keyslots_size_str,0,N_("LUKS2 header keyslots area size"), N_("bytes") },
POPT_TABLEEND
};
poptContext popt_context;
@@ -2644,6 +2664,19 @@ int main(int argc, const char **argv)
usage(popt_context, EXIT_FAILURE, _("Option --align-payload is allowed only for luksFormat."),
poptGetInvocationName(popt_context));
if ((opt_luks2_metadata_size_str || opt_luks2_keyslots_size_str) && strcmp(aname, "luksFormat"))
usage(popt_context, EXIT_FAILURE, _("Options --luks2-metadata-size and --opt-luks2-keyslots-size "
"are allowed only for luksFormat with LUKS2."),
poptGetInvocationName(popt_context));
if (opt_luks2_metadata_size_str &&
tools_string_to_size(NULL, opt_luks2_metadata_size_str, &opt_luks2_metadata_size))
usage(popt_context, EXIT_FAILURE, _("Invalid LUKS2 metadata size specification."),
poptGetInvocationName(popt_context));
if (opt_luks2_keyslots_size_str &&
tools_string_to_size(NULL, opt_luks2_keyslots_size_str, &opt_luks2_keyslots_size))
usage(popt_context, EXIT_FAILURE, _("Invalid LUKS2 keyslots size specification."),
poptGetInvocationName(popt_context));
if (opt_align_payload && opt_offset)
usage(popt_context, EXIT_FAILURE, _("Option --align-payload and --offset cannot be combined."),
poptGetInvocationName(popt_context));