summaryrefslogtreecommitdiffstats
path: root/openssl/mksslcert.sh
diff options
context:
space:
mode:
authorLukc <lukc@upyum.com>2010-12-11 19:15:23 +0100
committerLukc <lukc@upyum.com>2010-12-11 19:15:35 +0100
commit6d908a38e05b9d4135c65d23114a5874215b5bb8 (patch)
treeb5e6da6d95b9a1235d82032b509b80483a886ff5 /openssl/mksslcert.sh
downloadbase-6d908a38e05b9d4135c65d23114a5874215b5bb8.tar.gz
base-6d908a38e05b9d4135c65d23114a5874215b5bb8.tar.bz2
base-6d908a38e05b9d4135c65d23114a5874215b5bb8.tar.xz
base-6d908a38e05b9d4135c65d23114a5874215b5bb8.zip
Engagement initial.
Diffstat (limited to 'openssl/mksslcert.sh')
-rwxr-xr-xopenssl/mksslcert.sh47
1 files changed, 47 insertions, 0 deletions
diff --git a/openssl/mksslcert.sh b/openssl/mksslcert.sh
new file mode 100755
index 0000000..9cca3fb
--- /dev/null
+++ b/openssl/mksslcert.sh
@@ -0,0 +1,47 @@
+#!/bin/sh
+#
+# mksslcert
+#
+# creates self-signed openssl certificates based on
+# the local hostname or the given one
+# Fallback to localhost if not set.
+#
+# Jürgen Daubert, jue at jue dot li
+
+
+print_help() {
+ echo "usage: ${0##*/} <key> <cert> [hostname]"
+ echo " key full path to openssl private key"
+ echo " cert full path to openssl certificate"
+ echo " hostname host name of certificate"
+}
+
+main() {
+ if [ ! "$1" -o ! "$2" ]; then
+ print_help
+ exit 1
+ fi
+
+ KEY=$1
+ CRT=$2
+ FQDN=$(hostname -f) || FQDN=localhost
+ if [ ! -z "$3" ]; then
+ FQDN="$3"
+ fi
+ INFO=".\n.\n.\n.\n.\n$FQDN\nroot@$FQDN"
+ OPTS="req -new -nodes -x509 -days 365 -newkey rsa:1024"
+
+ echo -e $INFO | openssl $OPTS -out $CRT -keyout $KEY 2> /dev/null
+
+ if [ $? -ne 0 ]; then
+ echo "Error: creating of certificate failed"
+ exit 1
+ else
+ echo "SSL certificate $CRT with key $KEY for host $FQDN created"
+ chmod 0600 $CRT $KEY
+ fi
+}
+
+main "$@"
+
+# End of file