diff options
| author | ebiggers <ebiggers@google.com> | 2020-01-22 19:16:20 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-01-22 19:16:20 -0800 |
| commit | 303616dc52e2b1e71883417a291f07c59025215d (patch) | |
| tree | 7cbace927ccef0392706fff52d1a56cb906f52ee /cmd | |
| parent | 059482129c5fdafebc582887a4ae4ef80988b708 (diff) | |
| parent | 8cd1b3ba2e7a12cd68e2dfd0cbb5ec09ff92783b (diff) | |
Merge pull request #167 from ebiggers/recovery-passphrase
Automatically generate recovery passphrase when useful
Diffstat (limited to 'cmd')
| -rw-r--r-- | cmd/fscrypt/commands.go | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/cmd/fscrypt/commands.go b/cmd/fscrypt/commands.go index 41009b0..65e0f45 100644 --- a/cmd/fscrypt/commands.go +++ b/cmd/fscrypt/commands.go @@ -24,11 +24,13 @@ import ( "fmt" "log" "os" + "path/filepath" "github.com/pkg/errors" "github.com/urfave/cli" "github.com/google/fscrypt/actions" + "github.com/google/fscrypt/crypto" "github.com/google/fscrypt/filesystem" "github.com/google/fscrypt/keyring" "github.com/google/fscrypt/metadata" @@ -188,6 +190,7 @@ func encryptPath(path string) (err error) { } var policy *actions.Policy + var recoveryPassphrase *crypto.Key if policyFlag.Value != "" { log.Printf("getting policy for %q", path) @@ -227,6 +230,19 @@ func encryptPath(path string) (err error) { if policy, err = actions.CreatePolicy(ctx, protector); err != nil { return } + // Automatically generate a recovery passphrase if the protector + // is on a different filesystem from the policy. In practice, + // this happens for login passphrase-protected directories that + // aren't on the root filesystem, since login protectors are + // always stored on the root filesystem. + if ctx.Mount != protector.Context.Mount { + fmt.Printf("Generating recovery passphrase because protector is on a different filesystem.\n") + if recoveryPassphrase, _, err = actions.AddRecoveryPassphrase( + policy, filepath.Base(path)); err != nil { + return + } + defer recoveryPassphrase.Wipe() + } } // Successfully created policy should be reverted on failure. defer func() { @@ -255,6 +271,16 @@ func encryptPath(path string) (err error) { // EACCES at this point indicates ownership issues. err = errors.Wrap(ErrBadOwners, path) } + if err != nil { + return + } + if recoveryPassphrase != nil { + recoveryFile := filepath.Join(path, "fscrypt_recovery_readme.txt") + if err = actions.WriteRecoveryInstructions(recoveryPassphrase, recoveryFile); err != nil { + return + } + fmt.Printf("See %q for important recovery instructions!\n", recoveryFile) + } return } |