]> git.apps.os.sepia.ceph.com Git - fscrypt.git/log
fscrypt.git
8 years agoMerge pull request #30 from google/josephlr-patch-1
Joseph Richey [Tue, 25 Jul 2017 09:54:25 +0000 (02:54 -0700)]
Merge pull request #30 from google/josephlr-patch-1

README reformatting

8 years agoREADME reformatting
Joseph Richey [Tue, 25 Jul 2017 09:53:13 +0000 (02:53 -0700)]
README reformatting

The version badge was broken. This fixes it and inlines the version in the top line.

8 years agoMerge pull request #29 from google/docs
Joseph Richey [Sun, 23 Jul 2017 09:21:16 +0000 (02:21 -0700)]
Merge pull request #29 from google/docs

Fixed cloning instructions

8 years agoREADME: Fixed cloning documentation
Joseph Richey [Sun, 23 Jul 2017 09:10:36 +0000 (02:10 -0700)]
README: Fixed cloning documentation

8 years agoMerge pull request #27 from google/tests
Joseph Richey [Thu, 20 Jul 2017 01:17:29 +0000 (18:17 -0700)]
Merge pull request #27 from google/tests

coveralls: Adding Travis CI integration

8 years agoBuild system: no longer run make gen for make all
Joe Richey joerichey@google.com [Thu, 20 Jul 2017 01:10:18 +0000 (18:10 -0700)]
Build system: no longer run make gen for make all

8 years agocrypto: Add more tests for bad key lengths
Joe Richey joerichey@google.com [Thu, 20 Jul 2017 00:54:12 +0000 (17:54 -0700)]
crypto: Add more tests for bad key lengths

8 years agoREADME: add badges for license and code coverage
Joe Richey joerichey@google.com [Thu, 20 Jul 2017 00:42:44 +0000 (17:42 -0700)]
README: add badges for license and code coverage

8 years agocoveralls: Adding Travis CI integration
Joe Richey joerichey@google.com [Wed, 19 Jul 2017 23:55:43 +0000 (16:55 -0700)]
coveralls: Adding Travis CI integration

8 years agoMerge pull request #23 from google/fix
Joseph Richey [Wed, 19 Jul 2017 04:51:15 +0000 (21:51 -0700)]
Merge pull request #23 from google/fix

travis CI: Test config file

8 years agoMakefile: typo
Joe Richey joerichey@google.com [Wed, 19 Jul 2017 04:18:22 +0000 (21:18 -0700)]
Makefile: typo

8 years agoUpdate documentation about new build system
Joe Richey joerichey@google.com [Wed, 19 Jul 2017 04:09:55 +0000 (21:09 -0700)]
Update documentation about new build system

8 years agometadata: Remove "go generate" and regenerate
Joe Richey joerichey@google.com [Wed, 19 Jul 2017 04:09:24 +0000 (21:09 -0700)]
metadata: Remove "go generate" and regenerate

8 years agotests: Unit tests and Integration tests work
Joe Richey joerichey@google.com [Wed, 19 Jul 2017 04:08:02 +0000 (21:08 -0700)]
tests: Unit tests and Integration tests work

Now the testing functions will skip the integration tests if a testing
filesystem is not specified.

8 years agoTravis.yml and Makefile now run integration tests.
Joe Richey joerichey@google.com [Tue, 18 Jul 2017 18:04:50 +0000 (11:04 -0700)]
Travis.yml and Makefile now run integration tests.

8 years agoMerge pull request #22 from google/fix
Joseph Richey [Tue, 18 Jul 2017 17:59:40 +0000 (10:59 -0700)]
Merge pull request #22 from google/fix

Fixing fscrypt build system

8 years agoactions: Fixed flaky hashing test
Joe Richey joerichey@google.com [Tue, 18 Jul 2017 06:29:27 +0000 (23:29 -0700)]
actions: Fixed flaky hashing test

8 years agoBetter output for input_fail.py
Joe Richey joerichey@google.com [Tue, 18 Jul 2017 06:25:48 +0000 (23:25 -0700)]
Better output for input_fail.py

8 years agocmd/fscrypt: more nits to fix "make lint"
Joe Richey joerichey@google.com [Tue, 18 Jul 2017 06:18:49 +0000 (23:18 -0700)]
cmd/fscrypt: more nits to fix "make lint"

8 years agoSmall fixes so "make lint" doesn't complain.
Joe Richey joerichey@google.com [Tue, 18 Jul 2017 06:16:00 +0000 (23:16 -0700)]
Small fixes so "make lint" doesn't complain.

8 years agopam: Added missing documentation (fix "make lint")
Joe Richey joerichey@google.com [Tue, 18 Jul 2017 06:04:47 +0000 (23:04 -0700)]
pam: Added missing documentation (fix "make lint")

8 years agoChanges from "make format"
Joe Richey joerichey@google.com [Tue, 18 Jul 2017 05:52:51 +0000 (22:52 -0700)]
Changes from "make format"

8 years agoMakefile: Rewrite for presubmit checks
Joe Richey joerichey@google.com [Tue, 18 Jul 2017 05:51:23 +0000 (22:51 -0700)]
Makefile: Rewrite for presubmit checks

The commit reorganizes the Makefile, so that "make check" can run on
each PR to detect any errors.

8 years agoMerge pull request #21 from google/fix
Joseph Richey [Tue, 18 Jul 2017 01:26:19 +0000 (18:26 -0700)]
Merge pull request #21 from google/fix

Add PAM package

8 years agocmd/fscrypt: username and login token fix
Joe Richey joerichey@google.com [Tue, 18 Jul 2017 00:30:46 +0000 (17:30 -0700)]
cmd/fscrypt: username and login token fix

The commit changes how we get the username representation, and uses the
new pam API for checking the proposed login token.

8 years agopam: IsUserLoginToken now uses PAM library
Joe Richey joerichey@google.com [Tue, 18 Jul 2017 00:27:06 +0000 (17:27 -0700)]
pam: IsUserLoginToken now uses PAM library

8 years agopam: Add Go wrappers around PAM functions
Joe Richey joerichey@google.com [Tue, 18 Jul 2017 00:22:54 +0000 (17:22 -0700)]
pam: Add Go wrappers around PAM functions

This commit provides a Go interface to the PAM functions.

8 years agopam: C implementation for conversation and cleanup
Joe Richey joerichey@google.com [Tue, 18 Jul 2017 00:19:37 +0000 (17:19 -0700)]
pam: C implementation for conversation and cleanup

This commit adds in a C implementation for the pam_conv we will use in
login.go as well as adding three CleanupFuncs that will be used with
pam_set_data(). It also adds copyInfoSecret() which should be paired
with freeSecret().

8 years agocrypto: Conversion to/from C strings
Joe Richey joerichey@google.com [Tue, 18 Jul 2017 00:15:15 +0000 (17:15 -0700)]
crypto: Conversion to/from C strings

8 years agopam: Add PAM Items and Flags
Joe Richey joerichey@google.com [Mon, 17 Jul 2017 22:44:57 +0000 (15:44 -0700)]
pam: Add PAM Items and Flags

Code pulled from github.com/msteinert/pam

8 years agoutil: Add conversions for byte/pointer arrays
Joe Richey joerichey@google.com [Mon, 17 Jul 2017 22:40:02 +0000 (15:40 -0700)]
util: Add conversions for byte/pointer arrays

8 years agoMerge pull request #20 from google/fix
Joseph Richey [Mon, 17 Jul 2017 22:12:28 +0000 (15:12 -0700)]
Merge pull request #20 from google/fix

Refactor ReadLine functions

8 years agocmd/fscrypt: prompts now use command functions
Joe Richey joerichey@google.com [Mon, 17 Jul 2017 22:08:19 +0000 (15:08 -0700)]
cmd/fscrypt: prompts now use command functions

8 years agoutil: Move line reading into common package
Joe Richey joerichey@google.com [Mon, 17 Jul 2017 22:01:38 +0000 (15:01 -0700)]
util: Move line reading into common package

8 years agoMerge pull request #19 from google/fix
Joseph Richey [Mon, 17 Jul 2017 20:28:16 +0000 (13:28 -0700)]
Merge pull request #19 from google/fix

Separate encryption support from metadata support

8 years agocmd/fscrypt: Improve "fscrypt status"
Joe Richey joerichey@google.com [Mon, 17 Jul 2017 20:21:11 +0000 (13:21 -0700)]
cmd/fscrypt: Improve "fscrypt status"

Now that we can distinguish between lacking encryption support and
lacking fscrypt metadata, "fscrypt status" can now display this
additional information.

8 years agocmd/fscrypt: Check support before encrypting
Joe Richey joerichey@google.com [Mon, 17 Jul 2017 20:19:43 +0000 (13:19 -0700)]
cmd/fscrypt: Check support before encrypting

Almost all actions only need to to check that the fscrypt metadata
exists (this is handled by the Mount methods). Only "fscrypt encrypt"
need to be sure the filesystem also supports encryption, so this check
is added.

8 years agofilesystem: Distinguish support and setup for fs
Joe Richey joerichey@google.com [Mon, 17 Jul 2017 20:16:03 +0000 (13:16 -0700)]
filesystem: Distinguish support and setup for fs

This commit splits two pieces of functionality. Detecting if the fscrypt
metadata exists is now in CheckSetup() and checking if the filesystem
supports encryption is now in CheckSupport().

8 years agoMerge pull request #18 from google/fix
Joseph Richey [Mon, 17 Jul 2017 20:06:15 +0000 (13:06 -0700)]
Merge pull request #18 from google/fix

Polices can now be directly unlocked with Protectors

8 years agoactions: Add tests for policy unlocking
Joe Richey joerichey@google.com [Mon, 17 Jul 2017 19:32:03 +0000 (12:32 -0700)]
actions: Add tests for policy unlocking

8 years agoactions: Protectors can directly unlock Policies
Joe Richey joerichey@google.com [Mon, 17 Jul 2017 19:15:20 +0000 (12:15 -0700)]
actions: Protectors can directly unlock Policies

In addition to using callbacks, unlocked Protectors can now directly
unlock a policy. The error codes are updated to make more sense.

8 years agoMerge pull request #16 from google/fix
Joseph Richey [Fri, 14 Jul 2017 19:07:33 +0000 (12:07 -0700)]
Merge pull request #16 from google/fix

Use Description when placing keys in the keyring

8 years agoactions: Policies now have Description method
Joe Richey joerichey@google.com [Fri, 14 Jul 2017 19:04:21 +0000 (12:04 -0700)]
actions: Policies now have Description method

8 years agocrypto: Use single description parameter
Joe Richey joerichey@google.com [Fri, 14 Jul 2017 18:43:24 +0000 (11:43 -0700)]
crypto: Use single description parameter

Instead of using the service+descriptor parameters (which are always
combined in the same way), use a single description parameter.

8 years agoMerge pull request #15 from google/fix
Joseph Richey [Fri, 14 Jul 2017 18:38:20 +0000 (11:38 -0700)]
Merge pull request #15 from google/fix

Bug fixing for "fscrypt encrypt"

8 years agocmd/fscrypt: fix protector and policy cleanup
Joe Richey joerichey@google.com [Fri, 14 Jul 2017 18:32:41 +0000 (11:32 -0700)]
cmd/fscrypt: fix protector and policy cleanup

Protectors are only reverted if they were created, and Policies are only
depovisioned on failure.

8 years agovendor: Fixed package list so "make all" will work
Joe Richey joerichey@google.com [Fri, 14 Jul 2017 18:27:06 +0000 (11:27 -0700)]
vendor: Fixed package list so "make all" will work

During an earlier commit the vendor directory was self-referencing
various "fscrypt/<pkg>" packages. This no longer occurs.

8 years agoMerge pull request #14 from google/docs
Joseph Richey [Fri, 14 Jul 2017 03:19:49 +0000 (20:19 -0700)]
Merge pull request #14 from google/docs

Version now uses git tags and releases

8 years agoMakefile: version and data now pulled in directly
Joe Richey joerichey@google.com [Fri, 14 Jul 2017 01:46:18 +0000 (18:46 -0700)]
Makefile: version and data now pulled in directly

8 years agoREADME: Fixed version badge to pull from Git tags
Joseph Richey [Thu, 13 Jul 2017 22:47:40 +0000 (15:47 -0700)]
README: Fixed version badge to pull from Git tags

8 years agoMerge pull request #12 from google/docs
Joseph Richey [Thu, 13 Jul 2017 21:58:07 +0000 (14:58 -0700)]
Merge pull request #12 from google/docs

Cleanup README.md

8 years agoREADME: Add badges for protect, docs, report card
Joseph Richey [Thu, 13 Jul 2017 21:51:38 +0000 (14:51 -0700)]
README: Add badges for protect, docs, report card

8 years agoREADME: fix typos and formatting
Joseph Richey [Thu, 13 Jul 2017 21:50:54 +0000 (14:50 -0700)]
README: fix typos and formatting

Some of the documentation was misspelled or incorrectly formatted.

8 years agoFinalize import paths and documentation
Joe Richey joerichey@google.com [Wed, 28 Jun 2017 20:57:55 +0000 (13:57 -0700)]
Finalize import paths and documentation

This commit changes all the internal import paths from `fscrypt/foo` to
`github.com/google/fscrypt/foo` so that it can be built once we release
externaly. The documentation in README.md is updated accordingly.

Also, the README has a note noting that we do not make any guarantees
about project stability before 1.0 (when it ships with Ubuntu).

Change-Id: I6ba86e442c74057c8a06ba32a42e17f94833e280

8 years agoUpdate Makefile and README
Joe Richey joerichey@google.com [Wed, 21 Jun 2017 19:52:21 +0000 (12:52 -0700)]
Update Makefile and README

This commit updates the README and Makefile to get them ready for
external release. This includes adding some common pitfalls, including
example usage, and allowing for tarball creation.

Change-Id: I442338c7aff613a14bae449dbf091bfcaf73ed9d

8 years agocmd/fscrypt: commands to add/remove protectors
Joe Richey joerichey@google.com [Wed, 21 Jun 2017 19:50:11 +0000 (12:50 -0700)]
cmd/fscrypt: commands to add/remove protectors

This commit adds in the "fscrypt metadata add-protector-to-policy" and
the "fscrypt metadata remove-protector-from-policy" subcommands. These
commands allow for the creating of policies protected by multiple
protectors.

Change-Id: Id7e6c057448d15757c838a82d487a1b9806f585d

8 years agocmd/fscrypt: add metadata command
Joe Richey joerichey@google.com [Wed, 21 Jun 2017 17:27:59 +0000 (10:27 -0700)]
cmd/fscrypt: add metadata command

This command adds in the "fscrypt metadata" command. This command allows
advanced users to manipulate the metadata directly instead of just
creating a policy or protector as an option when encrypting a directory.

As some of these methods will require certain flags, error handling for
this case is also added. As the change passphrase method must indicate
when a old vs new password is necessary, additional KeyFuncs are added
which add this indicator.

Change-Id: Ibc92872088fae078df3c0eebd4f0cfcb7252d781

8 years agocmd/fscrypt: add in status and purge commands
Joe Richey joerichey@google.com [Wed, 21 Jun 2017 17:25:01 +0000 (10:25 -0700)]
cmd/fscrypt: add in status and purge commands

This commit adds in the status command, which has 2 functions, allowing
the user to query the state of the entire system or a specific
filesystem.

This commit also adds in the purge command to remove all policy keys
corresponding to a filesystem. This (along with getting the unlock
status for the status commands) uses additional keyctl functionality in
the crypto and actions packages.

Change-Id: Ic8e097b335c044c0b91973eff19753f363f4525d

8 years agocmd/fscrypt: setup, encrypt, unlock commands
Joe Richey joerichey@google.com [Wed, 21 Jun 2017 17:21:21 +0000 (10:21 -0700)]
cmd/fscrypt: setup, encrypt, unlock commands

This commit adds in the framework for adding commands and subcommands to
the fscrypt tool. This commit adds in the "setup", "encrypt", and
"unlock" commands. Additional information can be found by running:
    fscrypt <command> --help.

This commit defines how flags are parsed and errors are handled. It also
creates an extensible framework for prompting the user for information.

Change-Id: I159d7f44ee2b2bbc5e072f0802850e082d9a13ce

8 years agoactions: error handling and API changed
Joe Richey joerichey@google.com [Wed, 21 Jun 2017 17:03:44 +0000 (10:03 -0700)]
actions: error handling and API changed

This commit changes the error handling for the actions package to use
the error handling library github.com/pkg/errors. This means replacing
"errors" with "github.com/pkg/errors", reworking some of the error
values, and wrapping some errors with additional context.

This commit also changes the Protector/Policy API, moving most of the
package functionality into Protector or Policy methods. These types are
now "locked" when they are queried from the filesystem, and Unlock()
must be used to get their corresponding keys. Note that only certain
operations will require unlocking the keys. Certain unnecessary
functions and methods are also removed.

This CL also fixes two bugs reported by Tyler Hicks in CreateConfigFile.
CPU time is used instead of wall time, and kiB is used instead of kB.

Change-Id: I88f45659e9fe4938d148843e3289e7b6d5b698d8

8 years agoChange error handling to new package
Joe Richey joerichey@google.com [Wed, 21 Jun 2017 16:52:40 +0000 (09:52 -0700)]
Change error handling to new package

This commit changes the error handing for the crypto, filesystem,
metadata, pam, and util packages to use the error handling library
github.com/pkg/errors. This means elimination of the FSError type, an
increased use of wrapping errors (as opposed to logging), switching
on the Cause() of an error (as opposed to its value), and improving our
integration tests involving TEST_FILESYSTEM_ROOT.

This commit also fixes a few bugs with the keyring code to ensure that
our {Find|Remove|Insert}PolicyKey functions are always operating on the
same keyring. The check for filesystem support has been moved from the
filesystem package to the metadata package. Finally, the API for the
filesystem package has been slightly modified:
* filesystem.AllFilesystems() now returns all the filesystems in
  sorted order
* certain path methods are now public

O_SYNC is also removed for writing the metadata. We don't get that much
from syncing the metadata, as the actual file data could also be
corrupted by and IO error. The sync operation is also occasionally very
slow (~3 seconds) and can be unfriendly to battery life.

Change-Id: I392c2655141714b16dfdbc84ac09780072be2cf0

8 years agovendor: add in github.com/pkg/errors
Joe Richey joerichey@google.com [Fri, 16 Jun 2017 05:11:50 +0000 (22:11 -0700)]
vendor: add in github.com/pkg/errors

This commit adds in the github.com/pkg/errors package for handling
errors. This allows us to continue to add context to our errors as they
move up the call stack, but still be able to switch on their root cause.

Change-Id: I6fd55f184318ea1e28c93a84444a2627bff03682

8 years agoactions: Simplify the callback mechanism
Joe Richey joerichey@google.com [Thu, 1 Jun 2017 00:54:35 +0000 (17:54 -0700)]
actions: Simplify the callback mechanism

This commit makes the callbacks for getting keys easier to understand.
Functions which need keys now take a KeyFunc callback. This callback
contains a ProtectorInfo parameter (basically a read-only version of
metadata.ProtectorData) and a boolean which indicates if the call is
being retried. The documentation is also updated to say which functions
will retry the KeyFunc.

For selecting a protector, there is now an OptionFunc callback which
takes a slice of ProtectorOptions. A ProtectorOption is a ProtectorInfo
along with additional information about a linked filesystem (if
applicable).

This commit also adds in methods for getting the protector options for a
specific filesystem or policy. It also adds a function for getting the
policy descriptor for a specific path.

Change-Id: I41e0d94ffd44e7166b0c5cf1b5d18437960bdf90

8 years agovendor: update x/sys/unix
Joe Richey joerichey@google.com [Thu, 8 Jun 2017 17:54:14 +0000 (10:54 -0700)]
vendor: update x/sys/unix

This commit updates the vendored x/sys/unix to the current version. This
means that our vendored version of x/sys/unix no longer contains custom
patches. A few changes are needed in InsertPolicyKey() as the final API
differed slightly from our patches.

Change-Id: Ifff31c04e708f9dc4395ab5bfcc94e42fb46dea5

8 years agocrypto: add in additional keyring functionality
Joe Richey joerichey@google.com [Thu, 8 Jun 2017 17:51:04 +0000 (10:51 -0700)]
crypto: add in additional keyring functionality

This commit adds in the FindPolicyKey and RemovePolicyKey functions to
complement the InsertPolicyKey function. The existing functions were
also refactored slightly.

Change-Id: Iabd275f2186a9e3023d5efd44c772966123e3657

8 years agometadata: change encryption mode names
Joe Richey joerichey@google.com [Thu, 8 Jun 2017 17:41:55 +0000 (10:41 -0700)]
metadata: change encryption mode names

As new encryption modes are being added to the kernel that use 128 bit
keys (see https://patchwork.kernel.org/patch/9741913), we will need the
encryption modes to be more descriptive.

This change breaks backwards compatibility for the protobuf, but that's
fine because we have not released yet.

Change-Id: Ifb58d3d5a42db491f1e5393c12f3d260d9a091de

8 years agofilesystem: change support detection and bug-fixes
Joe Richey joerichey@google.com [Thu, 1 Jun 2017 00:52:15 +0000 (17:52 -0700)]
filesystem: change support detection and bug-fixes

Instead of checking if the filesystem type is correct, we now detect if
a filesystem supports encryption by trying to read a policy on its root
directory. The error returned tells us if there is support or not.

This commit also fixes a bug in the use libblkid. Throughout all of
fscrypt, cannonicalizePath() is used before any path comparison or
lookup. However, the canonical device path in the blkid cache may differ
from our idea of a canonical path. Additional blkid functions are needed
to perform the necessary translation. This is noted in the documentation
of makeLink().

Finally, this commit makes a few API changes. AllSupporedFilesystems()
now returns an error, and a GetProtector() method now replaces the
GetLinkedProtector() and GetEitherProtector() methods. A PathSorter has
also been added so Mounts can be sorted in a reliable order.

Change-Id: I664f46fafd1483ebecb743c061b03d708b3233a4

8 years agopam: checking a user's login passphrase
Joe Richey joerichey@google.com [Wed, 31 May 2017 19:49:06 +0000 (12:49 -0700)]
pam: checking a user's login passphrase

This commit adds in the fscrypt/pam package. This package will hold all
functionality related to Linux Pluggable Authentication Modules (PAM).
Right now this package uses cgo to mock a PAM conversation, allowing the
function to check if a provided passphrase actually belongs to a user.

Due to the nature of cgo callbacks, global state of the key to check is
necessary for this function. This commit also addresses some issues
about building the cgo components. Now, only the minimal linking flags
are included in the go files. Additional linker flags may now be
necessary to build a static binary of fscrypt. This is addressed in the
Makefile and README.

Finally, this commit fixes a bug where the tests would not run correctly
due to shared global state on the testing filesystem. Fixed, by having
all the tests run sequentially.

Change-Id: Ia43636801da984b505d2f43dd14127b7cfbf2c48

8 years agovendor: add in external packages for use with CLI
Joe Richey joerichey@google.com [Wed, 24 May 2017 02:12:26 +0000 (19:12 -0700)]
vendor: add in external packages for use with CLI

crypto/ssh/terminal gets us information about the terminal, such as
its dimensions and state. It also allows us to manipulate the terminal.
For example, we can put the terminal in raw mode when a passphrase needs
to be entered.

This commit also add the github.com/urfave/cli package which we will use
to write the command line tool component of fscrypt. This tool allows
for us to easily use commands and subcommands.

Note that this is actually the upstream repository with two PRs applied:

https://github.com/urfave/cli/pull/629
https://github.com/urfave/cli/pull/630

They fix bugs in the handling of custom usage errors.

Change-Id: I2d3ba967b1bce8f73440e3a06df4eaba7ab96c19

8 years agoactions: creating and unlocking policies
Joe Richey joerichey@google.com [Wed, 24 May 2017 01:59:39 +0000 (18:59 -0700)]
actions: creating and unlocking policies

This commit adds in the Policy structure. This structure represents an
unlocked policy key and its associated data. Policies can add or remove
Protectors, apply encryption policies to filesystem directories, and
provision a key into the kernel keyring.

Change-Id: I089710223221e0ea60188d523703469e5d67ad0e

8 years agoactions: creating and unlocking protectors
Joe Richey joerichey@google.com [Wed, 24 May 2017 01:59:39 +0000 (18:59 -0700)]
actions: creating and unlocking protectors

This commit adds in the Protector struct to the actions package. This
struct represents an unlocked Protector. They can be created from a
context or they can be unlocked using some provided data. In either
case, the data is provided via a callback mechanism.

Change-Id: I066e965b8e8e0feeba61d9c0e4472dd08965cafb

8 years agoactions: generate a config file for fscrypt
Joe Richey joerichey@google.com [Wed, 24 May 2017 01:57:13 +0000 (18:57 -0700)]
actions: generate a config file for fscrypt

This commit adds in the actions package. This package will be the
highest-level interface to the fscrypt packages. The public functions
in this package will be called directly from cmd/fscrypt.

The actions added in this commit pertain to creating and reading the
fscrypt global config file "fscrypt.conf". The challenging part about
creating this file is finding the correct hashing parameters for the
desired time target.

The getHashingCosts() function finds the desired costs by doubling the
costs and running the passphrase hash until the target is exceeded.
Then, a cost estimate is obtained using a linear interpolation between
the last two costs (and their time results).

Change-Id: I4a0eaf4856ec4ff49eb4360da3267f7caa9d07b2

8 years agofilesystem: creating the directories and files
Joe Richey joerichey@google.com [Wed, 24 May 2017 01:45:58 +0000 (18:45 -0700)]
filesystem: creating the directories and files

This commit adds in the filesystem subpackage. The goal of this package
is to provide and interface for adding to and removing from the metadata
storage for a given filesystem. This is primarily done in filesystem.go.
To facilitate this functionality, mountpoint.go exposes an interface for
querying the system about the current mounted filesystems and their
information. Note that this operation is done with a lazy loading
mechanism.

To refer to other filesystems, we use link files that can be parsed by
libblkid. The README is also updated to account for this new dependancy.

This package uses the FSError type under the hood so that error messages
will include the filesystem name, but callers can still check for
specific error instances.

Change-Id: I74fe4e84b8e3a5b73f1337c35307ffe0bf7cdea9

8 years agocrypto: tests, errors, and descriptor computation
Joe Richey joerichey@google.com [Wed, 24 May 2017 01:41:36 +0000 (18:41 -0700)]
crypto: tests, errors, and descriptor computation

This changes the crypto package so it now builds in light of the changes
to the util and metadata package. This commit also improves the error
handling, adds tests, and makes it so recovery keys now correspond to
Policy keys (as they are used to recover a directory in the absence of
any metadata).

The only feature addition here is the ability to compute descriptors.
For backwards compatibility, we keep the same descriptor algorithm used
before (double SHA512).

Change-Id: Ia2b53c6e85ce65c57595e6823d3c4c92219bc8dc

8 years agometadata: reorganize and add consistency checks
Joe Richey joerichey@google.com [Wed, 24 May 2017 01:38:38 +0000 (18:38 -0700)]
metadata: reorganize and add consistency checks

This commit adds in IsValid() checks for the metadata structures that
let us enforce stronger invariants than those imposed by the protobuf
package. The main uses of this will be to check that metadata is valid
before writing it to the filesystem, and to check that the filesystem
contains valid metadata before returning it to the user. These functions
also will log the exact reason if the validity checks fail.

To have these checks in the metadata package, all of the various
constants have been moved to a single metadata/constants.go file. The
uses of these constants were changed accordingly.

Finally, this commit standardizes our use of errors so that they always
begin with an appropriate prefix.

Change-Id: I99008e2ee803ebe5f6236eb8d83fc83efcd22718

8 years agoutil: better handing of custom errors
Joe Richey joerichey@google.com [Wed, 24 May 2017 01:32:18 +0000 (18:32 -0700)]
util: better handing of custom errors

This commit changes how we handle InvalidInput and System errors.
Instead of having formatting functions, the now just wrap a string and
should be created with fmt.Sprintf or similar. We also move all of the
error related code into a single place.

Finally, the utils package gets additional functionality with MinInt64
and GetUsername, and the UnderlyingError function gets better logging.

Note that this will break packages that depend on it. For instance,
metadata and crypto currently do not build. This is fixed in a later
commit.

Change-Id: I819e4d1970604456a5b4b6a7c86426f180a6d092

8 years agofscrypt: Adding additional documentation
Joe Richey joerichey@google.com [Wed, 24 May 2017 01:23:09 +0000 (18:23 -0700)]
fscrypt: Adding additional documentation

This commit moves most of the documentation about contributing to
fscrypt into CONTRIBUTING.md and updates the legal disclaimer.

It also updates the README.md to include all of fscrypt's planned
functionality and dependencies. Finally, the makefile is updated to
include more documentation, versioning support, and a different location
for the output file.

Change-Id: Ib7be98d41bc06dd12b02e42addf06e12a940235a

8 years agocrypto: passphrase hashing with Argon2
Joe Richey [Fri, 3 Mar 2017 01:32:50 +0000 (17:32 -0800)]
crypto: passphrase hashing with Argon2

This commit adds in the PassphraseHash function which hashes the
provided passphrase (in key form) using Argon2id. This cost parameters
for Argon2id and that salt are both fed into the function. It also
includes tests and benchmarks for the passphrase hashing.

Change-Id: I060db3e71213c756d45ce5603a0a59d3d7a1e609

8 years agocrypto: reading and writing recovery keys
Joe Richey [Thu, 2 Mar 2017 22:01:20 +0000 (14:01 -0800)]
crypto: reading and writing recovery keys

This commit adds in the concept of recovery codes: human-readable
strings that contain the necessary information to rederive a
cryptographic key. These keys look like:
73PZBXVP-DKJX7SKV-NNTFIC7A-QEGRPZUX-4K5ORRH2-MTKMKP3B-HFCA====

They are input or output directly to a io.Reader or io.Writer
respectively. This prevents the data from passing through unsecured
memory before it gets to its destination. Of course, if the provided
io.Reader or io.Writer is insecure, there is nothing we can do. In most
cases the provided io.Reader or io.Writer will be stdin or stdout. In
some rare cases you might want to pipe the output to another key.

This commit also adds tests and benchmarks for encoding/decoding
recovery codes. It also tests that encoding/decoding will fail in the
correct situations. A benchmark is also added to measure the effect of
locking the keys in memory.

Change-Id: Ifa0bc4c08582789785cf1cdd9a4acfe76c79534f

8 years agocrypto: secure key wrapping/unwrapping
Joe Richey [Thu, 2 Mar 2017 19:58:07 +0000 (11:58 -0800)]
crypto: secure key wrapping/unwrapping

This commit adds in the ability to use the WrappedKeyData from the
metadata package to wrap and unwrap cryptographic keys of any length.
This makes use of several cryptographic primitives:
- Unsalted, SHA256-based HKDF for key stretching
- AES256 in CTR mode for encryption
- SHA256-based HMAC for authentication

Note that the key wrapping/unwrapping uses an "Encrypt then MAC" scheme
for doing authenticated unwrapping. This means we can detect if bogus
metadata has been given. This package also standardizes the length for
fscrypt's internal keys.

This CL is the first to add benchmarks, which can be run with:
go test -bench=. ./...

Change-Id: I2e5fc23a8a8cc36b17ccb3f26f03edcaccc517e1

8 years agovendor: adding in golang.org/x/crypto/hkdf
Joe Richey joerichey@google.com [Tue, 18 Apr 2017 19:45:00 +0000 (12:45 -0700)]
vendor: adding in golang.org/x/crypto/hkdf

This commit adds in the golang.org/x/crypto/hkdf package which contains
the HMAC-based Extract-and-Expand Key Derivation Function (HKDF) as
defined in RFC 5869.

This package will be used later in the crypto package to stretch a
single cryptographic key into multiple keys.

Change-Id: I387230344bdeadc7d38c46994a228eecda2e12bd

8 years agocrypto: add secure random reader using getrandom
Joe Richey [Thu, 2 Mar 2017 19:58:07 +0000 (11:58 -0800)]
crypto: add secure random reader using getrandom

This commit adds in RandReader, a cryptographically secure io.Reader
that will fail when the os has insufficient randomness. This is done
using the getrandom() syscall in non-blocking mode.
  see: http://man7.org/linux/man-pages/man2/getrandom.2.html
Any kernel new enough to have filesystem encryption will also have this
syscall.

This RandReader is preferable to the one provided by the standard
library in crypto/rand. See the bugs:
https://github.com/golang/go/issues/11833
https://github.com/golang/go/issues/19274
This will be removed when go updates the crypto/rand implementation.

Change-Id: Icccaf07bc6011b95cd31a5c268e7486807dcffe2

8 years agocrypto: insert key into keyring from go
Joe Richey [Thu, 2 Mar 2017 19:47:07 +0000 (11:47 -0800)]
crypto: insert key into keyring from go

This commit adds in the ability to insert Keys into the kernel keyring
from go code. This is done via a patched version of x/sys/unix. We
also expose the specific requirements for keys that will be placed in
the keyring, namely PolicyKeyLen. The legacy services are also exposed.

Change-Id: I177928c9aa676cae13b749042b9a3996e7490f68

8 years agocrypto: Key struct for secure buffers
Joe Richey [Thu, 2 Mar 2017 19:22:43 +0000 (11:22 -0800)]
crypto: Key struct for secure buffers

This commit adds in the crypto package, which will hold all
of the security primitives for fscrypt. This first component deals with
securely handling keys in memory. To do this in a consistent way across
fscrypt, we introduce the Key struct.

Any sensitive memory (like keys, passwords, or recovery tokens) in
fscrypt will be held in a Key. No code outside of the crypto package
should access the Key's data directly. Convenience functions and methods
are provided to construct keys from io.Readers (either with fixed length
or with variable length) and to access information about the Keys.

The most important property of Keys is that the data is locked in memory
on construction, and the data is unlocked and wiped when Wipe is called.
This happens either by something like "defer key.Wipe()" or through the
finalizer.

Change-Id: Ice76335f3975efb439b3f1ab605ef34cb7fcb4d6

8 years agometadata: get and set policies from go
Joe Richey [Thu, 2 Mar 2017 18:38:33 +0000 (10:38 -0800)]
metadata: get and set policies from go

This commit adds in the ability to get and set policy data from go using
the GetPolicy and SetPolicy functions. This is done via a patch of the
x/sys/unix package that exposes the filesystem encryption structures.

Note that not all the fields of the PolicyData protocol buffer are
needed to get and set policies. The wrapped_policy_keys are not used and
will be written and read by other components of fscrypt.

To run the policy tests, the environment variable BASE_TEST_DIR must be
set to a directory for testing on a filesystem that supports encryption.

Change-Id: I13b1d983356845f3ffc1945cedf53234218f32e5

8 years agovendor: adding in golang.org/x/sys/unix package
Joe Richey joerichey@google.com [Mon, 17 Apr 2017 19:45:30 +0000 (12:45 -0700)]
vendor: adding in golang.org/x/sys/unix package

This commit adds in the golang.org/x/sys/unix package. This package
provides a low-level interface to unix syscalls. We will uses this
package instead of the built-in "syscall" package because the syscall
package is locked down (https://golang.org/pkg/syscall) and is not
exposing any new kernel functionality.

In fact, this is actually a patched version of the x/sys/unix package
pending review (first part: https://go-review.googlesource.com/c/37943).
The version included in this commit exposes all of the filesystem
encryption kernel interfaces to Go code.

Change-Id: Ic5f9c98b858ccb00db97502c9a60e9249aa8ba38

8 years agometadata: introduce protobuf structures
Joe Richey [Thu, 2 Mar 2017 18:15:23 +0000 (10:15 -0800)]
metadata: introduce protobuf structures

This commit adds in the metadata package. The primary purpose of this
package is to provide the on-disk metadata structures in the form of
protocol buffers. This includes:
- Policy metadata structure
- Protector metadata structure
- Config file structure
- All necessary sub-structures (wrapped keys, parameters, etc)

This commit also adds in an example usage of the Config structure, which
represents the structure of the global config file. All the package
does at this point is convert between the Config structure and a JSON
representation.

Here we introduce govendor, which is described more in the README. This
means we will have all of our Go dependencies in the vendor
subdirectory. This means we will have no Go source dependencies, only
dependencies on the build tools (Go and govendor). The README describes
this in detail.

Note that we commit the generated files.
  see: https://blog.golang.org/generate

Change-Id: Iaacd46666b5d3e4e865a0f4045dd63ed7e3d6f96

8 years agovendor: adding in golang/protobuf libraries
Joe Richey joerichey@google.com [Mon, 17 Apr 2017 19:35:29 +0000 (12:35 -0700)]
vendor: adding in golang/protobuf libraries

This commit adds in the two protocol buffer libraries for Go. The
github.com/golang/protobuf/proto package will let Go code read and write
protocol buffers. The github.com/golang/protobuf/jsonpb package lets Go
code output a JSON representation of protocol buffers.

These packages are stored in the vendor directory, meaning that they
will be imported instead of any installed system packages.

Change-Id: I8da8d15864f03a9b3f767a6af18795c8eca64844

8 years agoutil: convenience utilities for fscrypt
Joe Richey [Thu, 2 Mar 2017 00:57:27 +0000 (16:57 -0800)]
util: convenience utilities for fscrypt

This commit adds in the util package. This package provides
two functions for creating errors. These functions are:
- InvalidInputErrorF - bad input from user or caller
- SystemErrorF - low level failure

It also adds in a small function for converting Go byte slices into C
void pointers. This will be very useful for interoperating with C.

Change-Id: I87ad7946dd5fa26e28927590aff4bcc9fd5ce4f7

8 years agocmd/fscrypt: Initial stub program and docs
Joe Richey [Fri, 31 Mar 2017 17:14:20 +0000 (10:14 -0700)]
cmd/fscrypt: Initial stub program and docs

This commit adds in a stub fscrypt program. The binary just tells the
time and the tests do nothing, but the Makefile will build them! This
commit also adds documentation to the README that explains how to get,
build, run, test, format, lint, and install the code.

Also note that the executable is now in the cmd/fscrypt directory. The
library implementing the core functionality will be at the root. This
is essentially point 2 of https://medium.com/@benbjohnson/structuring-applications-in-go-3b04be4ff091

Change-Id: Ib7bd782e458bdf3db456beb978be4c75b4734561

8 years agoInitial Documentation for fscrypt
Joe Richey [Thu, 30 Mar 2017 21:39:09 +0000 (14:39 -0700)]
Initial Documentation for fscrypt

This commit includes the Apache 2.0 License and a README with
documentation on how to checkout the code, some context about Linux
filesystem encryption, and documentation stubs for fscrypt and
fscryptctl. Also adds in a simple .gitignore so we don't commit build
files.

Change-Id: I99d5f936c9d65516119dd58c81cfa95c1e6243c1

8 years agoFirst commit, adding README
Joe Richey [Wed, 26 Oct 2016 22:20:16 +0000 (15:20 -0700)]
First commit, adding README

Change-Id: I32cc74f278b4a19d91106a5cb20d8a9e96fb1351