3
3
# Mandos key generator - create a new OpenPGP key for a Mandos client
5
# Copyright © 2008 Teddy Hogeborn & Björn Påhlsson
5
# Copyright © 2007-2008 Teddy Hogeborn & Björn Påhlsson
7
7
# This program is free software: you can redistribute it and/or modify
8
8
# it under the terms of the GNU General Public License as published by
20
20
# Contact the authors at <mandos@fukt.bsnet.se>.
25
KEYDIR="/etc/keys/mandos"
30
KEYNAME="`hostname --fqdn 2>/dev/null || hostname`"
30
KEYNAME="`hostname --fqdn`"
32
32
KEYCOMMENT="Mandos client key"
35
35
KEYCOMMENT_ORIG="$KEYCOMMENT"
38
if [ ! -d "$KEYDIR" ]; then
39
KEYDIR="/etc/mandos/keys"
43
TEMP=`getopt --options vhpF:d:t:l:s:L:n:e:c:x:f \
44
--longoptions version,help,password,passfile:,dir:,type:,length:,subtype:,sublength:,name:,email:,comment:,expire:,force \
39
TEMP=`getopt --options vhd:t:l:n:e:c:x:f \
40
--longoptions version,help,password,dir:,type:,length:,subtype:,sublength:,name:,email:,comment:,expire:,force \
45
41
--name "$0" -- "$@"`
53
49
$basename [ OPTIONS ]
54
50
Encrypted password creation:
55
51
$basename { -p | --password } [ --name NAME ] [ --dir DIR]
56
$basename { -F | --passfile } FILE [ --name NAME ] [ --dir DIR]
58
53
Key creation options:
59
54
-v, --version Show program's version number and exit
75
70
-x TIME, --expire TIME
76
71
Key expire time. Default is no expiration.
77
72
See gpg(1) for syntax.
78
-f, --force Force overwriting old key files.
73
-f, --force Force overwriting old keys.
80
75
Password creation options:
81
-p, --password Create an encrypted password using the key in
82
the key directory. All options other than
83
--dir and --name are ignored.
84
-F FILE, --passfile FILE
85
Encrypt a password from FILE using the key in
76
-p, --password Create an encrypted password using the keys in
86
77
the key directory. All options other than
87
78
--dir and --name are ignored.
94
85
-p|--password) mode=password; shift;;
95
-F|--passfile) mode=password; PASSFILE="$2"; shift 2;;
96
86
-d|--dir) KEYDIR="$2"; shift 2;;
97
87
-t|--type) KEYTYPE="$2"; shift 2;;
98
88
-s|--subtype) SUBKEYTYPE="$2"; shift 2;;
158
148
[Nn][Oo]|[Ff][Aa][Ll][Ss][Ee]|*) FORCE=0;;
161
if [ \( -e "$SECKEYFILE" -o -e "$PUBKEYFILE" \) \
162
-a "$FORCE" -eq 0 ]; then
151
if { [ -e "$SECKEYFILE" ] || [ -e "$PUBKEYFILE" ]; } \
152
&& [ "$FORCE" -eq 0 ]; then
163
153
echo "Refusing to overwrite old key files; use --force" >&2
241
231
FILECOMMENT="$FILECOMMENT <$KEYEMAIL>"
244
# Export key from key rings to key files
234
# Export keys from key rings to key files
245
235
gpg --quiet --batch --no-tty --no-options --enable-dsa2 \
246
236
--homedir "$RINGDIR" --armor --export-options export-minimal \
247
237
--comment "$FILECOMMENT" --output "$SECKEYFILE" \
254
244
if [ "$mode" = password ]; then
255
# Import key into temporary key rings
245
# Import keys into temporary key rings
256
246
gpg --quiet --batch --no-tty --no-options --enable-dsa2 \
257
247
--homedir "$RINGDIR" --trust-model always --armor \
258
248
--import "$SECKEYFILE"
264
254
FINGERPRINT="`gpg --quiet --batch --no-tty --no-options \
265
255
--enable-dsa2 --homedir \"$RINGDIR\" --trust-model always \
266
256
--fingerprint --with-colons \
268
--expression='/^fpr:/{s/^fpr:.*:\\([0-9A-Z]*\\):\$/\\1/p;q}'`"
257
| sed -n -e '/^fpr:/{s/^fpr:.*:\\([0-9A-Z]*\\):\$/\\1/p;q}'`"
270
259
test -n "$FINGERPRINT"
272
261
FILECOMMENT="Encrypted password for a Mandos client"
274
if [ -n "$PASSFILE" ]; then
278
echo -n "Enter passphrase: " >&2
279
first="$(head --lines=1 | tr --delete '\n')"
280
echo -n -e "\nRepeat passphrase: " >&2
281
second="$(head --lines=1 | tr --delete '\n')"
284
if [ "$first" != "$second" ]; then
285
echo -e "Passphrase mismatch" >&2
290
fi | gpg --quiet --batch --no-tty --no-options --enable-dsa2 \
264
echo -n "Enter passphrase: " >&2
266
| gpg --quiet --batch --no-tty --no-options --enable-dsa2 \
291
267
--homedir "$RINGDIR" --trust-model always --armor --encrypt \
292
268
--recipient "$FINGERPRINT" --comment "$FILECOMMENT" \
294
status="${PIPESTATUS[0]}"
295
if [ "$status" -ne 0 ]; then
302
276
fingerprint = $FINGERPRINT
305
sed --quiet --expression='
306
280
/^-----BEGIN PGP MESSAGE-----$/,/^-----END PGP MESSAGE-----$/{
308
282
# Remove 24-bit Radix-64 checksum