Skip to content

Commit

Permalink
Add support for specifying label when creating LUKS devices
Browse files Browse the repository at this point in the history
  • Loading branch information
vojtechtrefny committed Oct 24, 2024
1 parent 019c631 commit a501bcb
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
4 changes: 3 additions & 1 deletion data/org.freedesktop.UDisks2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2099,7 +2099,7 @@
<!--
Format:
@type: The type of file system, partition table or other content to format the device with.
@options: Options - known options (in addition to <link linkend="udisks-std-options">standard options</link>) includes <parameter>label</parameter> (of type 's'), <parameter>uuid</parameter> (of type 's'), <parameter>take-ownership</parameter> (of type 'b'), <parameter>encrypt.passphrase</parameter> (of type 's' or 'ay'), <parameter>encrypt.type</parameter> (of type 's'), <parameter>encrypt.pbkdf</parameter> (of type 's'), <parameter>encrypt.memory</parameter> (of type 'u'), <parameter>encrypt.iterations</parameter> (of type 'u'), <parameter>encrypt.time</parameter> (of type 'u'), <parameter>encrypt.threads</parameter> (of type 'u'), <parameter>erase</parameter> (of type 's'), <parameter>mkfs-args</parameter> (of type 'as'), <parameter>no-block</parameter> (of type 'b') and <parameter>update-partition-type</parameter> (of type 'b').
@options: Options - known options (in addition to <link linkend="udisks-std-options">standard options</link>) includes <parameter>label</parameter> (of type 's'), <parameter>uuid</parameter> (of type 's'), <parameter>take-ownership</parameter> (of type 'b'), <parameter>encrypt.passphrase</parameter> (of type 's' or 'ay'), <parameter>encrypt.type</parameter> (of type 's'), <parameter>encrypt.label</parameter> (of type 's'), <parameter>encrypt.pbkdf</parameter> (of type 's'), <parameter>encrypt.memory</parameter> (of type 'u'), <parameter>encrypt.iterations</parameter> (of type 'u'), <parameter>encrypt.time</parameter> (of type 'u'), <parameter>encrypt.threads</parameter> (of type 'u'), <parameter>erase</parameter> (of type 's'), <parameter>mkfs-args</parameter> (of type 'as'), <parameter>no-block</parameter> (of type 'b') and <parameter>update-partition-type</parameter> (of type 'b').
Formats the device with a file system, partition table or
other well-known content.
Expand Down Expand Up @@ -2137,6 +2137,8 @@
Option <parameter>encrypt.type</parameter> can be used to
specify encryption "technology" that will be used. Currently
only <quote>luks1</quote> and <quote>luks2</quote> are supported.
Option <parameter>encrypt.label</parameter> can be used to specify
label for the LUKS format.
Following additional options for LUKS key derivation function can
be used:
Expand Down
11 changes: 10 additions & 1 deletion src/udiskslinuxblock.c
Original file line number Diff line number Diff line change
Expand Up @@ -1670,14 +1670,18 @@ static gchar *
make_block_luksname (UDisksBlock *block, GError **error)
{
BDCryptoLUKSInfo *info = NULL;
gchar *ret = NULL;

udisks_linux_block_encrypted_lock (block);
info = bd_crypto_luks_info (udisks_block_get_device (block), error);
udisks_linux_block_encrypted_unlock (block);

if (info)
{
gchar *ret = g_strdup_printf ("luks-%s", info->uuid);
if (info->label && g_strcmp0 (info->label, "") != 0)
ret = g_strdup (info->label);
else
ret = g_strdup_printf ("luks-%s", info->uuid);
bd_crypto_luks_info_free (info);

return ret;
Expand Down Expand Up @@ -3144,6 +3148,7 @@ format_create_luks (UDisksDaemon *daemon,
guint32 encrypt_iterations,
guint32 encrypt_time,
guint32 encrypt_threads,
const gchar *encrypt_label,
UDisksBlock **block_to_mkfs,
UDisksObject **object_to_mkfs,
GError **error)
Expand Down Expand Up @@ -3172,6 +3177,7 @@ format_create_luks (UDisksDaemon *daemon,
crypto_job_data.iterations = encrypt_iterations;
crypto_job_data.time = encrypt_time;
crypto_job_data.threads = encrypt_threads;
crypto_job_data.label = encrypt_label;

/* Create it */
udisks_linux_block_encrypted_lock (block);
Expand Down Expand Up @@ -3411,6 +3417,7 @@ udisks_linux_block_handle_format (UDisksBlock *block,
guint32 encrypt_iterations = 0;
guint32 encrypt_time = 0;
guint32 encrypt_threads = 0;
const gchar *encrypt_label = NULL;
const gchar *erase_type = NULL;
gboolean no_block = FALSE;
gboolean update_partition_type = FALSE;
Expand Down Expand Up @@ -3445,6 +3452,7 @@ udisks_linux_block_handle_format (UDisksBlock *block,
g_variant_lookup (options, "encrypt.iterations", "u", &encrypt_iterations);
g_variant_lookup (options, "encrypt.time", "u", &encrypt_time);
g_variant_lookup (options, "encrypt.threads", "u", &encrypt_threads);
g_variant_lookup (options, "encrypt.label", "&s", &encrypt_label);
g_variant_lookup (options, "erase", "&s", &erase_type);
g_variant_lookup (options, "no-block", "b", &no_block);
g_variant_lookup (options, "update-partition-type", "b", &update_partition_type);
Expand Down Expand Up @@ -3588,6 +3596,7 @@ udisks_linux_block_handle_format (UDisksBlock *block,
encrypt_iterations,
encrypt_time,
encrypt_threads,
encrypt_label,
&block_to_mkfs,
&object_to_mkfs,
&error))
Expand Down
3 changes: 2 additions & 1 deletion src/udiskslinuxencryptedhelpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,12 @@ gboolean luks_format_job_func (UDisksThreadedJob *job,
if (!context)
return FALSE;

if (data->pbkdf || data->memory || data->iterations || data->time || data->threads)
if (data->pbkdf || data->memory || data->iterations || data->time || data->threads || data->label)
{
extra = g_new0 (BDCryptoLUKSExtra, 1);
extra->pbkdf = bd_crypto_luks_pbkdf_new (data->pbkdf, NULL, data->memory, data->iterations,
data->time, data->threads);
extra->label = g_strdup (data->label);
}

/* device, cipher, key_size, context, min_entropy, luks_version, extra, error */
Expand Down
1 change: 1 addition & 0 deletions src/udiskslinuxencryptedhelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ typedef struct {
guint32 iterations;
guint32 time;
guint32 threads;
const gchar *label;
} CryptoJobData;

gboolean luks_format_job_func (UDisksThreadedJob *job,
Expand Down

0 comments on commit a501bcb

Please sign in to comment.