aboutsummaryrefslogtreecommitdiff
AgeCommit message (Collapse)Author
2020-05-09filesystem: improve errorsEric Biggers
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.
2020-05-09metadata: improve errorsEric Biggers
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.
2020-05-09keyring: improve errorsEric Biggers
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.
2020-05-09crypto: improve errorsEric Biggers
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.
2020-05-09actions/policy: improve errorsEric Biggers
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.
2020-05-09actions/protector: improve errorsEric Biggers
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.
2020-05-09actions/config: improve config file related errorsEric Biggers
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.
2020-05-09cmd/fscrypt: make wrapText() support code blocksEric Biggers
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
2020-05-09Merge pull request #217 from ebiggers/detect-incomplete-v1-lockingEric Biggers
Try to detect incomplete locking of v1-encrypted directory
2020-05-09Try to detect incomplete locking of v1-encrypted directoryEric Biggers
'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
2020-05-09keyring/user_keyring: switch to KEYCTL_UNLINKEric Biggers
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.
2020-05-09Merge pull request #218 from ebiggers/cli-testsEric Biggers
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.
2020-05-09cli-tests: add t_v1_policy_fs_keyringEric Biggers
Test using v1 encryption policies (deprecated) with use_fs_keyring_for_v1_policies = true.
2020-05-09cli-tests: add t_v1_policyEric Biggers
Test using v1 encryption policies (deprecated).
2020-05-09cli-tests: add t_unlockEric Biggers
Test unlocking a directory.
2020-05-09cli-tests: add t_statusEric Biggers
Test getting global, filesystem, and unencrypted directory status when the filesystem is or isn't set up for fscrypt.
2020-05-09cli-tests: add t_setupEric Biggers
Test 'fscrypt setup'.
2020-05-09cli-tests: add t_passphrase_hashingEric Biggers
Test that the passphrase hashing seems to take long enough.
2020-05-09cli-tests: add t_not_supportedEric Biggers
Test that fscrypt fails when the filesystem doesn't support encryption.
2020-05-09cli-tests: add t_not_enabledEric Biggers
Test that fscrypt fails when the filesystem doesn't have the encrypt feature enabled. Then test enabling it.
2020-05-09cli-tests: add t_lockEric Biggers
Test locking a directory.
2020-05-09cli-tests: add t_encrypt_raw_keyEric Biggers
Test encrypting a directory using a raw_key protector.
2020-05-09cli-tests: add t_encrypt_loginEric Biggers
Test encrypting a directory using a login (pam_passphrase) protector.
2020-05-09cli-tests: add t_encrypt_customEric Biggers
Test encrypting a directory using a custom_passphrase protector.
2020-05-09cli-tests: add t_encryptEric Biggers
Add general tests for 'fscrypt encrypt'. For protector-specific tests, see t_encrypt_custom, t_encrypt_login, and t_encrypt_raw_key.
2020-05-09cli-tests: add t_change_passphraseEric Biggers
Test changing the passphrase of a custom_passphrase protector.
2020-05-09Wire up shellcheck of cli-tests/*.sh to 'make lint'Eric Biggers
Enforce that all the cli-test scripts pass 'shellcheck'.
2020-05-09Add cli-tests frameworkEric Biggers
Add a framework for writing automated tests of the fscrypt command-line tool. See cli-tests/README.md for details.
2020-05-09cmd/fscrypt: add FSCRYPT_CONSISTENT_OUTPUT environmental variableEric Biggers
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.
2020-05-09cmd/fscrypt: add FSCRYPT_ROOT_MNT environmental variableEric Biggers
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 "/".
2020-05-09cmd/fscrypt: add FSCRYPT_CONF environmental variableEric Biggers
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.
2020-05-09travis.yml: stop overriding e2fsprogs version (#222)Eric Biggers
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.
2020-05-09keyring: cast FS_IOC_REMOVE_ENCRYPTION_KEY to uintptr (#221)Filip Stanis
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.]
2020-04-16Allow fscrypt to work in containers (#213)Eric Biggers
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
2020-03-24Release version v0.2.7v0.2.7Joe Richey
Signed-off-by: Joe Richey <joerichey@google.com>
2020-03-24Makefile: Use trimpath if available (#208)Joseph Richey
Passing -trimpath makes the build entirely reproducible. Signed-off-by: Joe Richey <joerichey@google.com>
2020-03-23cmd: Simplify "fscrypt --version" output (#207)Joseph Richey
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>
2020-03-23Merge pull request #205 from ebiggers/autoselect-v2Joseph Richey
Automatically enable policy_version 2 when kernel support is detected
2020-03-23README.md: update v2 policy-related documentationEric Biggers
- 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.
2020-03-23README.md: update examples to use v2 policiesEric Biggers
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'.
2020-03-23Improve error message when unlocking v2 policy is unsupportedEric Biggers
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.
2020-03-23Improve error message when setting v2 policy is unsupportedEric Biggers
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.
2020-03-23Create /etc/fscrypt.conf with policy_version 2 on kernel v5.4+Eric Biggers
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
2020-03-23Simplify choosing the key description prefixEric Biggers
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.
2020-03-19README.md: improve documentation for PAM configuration (#204)Eric Biggers
2020-02-22Makefile: clean up installation commands (#201)Eric Biggers
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.
2020-02-18Use DESTDIR for install prefix (#200)Anatol Pomozov
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.
2020-02-10Release version v0.2.6 (#198)v0.2.6Joseph Richey
* 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>
2020-01-29cmd/fscrypt/commands: allow disabling recovery passphrase (#193)Eric Biggers
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
2020-01-29Merge pull request #192 from ebiggers/cleanup-on-errorEric Biggers
Clean up policies and protectors on error