31
35
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 \
38
TEMP=`getopt --options vhd:t:l:n:e:c:x:f \
39
--longoptions version,help,dir:,type:,length:,name:,email:,comment:,expire:,force \
36
40
--name "$0" -- "$@"`
44
Usage: `basename $0` [options]
47
-v, --version Show program's version number and exit
48
-h, --help Show this help message and exit
49
-d DIR, --dir DIR Target directory for key files
50
-t TYPE, --type TYPE Key type. Default is DSA.
51
-l BITS, --length BITS
52
Key length in bits. Default is 1024.
53
-s TYPE, --subtype TYPE
54
Subkey type. Default is ELG-E.
55
-L BITS, --sublength BITS
56
Subkey length in bits. Default is 2048.
57
-n NAME, --name NAME Name of key. Default is the FQDN.
58
-e EMAIL, --email EMAIL
59
Email address of key. Default is empty.
60
-c COMMENT, --comment COMMENT
61
Comment field for key. The default value is
63
-x TIME, --expire TIME
64
Key expire time. Default is no expiration.
65
See gpg(1) for syntax.
66
-f, --force Force overwriting old keys.
38
70
eval set -- "$TEMP"
41
73
-d|--dir) KEYDIR="$2"; shift 2;;
42
74
-t|--type) KEYTYPE="$2"; shift 2;;
75
-s|--subtype) SUBKEYTYPE="$2"; shift 2;;
43
76
-l|--length) KEYLENGTH="$2"; shift 2;;
77
-L|--sublength) SUBKEYLENGTH="$2"; shift 2;;
44
78
-n|--name) KEYNAME="$2"; shift 2;;
45
79
-e|--email) KEYEMAIL="$2"; shift 2;;
46
80
-c|--comment) KEYCOMMENT="$2"; shift 2;;
47
-x|--expire) KEYCOMMENT="$2"; shift 2;;
81
-x|--expire) KEYEXPIRE="$2"; shift 2;;
48
82
-f|--force) FORCE=yes; shift;;
83
-v|--version) echo "$0 $VERSION"; exit;;
84
-h|--help) help; exit;;
50
86
*) echo "Internal error" >&2; exit 1;;
113
149
SECRING="`mktemp -t mandos-gpg-secring.XXXXXXXXXX`"
114
150
PUBRING="`mktemp -t mandos-gpg-pubring.XXXXXXXXXX`"
116
trap "rm --force $PUBRING $BATCHFILE; shred --remove $SECRING" EXIT
152
# Remove temporary files on exit
155
rm --force $PUBRING $BATCHFILE; \
156
shred --remove $SECRING; \
118
# Create batch file for GPG
160
# Create batch file for GnuPG
119
161
cat >"$BATCHFILE" <<EOF
120
162
Key-Type: $KEYTYPE
121
163
Key-Length: $KEYLENGTH
122
164
#Key-Usage: encrypt,sign,auth
165
Subkey-Type: $SUBKEYTYPE
166
Subkey-Length: $SUBKEYLENGTH
167
#Subkey-Usage: encrypt,sign,auth
123
168
Name-Real: $KEYNAME
126
171
Expire-Date: $KEYEXPIRE
172
#Preferences: <string>
127
174
%pubring $PUBRING
128
175
%secring $SECRING
181
# Generate a new key in the key rings
133
182
gpg --no-random-seed-file --quiet --batch --no-tty \
134
--no-default-keyring --no-options --batch \
183
--no-default-keyring --no-options --enable-dsa2 \
135
184
--secret-keyring "$SECRING" --keyring "$PUBRING" \
136
185
--gen-key "$BATCHFILE"
137
186
rm --force "$BATCHFILE"
188
# Backup any old key files
139
189
if cp --backup=numbered --force "$SECKEYFILE" "$SECKEYFILE" \
140
190
2>/dev/null; then
141
191
shred --remove "$SECKEYFILE"
154
204
FILECOMMENT="$FILECOMMENT <$KEYEMAIL>"
157
gpg --no-random-seed-file --quiet --batch --no-tty --armor \
158
--no-default-keyring --secret-keyring "$SECRING" \
159
--keyring "$PUBRING" --export-options export-minimal \
160
--comment "$FILECOMMENT" --output "$SECKEYFILE" \
162
gpg --no-random-seed-file --quiet --batch --no-tty --armor \
163
--no-default-keyring --secret-keyring "$SECRING" \
164
--keyring "$PUBRING" --export-options export-minimal \
165
--comment "$FILECOMMENT" --output "$PUBKEYFILE" \
207
# Export keys from key rings to key files
208
gpg --no-random-seed-file --quiet --batch --no-tty --armor \
209
--no-default-keyring --no-options --enable-dsa2 \
210
--secret-keyring "$SECRING" --keyring "$PUBRING" \
211
--export-options export-minimal --comment "$FILECOMMENT" \
212
--output "$SECKEYFILE" --export-secret-keys
213
gpg --no-random-seed-file --quiet --batch --no-tty --armor \
214
--no-default-keyring --no-options --enable-dsa2 \
215
--secret-keyring "$SECRING" --keyring "$PUBRING" \
216
--export-options export-minimal --comment "$FILECOMMENT" \
217
--output "$PUBKEYFILE" --export
221
# Remove the key rings
222
shred --remove "$SECRING"
223
rm --force "$PUBRING"