123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- #!/bin/sh
- if [ $# -ne 1 ]
- then
- echo -e "\nUse with a single name paramater for output files will be generated into current folder.\nAnd don't forget to edit [ req_dn ] section in script.\n"
- echo -e "Example:\n\n./mkcert.sh foo\n\n"
- exit 1
- fi
- OPENSSL=openssl
- DIR=`pwd`
- CONFIG=$1-ssl.config
- CERTDIR=$SSLDIR
- KEYDIR=$SSLDIR
- CERTFILE=$DIR/$1.cert
- KEYFILE=$DIR/$1.key
- REQFILE=$DIR/$1.req
- KEYBITS=1024
- DAYS=3650
- if [ ! -f $CONFIG ]; then
- cat > $CONFIG << EOF
- [ req ]
- default_bits = 1024
- encrypt_key = yes
- distinguished_name = req_dn
- x509_extensions = cert_type
- prompt = no
- [ req_dn ]
- C=XY
- ST=SomeState
- L=SomeCity
- O=SomeCompany
- OU=PisiLinux
- CN=mail.example.com
- [ cert_type ]
- nsCertType = server
- EOF
- fi
- if [ -f $CERTFILE ]; then
- echo "$CERTFILE already exists, won't overwrite"
- exit 1
- fi
- if [ -f $KEYFILE ]; then
- echo "$KEYFILE already exists, won't overwrite"
- exit 1
- fi
- $OPENSSL genrsa -out $KEYFILE $KEYBITS
- chmod 0600 $KEYFILE
- $OPENSSL req -new -key $KEYFILE -out $REQFILE -config $CONFIG
- $OPENSSL x509 -req -days $DAYS -in $REQFILE -signkey $KEYFILE -out $CERTFILE
- $OPENSSL x509 -subject -fingerprint -noout -in $CERTFILE || exit 2
|