Self signed IMAP certificate creation

#! /bin/sh
#
# mkimapdcert,v 1.1 2001/01/02 03:54:25 drobbins Exp
#
# Copyright 2000 Double Precision, Inc.  See COPYING for
# distribution information.
#
# This is a short script to quickly generate a self-signed X.509 key for
# IMAP over SSL.  Normally this script would get called by an automatic
# package installation routine.

# AXXELZ VERSION
# 2019NOV19

test -x /usr/bin/openssl || exit 0

myid="m4"
prefix="/usr"
pemfile="/etc/courier-imap/$myid.pem"
cerfile="/etc/courier-imap/$myid.cer"
randfile="/etc/courier-imap/$myid.rand"
days=3650

if test -f $pemfile
then
	echo "$pemfile already exists."
	exit 1
fi

cp /dev/null $pemfile
chmod 600 $pemfile
chown root $pemfile

cleanup() {
	rm -f $pemfile
	rm -f $randfile
	exit 1
}

dd if=/dev/urandom of=$randfile count=1 2>/dev/null
/usr/bin/openssl req -new -x509 -days $days -nodes -config /etc/courier-imap/imapd.cnf -out $pemfile -keyout $pemfile || cleanup
/usr/bin/openssl gendh -rand $randfile 512 >> $pemfile || cleanup
/usr/bin/openssl x509 -subject -dates -fingerprint -noout -in $pemfile || cleanup
rm -f $randfile

# FOR YOUR GROUP POLICIES
/usr/bin/openssl x509 -inform PEM -in $pemfile -outform DER -out $cerfile

# END

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.