]> git.apps.os.sepia.ceph.com Git - fscrypt.git/log
fscrypt.git
4 years agocli-tests: force processes spawned by 'expect' to have 80 column-output
Eric Biggers [Sat, 21 Nov 2020 23:29:26 +0000 (15:29 -0800)]
cli-tests: force processes spawned by 'expect' to have 80 column-output

Otherwise the cli tests fail when executed from GitHub Actions.

4 years agoREADME.md: add table of contents
Eric Biggers [Tue, 10 Nov 2020 04:43:48 +0000 (20:43 -0800)]
README.md: add table of contents

4 years agotravis.yml: upgrade to Ubuntu 20.04 and enable cli tests
Eric Biggers [Sun, 8 Nov 2020 04:30:51 +0000 (20:30 -0800)]
travis.yml: upgrade to Ubuntu 20.04 and enable cli tests

Now that Travis CI supports a version of Ubuntu that has a kernel that
supports v2 encryption policies, upgrade to it and enable the cli tests.

4 years agocmd/fscrypt: fix race condition in getPassphraseKey()
Eric Biggers [Sun, 8 Nov 2020 04:30:51 +0000 (20:30 -0800)]
cmd/fscrypt: fix race condition in getPassphraseKey()

Set the terminal to raw mode *before* printing the prompt.
Otherwise the user (or the automated test) might enter the
passphrase before the terminal gets put into raw mode.

This is needed for some of the CLI tests to pass reliably in Travis CI.

4 years agocli-tests/common.sh: fix _user_do()
Eric Biggers [Sun, 8 Nov 2020 04:30:51 +0000 (20:30 -0800)]
cli-tests/common.sh: fix _user_do()

Apparently, on some distros 'su' doesn't preserve $PATH.  So, manually
export it in the command.  Also, ensure that the shell stays as bash.

This is needed for some of the CLI tests to pass in Travis CI.

4 years agocmd/fscrypt: fix isDirUnlockedHeuristic() on latest kernels
Eric Biggers [Sat, 7 Nov 2020 22:20:45 +0000 (14:20 -0800)]
cmd/fscrypt: fix isDirUnlockedHeuristic() on latest kernels

On an "incompletely locked" directory, isDirUnlockedHeuristic() is
supposed to return true, but on Linux v5.10-rc1 and later it returns
false since now creating a subdirectory fails rather than succeeds.
This change was intentional, so make isDirUnlockedHeuristic() apply a
second heuristic too: also return true if any filenames in the directory
don't appear to be valid no-key names.

This fixes cli-tests/t_v1_encrypt on Linux v5.10-rc1 and later.

4 years agoTravis-ci: added support for ppc64le (#257)
sanjaymsh [Thu, 15 Oct 2020 12:27:25 +0000 (17:57 +0530)]
Travis-ci: added support for ppc64le (#257)

5 years agoFix nil error issue, Resolves https://github.com/google/fscrypt/issues/242
bitcodr [Fri, 7 Aug 2020 05:34:34 +0000 (10:04 +0430)]
Fix nil error issue, Resolves https://github.com/google/fscrypt/issues/242

5 years agoREADME.md: recommend 'sudo make install PREFIX=/usr' on Ubuntu (#244)
Eric Biggers [Fri, 7 Aug 2020 23:37:05 +0000 (16:37 -0700)]
README.md: recommend 'sudo make install PREFIX=/usr' on Ubuntu (#244)

Ubuntu's PAM configuration framework only recognizes files in /usr, not
/usr/local.  So for installs from source, unfortunately we have to
recommend installing to /usr, despite this not being conventional.

Resolves https://github.com/google/fscrypt/issues/240

5 years agoRelease version v0.2.9 (#238)
Eric Biggers [Sat, 13 Jun 2020 17:43:29 +0000 (10:43 -0700)]
Release version v0.2.9 (#238)

5 years agoMerge pull request #237 from ebiggers/t_v1_policy_fix
Eric Biggers [Sat, 13 Jun 2020 17:27:57 +0000 (10:27 -0700)]
Merge pull request #237 from ebiggers/t_v1_policy_fix

Adjust status message for v1 policies unlocked by another user and fix cli-tests/t_v1_policy

5 years agocmd/fscrypt: adjust status message for v1-encrypted dirs
Eric Biggers [Sat, 13 Jun 2020 17:06:15 +0000 (10:06 -0700)]
cmd/fscrypt: adjust status message for v1-encrypted dirs

When 'fscrypt status DIR' detects that a v1-encrypted directory is still
usable but its key seems to be absent, it shows the status as
"Unlocked: Partially (incompletely locked)".  But actually it can also
be the case that the directory is unlocked by another user.  Adjust the
status message accordingly.

This commit also fixes cli-tests/t_v1_policy.

5 years agocli-tests/t_v1_policy: clean up user keyrings at end of test
Eric Biggers [Sat, 13 Jun 2020 17:06:15 +0000 (10:06 -0700)]
cli-tests/t_v1_policy: clean up user keyrings at end of test

The test user's user keyring is still linked into root's user keyring at
the end of the test.  This is making the test flaky, as there is a
failure that only occurs the first time it is run.  Fix the test to
restore the initial state.  This makes it consistently fail (to be fixed
by the next commit).

5 years agoMerge pull request #235 from ebiggers/32bit-fix
Eric Biggers [Wed, 3 Jun 2020 01:02:08 +0000 (18:02 -0700)]
Merge pull request #235 from ebiggers/32bit-fix

* cmd/fscrypt: fix 32-bit build
* travis.yml: build 32-bit binary

5 years agocmd/fscrypt: fix 32-bit build
Eric Biggers [Wed, 3 Jun 2020 00:17:54 +0000 (17:17 -0700)]
cmd/fscrypt: fix 32-bit build

statfs.Bsize actually has platform-dependent type, despite the Go
documentation listing it as int64.  Fix the build for 32-bit platforms
by casting it to int64.

Resolves https://github.com/google/fscrypt/issues/233

5 years agotravis.yml: build 32-bit binary
Eric Biggers [Wed, 3 Jun 2020 00:09:21 +0000 (17:09 -0700)]
travis.yml: build 32-bit binary

Don't let people check in code that breaks 32-bit builds.

Update https://github.com/google/fscrypt/issues/233

5 years agoRelease version v0.2.8 (#230)
Eric Biggers [Wed, 20 May 2020 10:36:16 +0000 (03:36 -0700)]
Release version v0.2.8 (#230)

5 years agocmd/fscrypt: fix up path formatting in ErrDirNotEmpty suggestion (#229)
Eric Biggers [Fri, 15 May 2020 02:48:23 +0000 (19:48 -0700)]
cmd/fscrypt: fix up path formatting in ErrDirNotEmpty suggestion (#229)

Use %q, in case the paths contain whitespace.  Also clean the directory
path to remove trailing slashes before appending the ".new" suffix.

5 years agocmd/fscrypt: link to guide when interactively creating login protector (#225)
Eric Biggers [Thu, 14 May 2020 02:14:13 +0000 (19:14 -0700)]
cmd/fscrypt: link to guide when interactively creating login protector (#225)

Update https://github.com/google/fscrypt/issues/220

5 years agoREADME.md: try to disambiguate "fscrypt" (#226)
Eric Biggers [Thu, 14 May 2020 02:11:28 +0000 (19:11 -0700)]
README.md: try to disambiguate "fscrypt" (#226)

Explicitly mention that "fscrypt" here means the userspace tool, not the
kernel part.  Also write `fscrypt` in code font to emphasize this.

5 years agoREADME.md: further improve the "encryption not enabled" section (#227)
Eric Biggers [Thu, 14 May 2020 02:10:18 +0000 (19:10 -0700)]
README.md: further improve the "encryption not enabled" section (#227)

5 years agoREADME.md: fix typo "nrounds" => "rounds" (#228)
Eric Biggers [Thu, 14 May 2020 01:53:56 +0000 (18:53 -0700)]
README.md: fix typo "nrounds" => "rounds" (#228)

Update https://github.com/google/fscrypt/issues/220

5 years agoREADME.md: improve documentation for login protectors (#223)
Eric Biggers [Tue, 12 May 2020 16:45:42 +0000 (09:45 -0700)]
README.md: improve documentation for login protectors (#223)

Update https://github.com/google/fscrypt/issues/220

5 years agoDeclare instead of define variable in header file. (#224)
Shuai Wang [Sun, 10 May 2020 21:22:54 +0000 (14:22 -0700)]
Declare instead of define variable in header file. (#224)

This fixes link error with gcc 10 which defaults to -fno-common

5 years agoMerge pull request #219 from ebiggers/improve-errors
Eric Biggers [Sat, 9 May 2020 22:27:24 +0000 (15:27 -0700)]
Merge pull request #219 from ebiggers/improve-errors

Improve error messages and suggestions

5 years agocmd/fscrypt: improve errors
Eric Biggers [Sat, 9 May 2020 21:52:07 +0000 (14:52 -0700)]
cmd/fscrypt: improve errors

In checkEncryptable(), check whether the directory is already encrypted
before checking whether it's empty.

Also improve the error message for when a directory is nonempty.

Finally, translate keyring.ErrKeyAddedByOtherUsers and
keyring.ErrKeyFilesOpen into errors which include the directory.

5 years agocmd/fscrypt: remove ErrMaxPassphrase
Eric Biggers [Sat, 9 May 2020 21:52:07 +0000 (14:52 -0700)]
cmd/fscrypt: remove ErrMaxPassphrase

This isn't actually a valid error since crypto.NewKeyFromReader()
handles re-allocating the buffer to a larger size if it fills up.

5 years agofilesystem: improve errors
Eric Biggers [Sat, 9 May 2020 21:52:07 +0000 (14:52 -0700)]
filesystem: improve errors

Introduce filesystem.ErrEncryptionNotEnabled and
filesystem.ErrEncryptionNotSupported which include the Mount as context,
and translate the corresponding metadata/ errors into them.  Then make
these errors show much better suggestions.

Also replace lots of other filesystem/ errors with either custom types
or with unnamed one-off errors that include more context.  Fix backwards
wrapping in lots of cases.

Finally, don't include the mountpoint in places where it's not useful,
like OS-level errors that already include the path.

5 years agometadata: improve errors
Eric Biggers [Sat, 9 May 2020 21:52:07 +0000 (14:52 -0700)]
metadata: improve errors

ErrBadOwners:
Rename to ErrDirectoryNotOwned for clarity, move it from
cmd/fscrypt/ to metadata/ where it better belongs, and improve
the message.

ErrEncrypted:
Rename to ErrAlreadyEncrypted for clarity, and include the path.

ErrNotEncrypted:
Include the path.

ErrBadEncryptionOptions:
Include the path and bad options.

ErrEncryptionNotSupported:
ErrEncryptionNotEnabled:
Don't wrap with "get encryption policy %s", in preparation for
wrapping these with filesystem-level context instead.

Also avoid mixing together the error handling for the "get policy" and
"set policy" ioctls.  Make it very clear how we're handling the errors
from each ioctl.

5 years agokeyring: improve errors
Eric Biggers [Sat, 9 May 2020 21:52:07 +0000 (14:52 -0700)]
keyring: improve errors

ErrAccessUserKeyring:
Include the user, and fix the backwards wrapping.

ErrSessionUserKeyring:
Include the user.

ErrKeyAdd:
ErrKeyRemove:
ErrKeySearch:
ErrLinkUserKeyring:
Replace these with one-off unnamed errors because they are
never checked for, and this makes it easier for the callers to
provide better messages, e.g. fixing the backwards wrapping.

5 years agocrypto: improve errors
Eric Biggers [Sat, 9 May 2020 21:52:07 +0000 (14:52 -0700)]
crypto: improve errors

ErrKeyLock:
Rename to ErrMlockUlimit for clarity.

ErrGetrandomFail:
ErrKeyAlloc:
ErrKeyFree:
ErrNegativeLength:
Replace these with one-off unnamed errors because these were all
returned in only one place and were never checked for.  Also
these were all either wrapped backwards or discarded an
underlying error, so fix that too.

5 years agoactions/policy: improve errors
Eric Biggers [Sat, 9 May 2020 21:52:07 +0000 (14:52 -0700)]
actions/policy: improve errors

ErrMissingPolicyMetadata:
Include the mount, directory path, and metadata path.  Also move
the explanation into actions/ since it doesn't refer to any CLI
command.

ErrPolicyMetadataMismatch:
Include a lot more information.  Also start checking for
consistency of the policy key descriptors, not just the
encryption options.  Add a test for this.

ErrDifferentFilesystem:
Include the mountpoints.

ErrOnlyProtector:
Clarify the message and include the protector descriptor.

ErrAlreadyProtected:
ErrNotProtected:
Include the policy and protector descriptors.

ErrAccessDeniedPossiblyV2:
Make it slightly clearer what failed.  Also move the explanation
into actions/ since it doesn't refer to any CLI command.

5 years agoactions/protector: improve errors
Eric Biggers [Sat, 9 May 2020 21:52:07 +0000 (14:52 -0700)]
actions/protector: improve errors

ErrProtectorName:
Rename to ErrLoginProtectorName for clarity, and include the
name and user.

ErrMissingProtectorName:
Include the correct protector source.

ErrDuplicateName:
Rename to ErrProtectorNameExists for clarity, and remove a level
of wrapping by including the name directly.

ErrDuplicateUID:
Rename to ErrLoginProtectorExists for clarity, and remove a
level of wrapping by including the user directly.

5 years agoactions/config: improve config file related errors
Eric Biggers [Sat, 9 May 2020 21:52:06 +0000 (14:52 -0700)]
actions/config: improve config file related errors

ErrBadConfig:
Fix backwards wrapping, include the bad config, and make it
clear that this is an internal error.

ErrBadConfigFile:
Fix backwards wrapping, include the config file location, and
adjust the suggestion slightly.

ErrConfigFileExists:
Include the config file location.

ErrNoConfigFile:
Include the config file location, and adjust the suggestion
slightly.

5 years agocmd/fscrypt: make wrapText() support code blocks
Eric Biggers [Sat, 9 May 2020 21:52:06 +0000 (14:52 -0700)]
cmd/fscrypt: make wrapText() support code blocks

Allow the input text to contain "code blocks" denoted by lines beginning
with ">", e.g.:

    Foo bar baz:

    > echo foo
    > echo bar

Instead of squashing these lines together, preserve the line breaks
between them and add indentation, e.g.:

    Foo bar baz:

        echo foo
        echo bar

5 years agoMerge pull request #217 from ebiggers/detect-incomplete-v1-locking
Eric Biggers [Sat, 9 May 2020 22:21:07 +0000 (15:21 -0700)]
Merge pull request #217 from ebiggers/detect-incomplete-v1-locking

Try to detect incomplete locking of v1-encrypted directory

5 years agoTry to detect incomplete locking of v1-encrypted directory
Eric Biggers [Sat, 9 May 2020 21:17:17 +0000 (14:17 -0700)]
Try to detect incomplete locking of v1-encrypted directory

'fscrypt lock' on a v1-encrypted directory doesn't warn about in-use
files, as the kernel doesn't provide a way to easily detect it.

Instead, implement a heuristic where we check whether a subdirectory can
be created.  If yes, then the directory must not be fully locked.

Make both 'fscrypt lock' and 'fscrypt status' use this heuristic.

Resolves https://github.com/google/fscrypt/issues/215

5 years agokeyring/user_keyring: switch to KEYCTL_UNLINK
Eric Biggers [Sat, 9 May 2020 21:17:17 +0000 (14:17 -0700)]
keyring/user_keyring: switch to KEYCTL_UNLINK

KEYCTL_INVALIDATE has complicated semantics: it doesn't remove the key
from the keyring right away but rather marks it as being invalidated,
and then removes it asynchronously.  This nondeterministically breaks
the heuristic I'm implementing to detect v1-encrypted directories being
incompletely locked.

Instead, switch to KEYCTL_UNLINK, which has simpler semantics.

Note that Android uses KEYCTL_UNLINK too.

5 years agoMerge pull request #218 from ebiggers/cli-tests
Eric Biggers [Sat, 9 May 2020 22:15:12 +0000 (15:15 -0700)]
Merge pull request #218 from ebiggers/cli-tests

Add tests for command-line interface

Add tests that directly test the fscrypt command-line tool.

See cli-tests/README.md for information about the test framework.

The following test scripts are included:

* t_change_passphrase
* t_encrypt_custom
* t_encrypt_login
* t_encrypt_raw_key
* t_encrypt
* t_lock
* t_not_enabled
* t_not_supported
* t_passphrase_hashing
* t_setup
* t_status
* t_unlock
* t_v1_policy_fs_keyring
* t_v1_policy

Unfortunately, we can't actually make Travis CI run these tests yet because they need kernel v5.4 or later, and Travis CI doesn't support an Ubuntu version that has that yet. But for now, they can be run manually using make cli-test.

5 years agocli-tests: add t_v1_policy_fs_keyring
Eric Biggers [Sat, 9 May 2020 21:04:47 +0000 (14:04 -0700)]
cli-tests: add t_v1_policy_fs_keyring

Test using v1 encryption policies (deprecated) with
use_fs_keyring_for_v1_policies = true.

5 years agocli-tests: add t_v1_policy
Eric Biggers [Sat, 9 May 2020 21:04:47 +0000 (14:04 -0700)]
cli-tests: add t_v1_policy

Test using v1 encryption policies (deprecated).

5 years agocli-tests: add t_unlock
Eric Biggers [Sat, 9 May 2020 21:04:47 +0000 (14:04 -0700)]
cli-tests: add t_unlock

Test unlocking a directory.

5 years agocli-tests: add t_status
Eric Biggers [Sat, 9 May 2020 21:04:47 +0000 (14:04 -0700)]
cli-tests: add t_status

Test getting global, filesystem, and unencrypted directory status when
the filesystem is or isn't set up for fscrypt.

5 years agocli-tests: add t_setup
Eric Biggers [Sat, 9 May 2020 21:04:47 +0000 (14:04 -0700)]
cli-tests: add t_setup

Test 'fscrypt setup'.

5 years agocli-tests: add t_passphrase_hashing
Eric Biggers [Sat, 9 May 2020 21:04:47 +0000 (14:04 -0700)]
cli-tests: add t_passphrase_hashing

Test that the passphrase hashing seems to take long enough.

5 years agocli-tests: add t_not_supported
Eric Biggers [Sat, 9 May 2020 21:04:47 +0000 (14:04 -0700)]
cli-tests: add t_not_supported

Test that fscrypt fails when the filesystem doesn't support encryption.

5 years agocli-tests: add t_not_enabled
Eric Biggers [Sat, 9 May 2020 21:04:47 +0000 (14:04 -0700)]
cli-tests: add t_not_enabled

Test that fscrypt fails when the filesystem doesn't have the encrypt
feature enabled.  Then test enabling it.

5 years agocli-tests: add t_lock
Eric Biggers [Sat, 9 May 2020 21:04:47 +0000 (14:04 -0700)]
cli-tests: add t_lock

Test locking a directory.

5 years agocli-tests: add t_encrypt_raw_key
Eric Biggers [Sat, 9 May 2020 21:04:47 +0000 (14:04 -0700)]
cli-tests: add t_encrypt_raw_key

Test encrypting a directory using a raw_key protector.

5 years agocli-tests: add t_encrypt_login
Eric Biggers [Sat, 9 May 2020 21:04:47 +0000 (14:04 -0700)]
cli-tests: add t_encrypt_login

Test encrypting a directory using a login (pam_passphrase) protector.

5 years agocli-tests: add t_encrypt_custom
Eric Biggers [Sat, 9 May 2020 21:04:47 +0000 (14:04 -0700)]
cli-tests: add t_encrypt_custom

Test encrypting a directory using a custom_passphrase protector.

5 years agocli-tests: add t_encrypt
Eric Biggers [Sat, 9 May 2020 21:04:47 +0000 (14:04 -0700)]
cli-tests: add t_encrypt

Add general tests for 'fscrypt encrypt'.  For protector-specific tests,
see t_encrypt_custom, t_encrypt_login, and t_encrypt_raw_key.

5 years agocli-tests: add t_change_passphrase
Eric Biggers [Sat, 9 May 2020 21:04:47 +0000 (14:04 -0700)]
cli-tests: add t_change_passphrase

Test changing the passphrase of a custom_passphrase protector.

5 years agoWire up shellcheck of cli-tests/*.sh to 'make lint'
Eric Biggers [Sat, 9 May 2020 21:04:47 +0000 (14:04 -0700)]
Wire up shellcheck of cli-tests/*.sh to 'make lint'

Enforce that all the cli-test scripts pass 'shellcheck'.

5 years agoAdd cli-tests framework
Eric Biggers [Sat, 9 May 2020 21:04:47 +0000 (14:04 -0700)]
Add cli-tests framework

Add a framework for writing automated tests of the fscrypt command-line
tool.  See cli-tests/README.md for details.

5 years agocmd/fscrypt: add FSCRYPT_CONSISTENT_OUTPUT environmental variable
Eric Biggers [Sat, 9 May 2020 21:04:47 +0000 (14:04 -0700)]
cmd/fscrypt: add FSCRYPT_CONSISTENT_OUTPUT environmental variable

Allow setting FSCRYPT_CONSISTENT_OUTPUT=1 in the environment to cause
policies and protectors to sorted by last modification time.  The CLI
tests need this to make the output of 'fscrypt' ordered in a consistent
way with regard to the operations performed.

5 years agocmd/fscrypt: add FSCRYPT_ROOT_MNT environmental variable
Eric Biggers [Sat, 9 May 2020 21:04:47 +0000 (14:04 -0700)]
cmd/fscrypt: add FSCRYPT_ROOT_MNT environmental variable

Allow overriding the mountpoint where login protectors are stored by
setting the FSCRYPT_ROOT_MNT environmental variable.  The CLI tests need
this to avoid touching the real "/".

5 years agocmd/fscrypt: add FSCRYPT_CONF environmental variable
Eric Biggers [Sat, 9 May 2020 21:04:47 +0000 (14:04 -0700)]
cmd/fscrypt: add FSCRYPT_CONF environmental variable

Allow overriding the location of fscrypt.conf by setting the
FSCRYPT_CONF environmental variable.  The CLI tests need this to avoid
touching the real /etc/fscrypt.conf.

5 years agotravis.yml: stop overriding e2fsprogs version (#222)
Eric Biggers [Sat, 9 May 2020 19:54:37 +0000 (12:54 -0700)]
travis.yml: stop overriding e2fsprogs version (#222)

There's no longer a need to override the Ubuntu version that the
Travis CI builds install e2fsprogs from, since we now use
"dist: bionic", and e2fsprogs in Bionic supports encryption.

5 years agokeyring: cast FS_IOC_REMOVE_ENCRYPTION_KEY to uintptr (#221)
Filip Stanis [Tue, 5 May 2020 01:48:26 +0000 (02:48 +0100)]
keyring: cast FS_IOC_REMOVE_ENCRYPTION_KEY to uintptr (#221)

Since v0.2.6, fscrypt only builds for 64-bit systems.  E.g. trying to
build on Raspbian fails with the following error:

  $ go get github.com/google/fscrypt/cmd/fscrypt
  # github.com/google/fscrypt/keyring
  go/src/github.com/google/fscrypt/keyring/fs_keyring.go:231:6: constant 3225445912 overflows int
  go/src/github.com/google/fscrypt/keyring/fs_keyring.go:235:7: constant 3225445913 overflows int

Fix it by making the 'ioc' variable have type uintptr.

[EB - removed the later cast to uintptr that became unnecessary, and
 added explanation to commit message.]

5 years agoAllow fscrypt to work in containers (#213)
Eric Biggers [Fri, 17 Apr 2020 03:43:48 +0000 (20:43 -0700)]
Allow fscrypt to work in containers (#213)

Update the /proc/self/mountinfo parsing code to allow selecting a Mount
with Subtree != "/", i.e. a Mount not of the full filesystem.  This is
needed to allow fscrypt to work in containers, where the root of the
filesystem may not be mounted.

See findMainMount() for details about the algorithm used.

Resolves https://github.com/google/fscrypt/issues/211

5 years agoRelease version v0.2.7
Joe Richey [Tue, 24 Mar 2020 07:17:57 +0000 (00:17 -0700)]
Release version v0.2.7

Signed-off-by: Joe Richey <joerichey@google.com>
5 years agoMakefile: Use trimpath if available (#208)
Joseph Richey [Tue, 24 Mar 2020 07:16:12 +0000 (00:16 -0700)]
Makefile: Use trimpath if available (#208)

Passing -trimpath makes the build entirely reproducible.

Signed-off-by: Joe Richey <joerichey@google.com>
5 years agocmd: Simplify "fscrypt --version" output (#207)
Joseph Richey [Mon, 23 Mar 2020 21:24:48 +0000 (14:24 -0700)]
cmd: Simplify "fscrypt --version" output (#207)

There's no need to include the build time, author, and copyright info
in the output of "fscrypt --version". This information is:

  - Overly complex (the current string is hard to parse)
  - Inaccurate (there are other authors than just me)
  - Unnecessary (the Apache 2 license is for Source Code)
  - Makes reproducible builds impossible

The default version string is just fine.

Signed-off-by: Joe Richey <joerichey@google.com>
5 years agoMerge pull request #205 from ebiggers/autoselect-v2
Joseph Richey [Mon, 23 Mar 2020 21:24:23 +0000 (14:24 -0700)]
Merge pull request #205 from ebiggers/autoselect-v2

Automatically enable policy_version 2 when kernel support is detected

5 years agoREADME.md: update v2 policy-related documentation
Eric Biggers [Wed, 18 Mar 2020 04:10:58 +0000 (21:10 -0700)]
README.md: update v2 policy-related documentation

- Mention that a v5.4+ kernel is recommended.

- Mention that policy_version defaults to 1 when unset.

- Emphasize that v2 policies are the recommended solution to the key
  visibility problems, and add some more information.

5 years agoREADME.md: update examples to use v2 policies
Eric Biggers [Wed, 18 Mar 2020 04:10:58 +0000 (21:10 -0700)]
README.md: update examples to use v2 policies

Since on new kernels v1 encryption policies are deprecated in favor of
v2, update the examples to show v2.  This mostly just consists of
updating the output, as the commands are essentially the same with one
notable difference in 'fscrypt lock'.

5 years agoImprove error message when unlocking v2 policy is unsupported
Eric Biggers [Wed, 18 Mar 2020 04:10:58 +0000 (21:10 -0700)]
Improve error message when unlocking v2 policy is unsupported

If trying to unlock a v2-encrypted directory fails because the kernel
lacks support for v2 policies, show a better error message.  This can
happen if someone downgrades their kernel or tries to access encrypted
directories on removable storage from a computer with an older kernel.

Detecting this case is difficult since all we have to go with is EACCES
when opening the directory.  Implement a heuristic where if get EACCES,
we actually have read access to the directory, and the kernel doesn't
support v2 policies, we show the improved error message.

Before:

  # fscrypt unlock dir
  [ERROR] fscrypt unlock: open dir: permission denied

After:

  # fscrypt unlock dir
  [ERROR] fscrypt unlock: open dir: permission denied

  This may be caused by the directory using a v2 encryption policy and
  the current kernel not supporting it. If indeed the case, then this
  directory can only be used on kernel v5.4 and later. You can create
  directories accessible on older kernels by changing policy_version to
  1 in /etc/fscrypt.conf.

5 years agoImprove error message when setting v2 policy is unsupported
Eric Biggers [Wed, 18 Mar 2020 04:10:58 +0000 (21:10 -0700)]
Improve error message when setting v2 policy is unsupported

If trying to encrypt a directory using a v2 policy fails due to the
kernel lacking support for v2 policies, show a better error message.

One way this can happen is if someone runs 'fscrypt setup' with a new
kernel and then downgrades to an old kernel.

Before:

  # echo -n hunter2 | fscrypt encrypt dir --source=custom_passphrase --name=foo --quiet
  [ERROR] fscrypt encrypt: inappropriate ioctl for device: system error: could not add key to the keyring

After:

  # echo -n hunter2 | fscrypt encrypt dir --source=custom_passphrase --name=foo --quiet
  [ERROR] fscrypt encrypt: kernel is too old to support v2 encryption policies

  v2 encryption policies are only supported by kernel version 5.4 and
  later. Either use a newer kernel, or change policy_version to 1 in
  /etc/fscrypt.conf.

5 years agoCreate /etc/fscrypt.conf with policy_version 2 on kernel v5.4+
Eric Biggers [Wed, 18 Mar 2020 04:10:58 +0000 (21:10 -0700)]
Create /etc/fscrypt.conf with policy_version 2 on kernel v5.4+

v2 encryption policies are now recommended, due to various security and
usability advantages over v1 policies.  Many people have been running
into the usability problems with v1, so it's desirable to get people
onto v2 without having to manually opt-in.

Therefore, when 'fscrypt setup' creates /etc/fscrypt.conf, enable
policy_version 2 automatically if the kernel supports it.

I decided to go with this solution over the policy_version "auto" I
suggested originally because this way is simpler, it can still be
changed to "auto" later if desired, and "auto" might require changing
how we parse the config file (since currently the config file is mapped
directly to a protobuf where policy_version is an 'int' and is shared
with EncryptionOptions).

Resolves https://github.com/google/fscrypt/issues/182

5 years agoSimplify choosing the key description prefix
Eric Biggers [Wed, 18 Mar 2020 04:10:58 +0000 (21:10 -0700)]
Simplify choosing the key description prefix

There's no real need to allow users to choose the key description prefix
(a.k.a. the "service"), since on ext4 and f2fs we can just use "ext4"
and "f2fs" for compatibility with all kernels both old and new, and on
other filesystems we can just use "fscrypt".  So, let's do that.

Since this removes the point of the "--legacy" option to 'fscrypt setup'
and the "compatibility" field in /etc/fscrypt.conf, remove those too.

Specifically, we start ignoring the "compatibility" in existing config
files and not writing it to new ones.  The corresponding protobuf field
number and name are reserved.  We stop accepting the "--legacy" option
at all, although since it was default true and there was no real reason
for anyone to change it to false, probably no one will notice.  If
anyone does, they should just stop specifying the option.

Note that this change only affects user keyrings and thus only affects
v1 encryption policies, which are deprecated in favor of v2 anyway.

5 years agoREADME.md: improve documentation for PAM configuration (#204)
Eric Biggers [Fri, 20 Mar 2020 04:50:04 +0000 (21:50 -0700)]
README.md: improve documentation for PAM configuration (#204)

5 years agoMakefile: clean up installation commands (#201)
Eric Biggers [Sat, 22 Feb 2020 21:28:17 +0000 (13:28 -0800)]
Makefile: clean up installation commands (#201)

Improve the documentation for the installation-related Makefile
variables, and update the commands to remove the forward slash after
$(DESTDIR) in order to remove a duplicate forward slash and match the
recommended usage.

5 years agoUse DESTDIR for install prefix (#200)
Anatol Pomozov [Wed, 19 Feb 2020 07:32:50 +0000 (23:32 -0800)]
Use DESTDIR for install prefix (#200)

DESTDIR has a well established purpose
https://www.gnu.org/prep/standards/html_node/DESTDIR.html
It is a suffix for all the files to be installed. And it is used by
package managers who installs the files into some $tmpdir before
creating a package.

Change the build commands to follow this convention.

Add BINDIR that does the same what previous did $DESTDIR.

5 years agoRelease version v0.2.6 (#198)
Joseph Richey [Tue, 11 Feb 2020 07:20:14 +0000 (23:20 -0800)]
Release version v0.2.6 (#198)

* Release version v0.2.6

Fixes #195

Also, update the encrypted API key.
My person access token had expired, this one should work now.

Signed-off-by: Joe Richey <joerichey@google.com>
5 years agocmd/fscrypt/commands: allow disabling recovery passphrase (#193)
Eric Biggers [Thu, 30 Jan 2020 03:27:10 +0000 (19:27 -0800)]
cmd/fscrypt/commands: allow disabling recovery passphrase (#193)

While it's important to generate a recovery passphrase in the linked
protector case to avoid data loss if the system is reinstalled, some
people really don't want it (even though it can be safely ignored as it
almost certainly has far more entropy than the login passphrase).

As a compromise, prompt for y/n before generating it, with default y.
Also, to allow disabling the recovery passphrase during noninteractive
use, add a --no-recovery command-line option.

Update https://github.com/google/fscrypt/issues/186

5 years agoMerge pull request #192 from ebiggers/cleanup-on-error
Eric Biggers [Thu, 30 Jan 2020 02:46:57 +0000 (18:46 -0800)]
Merge pull request #192 from ebiggers/cleanup-on-error

Clean up policies and protectors on error

5 years agoactions/policy: revert new protector links on failure
Eric Biggers [Tue, 28 Jan 2020 04:16:35 +0000 (20:16 -0800)]
actions/policy: revert new protector links on failure

Ensure that when an encryption policy is reverted (e.g. due to
encryptPath() failing after the policy was created), we also delete any
new protector links that were created for the policy, as this is not
handled by the logic that reverts new protectors.

5 years agofilesystem: don't overwrite existing protector links
Eric Biggers [Tue, 28 Jan 2020 04:16:35 +0000 (20:16 -0800)]
filesystem: don't overwrite existing protector links

When adding a protector to a policy, don't unconditionally overwrite the
protector link, because it may already exist.  Instead, if it already
exists and points to the mount, just use it.  If it already exists and
points to the wrong place, return an error.

Also add a bool to the return value of AddLinkedProtector() so that
callers can check whether the link was newly created or not.

5 years agocmd/fscrypt/commands: clean up properly when encryptPath() fails
Eric Biggers [Tue, 28 Jan 2020 04:16:35 +0000 (20:16 -0800)]
cmd/fscrypt/commands: clean up properly when encryptPath() fails

Move the deferred locking and deletion of the policy on failure to the
correct places, so that it's done in all failure cases, including in the
case where adding the recovery protector fails.

Also make the recovery protector be locked and deleted on failure.

Finally, put all the code to do deferred deprovisioning of the policy in
the same place: right after it's provisioned.

5 years agoactions/recovery: revert protector if it can't be added to policy
Eric Biggers [Tue, 28 Jan 2020 04:16:35 +0000 (20:16 -0800)]
actions/recovery: revert protector if it can't be added to policy

Ensure that a failed AddRecoveryPassphrase() doesn't leave around an
unneeded protector file.

5 years agocmd/fscrypt/errors: explicitly mark error messages as errors (#191)
Eric Biggers [Tue, 28 Jan 2020 09:58:51 +0000 (01:58 -0800)]
cmd/fscrypt/errors: explicitly mark error messages as errors (#191)

When an fscrypt command fails and prints an error message, in some cases
it isn't clear that the message is actually an error, e.g.:

    fscrypt encrypt: login protectors do not need a name

Make it clear by always prefixing the message with "[ERROR] ", e.g.

    [ERROR] fscrypt encrypt: login protectors do not need a name

Update https://github.com/google/fscrypt/issues/186

5 years agocmd/fscrypt/setup: don't prompt to create /etc/fscrypt.conf (#190)
Eric Biggers [Tue, 28 Jan 2020 09:57:46 +0000 (01:57 -0800)]
cmd/fscrypt/setup: don't prompt to create /etc/fscrypt.conf (#190)

When 'fscrypt setup' sees that /etc/fscrypt.conf doesn't exist, don't
ask for confirmation before creating it.  Just do it.  This is the
normal use, and there's not a good reason to ask the user to confirm it.

5 years agoactions/recovery: ensure recovery passphrase is really custom_passphrase
Eric Biggers [Tue, 28 Jan 2020 03:24:30 +0000 (19:24 -0800)]
actions/recovery: ensure recovery passphrase is really custom_passphrase

If the login protector was just created by the same 'fscrypt encrypt'
command, then policy.Context.Config.Source will be pam_passphrase.  This
needs to be overridden to custom_passphrase when creating the protector
for the recovery passphrase.

This fixes the following error:

    fscrypt encrypt: login protectors do not need a name

Resolves https://github.com/google/fscrypt/issues/187
Update https://github.com/google/fscrypt/issues/186

5 years agoDocument how to check for kernel config options (#183)
ebiggers [Thu, 23 Jan 2020 21:46:18 +0000 (13:46 -0800)]
Document how to check for kernel config options (#183)

Resolves https://github.com/google/fscrypt/issues/181

5 years agoprivileges.go: remove a stale comment (#184)
ebiggers [Thu, 23 Jan 2020 21:42:10 +0000 (13:42 -0800)]
privileges.go: remove a stale comment (#184)

The workaround for Go versions before 1.10 was already removed by
commit 3022c1603d96 ("Ensure setting user privileges is reversible").

5 years agofilesystem: remove canonicalizePath() (#185)
ebiggers [Thu, 23 Jan 2020 21:41:42 +0000 (13:41 -0800)]
filesystem: remove canonicalizePath() (#185)

canonicalizePath() is now only used by an error path in
getMountFromLink(), which we can make use getDeviceName() instead.

5 years agoMerge pull request #167 from ebiggers/recovery-passphrase
ebiggers [Thu, 23 Jan 2020 03:16:20 +0000 (19:16 -0800)]
Merge pull request #167 from ebiggers/recovery-passphrase

Automatically generate recovery passphrase when useful

5 years agoAutomatically generate recovery passphrase when useful
Eric Biggers [Wed, 27 Nov 2019 20:04:13 +0000 (12:04 -0800)]
Automatically generate recovery passphrase when useful

If a user re-installs their system (or otherwise loses the /.fscrypt
directory on the root filesystem) they also lose access to any login
passphrase-protected directories on other filesystems, unless additional
protectors were manually added.  This can be unexpected, as it may be
expected that the old login passphrase would still work.

We can't really fix this by storing a login protector on every
filesystem because:

- If a user were to have N login protectors, it would take them N times
  longer to log in, as every login protector would need to be unlocked.

- If a user were to change their login passphrase while any external
  volumes were unmounted, login protectors would get out of sync.

- It's preferable that an external volume isn't unlockable by itself
  using only a login passphrase, as login passphrases are often weak.

Instead, generate a recovery passphrase when creating a login
passphrase-protected directory on a non-root filesystem.

The recovery passphrase is added as a custom_passphrase protector, thus
giving the policy two protectors: one pam_passphrase and one
custom_passphrase.  Then this passphrase is written to a file in the new
encrypted directory.  Writing the passphrase to a file here is okay
since it's encrypted, but it's obviously useless by itself; it's up to
the user to store this passphrase somewhere else if they need it.

Use a recovery passphrase instead of a "recovery code" that encodes the
policy key directly because a passphrase is more user-friendly: it can
safely be made much shorter than a key, and it works just like any other
fscrypt protector.  Also, it's not as critical to allow recovery when
the .fscrypt directory on the *same* filesystem is deleted.

Resolves https://github.com/google/fscrypt/issues/164

5 years agoMerge pull request #148 from ebiggers/fscrypt-key-mgmt-improvements
ebiggers [Thu, 23 Jan 2020 02:28:23 +0000 (18:28 -0800)]
Merge pull request #148 from ebiggers/fscrypt-key-mgmt-improvements

Filesystem keyring and v2 encryption policy support

5 years agoREADME.md: document new settings and troubleshooting key access
Eric Biggers [Mon, 16 Dec 2019 03:31:39 +0000 (19:31 -0800)]
README.md: document new settings and troubleshooting key access

Document the new /etc/fscrypt.conf settings for the filesystem keyring
and v2 encryption policies, and add a new subsection for troubleshooting
key access problems.

5 years agocmd/fscrypt, keyring: add --all-users option to 'fscrypt lock'
Eric Biggers [Mon, 16 Dec 2019 03:31:39 +0000 (19:31 -0800)]
cmd/fscrypt, keyring: add --all-users option to 'fscrypt lock'

Allow root to provide the --all-users option to 'fscrypt lock' to force
an encryption key to be removed from the filesystem (i.e., force an
encrypted directory to be locked), even if other users have added it.

To implement this option, we just need to use the
FS_IOC_REMOVE_ENCRYPTION_KEY_ALL_USERS ioctl rather than
FS_IOC_REMOVE_ENCRYPTION_KEY.

In theory this option could be implemented for the user keyrings case
too, but it would be difficult and the user keyrings are being
deprecated for fscrypt, so don't bother.

5 years agoKeyring support for v2 encryption policies
Eric Biggers [Mon, 16 Dec 2019 03:31:39 +0000 (19:31 -0800)]
Keyring support for v2 encryption policies

Implement adding/removing v2 encryption policy keys to/from the kernel.
The kernel requires that the new ioctls FS_IOC_ADD_ENCRYPTION_KEY and
FS_IOC_REMOVE_ENCRYPTION_KEY be used for this.  Root is not required.

However, non-root support brings an extra complication: the kernel keeps
track of which users have called FS_IOC_ADD_ENCRYPTION_KEY for the same
key.  FS_IOC_REMOVE_ENCRYPTION_KEY only works as one of these users, and
it only removes the calling user's claim to the key; the key is only
truly removed when the last claim is removed.

Implement the following behavior:

- 'fscrypt unlock' and pam_fscrypt add the key for the user, even if
  other user(s) have it added already.  This behavior is needed so that
  another user can't remove the key out from under the user.

- 'fscrypt lock' and pam_fscrypt remove the key for the user.  However,
  if the key wasn't truly removed because other users still have it
  added, 'fscrypt lock' prints a warning.

- 'fscrypt status' shows whether the directory is unlocked for anyone.

5 years agoMetadata support for v2 encryption policies
Eric Biggers [Mon, 16 Dec 2019 03:31:39 +0000 (19:31 -0800)]
Metadata support for v2 encryption policies

Linux v5.4 and later supports v2 encryption policies.  These have
several advantages over v1 encryption policies:

- Their encryption keys can be added/removed to/from the filesystem by
  non-root users, thus gaining the benefits of the filesystem keyring
  while also retaining support for non-root use.

- They use a more standard, secure, and flexible key derivation
  function.  Because of this, some future kernel-level fscrypt features
  will be implemented for v2 policies only.

- They prevent a denial-of-service attack where a user could associate
  the wrong key with another user's encrypted files.

Prepare the fscrypt tool to support v2 encryption policies by:

- Adding a policy_version field to the EncryptionOptions, i.e. to the
  config file and to the policy metadata files.

- Using the kernel-specified algorithm to compute the key descriptor for
  v2 policies.

- Handling setting and getting v2 policies.

Actually adding/removing the keys for v2 policies to/from the kernel is
left for the next patch.

5 years agopam_fscrypt: update to handle filesystem keyring
Eric Biggers [Mon, 16 Dec 2019 03:31:39 +0000 (19:31 -0800)]
pam_fscrypt: update to handle filesystem keyring

FS_IOC_ADD_ENCRYPTION_KEY and FS_IOC_REMOVE_ENCRYPTION_KEY require root
for v1 policy keys, so update the PAM module to re-acquire root
privileges while provisioning/deprovisioning policies that need this.

Also, only set up the user keyring if it will actually be used.

5 years agocmd/fscrypt: adjust user and keyring validation and preparation
Eric Biggers [Mon, 16 Dec 2019 03:31:39 +0000 (19:31 -0800)]
cmd/fscrypt: adjust user and keyring validation and preparation

Don't force the user to provide a --user argument when running fscrypt
as root if they're doing something where the TargetUser isn't actually
needed, such as provisioning/deprovisioning a v1 encryption policy
to/from the filesystem keyring, or creating a non-login protector.

Also don't set up the user keyring (or check for it being set up) if it
won't actually be used.

Finally, if we'll be provisioning/deprovisioning a v1 encryption policy
to/from the filesystem keyring, make sure the command is running as
root, since the kernel requires this.

5 years agocmd/fscrypt: add 'fscrypt lock' command
Eric Biggers [Mon, 16 Dec 2019 03:31:39 +0000 (19:31 -0800)]
cmd/fscrypt: add 'fscrypt lock' command

Add support for 'fscrypt lock'.  This command "locks" a directory,
undoing 'fscrypt unlock'.

When the filesystem keyring is used, 'fscrypt lock' also detects when a
directory wasn't fully locked due to some files still being in-use.  It
can then be run again later to try to finish locking the files.

5 years agokeyring: support filesystem keyring with v1 encryption policies
Eric Biggers [Mon, 16 Dec 2019 03:31:39 +0000 (19:31 -0800)]
keyring: support filesystem keyring with v1 encryption policies

Linux v5.4 and later allows fscrypt keys to be added/removed directly
to/from the filesystem via the new ioctls FS_IOC_ADD_ENCRYPTION_KEY and
FS_IOC_REMOVE_ENCRYPTION_KEY.  Among other benefits, these fix the key
visibility problems that many users have been running into, where system
services and containers can't access encrypted files.

Allow the user to opt-in to using these new ioctls for their existing
encrypted directories by setting in their /etc/fscrypt.conf:

"use_fs_keyring_for_v1_policies": true

Note that it can't really be on by default, since for v1 policies the
ioctls require root, whereas user keyrings don't.  I.e., setting this to
true means that users will need to use 'sudo fscrypt unlock', not
'fscrypt unlock'.  v2 policies won't have this restriction.

5 years agoAdd keyring package
Eric Biggers [Mon, 16 Dec 2019 03:31:39 +0000 (19:31 -0800)]
Add keyring package

In preparation for introducing support for the new filesystem-level
keyrings, move the existing user keyring management code from
security/keyring.go and crypto/crypto.go into a new package, 'keyring'.

This package provides functions AddEncryptionKey, RemoveEncryptionKey,
and GetEncryptionKeyStatus which delegate to either the filesystem
keyring (added by a later patch) or to the user keyring.  This provides
a common interface to both types of keyrings, to the extent possible.

5 years agoREADME.md: document /etc/fscrypt.conf
Eric Biggers [Sun, 5 Jan 2020 17:59:37 +0000 (09:59 -0800)]
README.md: document /etc/fscrypt.conf