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