]> ruderich.org/simon Gitweb - tlsproxy/tlsproxy.git/commitdiff
src/tlsproxy-add,src/tlsproxy-setup: Cleanup.
authorSimon Ruderich <simon@ruderich.org>
Fri, 12 Apr 2013 14:47:42 +0000 (16:47 +0200)
committerSimon Ruderich <simon@ruderich.org>
Fri, 12 Apr 2013 14:47:42 +0000 (16:47 +0200)
src/tlsproxy-add
src/tlsproxy-setup

index be8cb8a002b392d1795c2d39f1da5037601d6e6e..b57697aa322ae07f7f2262a0cd5942b554b71713 100755 (executable)
@@ -20,7 +20,9 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 
-if [ "x$1" = x ]; then
+set -e
+
+if test "$#" -eq 0; then
     echo "Usage: $0 <hostname> [<server-certificate>]"
     echo
     echo "Add the server certificate <server-certificate> (as .pem file) for "
@@ -38,12 +40,8 @@ if [ "x$1" = x ]; then
     exit 1
 fi
 
-tempfile=`mktemp` || exit 1
-
-die() {
-    rm -f "$tempfile"
-    exit 1
-}
+tempfile=`mktemp`
+trap 'rm -f "$tempfile"' EXIT
 
 # Generate server certificate for given host.
 echo 'organization = tlsproxy' > "$tempfile"
@@ -56,11 +54,11 @@ certtool --generate-certificate \
          --load-ca-certificate proxy-ca.pem \
          --load-ca-privkey proxy-ca-key.pem \
          --template "$tempfile" \
-         --outfile "certificate-$1-proxy.pem" || die
+         --outfile "certificate-$1-proxy.pem"
 rm "$tempfile"
 
-if [ "x$2" = x ]; then
-    echo please enter server certificate
+if test "x$2" = x; then
+    echo 'Please enter server certificate (Ctrl-D to terminate input).'
     cat > "certificate-$1-server.pem"
 else
     cp "$2" "certificate-$1-server.pem"
index 1c653267a40486c9fe174a225d947d8d591bc449..a17b390e1f924407784a295916669f9180c10d2d 100755 (executable)
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 
-tempfile=`mktemp` || exit 1
+set -e
 
-die() {
-    rm -f "$tempfile"
-    exit 1
-}
+tempfile=`mktemp`
+trap 'rm -f "$tempfile"' EXIT
 
 # Generate proxy CA key file.
-certtool --generate-privkey > proxy-ca-key.pem || die
+certtool --generate-privkey \
+         --outfile proxy-ca-key.pem
 # Generate proxy CA.
 echo 'cn = tlsproxy CA' > "$tempfile"
 echo ca                >> "$tempfile"
@@ -36,10 +35,11 @@ echo cert_signing_key  >> "$tempfile"
 certtool --generate-self-signed \
          --load-privkey proxy-ca-key.pem \
          --template "$tempfile" \
-         --outfile proxy-ca.pem || die
+         --outfile proxy-ca.pem
 
 # Generate proxy key file.
-certtool --generate-privkey > proxy-key.pem || die
+certtool --generate-privkey \
+         --outfile proxy-key.pem
 
 # Generate proxy "invalid" server certificate. It's used for problematic
 # connections.
@@ -51,7 +51,7 @@ echo signing_key              >> "$tempfile"
 certtool --generate-self-signed \
          --load-privkey proxy-key.pem \
          --template "$tempfile" \
-         --outfile proxy-invalid.pem || die
+         --outfile proxy-invalid.pem
 
 rm "$tempfile"