Skip to contentSkip to conversation

Key derivation and passprhase wrapping

DISCUSSION Wiebe Cazemier 2 participants 5 messages Jan 18, 2016 – Jan 29, 2016 1 message not in the archive Ecrypt file system

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

Hi,

I was looking at the ecryptfs source code, and saw that the actual encryption key inserted into the kernel keyring is the *original* wrapped passphrase, SHA512'ed 65536 times. Why is a user-given passphrase encrypted as key, and not data from /dev/random? I unwrapped the passphrase on my Linux Mint system and saw it is actually a random string, so the Ubuntu/Mint installer took care of it for me. But why is that responsibility given to the user / outside world? One of the problems is that I can't change it. Had I made a ecryptfs archive myself and wrapped 'hello' as passphrase, that weak key will be used and cannot be changed by rewrapping.

Would it be possible/feasible to do something like:

* generate random encryption key A for insertion into kernel keyring.
* derive encryption key B from password with 'generate_passphrase_sig(...)' to encrypt key A.
* In v2 wrapped passphrase file, Octets 26-N1, store encrypted A, instead of encrypted passphrase.

Depending on how it's implemented, it could even be done completely backwards compatible (by ignoring the to-wrap passphrase).

Regards,

Wiebe

#2 lore raw
Quoted 6 lines · Wiebe Cazemier

Hi,

I was looking at the ecryptfs source code, and saw that the actual encryption key inserted into the kernel keyring is the *original* wrapped passphrase, SHA512'ed 65536 times. Why is a user-given passphrase encrypted as key, and not data from /dev/random?

This assumes that the mount.ecryptfs helper is used and not the mount.ecryptfs_private helper.

mount.ecryptfs does key stretching (SHA512 * 65536) on a user-provided passphrase and uses that as the file encryption key encryption key (FEKEK). This keeps things simple so that the only thing a user needs to access their encrypted files is the passphrase. There's no chance of losing track of a file containing a wrapped FEKEK that is randomly generated. However, mount.ecryptfs could be extended to make use of wrapped, randomly generated FEKEK which would provide a more secure option.

Quoted 4 lines

I unwrapped the passphrase on my Linux Mint system and saw it is actually a random string, so the Ubuntu/Mint installer took care of it for me. But why is that responsibility given to the user / outside world?

All of the logic that set up that random FEKEK is in upstream ecryptfs-utils. The confusion is probably caused by the unfortunate split between the mount.ecryptfs and mount.ecryptfs_private helpers.

Quoted 9 lines

One of the problems is that I can't change it. Had I made a ecryptfs archive myself and wrapped 'hello' as passphrase, that weak key will be used and cannot be changed by rewrapping.

Would it be possible/feasible to do something like:

* generate random encryption key A for insertion into kernel keyring.
* derive encryption key B from password with 'generate_passphrase_sig(...)' to encrypt key A.
* In v2 wrapped passphrase file, Octets 26-N1, store encrypted A, instead of encrypted passphrase.

I'm not following the intent here. You're wanting to change the FEKEK that the Ubuntu/Mint installer generated?

Tyler

Quoted 10 lines

Depending on how it's implemented, it could even be done completely backwards compatible (by ignoring the to-wrap passphrase).

Regards,

Wiebe
--
To unsubscribe from this list: send the line "unsubscribe ecryptfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#3 lore raw

----- Original Message -----

Quoted 47 lines

From: "Tyler Hicks" <[email protected]>
To: "Wiebe Cazemier" <[email protected]>
Cc: [email protected]
Sent: Wednesday, 20 January, 2016 4:05:57 AM
Subject: Re: Key derivation and passprhase wrapping

Quoted 6 lines · Wiebe Cazemier

Hi,

I was looking at the ecryptfs source code, and saw that the actual encryption key inserted into the kernel keyring is the *original* wrapped passphrase, SHA512'ed 65536 times. Why is a user-given passphrase encrypted as key, and not data from /dev/random?

This assumes that the mount.ecryptfs helper is used and not the mount.ecryptfs_private helper.

mount.ecryptfs does key stretching (SHA512 * 65536) on a user-provided passphrase and uses that as the file encryption key encryption key (FEKEK). This keeps things simple so that the only thing a user needs to access their encrypted files is the passphrase. There's no chance of losing track of a file containing a wrapped FEKEK that is randomly generated. However, mount.ecryptfs could be extended to make use of wrapped, randomly generated FEKEK which would provide a more secure option.

Quoted 4 lines

I unwrapped the passphrase on my Linux Mint system and saw it is actually a random string, so the Ubuntu/Mint installer took care of it for me. But why is that responsibility given to the user / outside world?

All of the logic that set up that random FEKEK is in upstream ecryptfs-utils. The confusion is probably caused by the unfortunate split between the mount.ecryptfs and mount.ecryptfs_private helpers.

Quoted 11 lines

One of the problems is that I can't change it. Had I made a ecryptfs archive myself and wrapped 'hello' as passphrase, that weak key will be used and cannot be changed by rewrapping.

Would it be possible/feasible to do something like:

* generate random encryption key A for insertion into kernel keyring.
* derive encryption key B from password with 'generate_passphrase_sig(...)' to encrypt key A.
* In v2 wrapped passphrase file, Octets 26-N1, store encrypted A, instead of encrypted passphrase.

Quoted 12 lines

I'm not following the intent here. You're wanting to change the FEKEK that the Ubuntu/Mint installer generated?

Tyler

Quoted 7 lines

Depending on how it's implemented, it could even be done completely backwards compatible (by ignoring the to-wrap passphrase).

Regards,

Wiebe

I think I missed an important bit. I was looking at ecryptfs-wrap-passphrase, which makes you supply the FEK and FEKEK, but ecryptfs-setup-private actually already uses a random passphrase:

-m, --mountpass MOUNTPASS
Passphrase for mounting the ecryptfs directory, default is 16 bytes from /dev/urandom if omitted

Never mind ;)

#4 lore raw

----- Original Message -----

Quoted 6 lines

From: "Wiebe Cazemier" <[email protected]>
To: "Tyler Hicks" <[email protected]>
Cc: [email protected]
Sent: Wednesday, 20 January, 2016 8:51:43 PM
Subject: Re: Key derivation and passprhase wrapping

Quoted 8 lines

I think I missed an important bit. I was looking at ecryptfs-wrap-passphrase, which makes you supply the FEK and FEKEK, but ecryptfs-setup-private actually already uses a random passphrase:

-m, --mountpass MOUNTPASS
Passphrase for mounting the ecryptfs directory, default is 16 bytes from /dev/urandom if omitted

I do see an issue though. The bash script says:

  random_data=`head -c 16000 /dev/urandom | od -x` || error_testing "$temp" "$(gettext 'Could not generate random data')"

But when urandom can't be read (doesn't exist, no file handles, whatever):

random_data=head -c 16000 /dev/urando | od -x || echo "fail"
head: cannot open ‘/dev/urando’ for reading: No such file or directory

Note, no 'fail' and $? == 0. And:

echo $random_data
0000000

Regards,

Wiebe

#5 lore raw
Quoted 22 lines · Wiebe Cazemier

----- Original Message -----

Quoted 6 lines

From: "Wiebe Cazemier" <[email protected]>
To: "Tyler Hicks" <[email protected]>
Cc: [email protected]
Sent: Wednesday, 20 January, 2016 8:51:43 PM
Subject: Re: Key derivation and passprhase wrapping

Quoted 8 lines

I think I missed an important bit. I was looking at ecryptfs-wrap-passphrase, which makes you supply the FEK and FEKEK, but ecryptfs-setup-private actually already uses a random passphrase:

-m, --mountpass MOUNTPASS
Passphrase for mounting the ecryptfs directory, default is 16 bytes from /dev/urandom if omitted

I do see an issue though. The bash script says:

  random_data=`head -c 16000 /dev/urandom | od -x` || error_testing "$temp" "$(gettext 'Could not generate random data')"

But when urandom can't be read (doesn't exist, no file handles, whatever):

Quoted 7 lines

random_data=head -c 16000 /dev/urando | od -x || echo "fail"
head: cannot open ‘/dev/urando’ for reading: No such file or directory

Note, no 'fail' and $? == 0. And:

echo $random_data
0000000

For completeness, we should mention that this is being tracked in Launchpad:

https://launchpad.net/bugs/1539553

Tyler