Encrypting private directory with pefs
pefs is a kernel level cryptographic filesystem. It works transparently on top of other filesystems and doesn’t require root privileges. There is no need to allocate another partition and take additional care of backups, resizing partition when it fills up, etc.
# make -C /usr/src/sys/modules/salsa20 obj all install clean
# make -C /usr/src/sys/modules/pefs obj all install clean
# make -C /usr/src/sbin/pefs obj all install clean
Note: It’s being developed on amd64 9-CURRENT, and was tested on i386 8-CURRENT some time ago (before branching). It should also work on 7-STABLE, but I’m not able to test it. Would appreciate any feedback and will try to fix all incompatibilities.
Create a new directory to encrypt. Let it be ~/Private:
% mkdir ~/Private
And mount pefs on top of it (root privileges are necessary to mount filesystem unless you have vfs.usermount sysctl set to non-zero):
% pefs mount ~/Private ~/Private
At this point ~/Private behaves like read-only filesystem because no keys are set up yet. To make it useful add a new key:
% pefs addkey ~/Private
After entering a passphrase, you can check active keys:
% pefs showkeys ~/Private
0 b0bed3f7f33e461b aes256-ctr
As you can see AES algorithm is used by default (in CTR mode with 256 bit key). It can be changed with pefs addkey -a option.
You should take into account that pefs doesn’t save any metadata. That means that there is no way for filesystem to “verify” the key. To work around it key chaining can be used (pefs showchain, setchain, delchain). I’m going show how it works in next posts.
Let’s give it a try:
% echo "Hello WORLD" > ~/Private/test
% ls -Al ~/Private
-rw-r--r-- 1 gleb gleb 12 Oct 1 12:55 test
% cat ~/Private/test
Here is what it looks like at lower filesystem level:
% pefs unmount ~/Private
% ls -Al ~/Private
-rw-r--r-- 1 gleb gleb 12 Oct 1 12:55 .DU6eudxZGtO8Ry_2Z3Sl+tq2hV3O75jq
% hd ~/Private/.DU6eudxZGtO8Ry_2Z3Sl+tq2hV3O75jq
00000000 7f 1e 1b 05 fc 8a 5c 38 fc d8 2d 5f |......\8..-_|
Your result is going to be different because pefs uses random tweak value to encrypt files. This tweak is saved in encrypted file name. Using the tweak also means that the same files have different encrypted content.