bzr branch
http://bzr.recompile.se/loggerhead/mandos/release
73
by Teddy Hogeborn
* Makefile (COVERAGE): Change back to "--coverage". |
1 |
#!/bin/sh -e
|
67
by Teddy Hogeborn
* mandos-keygen: New program to generate new client keys on |
2 |
#
|
73
by Teddy Hogeborn
* Makefile (COVERAGE): Change back to "--coverage". |
3 |
# Mandos key generator - create a new OpenPGP key for a Mandos client
|
67
by Teddy Hogeborn
* mandos-keygen: New program to generate new client keys on |
4 |
#
|
237.7.227
by Teddy Hogeborn
Update copyright year. |
5 |
# Copyright © 2008-2014 Teddy Hogeborn
|
6 |
# Copyright © 2008-2014 Björn Påhlsson
|
|
67
by Teddy Hogeborn
* mandos-keygen: New program to generate new client keys on |
7 |
#
|
8 |
# This program is free software: you can redistribute it and/or modify
|
|
9 |
# it under the terms of the GNU General Public License as published by
|
|
10 |
# the Free Software Foundation, either version 3 of the License, or
|
|
11 |
# (at your option) any later version.
|
|
12 |
#
|
|
13 |
# This program is distributed in the hope that it will be useful,
|
|
14 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
15 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
16 |
# GNU General Public License for more details.
|
|
17 |
#
|
|
18 |
# You should have received a copy of the GNU General Public License
|
|
19 |
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
20 |
#
|
|
237.11.2
by Teddy Hogeborn
Change "fukt.bsnet.se" to "recompile.se" throughout. |
21 |
# Contact the authors at <mandos@recompile.se>.
|
67
by Teddy Hogeborn
* mandos-keygen: New program to generate new client keys on |
22 |
#
|
23 |
||
324
by Teddy Hogeborn
* Makefile (version): Changed to "1.6.9". |
24 |
VERSION="1.6.9" |
73
by Teddy Hogeborn
* Makefile (COVERAGE): Change back to "--coverage". |
25 |
|
163
by Teddy Hogeborn
* Makefile (PIDDIR, USER, GROUP): Removed. |
26 |
KEYDIR="/etc/keys/mandos" |
237.7.169
by Teddy Hogeborn
* debian/mandos-client.README.Debian: Update Linux documentation link. |
27 |
KEYTYPE=RSA |
28 |
KEYLENGTH=4096 |
|
29 |
SUBKEYTYPE=RSA |
|
30 |
SUBKEYLENGTH=4096 |
|
196
by Teddy Hogeborn
* mandos-keygen (KEYNAME): Fall back to plain "hostname" if the |
31 |
KEYNAME="`hostname --fqdn 2>/dev/null || hostname`" |
67
by Teddy Hogeborn
* mandos-keygen: New program to generate new client keys on |
32 |
KEYEMAIL="" |
237.7.179
by Teddy Hogeborn
* mandos (priority): Bug fix: Add even more magic to make the old |
33 |
KEYCOMMENT="" |
67
by Teddy Hogeborn
* mandos-keygen: New program to generate new client keys on |
34 |
KEYEXPIRE=0 |
35 |
FORCE=no |
|
237.7.256
by Teddy Hogeborn
mandos-keygen: Generate "checker" option to use SSH fingerprints. |
36 |
SSH=yes |
67
by Teddy Hogeborn
* mandos-keygen: New program to generate new client keys on |
37 |
KEYCOMMENT_ORIG="$KEYCOMMENT" |
97
by Teddy Hogeborn
* mandos-keygen: Bug fix: Recognize new options --subtype and |
38 |
mode=keygen |
67
by Teddy Hogeborn
* mandos-keygen: New program to generate new client keys on |
39 |
|
179
by Teddy Hogeborn
* INSTALL: New file. |
40 |
if [ ! -d "$KEYDIR" ]; then |
41 |
KEYDIR="/etc/mandos/keys" |
|
42 |
fi
|
|
43 |
||
67
by Teddy Hogeborn
* mandos-keygen: New program to generate new client keys on |
44 |
# Parse options
|
237.7.256
by Teddy Hogeborn
mandos-keygen: Generate "checker" option to use SSH fingerprints. |
45 |
TEMP=`getopt --options vhpF:d:t:l:s:L:n:e:c:x:fS \ |
46 |
--longoptions version,help,password,passfile:,dir:,type:,length:,subtype:,sublength:,name:,email:,comment:,expire:,force,no-ssh \ |
|
67
by Teddy Hogeborn
* mandos-keygen: New program to generate new client keys on |
47 |
--name "$0" -- "$@"` |
48 |
||
73
by Teddy Hogeborn
* Makefile (COVERAGE): Change back to "--coverage". |
49 |
help(){
|
237.7.288
by Teddy Hogeborn
mandos-keygen: Fix some stylistic quoting issues. |
50 |
basename="`basename "$0"`" |
73
by Teddy Hogeborn
* Makefile (COVERAGE): Change back to "--coverage". |
51 |
cat <<EOF |
97
by Teddy Hogeborn
* mandos-keygen: Bug fix: Recognize new options --subtype and |
52 |
Usage: $basename [ -v | --version ]
|
53 |
$basename [ -h | --help ]
|
|
54 |
Key creation:
|
|
55 |
$basename [ OPTIONS ]
|
|
56 |
Encrypted password creation:
|
|
57 |
$basename { -p | --password } [ --name NAME ] [ --dir DIR]
|
|
198
by Teddy Hogeborn
* mandos-keygen: New "--passfile" option. Confirm entered password. |
58 |
$basename { -F | --passfile } FILE [ --name NAME ] [ --dir DIR]
|
73
by Teddy Hogeborn
* Makefile (COVERAGE): Change back to "--coverage". |
59 |
|
97
by Teddy Hogeborn
* mandos-keygen: Bug fix: Recognize new options --subtype and |
60 |
Key creation options:
|
73
by Teddy Hogeborn
* Makefile (COVERAGE): Change back to "--coverage". |
61 |
-v, --version Show program's version number and exit
|
62 |
-h, --help Show this help message and exit
|
|
63 |
-d DIR, --dir DIR Target directory for key files
|
|
237.7.169
by Teddy Hogeborn
* debian/mandos-client.README.Debian: Update Linux documentation link. |
64 |
-t TYPE, --type TYPE Key type. Default is RSA.
|
73
by Teddy Hogeborn
* Makefile (COVERAGE): Change back to "--coverage". |
65 |
-l BITS, --length BITS
|
237.7.169
by Teddy Hogeborn
* debian/mandos-client.README.Debian: Update Linux documentation link. |
66 |
Key length in bits. Default is 4096.
|
96
by Teddy Hogeborn
* Makefile (PREFIX, CONFDIR, MANDIR): Use $(DESTDIR). |
67 |
-s TYPE, --subtype TYPE
|
237.7.175
by Teddy Hogeborn
* mandos-keygen: Bug fix: Specify key usage to avoid creating keys |
68 |
Subkey type. Default is RSA.
|
96
by Teddy Hogeborn
* Makefile (PREFIX, CONFDIR, MANDIR): Use $(DESTDIR). |
69 |
-L BITS, --sublength BITS
|
237.7.169
by Teddy Hogeborn
* debian/mandos-client.README.Debian: Update Linux documentation link. |
70 |
Subkey length in bits. Default is 4096.
|
73
by Teddy Hogeborn
* Makefile (COVERAGE): Change back to "--coverage". |
71 |
-n NAME, --name NAME Name of key. Default is the FQDN.
|
97
by Teddy Hogeborn
* mandos-keygen: Bug fix: Recognize new options --subtype and |
72 |
-e ADDRESS, --email ADDRESS
|
73
by Teddy Hogeborn
* Makefile (COVERAGE): Change back to "--coverage". |
73 |
Email address of key. Default is empty.
|
123
by Teddy Hogeborn
* mandos-keygen: Minor help text change. |
74 |
-c TEXT, --comment TEXT
|
237.7.179
by Teddy Hogeborn
* mandos (priority): Bug fix: Add even more magic to make the old |
75 |
Comment field for key. The default is empty.
|
73
by Teddy Hogeborn
* Makefile (COVERAGE): Change back to "--coverage". |
76 |
-x TIME, --expire TIME
|
77 |
Key expire time. Default is no expiration.
|
|
78 |
See gpg(1) for syntax.
|
|
198
by Teddy Hogeborn
* mandos-keygen: New "--passfile" option. Confirm entered password. |
79 |
-f, --force Force overwriting old key files.
|
97
by Teddy Hogeborn
* mandos-keygen: Bug fix: Recognize new options --subtype and |
80 |
|
81 |
Password creation options:
|
|
198
by Teddy Hogeborn
* mandos-keygen: New "--passfile" option. Confirm entered password. |
82 |
-p, --password Create an encrypted password using the key in
|
83 |
the key directory. All options other than
|
|
84 |
--dir and --name are ignored.
|
|
85 |
-F FILE, --passfile FILE
|
|
86 |
Encrypt a password from FILE using the key in
|
|
97
by Teddy Hogeborn
* mandos-keygen: Bug fix: Recognize new options --subtype and |
87 |
the key directory. All options other than
|
123
by Teddy Hogeborn
* mandos-keygen: Minor help text change. |
88 |
--dir and --name are ignored.
|
237.7.256
by Teddy Hogeborn
mandos-keygen: Generate "checker" option to use SSH fingerprints. |
89 |
-S, --no-ssh Don't get SSH key or set "checker" option.
|
73
by Teddy Hogeborn
* Makefile (COVERAGE): Change back to "--coverage". |
90 |
EOF
|
91 |
}
|
|
92 |
||
67
by Teddy Hogeborn
* mandos-keygen: New program to generate new client keys on |
93 |
eval set -- "$TEMP" |
94 |
while :; do |
|
95 |
case "$1" in |
|
97
by Teddy Hogeborn
* mandos-keygen: Bug fix: Recognize new options --subtype and |
96 |
-p|--password) mode=password; shift;; |
198
by Teddy Hogeborn
* mandos-keygen: New "--passfile" option. Confirm entered password. |
97 |
-F|--passfile) mode=password; PASSFILE="$2"; shift 2;; |
67
by Teddy Hogeborn
* mandos-keygen: New program to generate new client keys on |
98 |
-d|--dir) KEYDIR="$2"; shift 2;; |
99 |
-t|--type) KEYTYPE="$2"; shift 2;; |
|
96
by Teddy Hogeborn
* Makefile (PREFIX, CONFDIR, MANDIR): Use $(DESTDIR). |
100 |
-s|--subtype) SUBKEYTYPE="$2"; shift 2;; |
67
by Teddy Hogeborn
* mandos-keygen: New program to generate new client keys on |
101 |
-l|--length) KEYLENGTH="$2"; shift 2;; |
96
by Teddy Hogeborn
* Makefile (PREFIX, CONFDIR, MANDIR): Use $(DESTDIR). |
102 |
-L|--sublength) SUBKEYLENGTH="$2"; shift 2;; |
67
by Teddy Hogeborn
* mandos-keygen: New program to generate new client keys on |
103 |
-n|--name) KEYNAME="$2"; shift 2;; |
104 |
-e|--email) KEYEMAIL="$2"; shift 2;; |
|
105 |
-c|--comment) KEYCOMMENT="$2"; shift 2;; |
|
87
by Teddy Hogeborn
* Makefile: Bug fix: fixed creation of man pages in "plugins.d". |
106 |
-x|--expire) KEYEXPIRE="$2"; shift 2;; |
67
by Teddy Hogeborn
* mandos-keygen: New program to generate new client keys on |
107 |
-f|--force) FORCE=yes; shift;; |
237.7.256
by Teddy Hogeborn
mandos-keygen: Generate "checker" option to use SSH fingerprints. |
108 |
-S|--no-ssh) SSH=no; shift;; |
73
by Teddy Hogeborn
* Makefile (COVERAGE): Change back to "--coverage". |
109 |
-v|--version) echo "$0 $VERSION"; exit;; |
110 |
-h|--help) help; exit;; |
|
67
by Teddy Hogeborn
* mandos-keygen: New program to generate new client keys on |
111 |
--) shift; break;; |
112 |
*) echo "Internal error" >&2; exit 1;; |
|
113 |
esac |
|
114 |
done
|
|
115 |
if [ "$#" -gt 0 ]; then |
|
237.7.288
by Teddy Hogeborn
mandos-keygen: Fix some stylistic quoting issues. |
116 |
echo "Unknown arguments: '$*'" >&2 |
67
by Teddy Hogeborn
* mandos-keygen: New program to generate new client keys on |
117 |
exit 1 |
118 |
fi
|
|
119 |
||
120 |
SECKEYFILE="$KEYDIR/seckey.txt" |
|
121 |
PUBKEYFILE="$KEYDIR/pubkey.txt" |
|
122 |
||
123 |
# Check for some invalid values
|
|
159
by Teddy Hogeborn
* Makefile (run-client): Do not depend on the key ring files. |
124 |
if [ ! -d "$KEYDIR" ]; then |
67
by Teddy Hogeborn
* mandos-keygen: New program to generate new client keys on |
125 |
echo "$KEYDIR not a directory" >&2 |
126 |
exit 1 |
|
127 |
fi
|
|
159
by Teddy Hogeborn
* Makefile (run-client): Do not depend on the key ring files. |
128 |
if [ ! -r "$KEYDIR" ]; then |
129 |
echo "Directory $KEYDIR not readable" >&2 |
|
97
by Teddy Hogeborn
* mandos-keygen: Bug fix: Recognize new options --subtype and |
130 |
exit 1 |
131 |
fi
|
|
132 |
||
133 |
if [ "$mode" = keygen ]; then |
|
159
by Teddy Hogeborn
* Makefile (run-client): Do not depend on the key ring files. |
134 |
if [ ! -w "$KEYDIR" ]; then |
135 |
echo "Directory $KEYDIR not writeable" >&2 |
|
136 |
exit 1 |
|
137 |
fi |
|
97
by Teddy Hogeborn
* mandos-keygen: Bug fix: Recognize new options --subtype and |
138 |
if [ -z "$KEYTYPE" ]; then |
139 |
echo "Empty key type" >&2 |
|
140 |
exit 1 |
|
141 |
fi |
|
142 |
|
|
143 |
if [ -z "$KEYNAME" ]; then |
|
144 |
echo "Empty key name" >&2 |
|
145 |
exit 1 |
|
146 |
fi |
|
147 |
|
|
148 |
if [ -z "$KEYLENGTH" ] || [ "$KEYLENGTH" -lt 512 ]; then |
|
149 |
echo "Invalid key length" >&2 |
|
150 |
exit 1 |
|
151 |
fi |
|
237.2.37
by Teddy Hogeborn
* mandos-keygen (password): Remove bashism "${PIPESTATUS}". |
152 |
|
97
by Teddy Hogeborn
* mandos-keygen: Bug fix: Recognize new options --subtype and |
153 |
if [ -z "$KEYEXPIRE" ]; then |
154 |
echo "Empty key expiration" >&2 |
|
155 |
exit 1 |
|
156 |
fi |
|
157 |
|
|
158 |
# Make FORCE be 0 or 1 |
|
159 |
case "$FORCE" in |
|
160 |
[Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]) FORCE=1;; |
|
161 |
[Nn][Oo]|[Ff][Aa][Ll][Ss][Ee]|*) FORCE=0;; |
|
162 |
esac |
|
163 |
|
|
168
by Teddy Hogeborn
* initramfs-tools-hook: Use long options where available. Use only |
164 |
if [ \( -e "$SECKEYFILE" -o -e "$PUBKEYFILE" \) \ |
165 |
-a "$FORCE" -eq 0 ]; then |
|
97
by Teddy Hogeborn
* mandos-keygen: Bug fix: Recognize new options --subtype and |
166 |
echo "Refusing to overwrite old key files; use --force" >&2 |
167 |
exit 1 |
|
168 |
fi |
|
169 |
|
|
170 |
# Set lines for GnuPG batch file |
|
171 |
if [ -n "$KEYCOMMENT" ]; then |
|
172 |
KEYCOMMENTLINE="Name-Comment: $KEYCOMMENT" |
|
173 |
fi |
|
174 |
if [ -n "$KEYEMAIL" ]; then |
|
175 |
KEYEMAILLINE="Name-Email: $KEYEMAIL" |
|
176 |
fi |
|
237.2.37
by Teddy Hogeborn
* mandos-keygen (password): Remove bashism "${PIPESTATUS}". |
177 |
|
97
by Teddy Hogeborn
* mandos-keygen: Bug fix: Recognize new options --subtype and |
178 |
# Create temporary gpg batch file |
159
by Teddy Hogeborn
* Makefile (run-client): Do not depend on the key ring files. |
179 |
BATCHFILE="`mktemp -t mandos-keygen-batch.XXXXXXXXXX`" |
97
by Teddy Hogeborn
* mandos-keygen: Bug fix: Recognize new options --subtype and |
180 |
fi
|
181 |
||
182 |
if [ "$mode" = password ]; then |
|
183 |
# Create temporary encrypted password file |
|
159
by Teddy Hogeborn
* Makefile (run-client): Do not depend on the key ring files. |
184 |
SECFILE="`mktemp -t mandos-keygen-secfile.XXXXXXXXXX`" |
185 |
fi
|
|
186 |
||
187 |
# Create temporary key ring directory
|
|
188 |
RINGDIR="`mktemp -d -t mandos-keygen-keyrings.XXXXXXXXXX`" |
|
97
by Teddy Hogeborn
* mandos-keygen: Bug fix: Recognize new options --subtype and |
189 |
|
73
by Teddy Hogeborn
* Makefile (COVERAGE): Change back to "--coverage". |
190 |
# Remove temporary files on exit
|
94
by Teddy Hogeborn
* clients.conf ([DEFAULT]/checker): Update to new default value. |
191 |
trap " |
96
by Teddy Hogeborn
* Makefile (PREFIX, CONFDIR, MANDIR): Use $(DESTDIR). |
192 |
set +e; \
|
159
by Teddy Hogeborn
* Makefile (run-client): Do not depend on the key ring files. |
193 |
test -n \"$SECFILE\" && shred --remove \"$SECFILE\"; \ |
237.7.256
by Teddy Hogeborn
mandos-keygen: Generate "checker" option to use SSH fingerprints. |
194 |
shred --remove \"$RINGDIR\"/sec* 2>/dev/null; |
159
by Teddy Hogeborn
* Makefile (run-client): Do not depend on the key ring files. |
195 |
test -n \"$BATCHFILE\" && rm --force \"$BATCHFILE\"; \ |
196 |
rm --recursive --force \"$RINGDIR\"; |
|
237.7.42
by Teddy Hogeborn
* mandos-keygen: Loop until passwords match when run interactively. |
197 |
tty --quiet && stty echo; \
|
94
by Teddy Hogeborn
* clients.conf ([DEFAULT]/checker): Update to new default value. |
198 |
" EXIT |
67
by Teddy Hogeborn
* mandos-keygen: New program to generate new client keys on |
199 |
|
237.2.215
by teddy at bsnet
* debian/control (Standards-Version): Updated to "3.9.1". |
200 |
set -e |
201 |
||
166
by Teddy Hogeborn
* Makefile (confdir/clients.conf): Tighten permissions to "u=rw". |
202 |
umask 077 |
73
by Teddy Hogeborn
* Makefile (COVERAGE): Change back to "--coverage". |
203 |
|
97
by Teddy Hogeborn
* mandos-keygen: Bug fix: Recognize new options --subtype and |
204 |
if [ "$mode" = keygen ]; then |
205 |
# Create batch file for GnuPG |
|
206 |
cat >"$BATCHFILE" <<-EOF |
|
207 |
Key-Type: $KEYTYPE
|
|
208 |
Key-Length: $KEYLENGTH
|
|
237.7.175
by Teddy Hogeborn
* mandos-keygen: Bug fix: Specify key usage to avoid creating keys |
209 |
Key-Usage: sign,auth
|
97
by Teddy Hogeborn
* mandos-keygen: Bug fix: Recognize new options --subtype and |
210 |
Subkey-Type: $SUBKEYTYPE
|
211 |
Subkey-Length: $SUBKEYLENGTH
|
|
237.7.175
by Teddy Hogeborn
* mandos-keygen: Bug fix: Specify key usage to avoid creating keys |
212 |
Subkey-Usage: encrypt
|
97
by Teddy Hogeborn
* mandos-keygen: Bug fix: Recognize new options --subtype and |
213 |
Name-Real: $KEYNAME
|
214 |
$KEYCOMMENTLINE
|
|
215 |
$KEYEMAILLINE
|
|
216 |
Expire-Date: $KEYEXPIRE
|
|
217 |
#Preferences: <string>
|
|
218 |
#Handle: <no-spaces>
|
|
159
by Teddy Hogeborn
* Makefile (run-client): Do not depend on the key ring files. |
219 |
#%pubring pubring.gpg
|
220 |
#%secring secring.gpg
|
|
97
by Teddy Hogeborn
* mandos-keygen: Bug fix: Recognize new options --subtype and |
221 |
%commit
|
222 |
EOF
|
|
223 |
|
|
237.2.156
by Teddy Hogeborn
* mandos-keygen (keygen): Warn about long key generation time. |
224 |
if tty --quiet; then |
225 |
cat <<-EOF |
|
226 |
Note: Due to entropy requirements, key generation could take
|
|
227 |
anything from a few minutes to SEVERAL HOURS. Please be
|
|
228 |
patient and/or supply the system with more entropy if needed.
|
|
229 |
EOF
|
|
230 |
echo -n "Started: " |
|
231 |
date
|
|
232 |
fi |
|
233 |
|
|
237.7.211
by Teddy Hogeborn
* mandos-keygen (keygen): Add workaround for Debian bug #737128. |
234 |
# Make sure trustdb.gpg exists; |
235 |
# this is a workaround for Debian bug #737128 |
|
236 |
gpg --quiet --batch --no-tty --no-options --enable-dsa2 \ |
|
237 |
--homedir "$RINGDIR" \ |
|
238 |
--import-ownertrust < /dev/null |
|
97
by Teddy Hogeborn
* mandos-keygen: Bug fix: Recognize new options --subtype and |
239 |
# Generate a new key in the key rings |
159
by Teddy Hogeborn
* Makefile (run-client): Do not depend on the key ring files. |
240 |
gpg --quiet --batch --no-tty --no-options --enable-dsa2 \ |
241 |
--homedir "$RINGDIR" --trust-model always \ |
|
97
by Teddy Hogeborn
* mandos-keygen: Bug fix: Recognize new options --subtype and |
242 |
--gen-key "$BATCHFILE" |
243 |
rm --force "$BATCHFILE" |
|
159
by Teddy Hogeborn
* Makefile (run-client): Do not depend on the key ring files. |
244 |
|
237.2.156
by Teddy Hogeborn
* mandos-keygen (keygen): Warn about long key generation time. |
245 |
if tty --quiet; then |
246 |
echo -n "Finished: " |
|
247 |
date
|
|
248 |
fi |
|
249 |
|
|
97
by Teddy Hogeborn
* mandos-keygen: Bug fix: Recognize new options --subtype and |
250 |
# Backup any old key files |
251 |
if cp --backup=numbered --force "$SECKEYFILE" "$SECKEYFILE" \ |
|
252 |
2>/dev/null; then |
|
253 |
shred --remove "$SECKEYFILE" |
|
254 |
fi |
|
255 |
if cp --backup=numbered --force "$PUBKEYFILE" "$PUBKEYFILE" \ |
|
256 |
2>/dev/null; then |
|
257 |
rm --force "$PUBKEYFILE" |
|
258 |
fi |
|
259 |
|
|
260 |
FILECOMMENT="Mandos client key for $KEYNAME" |
|
261 |
if [ "$KEYCOMMENT" != "$KEYCOMMENT_ORIG" ]; then |
|
262 |
FILECOMMENT="$FILECOMMENT ($KEYCOMMENT)" |
|
263 |
fi |
|
264 |
|
|
265 |
if [ -n "$KEYEMAIL" ]; then |
|
266 |
FILECOMMENT="$FILECOMMENT <$KEYEMAIL>" |
|
267 |
fi |
|
268 |
|
|
198
by Teddy Hogeborn
* mandos-keygen: New "--passfile" option. Confirm entered password. |
269 |
# Export key from key rings to key files |
159
by Teddy Hogeborn
* Makefile (run-client): Do not depend on the key ring files. |
270 |
gpg --quiet --batch --no-tty --no-options --enable-dsa2 \ |
271 |
--homedir "$RINGDIR" --armor --export-options export-minimal \ |
|
272 |
--comment "$FILECOMMENT" --output "$SECKEYFILE" \ |
|
273 |
--export-secret-keys
|
|
274 |
gpg --quiet --batch --no-tty --no-options --enable-dsa2 \ |
|
275 |
--homedir "$RINGDIR" --armor --export-options export-minimal \ |
|
276 |
--comment "$FILECOMMENT" --output "$PUBKEYFILE" --export |
|
97
by Teddy Hogeborn
* mandos-keygen: Bug fix: Recognize new options --subtype and |
277 |
fi
|
278 |
||
279 |
if [ "$mode" = password ]; then |
|
237.7.256
by Teddy Hogeborn
mandos-keygen: Generate "checker" option to use SSH fingerprints. |
280 |
|
281 |
# Make SSH be 0 or 1 |
|
282 |
case "$SSH" in |
|
283 |
[Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]) SSH=1;; |
|
284 |
[Nn][Oo]|[Ff][Aa][Ll][Ss][Ee]|*) SSH=0;; |
|
285 |
esac |
|
286 |
|
|
287 |
if [ $SSH -eq 1 ]; then |
|
288 |
set +e |
|
289 |
ssh_fingerprint="`ssh-keyscan localhost 2>/dev/null`" |
|
290 |
if [ $? -ne 0 ]; then |
|
291 |
ssh_fingerprint="" |
|
292 |
fi |
|
293 |
set -e |
|
294 |
ssh_fingerprint="${ssh_fingerprint#localhost }" |
|
295 |
fi |
|
296 |
|
|
198
by Teddy Hogeborn
* mandos-keygen: New "--passfile" option. Confirm entered password. |
297 |
# Import key into temporary key rings |
159
by Teddy Hogeborn
* Makefile (run-client): Do not depend on the key ring files. |
298 |
gpg --quiet --batch --no-tty --no-options --enable-dsa2 \ |
299 |
--homedir "$RINGDIR" --trust-model always --armor \ |
|
300 |
--import "$SECKEYFILE" |
|
301 |
gpg --quiet --batch --no-tty --no-options --enable-dsa2 \ |
|
302 |
--homedir "$RINGDIR" --trust-model always --armor \ |
|
303 |
--import "$PUBKEYFILE" |
|
304 |
|
|
97
by Teddy Hogeborn
* mandos-keygen: Bug fix: Recognize new options --subtype and |
305 |
# Get fingerprint of key |
159
by Teddy Hogeborn
* Makefile (run-client): Do not depend on the key ring files. |
306 |
FINGERPRINT="`gpg --quiet --batch --no-tty --no-options \ |
237.7.288
by Teddy Hogeborn
mandos-keygen: Fix some stylistic quoting issues. |
307 |
--enable-dsa2 --homedir "$RINGDIR" --trust-model always \ |
159
by Teddy Hogeborn
* Makefile (run-client): Do not depend on the key ring files. |
308 |
--fingerprint --with-colons \
|
168
by Teddy Hogeborn
* initramfs-tools-hook: Use long options where available. Use only |
309 |
| sed --quiet \
|
310 |
--expression='/^fpr:/{s/^fpr:.*:\\([0-9A-Z]*\\):\$/\\1/p;q}'`"
|
|
97
by Teddy Hogeborn
* mandos-keygen: Bug fix: Recognize new options --subtype and |
311 |
|
312 |
test -n "$FINGERPRINT" |
|
313 |
|
|
314 |
FILECOMMENT="Encrypted password for a Mandos client" |
|
315 |
|
|
237.7.42
by Teddy Hogeborn
* mandos-keygen: Loop until passwords match when run interactively. |
316 |
while [ ! -s "$SECFILE" ]; do |
317 |
if [ -n "$PASSFILE" ]; then |
|
318 |
cat "$PASSFILE" |
|
198
by Teddy Hogeborn
* mandos-keygen: New "--passfile" option. Confirm entered password. |
319 |
else |
237.7.42
by Teddy Hogeborn
* mandos-keygen: Loop until passwords match when run interactively. |
320 |
tty --quiet && stty -echo |
237.7.176
by Teddy Hogeborn
* Makefile (install-client-nokey): Install "mandos-change-keytype". |
321 |
echo -n "Enter passphrase: " >&2 |
237.7.162
by Teddy Hogeborn
* mandos: Comment changes. |
322 |
read first |
237.7.42
by Teddy Hogeborn
* mandos-keygen: Loop until passwords match when run interactively. |
323 |
tty --quiet && echo >&2 |
237.7.176
by Teddy Hogeborn
* Makefile (install-client-nokey): Install "mandos-change-keytype". |
324 |
echo -n "Repeat passphrase: " >&2 |
237.7.162
by Teddy Hogeborn
* mandos: Comment changes. |
325 |
read second |
237.7.42
by Teddy Hogeborn
* mandos-keygen: Loop until passwords match when run interactively. |
326 |
if tty --quiet; then |
327 |
echo >&2 |
|
328 |
stty echo |
|
329 |
fi |
|
330 |
if [ "$first" != "$second" ]; then |
|
331 |
echo "Passphrase mismatch" >&2 |
|
332 |
touch "$RINGDIR"/mismatch |
|
333 |
else |
|
334 |
echo -n "$first" |
|
335 |
fi |
|
336 |
fi | gpg --quiet --batch --no-tty --no-options --enable-dsa2 \ |
|
337 |
--homedir "$RINGDIR" --trust-model always --armor \ |
|
338 |
--encrypt --sign --recipient "$FINGERPRINT" --comment \ |
|
339 |
"$FILECOMMENT" > "$SECFILE" |
|
340 |
if [ -e "$RINGDIR"/mismatch ]; then |
|
341 |
rm --force "$RINGDIR"/mismatch |
|
342 |
if tty --quiet; then |
|
343 |
> "$SECFILE" |
|
344 |
else |
|
345 |
exit 1 |
|
346 |
fi |
|
198
by Teddy Hogeborn
* mandos-keygen: New "--passfile" option. Confirm entered password. |
347 |
fi |
237.7.42
by Teddy Hogeborn
* mandos-keygen: Loop until passwords match when run interactively. |
348 |
done |
97
by Teddy Hogeborn
* mandos-keygen: Bug fix: Recognize new options --subtype and |
349 |
|
350 |
cat <<-EOF |
|
351 |
[$KEYNAME]
|
|
99
by Teddy Hogeborn
* mandos (fingerprint): Bug fix: Check crtverify.value, not crtverify. |
352 |
host = $KEYNAME
|
97
by Teddy Hogeborn
* mandos-keygen: Bug fix: Recognize new options --subtype and |
353 |
fingerprint = $FINGERPRINT
|
354 |
secret =
|
|
198
by Teddy Hogeborn
* mandos-keygen: New "--passfile" option. Confirm entered password. |
355 |
EOF
|
168
by Teddy Hogeborn
* initramfs-tools-hook: Use long options where available. Use only |
356 |
sed --quiet --expression=' |
97
by Teddy Hogeborn
* mandos-keygen: Bug fix: Recognize new options --subtype and |
357 |
/^-----BEGIN PGP MESSAGE-----$/,/^-----END PGP MESSAGE-----$/{
|
358 |
/^$/,${
|
|
103
by Teddy Hogeborn
* mandos-keygen: Strip 24-bit checksum of Radix-64 from output to make |
359 |
# Remove 24-bit Radix-64 checksum
|
360 |
s/=....$//
|
|
97
by Teddy Hogeborn
* mandos-keygen: Bug fix: Recognize new options --subtype and |
361 |
# Indent four spaces
|
362 |
/^[^-]/s/^/ /p
|
|
363 |
}
|
|
364 |
}' < "$SECFILE" |
|
237.7.256
by Teddy Hogeborn
mandos-keygen: Generate "checker" option to use SSH fingerprints. |
365 |
if [ -n "$ssh_fingerprint" ]; then |
237.7.275
by Teddy Hogeborn
Bug fix for mandos-keygen: Unquote escaped hostname in SSH checker. |
366 |
echo 'checker = ssh-keyscan %%(host)s 2>/dev/null | grep --fixed-strings --line-regexp --quiet --regexp=%%(host)s" %(ssh_fingerprint)s"' |
237.7.256
by Teddy Hogeborn
mandos-keygen: Generate "checker" option to use SSH fingerprints. |
367 |
echo "ssh_fingerprint = ${ssh_fingerprint}" |
368 |
fi |
|
97
by Teddy Hogeborn
* mandos-keygen: Bug fix: Recognize new options --subtype and |
369 |
fi
|
73
by Teddy Hogeborn
* Makefile (COVERAGE): Change back to "--coverage". |
370 |
|
371 |
trap - EXIT |
|
372 |
||
97
by Teddy Hogeborn
* mandos-keygen: Bug fix: Recognize new options --subtype and |
373 |
set +e |
374 |
# Remove the password file, if any
|
|
375 |
if [ -n "$SECFILE" ]; then |
|
376 |
shred --remove "$SECFILE" |
|
377 |
fi
|
|
73
by Teddy Hogeborn
* Makefile (COVERAGE): Change back to "--coverage". |
378 |
# Remove the key rings
|
237.7.256
by Teddy Hogeborn
mandos-keygen: Generate "checker" option to use SSH fingerprints. |
379 |
shred --remove "$RINGDIR"/sec* 2>/dev/null |
159
by Teddy Hogeborn
* Makefile (run-client): Do not depend on the key ring files. |
380 |
rm --recursive --force "$RINGDIR" |