31
33
KEYCOMMENT_ORIG="$KEYCOMMENT"
34
TEMP=`getopt --options d:t:l:n:e:c:x:f \
35
--longoptions dir:,type:,length:,name:,email:,comment:,expire:,force \
36
TEMP=`getopt --options vhd:t:l:n:e:c:x:f \
37
--longoptions version,help,dir:,type:,length:,name:,email:,comment:,expire:,force \
36
38
--name "$0" -- "$@"`
42
Usage: `basename $0` [options]
45
-v, --version Show program's version number and exit
46
-h, --help Show this help message and exit
47
-d DIR, --dir DIR Target directory for key files
48
-t TYPE, --type TYPE Key type. Default is DSA.
49
-l BITS, --length BITS
50
Key length in bits. Default is 1024.
51
-n NAME, --name NAME Name of key. Default is the FQDN.
52
-e EMAIL, --email EMAIL
53
Email address of key. Default is empty.
54
-c COMMENT, --comment COMMENT
55
Comment field for key. The default value is
57
-x TIME, --expire TIME
58
Key expire time. Default is no expiration.
59
See gpg(1) for syntax.
60
-f, --force Force overwriting old keys.
38
64
eval set -- "$TEMP"
46
72
-c|--comment) KEYCOMMENT="$2"; shift 2;;
47
73
-x|--expire) KEYCOMMENT="$2"; shift 2;;
48
74
-f|--force) FORCE=yes; shift;;
75
-v|--version) echo "$0 $VERSION"; exit;;
76
-h|--help) help; exit;;
50
78
*) echo "Internal error" >&2; exit 1;;
113
141
SECRING="`mktemp -t mandos-gpg-secring.XXXXXXXXXX`"
114
142
PUBRING="`mktemp -t mandos-gpg-pubring.XXXXXXXXXX`"
144
# Remove temporary files on exit
116
145
trap "rm --force $PUBRING $BATCHFILE; shred --remove $SECRING" EXIT
118
# Create batch file for GPG
147
# Create batch file for GnuPG
119
148
cat >"$BATCHFILE" <<EOF
120
149
Key-Type: $KEYTYPE
121
150
Key-Length: $KEYLENGTH
163
# Generate a new key in the key rings
133
164
gpg --no-random-seed-file --quiet --batch --no-tty \
134
--no-default-keyring --batch --secret-keyring "$SECRING" \
135
--keyring "$PUBRING" --gen-key "$BATCHFILE"
165
--no-default-keyring --no-options --batch \
166
--secret-keyring "$SECRING" --keyring "$PUBRING" \
167
--gen-key "$BATCHFILE"
136
168
rm --force "$BATCHFILE"
170
# Backup any old key files
138
171
if cp --backup=numbered --force "$SECKEYFILE" "$SECKEYFILE" \
139
172
2>/dev/null; then
140
173
shred --remove "$SECKEYFILE"
153
186
FILECOMMENT="$FILECOMMENT <$KEYEMAIL>"
189
# Export keys from key rings to key files
156
190
gpg --no-random-seed-file --quiet --batch --no-tty --armor \
157
191
--no-default-keyring --secret-keyring "$SECRING" \
158
192
--keyring "$PUBRING" --export-options export-minimal \