33
31
KEYCOMMENT_ORIG="$KEYCOMMENT"
36
TEMP=`getopt --options vhd:t:l:n:e:c:x:f \
37
--longoptions version,help,dir:,type:,length:,name:,email:,comment:,expire:,force \
34
TEMP=`getopt --options d:t:l:n:e:c:x:f \
35
--longoptions dir:,type:,length:,name:,email:,comment:,expire:,force \
38
36
--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.
64
38
eval set -- "$TEMP"
72
46
-c|--comment) KEYCOMMENT="$2"; shift 2;;
73
47
-x|--expire) KEYCOMMENT="$2"; shift 2;;
74
48
-f|--force) FORCE=yes; shift;;
75
-v|--version) echo "$0 $VERSION"; exit;;
76
-h|--help) help; exit;;
78
50
*) echo "Internal error" >&2; exit 1;;
141
113
SECRING="`mktemp -t mandos-gpg-secring.XXXXXXXXXX`"
142
114
PUBRING="`mktemp -t mandos-gpg-pubring.XXXXXXXXXX`"
144
# Remove temporary files on exit
145
116
trap "rm --force $PUBRING $BATCHFILE; shred --remove $SECRING" EXIT
147
# Create batch file for GnuPG
118
# Create batch file for GPG
148
119
cat >"$BATCHFILE" <<EOF
149
120
Key-Type: $KEYTYPE
150
121
Key-Length: $KEYLENGTH
163
# Generate a new key in the key rings
164
133
gpg --no-random-seed-file --quiet --batch --no-tty \
165
--no-default-keyring --no-options --batch \
166
--secret-keyring "$SECRING" --keyring "$PUBRING" \
167
--gen-key "$BATCHFILE"
134
--no-default-keyring --batch --secret-keyring "$SECRING" \
135
--keyring "$PUBRING" --gen-key "$BATCHFILE"
168
136
rm --force "$BATCHFILE"
170
# Backup any old key files
171
138
if cp --backup=numbered --force "$SECKEYFILE" "$SECKEYFILE" \
172
139
2>/dev/null; then
173
140
shred --remove "$SECKEYFILE"
186
153
FILECOMMENT="$FILECOMMENT <$KEYEMAIL>"
189
# Export keys from key rings to key files
190
156
gpg --no-random-seed-file --quiet --batch --no-tty --armor \
191
157
--no-default-keyring --secret-keyring "$SECRING" \
192
158
--keyring "$PUBRING" --export-options export-minimal \