#!/bin/sh # # /usr/local/sbin/localmksslcerts # Copyright 2001-2002 Jonas Smedegaard # # $Id: localmksslcerts,v 1.7 2002-10-17 17:23:36 jonas Exp $ # # Generate certificates for mail (and other) servers # Based on uw-imapd-ssl post-install script # prg=$(basename $0) copyright="(C) 2001-2002 Jonas Smedegaard " usage() { echo "$prg, $copyright Usage: $prg [--fqdn ] [--issuer ] --daemon [...] [--force] or: $prg [] [...] [-f] Options: --fqdn Fully Qualified Domain Name for this host. --daemon Daemon(s) in need for a certificate (separate certificate is generated for each daemon) --issuer Email address of the person responsible for the certificate -f, --force Force overwriting existing certificate -h, --help This help text If issuer is not given, \"postmaster@\" is used." exit 1 } # Set some defaults CWD=`pwd` PATH=$PATH:/usr/bin/ssl COUNTRY='.' STATE='.' LOCALITY='.' DAYS2EXPIRE=365 fqdn='' daemons='' issuer='' force='' args='' while [ $# -gt 0 ]; do doubleshift='' case $1 in --fqdn) fqdn="$2"; doubleshift=1;; --daemon) daemons="$daemons$2 "; doubleshift=1;; --issuer) issuer="$2"; doubleshift=1;; --force|-f) force=1;; -*) usage;; *) args="$args$1 ";; esac if [ -n "$doubleshift" ];then if [ $# -gt 1 ]; then shift else echo "Missing parameter for option \"$1\"!" usage fi fi shift done set -- $args if [ -z "$issuer" ]; then DOMAINNAME=`hostname -d` ISSUER="postmaster@$DOMAINNAME" fi if [ -z "$fqdn" ]; then if [ $# -gt 0 ]; then fqdn=$1 shift else echo "Too few parameters!" usage fi fi cd /etc/ssl/certs for daemon in $daemons $@; do if [ -f $daemon.pem ]; then if [ -n $force ]; then rm -f `openssl x509 -noout -hash < $daemon.pem`.0 rm -f $daemon.pem else echo "You already have /etc/ssl/certs/$daemon.pem - exiting...!" exit 1 fi fi echo -n "Generating $daemon certificate..." openssl req -new -x509 -nodes -out $daemon.pem -keyout $daemon.pem -days $DAYS2EXPIRE > /dev/null 2>&1 <<+ $COUNTRY $STATE $LOCALITY $fqdn $fqdn $fqdn $issuer + ln -sf $daemon.pem `openssl x509 -noout -hash < $daemon.pem`.0 echo "Done!" chown root.root /etc/ssl/certs/$daemon.pem chmod 0640 /etc/ssl/certs/$daemon.pem done cd $CWD