This commit is contained in:
Bob Mottram 2015-06-19 19:40:50 +01:00
parent 86bf6c7666
commit 23eb5fac45
1 changed files with 17 additions and 12 deletions

View File

@ -33,7 +33,6 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
USERNAME= USERNAME=
CLIENT_CERT_PASSWORD=
COUNTRY_CODE="US" COUNTRY_CODE="US"
AREA="Free Speech Zone" AREA="Free Speech Zone"
LOCATION="Freedomville" LOCATION="Freedomville"
@ -49,7 +48,6 @@ function show_help {
echo '' echo ''
echo ' --help Show help' echo ' --help Show help'
echo ' -u --username [name] Username' echo ' -u --username [name] Username'
echo ' -p --password [text] Client certificate install password'
echo '' echo ''
exit 0 exit 0
} }
@ -66,10 +64,6 @@ case $key in
shift shift
USERNAME="$1" USERNAME="$1"
;; ;;
-p|--password)
shift
CLIENT_CERT_PASSWORD="$1"
;;
*) *)
# unknown option # unknown option
;; ;;
@ -113,7 +107,10 @@ if [ ! -f /etc/ssl/private/$USERNAME.key ]; then
fi fi
# create a certificate request # create a certificate request
openssl req -new -sha256 -subj "/O=$ORGANISATION/OU=$UNIT/C=$COUNTRY_CODE/ST=$AREA/L=$LOCATION/CN=$USERNAME" -key /etc/ssl/private/$USERNAME.key -out /etc/ssl/requests/$USERNAME.csr openssl req -new -sha256 -subj \
"/O=$ORGANISATION/OU=$UNIT/C=$COUNTRY_CODE/ST=$AREA/L=$LOCATION/CN=$USERNAME" \
-key /etc/ssl/private/$USERNAME.key \
-out /etc/ssl/requests/$USERNAME.csr
if [ ! -f /etc/ssl/requests/$USERNAME.csr ]; then if [ ! -f /etc/ssl/requests/$USERNAME.csr ]; then
echo 'Certificate request was not created' echo 'Certificate request was not created'
@ -123,7 +120,9 @@ fi
# sign the certificate request # sign the certificate request
cd /etc/ssl cd /etc/ssl
openssl ca -config /etc/ssl/dovecot-ca.cnf -in /etc/ssl/requests/$USERNAME.csr -out /etc/ssl/certs/$USERNAME.cer openssl ca -config /etc/ssl/dovecot-ca.cnf \
-in /etc/ssl/requests/$USERNAME.csr \
-out /etc/ssl/certs/$USERNAME.cer
if [ ! -f /etc/ssl/certs/$USERNAME.cer ]; then if [ ! -f /etc/ssl/certs/$USERNAME.cer ]; then
echo 'Authentication certificate was not created' echo 'Authentication certificate was not created'
@ -137,12 +136,18 @@ mv /etc/ssl/certs/$USERNAME.cer /home/$USERNAME/emailcert
cp /etc/ssl/certs/dovecot-ca.crt /home/$USERNAME/emailcert cp /etc/ssl/certs/dovecot-ca.crt /home/$USERNAME/emailcert
mv /etc/ssl/private/$USERNAME.key /home/$USERNAME/emailcert mv /etc/ssl/private/$USERNAME.key /home/$USERNAME/emailcert
mv /etc/ssl/certs/$USERNAME.crt /home/$USERNAME/emailcert mv /etc/ssl/certs/$USERNAME.crt /home/$USERNAME/emailcert
openssl pkcs12 -export -in /home/$USERNAME/emailcert/$USERNAME.cer -out /home/$USERNAME/emailcert/$USERNAME.p12 -inkey /home/$USERNAME/emailcert/$USERNAME.key -certfile /home/$USERNAME/emailcert/dovecot-ca.crt -password "$CLIENT_CERT_PASSWORD" openssl pkcs12 -export -in /home/$USERNAME/emailcert/$USERNAME.cer \
-out /home/$USERNAME/emailcert/$USERNAME.p12 \
-inkey /home/$USERNAME/emailcert/$USERNAME.key \
-certfile /home/$USERNAME/emailcert/dovecot-ca.crt \
-outpass pass:
# make an install script # make an install script
echo '#!/bin/bash' > /home/$USERNAME/emailcert/install.sh echo '#!/bin/bash' > /home/$USERNAME/emailcert/install.sh
echo "sudo mv $USERNAME.crt /etc/ssl/certs" >> /home/$USERNAME/emailcert/install.sh echo "sudo mv $USERNAME.crt /etc/ssl/certs" >> \
echo "sudo mv $USERNAME.key /etc/ssl/private" >> /home/$USERNAME/emailcert/install.sh /home/$USERNAME/emailcert/install.sh
echo "sudo mv $USERNAME.key /etc/ssl/private" >> \
/home/$USERNAME/emailcert/install.sh
echo 'exit 0' >> /home/$USERNAME/emailcert/install.sh echo 'exit 0' >> /home/$USERNAME/emailcert/install.sh
# set permissions for the user # set permissions for the user
@ -154,7 +159,7 @@ shred -zu /etc/ssl/requests/$USERNAME.csr
echo 'Email authentication certificate created. You can obtain it on the client with:' echo 'Email authentication certificate created. You can obtain it on the client with:'
echo '' echo ''
echo " scp -P 2222 -r $USERNAME@mydomainname:/home/$USERNAME/emailcert ~/" echo " scp -P 2222 -r $USERNAME@$HOSTNAME:/home/$USERNAME/emailcert ~/"
echo '' echo ''
exit 0 exit 0