3
3
# Mandos key generator - create new keys for a Mandos client
5
# Copyright © 2008-2018 Teddy Hogeborn
6
# Copyright © 2008-2018 Björn Påhlsson
5
# Copyright © 2008-2019 Teddy Hogeborn
6
# Copyright © 2008-2019 Björn Påhlsson
8
8
# This file is part of Mandos.
203
204
test -n \"$SECFILE\" && shred --remove \"$SECFILE\"; \
205
test -n \"$TLS_PRIVKEYTMP\" && shred --remove \"$TLS_PRIVKEYTMP\"; \
204
206
shred --remove \"$RINGDIR\"/sec* 2>/dev/null;
205
207
test -n \"$BATCHFILE\" && rm --force \"$BATCHFILE\"; \
206
208
rm --recursive --force \"$RINGDIR\";
241
243
echo -n "Started: "
245
# Backup any old key files
246
if cp --backup=numbered --force "$TLS_PRIVKEYFILE" "$TLS_PRIVKEYFILE" \
248
shred --remove "$TLS_PRIVKEYFILE"
250
if cp --backup=numbered --force "$TLS_PUBKEYFILE" "$TLS_PUBKEYFILE" \
252
rm --force "$TLS_PUBKEYFILE"
255
## Generate TLS private key
257
# First try certtool from GnuTLS
258
if ! certtool --generate-privkey --password='' \
259
--outfile "$TLS_PRIVKEYFILE" --sec-param ultra \
260
--key-type="$TLS_KEYTYPE" --pkcs8 --no-text 2>/dev/null; then
261
# Otherwise try OpenSSL
262
if ! openssl genpkey -algorithm X25519 -out \
263
/etc/keys/mandos/tls-privkey.pem; then
264
rm --force /etc/keys/mandos/tls-privkey.pem
265
# None of the commands succeded; give up
247
# Generate TLS private key
248
if certtool --generate-privkey --password='' \
249
--outfile "$TLS_PRIVKEYTMP" --sec-param ultra \
250
--key-type="$TLS_KEYTYPE" --pkcs8 --no-text 2>/dev/null; then
252
# Backup any old key files
253
if cp --backup=numbered --force "$TLS_PRIVKEYFILE" "$TLS_PRIVKEYFILE" \
255
shred --remove "$TLS_PRIVKEYFILE" 2>/dev/null || :
272
# First try certtool from GnuTLS
273
if ! certtool --password='' --load-privkey="$TLS_PRIVKEYFILE" \
274
--outfile="$TLS_PUBKEYFILE" --pubkey-info --no-text \
276
# Otherwise try OpenSSL
277
if ! openssl pkey -in "$TLS_PRIVKEYFILE" \
278
-out "$TLS_PUBKEYFILE" -pubout; then
257
if cp --backup=numbered --force "$TLS_PUBKEYFILE" "$TLS_PUBKEYFILE" \
279
259
rm --force "$TLS_PUBKEYFILE"
280
# None of the commands succeded; give up
261
cp --archive "$TLS_PRIVKEYTMP" "$TLS_PRIVKEYFILE"
262
shred --remove "$TLS_PRIVKEYTMP" 2>/dev/null || :
266
# First try certtool from GnuTLS
267
if ! certtool --password='' --load-privkey="$TLS_PRIVKEYFILE" \
268
--outfile="$TLS_PUBKEYFILE" --pubkey-info --no-text \
270
# Otherwise try OpenSSL
271
if ! openssl pkey -in "$TLS_PRIVKEYFILE" \
272
-out "$TLS_PUBKEYFILE" -pubout; then
273
rm --force "$TLS_PUBKEYFILE"
274
# None of the commands succeded; give up
301
296
# Backup any old key files
302
297
if cp --backup=numbered --force "$SECKEYFILE" "$SECKEYFILE" \
303
298
2>/dev/null; then
304
shred --remove "$SECKEYFILE"
299
shred --remove "$SECKEYFILE" 2>/dev/null || :
306
301
if cp --backup=numbered --force "$PUBKEYFILE" "$PUBKEYFILE" \
307
302
2>/dev/null; then
370
365
test -n "$FINGERPRINT"
372
KEY_ID="$(certtool --key-id --hash=sha256 \
367
if [ -r "$TLS_PUBKEYFILE" ]; then
368
KEY_ID="$(certtool --key-id --hash=sha256 \
373
369
--infile="$TLS_PUBKEYFILE" 2>/dev/null || :)"
375
if [ -z "$KEY_ID" ]; then
376
KEY_ID=$(openssl pkey -pubin -in /tmp/tls-pubkey.pem \
379
| sed --expression='s/^.*[^[:xdigit:]]//')
371
if [ -z "$KEY_ID" ]; then
372
KEY_ID=$(openssl pkey -pubin -in "$TLS_PUBKEYFILE" \
375
| sed --expression='s/^.*[^[:xdigit:]]//')
383
380
FILECOMMENT="Encrypted password for a Mandos client"
444
445
# Remove the password file, if any
445
446
if [ -n "$SECFILE" ]; then
446
shred --remove "$SECFILE"
447
shred --remove "$SECFILE" 2>/dev/null
448
449
# Remove the key rings
449
450
shred --remove "$RINGDIR"/sec* 2>/dev/null