CRUX-ARM : Home

Home :: Documentation :: Download :: Development :: Community :: Ports :: Packages :: Bugs :: Links :: About :: Donors
prt-get: updated .footprint. Thanks frinnst
[ports/core-arm64.git] / openssl / mksslcert.sh
CommitLineData
f477cb55
VM
1#!/bin/sh
2#
3# mksslcert
4#
5# creates self-signed openssl certificates based on
6# the local hostname or the given one
7# Fallback to localhost if not set.
8#
9# Juergen Daubert, jue at crux dot nu
10
11
12print_help() {
13 echo "usage: ${0##*/} <key> <cert> [hostname]"
14 echo " key full path to openssl private key"
15 echo " cert full path to openssl certificate"
16 echo " hostname host name of certificate"
17}
18
19main() {
20 if [ ! "$1" -o ! "$2" ]; then
21 print_help
22 exit 1
23 fi
24
25 KEY=$1
26 CRT=$2
27 FQDN=$(hostname -f) || FQDN=localhost
28 if [ ! -z "$3" ]; then
29 FQDN="$3"
30 fi
31 INFO=".\n.\n.\n.\n.\n$FQDN\nroot@$FQDN"
32 OPTS="req -new -nodes -x509 -days 365 -newkey rsa:2048"
33
34 printf "$INFO\n" | openssl $OPTS -out $CRT -keyout $KEY 2> /dev/null
35
36 if [ $? -ne 0 ]; then
37 echo "Error: creating of certificate failed"
38 exit 1
39 else
40 echo "SSL certificate $CRT with key $KEY for host $FQDN created"
41 chmod 0600 $CRT $KEY
42 fi
43}
44
45main "$@"
46
47# End of file