/mandos/release

To get this branch, use:
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.355 by Teddy Hogeborn
Update copyright year.
5
# Copyright © 2008-2016 Teddy Hogeborn
6
# Copyright © 2008-2016 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
351 by Teddy Hogeborn
* Makefile (version): Change to 1.7.11.
24
VERSION="1.7.11"
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
237.7.396 by Teddy Hogeborn
mandos-keygen: Try to use ECDSA keys with ssh-keyscan(1) by default.
288
	for ssh_keytype in ecdsa-sha2-nistp256 ed25519 rsa; do
237.7.295 by Teddy Hogeborn
mandos-keygen: Bug fix: Only use one SSH key from ssh-keyscan
289
	    set +e
290
	    ssh_fingerprint="`ssh-keyscan -t $ssh_keytype localhost 2>/dev/null`"
291
	    set -e
292
	    if [ $? -ne 0 ]; then
293
		ssh_fingerprint=""
294
		continue
295
	    fi
296
	    if [ -n "$ssh_fingerprint" ]; then
297
		ssh_fingerprint="${ssh_fingerprint#localhost }"
298
		break
299
	    fi
300
	done
237.7.256 by Teddy Hogeborn
mandos-keygen: Generate "checker" option to use SSH fingerprints.
301
    fi
302
    
198 by Teddy Hogeborn
* mandos-keygen: New "--passfile" option. Confirm entered password.
303
    # Import key into temporary key rings
159 by Teddy Hogeborn
* Makefile (run-client): Do not depend on the key ring files.
304
    gpg --quiet --batch --no-tty --no-options --enable-dsa2 \
305
	--homedir "$RINGDIR" --trust-model always --armor \
306
	--import "$SECKEYFILE"
307
    gpg --quiet --batch --no-tty --no-options --enable-dsa2 \
308
	--homedir "$RINGDIR" --trust-model always --armor \
309
	--import "$PUBKEYFILE"
310
    
97 by Teddy Hogeborn
* mandos-keygen: Bug fix: Recognize new options --subtype and
311
    # Get fingerprint of key
159 by Teddy Hogeborn
* Makefile (run-client): Do not depend on the key ring files.
312
    FINGERPRINT="`gpg --quiet --batch --no-tty --no-options \
237.7.288 by Teddy Hogeborn
mandos-keygen: Fix some stylistic quoting issues.
313
	--enable-dsa2 --homedir "$RINGDIR" --trust-model always \
159 by Teddy Hogeborn
* Makefile (run-client): Do not depend on the key ring files.
314
	--fingerprint --with-colons \
168 by Teddy Hogeborn
* initramfs-tools-hook: Use long options where available. Use only
315
	| sed --quiet \
316
	--expression='/^fpr:/{s/^fpr:.*:\\([0-9A-Z]*\\):\$/\\1/p;q}'`"
97 by Teddy Hogeborn
* mandos-keygen: Bug fix: Recognize new options --subtype and
317
    
318
    test -n "$FINGERPRINT"
319
    
320
    FILECOMMENT="Encrypted password for a Mandos client"
321
    
237.7.42 by Teddy Hogeborn
* mandos-keygen: Loop until passwords match when run interactively.
322
    while [ ! -s "$SECFILE" ]; do
323
	if [ -n "$PASSFILE" ]; then
324
	    cat "$PASSFILE"
198 by Teddy Hogeborn
* mandos-keygen: New "--passfile" option. Confirm entered password.
325
	else
237.7.42 by Teddy Hogeborn
* mandos-keygen: Loop until passwords match when run interactively.
326
	    tty --quiet && stty -echo
237.7.176 by Teddy Hogeborn
* Makefile (install-client-nokey): Install "mandos-change-keytype".
327
	    echo -n "Enter passphrase: " >&2
237.7.162 by Teddy Hogeborn
* mandos: Comment changes.
328
	    read first
237.7.42 by Teddy Hogeborn
* mandos-keygen: Loop until passwords match when run interactively.
329
	    tty --quiet && echo >&2
237.7.176 by Teddy Hogeborn
* Makefile (install-client-nokey): Install "mandos-change-keytype".
330
	    echo -n "Repeat passphrase: " >&2
237.7.162 by Teddy Hogeborn
* mandos: Comment changes.
331
	    read second
237.7.42 by Teddy Hogeborn
* mandos-keygen: Loop until passwords match when run interactively.
332
	    if tty --quiet; then
333
		echo >&2
334
		stty echo
335
	    fi
336
	    if [ "$first" != "$second" ]; then
337
		echo "Passphrase mismatch" >&2
338
		touch "$RINGDIR"/mismatch
339
	    else
340
		echo -n "$first"
341
	    fi
342
	fi | gpg --quiet --batch --no-tty --no-options --enable-dsa2 \
343
	    --homedir "$RINGDIR" --trust-model always --armor \
344
	    --encrypt --sign --recipient "$FINGERPRINT" --comment \
345
	    "$FILECOMMENT" > "$SECFILE"
346
	if [ -e "$RINGDIR"/mismatch ]; then
347
	    rm --force "$RINGDIR"/mismatch
348
	    if tty --quiet; then
349
		> "$SECFILE"
350
	    else
351
		exit 1
352
	    fi
198 by Teddy Hogeborn
* mandos-keygen: New "--passfile" option. Confirm entered password.
353
	fi
237.7.42 by Teddy Hogeborn
* mandos-keygen: Loop until passwords match when run interactively.
354
    done
97 by Teddy Hogeborn
* mandos-keygen: Bug fix: Recognize new options --subtype and
355
    
356
    cat <<-EOF
357
	[$KEYNAME]
99 by Teddy Hogeborn
* mandos (fingerprint): Bug fix: Check crtverify.value, not crtverify.
358
	host = $KEYNAME
97 by Teddy Hogeborn
* mandos-keygen: Bug fix: Recognize new options --subtype and
359
	fingerprint = $FINGERPRINT
360
	secret =
198 by Teddy Hogeborn
* mandos-keygen: New "--passfile" option. Confirm entered password.
361
	EOF
168 by Teddy Hogeborn
* initramfs-tools-hook: Use long options where available. Use only
362
    sed --quiet --expression='
97 by Teddy Hogeborn
* mandos-keygen: Bug fix: Recognize new options --subtype and
363
	/^-----BEGIN PGP MESSAGE-----$/,/^-----END PGP MESSAGE-----$/{
364
	    /^$/,${
103 by Teddy Hogeborn
* mandos-keygen: Strip 24-bit checksum of Radix-64 from output to make
365
		# Remove 24-bit Radix-64 checksum
366
		s/=....$//
97 by Teddy Hogeborn
* mandos-keygen: Bug fix: Recognize new options --subtype and
367
		# Indent four spaces
368
		/^[^-]/s/^/    /p
369
	    }
370
	}' < "$SECFILE"
237.7.256 by Teddy Hogeborn
mandos-keygen: Generate "checker" option to use SSH fingerprints.
371
    if [ -n "$ssh_fingerprint" ]; then
237.7.295 by Teddy Hogeborn
mandos-keygen: Bug fix: Only use one SSH key from ssh-keyscan
372
	echo 'checker = ssh-keyscan -t '"$ssh_keytype"' %%(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.
373
	echo "ssh_fingerprint = ${ssh_fingerprint}"
374
    fi
97 by Teddy Hogeborn
* mandos-keygen: Bug fix: Recognize new options --subtype and
375
fi
73 by Teddy Hogeborn
* Makefile (COVERAGE): Change back to "--coverage".
376
377
trap - EXIT
378
97 by Teddy Hogeborn
* mandos-keygen: Bug fix: Recognize new options --subtype and
379
set +e
380
# Remove the password file, if any
381
if [ -n "$SECFILE" ]; then
382
    shred --remove "$SECFILE"
383
fi
73 by Teddy Hogeborn
* Makefile (COVERAGE): Change back to "--coverage".
384
# Remove the key rings
237.7.256 by Teddy Hogeborn
mandos-keygen: Generate "checker" option to use SSH fingerprints.
385
shred --remove "$RINGDIR"/sec* 2>/dev/null
159 by Teddy Hogeborn
* Makefile (run-client): Do not depend on the key ring files.
386
rm --recursive --force "$RINGDIR"