From e1027f3967e8c1594a7e5ba40e92c011c60418e3 Mon Sep 17 00:00:00 2001 From: Stefan Knoblich Date: Thu, 17 Jan 2008 14:37:45 +0000 Subject: [PATCH] More gentls_cert improvements: check for usable CA and improve confirmation prompt in create command git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@7266 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- scripts/gentls_cert.in | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/scripts/gentls_cert.in b/scripts/gentls_cert.in index 1e85f5487c..0136b5859c 100644 --- a/scripts/gentls_cert.in +++ b/scripts/gentls_cert.in @@ -12,15 +12,25 @@ OUTFILE="agent.pem" umask 037 -setup_ca() { - echo "Creating new CA..." +check_ca() { + for x in cacert.pem cakey.pem config.tpl; do + if [ ! -e "${CONFDIR}/CA/${x}" ]; then + return 1 + fi + done - if [ -e "${CONFDIR}/CA/cacert.pem" ] || [ -e "${CONFDIR}/CA/cakey.pem" ] - then - echo "existing CA found in \"${CONFDIR}/CA\"!" + return 0 +} + +setup_ca() { + if check_ca; then + echo "Existing CA found in \"${CONFDIR}/CA\"" + echo "(Use \"gentls_cert remove\" to delete)" exit 1 fi + echo "Creating new CA..." + if [ ! -d "${CONFDIR}/CA" ]; then mkdir -p -m 750 "${CONFDIR}/CA" || exit 1 fi @@ -68,6 +78,11 @@ setup_ca() { generate_cert() { local val="" + if ! check_ca; then + echo "No existing CA found, please create one with \"gentls_cert setup\" first" + exit 1 + fi + echo "Generating new certificate..." echo @@ -78,9 +93,9 @@ generate_cert() { echo echo "Certificate filename \"${OUTFILE}\"" echo - echo "[Enter \"OK\" to accept]" + echo "[Is this OK? (y/N)]" read val - if [ "${val}" != "OK" ]; then + if [ "${val}" != "y" ] && [ "${val}" != "Y" ]; then echo "Aborted" return 2 fi