~ecryptfs/ecryptfs/trunk

« back to all changes in this revision

Viewing changes to src/utils/ecryptfs-recover-private

  • Committer: Dustin Kirkland
  • Date: 2016-02-27 00:00:23 UTC
  • Revision ID: kirkland@ubuntu.com-20160227000023-h0e4oui5y1vbaurd
openingĀ 112

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
#    ecryptfs-recover-private
4
4
#    Copyright (C) 2010 Canonical Ltd.
5
5
#
6
 
#    Authors: Dustin Kirkland <kirkland@canonical.com>
 
6
#    Authors: Dustin Kirkland <kirkland@ubuntu.com>
7
7
#
8
8
#    This program is free software: you can redistribute it and/or modify
9
9
#    it under the terms of the GNU General Public License as published by
30
30
[ "$(id -u)" = "0" ] || error "This program must be run as root."
31
31
 
32
32
# Handle parameters
 
33
opts="ro"
 
34
if [ "$1" = "--rw" ]; then
 
35
        opts="rw"
 
36
        shift
 
37
fi
 
38
 
33
39
if [ -d "$1" ]; then
34
40
        # Allow for target directories on the command line
35
41
        dirs="$@"
56
62
        # Determine if filename encryption is on
57
63
        ls "$d/ECRYPTFS_FNEK_ENCRYPTED"* >/dev/null 2>&1 && fnek="--fnek" || fnek=
58
64
        if [ -f "$d/../.ecryptfs/wrapped-passphrase" ]; then
59
 
                # Use the wrapped-passphrase, if available
60
 
                info "Enter your LOGIN passphrase..."
61
 
                ecryptfs-insert-wrapped-passphrase-into-keyring "$d/../.ecryptfs/wrapped-passphrase"
62
 
                sigs=$(sed -e "s/[^0-9a-f]//g" "$d/../.ecryptfs/Private.sig")
 
65
                info "Found your wrapped-passphrase"
 
66
                echo -n "Do you know your LOGIN passphrase? [Y/n] "
 
67
                lpw=$(head -n1)
 
68
                case "$lpw" in
 
69
                        y|Y|"")
 
70
                                # Use the wrapped-passphrase, if available
 
71
                                info "Enter your LOGIN passphrase..."
 
72
                                ecryptfs-insert-wrapped-passphrase-into-keyring "$d/../.ecryptfs/wrapped-passphrase"
 
73
                                sigs=$(sed -e "s/[^0-9a-f]//g" "$d/../.ecryptfs/Private.sig")
 
74
                                use_mount_passphrase=0
 
75
                        ;;
 
76
                        *)
 
77
                                use_mount_passphrase=1
 
78
                        ;;
 
79
                esac
63
80
        else
64
81
                # Fall back to mount passphrase
65
 
                echo
66
82
                info "Could not find your wrapped passphrase file."
 
83
                use_mount_passphrase=1
 
84
        fi
 
85
        if [ "$use_mount_passphrase" = "1" ]; then
 
86
 
67
87
                info "To recover this directory, you MUST have your original MOUNT passphrase."
68
88
                info "When you first setup your encrypted private directory, you were told to record"
69
89
                info "your MOUNT passphrase."
81
101
                1)
82
102
                        mount_sig=$(echo "$sigs" | head -n1)
83
103
                        fnek_sig=
84
 
                        mount_opts="ro,ecryptfs_sig=$mount_sig,ecryptfs_cipher=aes,ecryptfs_key_bytes=16"
 
104
                        mount_opts="$opts,ecryptfs_sig=$mount_sig,ecryptfs_cipher=aes,ecryptfs_key_bytes=16"
85
105
                ;;
86
106
                2)
87
107
                        mount_sig=$(echo "$sigs" | head -n1)
88
108
                        fnek_sig=$(echo "$sigs" | tail -n1)
89
 
                        mount_opts="ro,ecryptfs_sig=$mount_sig,ecryptfs_fnek_sig=$fnek_sig,ecryptfs_cipher=aes,ecryptfs_key_bytes=16"
 
109
                        mount_opts="$opts,ecryptfs_sig=$mount_sig,ecryptfs_fnek_sig=$fnek_sig,ecryptfs_cipher=aes,ecryptfs_key_bytes=16"
90
110
                ;;
91
111
                *)
92
112
                        continue
95
115
        (keyctl list @u | grep -qs "$mount_sig") || error "The key required to access this private data is not available."
96
116
        (keyctl list @u | grep -qs "$fnek_sig") || error "The key required to access this private data is not available."
97
117
        tmpdir=$(mktemp -d /tmp/ecryptfs.XXXXXXXX)
98
 
        mount -i -t ecryptfs -o "$mount_opts" "$d" "$tmpdir"
99
 
        info "Success!  Private data mounted read-only at [$tmpdir]."
 
118
        if mount -i -t ecryptfs -o "$mount_opts" "$d" "$tmpdir"; then
 
119
                info "Success!  Private data mounted at [$tmpdir]."
 
120
        else
 
121
                error "Failed to mount private data at [$tmpdir]."
 
122
        fi
100
123
done