소스 검색

Recover gpg key from fragments

Bob Mottram 9 년 전
부모
커밋
ddc05477e7
4개의 변경된 파일124개의 추가작업 그리고 0개의 파일을 삭제
  1. 4
    0
      Makefile
  2. 1
    0
      debian/source/include-binaries
  3. BIN
      man/freedombone-recoverkey.1.gz
  4. 119
    0
      src/freedombone-recoverkey

+ 4
- 0
Makefile 파일 보기

@@ -12,6 +12,7 @@ install:
12 12
 	mkdir -p ${DESTDIR}${PREFIX}/bin
13 13
 	install -m 755 src/${APP} ${DESTDIR}${PREFIX}/bin
14 14
 	install -m 755 src/${APP}-splitkey ${DESTDIR}${PREFIX}/bin
15
+	install -m 755 src/${APP}-recoverkey ${DESTDIR}${PREFIX}/bin
15 16
 	install -m 755 src/${APP}-prep ${DESTDIR}${PREFIX}/bin
16 17
 	install -m 755 src/${APP}-client ${DESTDIR}${PREFIX}/bin
17 18
 	install -m 755 src/${APP}-remote ${DESTDIR}${PREFIX}/bin
@@ -32,6 +33,7 @@ install:
32 33
 	mkdir -m 755 -p ${DESTDIR}${PREFIX}/share/man/man1
33 34
 	install -m 644 man/${APP}.1.gz ${DESTDIR}${PREFIX}/share/man/man1
34 35
 	install -m 644 man/${APP}-splitkey.1.gz ${DESTDIR}${PREFIX}/share/man/man1
36
+	install -m 644 man/${APP}-recoverkey.1.gz ${DESTDIR}${PREFIX}/share/man/man1
35 37
 	install -m 644 man/${APP}-prep.1.gz ${DESTDIR}${PREFIX}/share/man/man1
36 38
 	install -m 644 man/${APP}-client.1.gz ${DESTDIR}${PREFIX}/share/man/man1
37 39
 	install -m 644 man/${APP}-remote.1.gz ${DESTDIR}${PREFIX}/share/man/man1
@@ -52,6 +54,7 @@ install:
52 54
 uninstall:
53 55
 	rm -f ${PREFIX}/share/man/man1/${APP}.1.gz
54 56
 	rm -f ${PREFIX}/share/man/man1/${APP}-splitkey.1.gz
57
+	rm -f ${PREFIX}/share/man/man1/${APP}-recoverkey.1.gz
55 58
 	rm -f ${PREFIX}/share/man/man1/${APP}-prep.1.gz
56 59
 	rm -f ${PREFIX}/share/man/man1/${APP}-client.1.gz
57 60
 	rm -f ${PREFIX}/share/man/man1/${APP}-remote.1.gz
@@ -72,6 +75,7 @@ uninstall:
72 75
 	rm -rf ${PREFIX}/share/${APP}
73 76
 	rm -f ${PREFIX}/bin/${APP}
74 77
 	rm -f ${PREFIX}/bin/${APP}-splitkey
78
+	rm -f ${PREFIX}/bin/${APP}-recoverkey
75 79
 	rm -f ${PREFIX}/bin/${APP}-prep
76 80
 	rm -f ${PREFIX}/bin/${APP}-client
77 81
 	rm -f ${PREFIX}/bin/${APP}-remote

+ 1
- 0
debian/source/include-binaries 파일 보기

@@ -1,5 +1,6 @@
1 1
 man/freedombone.1.gz
2 2
 man/freedombone-splitkey.1.gz
3
+man/freedombone-recoverkey.1.gz
3 4
 man/freedombone-prep.1.gz
4 5
 man/freedombone-client.1.gz
5 6
 man/freedombone-remote.1.gz

BIN
man/freedombone-recoverkey.1.gz 파일 보기


+ 119
- 0
src/freedombone-recoverkey 파일 보기

@@ -0,0 +1,119 @@
1
+#!/bin/bash
2
+#
3
+# .---.                  .              .
4
+# |                      |              |
5
+# |--- .--. .-.  .-.  .-.|  .-. .--.--. |.-.  .-. .--.  .-.
6
+# |    |   (.-' (.-' (   | (   )|  |  | |   )(   )|  | (.-'
7
+# '    '     --'  --'  -' -  -' '  '   -' -'   -' '   -  --'
8
+#
9
+#                    Freedom in the Cloud
10
+#
11
+# A script which recovers a user's gpg key from a number of fragments
12
+
13
+# License
14
+# =======
15
+#
16
+# Copyright (C) 2015 Bob Mottram <bob@robotics.uk.to>
17
+#
18
+# This program is free software: you can redistribute it and/or modify
19
+# it under the terms of the GNU General Public License as published by
20
+# the Free Software Foundation, either version 3 of the License, or
21
+# (at your option) any later version.
22
+#
23
+# This program is distributed in the hope that it will be useful,
24
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
25
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26
+# GNU General Public License for more details.
27
+#
28
+# You should have received a copy of the GNU General Public License
29
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
30
+
31
+function show_help {
32
+    echo ''
33
+    echo 'freedombone-recoverkey -u [username]'
34
+    echo ''
35
+    exit 0
36
+}
37
+
38
+while [[ $# > 1 ]]
39
+do
40
+key="$1"
41
+
42
+case $key in
43
+    -h|--help)
44
+    show_help
45
+    ;;
46
+    -u|--user)
47
+    shift
48
+    MY_USERNAME="$1"
49
+    ;;
50
+    *)
51
+    # unknown option
52
+    ;;
53
+esac
54
+shift
55
+done
56
+
57
+if [ ! $MY_USERNAME ]; then
58
+    show_help
59
+fi
60
+if [ ! -d /home/$MY_USERNAME ]; then
61
+    echo "User $MY_USERNAME does not exist on the system"
62
+    exit 7270
63
+fi
64
+
65
+if [ ! $MY_USERNAME ]; then
66
+    echo 'No username given'
67
+    exit 3578
68
+fi
69
+if [ ! -d /home/$MY_USERNAME ]; then
70
+    echo "User $MY_USERNAME does not exist on the system"
71
+    exit 7270
72
+fi
73
+FRAGMENTS_DIR=/home/$MY_USERNAME/.gnupg_fragments
74
+if [ ! -d $FRAGMENTS_DIR ]; then
75
+    echo 'No fragments have been recovered, so the key cannot be recovered'
76
+    exit 7483
77
+fi
78
+
79
+# join the fragments
80
+if [ ! -d /home/$MY_USERNAME/.tempgnupg ]; then
81
+    mkdir /home/$MY_USERNAME/.tempgnupg
82
+fi
83
+KEYS_FILE=/home/$MY_USERNAME/.tempgnupg/tempfile.asc
84
+cat $FRAGMENTS_DIR/data* > $KEYS_FILE.gpg
85
+if [ ! "$?" = "0" ]; then
86
+    echo 'Unable to find key fragments'
87
+    exit 8727
88
+fi
89
+
90
+# decrypt the file
91
+cd /home/$MY_USERNAME/.tempgnupg
92
+gpg -d $KEYS_FILE.gpg -o $KEYS_FILE
93
+if [ ! "$?" = "0" ]; then
94
+    echo 'Unable to decrypt data. This may mean that not enough fragments are available'
95
+    exit 6283
96
+fi
97
+shred -zu $KEYS_FILE.gpg
98
+if [ ! -f $KEYS_FILE ]; then
99
+    echo 'Unable to find decrypted key file. This may mean that not enough fragments are available'
100
+    exit 8358
101
+fi
102
+echo 'Key fragments decrypted'
103
+
104
+# import the gpg key
105
+su -c "gpg --allow-secret-key-import --import $KEYS_FILE" - $MY_USERNAME
106
+if [ ! "$?" = "0" ]; then
107
+    echo 'Unable to import gpg key'
108
+    shred -zu $KEYS_FILE
109
+    rm -rf /home/$MY_USERNAME/.tempgnupg
110
+    exit 3682
111
+fi
112
+shred -zu $KEYS_FILE
113
+chown -R $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.gnupg
114
+chmod -R 600 /home/$MY_USERNAME/.gnupg
115
+rm -rf /home/$MY_USERNAME/.tempgnupg
116
+
117
+echo 'GPG key was recovered'
118
+
119
+exit 0