2014-06-21 22:15:53 +00:00
|
|
|
#!/bin/bash
|
|
|
|
#
|
|
|
|
# SSL Certificate
|
|
|
|
#
|
|
|
|
# Create a self-signed SSL certificate if one has not yet been created.
|
|
|
|
#
|
2014-06-30 13:15:36 +00:00
|
|
|
# The certificate is for PRIMARY_HOSTNAME specifically and is used for:
|
2014-06-21 22:15:53 +00:00
|
|
|
#
|
|
|
|
# * IMAP
|
|
|
|
# * SMTP submission (port 587) and opportunistic TLS (when on the receiving end)
|
|
|
|
# * the DNSSEC DANE TLSA record for SMTP
|
2014-06-30 13:15:36 +00:00
|
|
|
# * HTTPS (for PRIMARY_HOSTNAME only)
|
2014-06-21 22:15:53 +00:00
|
|
|
#
|
2014-06-30 13:15:36 +00:00
|
|
|
# When other domains besides PRIMARY_HOSTNAME are served over HTTPS,
|
2014-06-21 22:15:53 +00:00
|
|
|
# we generate a domain-specific self-signed certificate in the management
|
|
|
|
# daemon (web_update.py) as needed.
|
|
|
|
|
|
|
|
source setup/functions.sh # load our functions
|
|
|
|
source /etc/mailinabox.conf # load global vars
|
|
|
|
|
|
|
|
apt_install openssl
|
|
|
|
|
|
|
|
mkdir -p $STORAGE_ROOT/ssl
|
|
|
|
if [ ! -f $STORAGE_ROOT/ssl/ssl_certificate.pem ]; then
|
|
|
|
# Generate a new private key if one doesn't already exist.
|
|
|
|
# Set the umask so the key file is not world-readable.
|
|
|
|
(umask 077; openssl genrsa -out $STORAGE_ROOT/ssl/ssl_private_key.pem 2048)
|
|
|
|
fi
|
|
|
|
if [ ! -f $STORAGE_ROOT/ssl/ssl_cert_sign_req.csr ]; then
|
|
|
|
# Generate a certificate signing request if one doesn't already exist.
|
|
|
|
openssl req -new -key $STORAGE_ROOT/ssl/ssl_private_key.pem -out $STORAGE_ROOT/ssl/ssl_cert_sign_req.csr \
|
2014-06-30 13:15:36 +00:00
|
|
|
-subj "/C=$CSR_COUNTRY/ST=/L=/O=/CN=$PRIMARY_HOSTNAME"
|
2014-06-21 22:15:53 +00:00
|
|
|
fi
|
|
|
|
if [ ! -f $STORAGE_ROOT/ssl/ssl_certificate.pem ]; then
|
|
|
|
# Generate a SSL certificate by self-signing if a SSL certificate doesn't yet exist.
|
|
|
|
openssl x509 -req -days 365 \
|
|
|
|
-in $STORAGE_ROOT/ssl/ssl_cert_sign_req.csr -signkey $STORAGE_ROOT/ssl/ssl_private_key.pem -out $STORAGE_ROOT/ssl/ssl_certificate.pem
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo
|
|
|
|
echo "Your SSL certificate's fingerpint is:"
|
2014-07-16 13:33:40 +00:00
|
|
|
openssl x509 -in $STORAGE_ROOT/ssl/ssl_certificate.pem -noout -fingerprint
|
2014-06-21 22:15:53 +00:00
|
|
|
echo
|