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"
70
44
-n|--name) KEYNAME="$2"; shift 2;;
71
45
-e|--email) KEYEMAIL="$2"; shift 2;;
72
46
-c|--comment) KEYCOMMENT="$2"; shift 2;;
73
-x|--expire) KEYEXPIRE="$2"; shift 2;;
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
147
rm --force $PUBRING $BATCHFILE;
148
shred --remove $SECRING;
116
trap "rm --force $PUBRING $BATCHFILE; shred --remove $SECRING" EXIT
152
# Create batch file for GnuPG
118
# Create batch file for GPG
153
119
cat >"$BATCHFILE" <<EOF
154
120
Key-Type: $KEYTYPE
155
121
Key-Length: $KEYLENGTH
168
# Generate a new key in the key rings
169
133
gpg --no-random-seed-file --quiet --batch --no-tty \
170
--no-default-keyring --no-options --batch \
171
--secret-keyring "$SECRING" --keyring "$PUBRING" \
172
--gen-key "$BATCHFILE"
134
--no-default-keyring --batch --secret-keyring "$SECRING" \
135
--keyring "$PUBRING" --gen-key "$BATCHFILE"
173
136
rm --force "$BATCHFILE"
175
# Backup any old key files
176
138
if cp --backup=numbered --force "$SECKEYFILE" "$SECKEYFILE" \
177
139
2>/dev/null; then
178
140
shred --remove "$SECKEYFILE"
191
153
FILECOMMENT="$FILECOMMENT <$KEYEMAIL>"
194
# Export keys from key rings to key files
195
156
gpg --no-random-seed-file --quiet --batch --no-tty --armor \
196
--no-default-keyring --no-options --secret-keyring "$SECRING" \
157
--no-default-keyring --secret-keyring "$SECRING" \
197
158
--keyring "$PUBRING" --export-options export-minimal \
198
159
--comment "$FILECOMMENT" --output "$SECKEYFILE" \
199
160
--export-secret-keys
200
161
gpg --no-random-seed-file --quiet --batch --no-tty --armor \
201
--no-default-keyring --no-options --secret-keyring "$SECRING" \
162
--no-default-keyring --secret-keyring "$SECRING" \
202
163
--keyring "$PUBRING" --export-options export-minimal \
203
164
--comment "$FILECOMMENT" --output "$PUBKEYFILE" \
208
# Remove the key rings
209
shred --remove "$SECRING"
210
rm --force "$PUBRING"