From 0fdd390c1170e820078ed80fec7b2760a0cb0fcd Mon Sep 17 00:00:00 2001 From: Eric F Crist Date: Tue, 14 Apr 2020 19:36:14 -0500 Subject: [PATCH] Check for dh.pem before overwriting gen-dh would overwrite dh.pem without warning In batch mode, easyrsa now exits 1 if dh.pem exists. In interactive move, the user is prompted if dh.pem exists. Fixes #373 Signed-off-by: Eric F Crist --- easyrsa3/easyrsa | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/easyrsa3/easyrsa b/easyrsa3/easyrsa index 2e1250f..0022de8 100755 --- a/easyrsa3/easyrsa +++ b/easyrsa3/easyrsa @@ -711,6 +711,18 @@ gen_dh() { verify_pki_init out_file="$EASYRSA_PKI/dh.pem" + + # check to see if we already have a dh parameters file + if [ -e "$EASYRSA_PKI/dh.pem" ]; then + if [ "$EASYRSA_BATCH" = "1" ]; then + # if batch is enabled, die + die "file $EASYRSA_PKI/dh.pem already exists!" + else + # warn the user, give them a chance to force overwrite + confirm "Overwrite? " "yes" "*** File $EASYRSA_PKI/dh.pem already exists! ***" + fi + fi + "$EASYRSA_OPENSSL" dhparam -out "$out_file" "$EASYRSA_KEY_SIZE" || \ die "Failed to build DH params" notice "\