|
@@ -28,85 +28,6 @@
|
28
|
28
|
# You should have received a copy of the GNU Affero General Public License
|
29
|
29
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
30
|
30
|
|
31
|
|
-function gpg_delete_key {
|
32
|
|
- key_username=$1
|
33
|
|
- key_id=$2
|
34
|
|
-
|
35
|
|
- su -c "gpg --batch --quiet --homedir=/home/$key_username/.gnupg --delete-secret-key $key_id" - $key_username
|
36
|
|
- su -c "gpg --batch --quiet --homedir=/home/$key_username/.gnupg --delete-key $key_id" - $key_username
|
37
|
|
-}
|
38
|
|
-
|
39
|
|
-function gpg_set_permissions {
|
40
|
|
- key_username=$1
|
41
|
|
-
|
42
|
|
- if [[ "$key_username" != 'root' ]]; then
|
43
|
|
- chmod 700 /home/$key_username/.gnupg
|
44
|
|
- chmod -R 600 /home/$key_username/.gnupg/*
|
45
|
|
- chown -R $key_username:$key_username /home/$key_username/.gnupg
|
46
|
|
- else
|
47
|
|
- chmod 700 /root/.gnupg
|
48
|
|
- chmod -R 600 /root/.gnupg/*
|
49
|
|
- chown -R $key_username:$key_username /root/.gnupg
|
50
|
|
- fi
|
51
|
|
-}
|
52
|
|
-
|
53
|
|
-function reconstruct_key {
|
54
|
|
- key_username=$1
|
55
|
|
- key_interactive=$2
|
56
|
|
-
|
57
|
|
- if [ ! -d /home/$key_username/.gnupg_fragments ]; then
|
58
|
|
- return
|
59
|
|
- fi
|
60
|
|
- cd /home/$key_username/.gnupg_fragments
|
61
|
|
- no_of_shares=$(ls -afq keyshare.asc.* | wc -l)
|
62
|
|
- if (( no_of_shares < 4 )); then
|
63
|
|
- if [ $key_interactive ]; then
|
64
|
|
- dialog --title $"Recover Encryption Keys" --msgbox $'Not enough fragments to reconstruct the key' 6 70
|
65
|
|
- else
|
66
|
|
- echo $'Not enough fragments to reconstruct the key'
|
67
|
|
- fi
|
68
|
|
- exit 7348
|
69
|
|
- fi
|
70
|
|
- gfcombine /home/$key_username/.gnupg_fragments/keyshare*
|
71
|
|
- if [ ! "$?" = "0" ]; then
|
72
|
|
- if [ $key_interactive ]; then
|
73
|
|
- dialog --title $"Recover Encryption Keys" --msgbox $'Unable to reconstruct the key' 6 70
|
74
|
|
- else
|
75
|
|
- echo $'Unable to reconstruct the key'
|
76
|
|
- fi
|
77
|
|
- exit 7348
|
78
|
|
- fi
|
79
|
|
-
|
80
|
|
- KEYS_FILE=/home/$key_username/.gnupg_fragments/keyshare.asc
|
81
|
|
- if [ ! -f $KEYS_FILE ]; then
|
82
|
|
- if [ $key_interactive ]; then
|
83
|
|
- dialog --title $"Recover Encryption Keys" --msgbox $'Unable to reconstruct the key' 6 70
|
84
|
|
- else
|
85
|
|
- echo $'Unable to reconstruct the key'
|
86
|
|
- fi
|
87
|
|
- exit 52852
|
88
|
|
- fi
|
89
|
|
-
|
90
|
|
- gpg --homedir=/home/$key_username/.gnupg --allow-secret-key-import --import $KEYS_FILE
|
91
|
|
- if [ ! "$?" = "0" ]; then
|
92
|
|
- shred -zu $KEYS_FILE
|
93
|
|
- rm -rf /home/$key_username/.tempgnupg
|
94
|
|
- if [ $key_interactive ]; then
|
95
|
|
- dialog --title $"Recover Encryption Keys" --msgbox $'Unable to import gpg key' 6 70
|
96
|
|
- else
|
97
|
|
- echo $'Unable to import gpg key'
|
98
|
|
- fi
|
99
|
|
- exit 96547
|
100
|
|
- fi
|
101
|
|
- shred -zu $KEYS_FILE
|
102
|
|
-
|
103
|
|
- if [ $key_interactive ]; then
|
104
|
|
- dialog --title $"Recover Encryption Keys" --msgbox $'Key has been reconstructed' 6 70
|
105
|
|
- else
|
106
|
|
- echo $'Key has been reconstructed'
|
107
|
|
- fi
|
108
|
|
-}
|
109
|
|
-
|
110
|
31
|
function interactive_gpg_from_usb {
|
111
|
32
|
dialog --title $"Recover Encryption Keys" \
|
112
|
33
|
--msgbox $'Plug in a USB keydrive containing a copy of your full key or key fragment' 6 70
|
|
@@ -121,7 +42,7 @@ function interactive_gpg_from_usb {
|
121
|
42
|
|
122
|
43
|
if [ ! -b $USB_DRIVE ]; then
|
123
|
44
|
if (( GPG_CTR > 0 )); then
|
124
|
|
- reconstruct_key $MY_USERNAME interactive
|
|
45
|
+ gpg_reconstruct_key $MY_USERNAME interactive
|
125
|
46
|
return 0
|
126
|
47
|
fi
|
127
|
48
|
dialog --title $"Recover Encryption Keys" --msgbox $'No USB drive found' 6 30
|
|
@@ -133,7 +54,7 @@ function interactive_gpg_from_usb {
|
133
|
54
|
if [ ! -d $USB_MOUNT ]; then
|
134
|
55
|
if (( GPG_CTR > 0 )); then
|
135
|
56
|
backup_unmount_drive ${USB_DRIVE}
|
136
|
|
- reconstruct_key $MY_USERNAME interactive
|
|
57
|
+ gpg_reconstruct_key $MY_USERNAME interactive
|
137
|
58
|
return 0
|
138
|
59
|
fi
|
139
|
60
|
dialog --title $"Recover Encryption Keys" \
|
|
@@ -146,7 +67,7 @@ function interactive_gpg_from_usb {
|
146
|
67
|
if [ ! -d $USB_MOUNT/.gnupg_fragments ]; then
|
147
|
68
|
if (( GPG_CTR > 0 )); then
|
148
|
69
|
backup_unmount_drive ${USB_DRIVE}
|
149
|
|
- reconstruct_key $MY_USERNAME interactive
|
|
70
|
+ gpg_reconstruct_key $MY_USERNAME interactive
|
150
|
71
|
return 0
|
151
|
72
|
fi
|
152
|
73
|
dialog --title $"Recover Encryption Keys" \
|
|
@@ -209,8 +130,9 @@ function interactive_gpg_from_usb {
|
209
|
130
|
cp -r $USB_MOUNT/.gnupg/* $HOME_DIR/.gnupg
|
210
|
131
|
GPG_LOADING="no"
|
211
|
132
|
dialog --title $"Recover Encryption Keys" \
|
212
|
|
- --msgbox $"GPG Keyring loaded to $HOME_DIR" 6 70
|
|
133
|
+ --msgbox $"GPG Keyring directory loaded to $HOME_DIR" 6 70
|
213
|
134
|
else
|
|
135
|
+ # Collect fragments from the USB drive
|
214
|
136
|
if [ ! -d $HOME_DIR/.gnupg_fragments ]; then
|
215
|
137
|
mkdir $HOME_DIR/.gnupg_fragments
|
216
|
138
|
fi
|