CentOS 6: Fetchmail-SSL-Zertifikate erneuern
Im Tutorial CentOS 6: Fetchmail mit SSL absichern habe ich beschrieben, wie Sie die Verbindung zwischen dem Fetchmail-Daemon und den Mailservern von Web.de, GMX.net, GoogleMail.com und T-Online.de mit SSL absichern können. Da die Zertifikate auf den Mailservern nur begrenzt gültig sind, werden diese von den Betreibern regelmäßig ausgetauscht. Das bedeutet, dass der Fetchmail-Daemon keine E-Mails vom betroffenen Mailserver abholen kann, solange er nicht das neue Server-Zertifikat und den dazu passenden Fingerprint kennt.
Wenn Sie in der entsprechenden Logdatei des Fetchmail-Daemons die folgenden Meldungen vorfinden, wurde sehr wahrscheinlich das Server-Zertifikat ausgetauscht.
[root@centos6 ~]# tail -f /var/log/maillog
[...]
Sep 6 15:57:00 centos6 fetchmail[25042]: pop.gmx.net-Fingerabdrücke stimmen nicht überein!
Sep 6 15:57:00 centos6 fetchmail[25042]: SSL-Verbindung fehlgeschlagen.
[...]
[...]
Sep 6 15:57:00 centos6 fetchmail[25042]: pop.gmx.net-Fingerabdrücke stimmen nicht überein!
Sep 6 15:57:00 centos6 fetchmail[25042]: SSL-Verbindung fehlgeschlagen.
[...]
Das Server-Zertifikat und den Fingerprint können Sie mit den gleichen Befehlen wie im Tutorial CentOS 6: Fetchmail mit SSL absichern beschrieben aktualisieren. Zur Erleichterung dieser Arbeit habe ich das folgende Shell Skript geschrieben, welches alle Änderungen automatisch vornimmt.
###########################################################################
## ##
## Fetchmaild SSL Update Script ##
## ##
## Creation: 24.04.2010 ##
## Last Update: 22.02.2014 ##
## ##
## Copyright (c) 2010-2014 by Georg Kainzbauer <http://www.gtkdb.de> ##
## ##
## This program is free software; you can redistribute it and/or modify ##
## it under the terms of the GNU General Public License as published by ##
## the Free Software Foundation; either version 2 of the License, or ##
## (at your option) any later version. ##
## ##
###########################################################################
#!/bin/bash
# Directory with the mail server certificates
CERTSDIR=/etc/ssl/fetchmaild
# Path of fetchmailrc
FETCHMAILRC=/etc/fetchmailrc
# Lock file
LOCKFILE=/var/tmp/fetchmaild_ssl_update.lock
###################################################################
# NORMALLY THERE IS NO NEED TO CHANGE ANYTHING BELOW THIS COMMENT #
###################################################################
function log()
{
echo `date +%d.%m.%Y%t%H:%M:%S` " LOG:" $1
}
function error()
{
echo `date +%d.%m.%Y%t%H:%M:%S` " ERROR:" $1
}
# Check if POP3/IMAP server address was specified
if [ -z $1 ] ; then
error "Please specify POP3/IMAP server."
exit 1
else
SERVER=$1
fi
# Check if POP3/IMAP port was specified
if [ -z $2 ] ; then
error "Please specify POP3/IMAP port."
exit 1
else
SERVERPORT=$2
fi
# Check if local certificate exists
if [ ! -f ${CERTSDIR}/${SERVER}.pem ] ; then
error "No local certificate for ${SERVER} found."
exit 1
fi
if [ -f ${LOCKFILE} ] ; then
kill -0 $(cat ${LOCKFILE}) >/dev/null 2>&1
if [ $? -eq 0 ] ; then
error "Previous process still running."
exit 1
else
log "Deprecated lock file found. Remove lock file."
rm -f ${LOCKFILE}
fi
fi
echo $$ >${LOCKFILE}
# Generate fingerprint of local old certificate
OLDFINGERPRINT=$(openssl x509 -in ${CERTSDIR}/${SERVER}.pem -fingerprint -noout -md5 | cut -d= -f2)
# Download current certificate
echo "quit" | openssl s_client -connect ${SERVER}:${SERVERPORT} -showcerts 2>/dev/null | sed -ne '/BEGIN/,/END/p' > ${CERTSDIR}/${SERVER}.pem
# Generate fingerprint of local new certificate
NEWFINGERPRINT=$(openssl x509 -in ${CERTSDIR}/${SERVER}.pem -fingerprint -noout -md5 | cut -d= -f2)
# Print old and new fingerprint
log "Old fingerprint: ${OLDFINGERPRINT}"
log "New fingerprint: ${NEWFINGERPRINT}"
# Update fingerprint in fetchmailrc
sed -i "s/${OLDFINGERPRINT}/${NEWFINGERPRINT}/g" ${FETCHMAILRC}
rm -f ${LOCKFILE}
exit 0
## ##
## Fetchmaild SSL Update Script ##
## ##
## Creation: 24.04.2010 ##
## Last Update: 22.02.2014 ##
## ##
## Copyright (c) 2010-2014 by Georg Kainzbauer <http://www.gtkdb.de> ##
## ##
## This program is free software; you can redistribute it and/or modify ##
## it under the terms of the GNU General Public License as published by ##
## the Free Software Foundation; either version 2 of the License, or ##
## (at your option) any later version. ##
## ##
###########################################################################
#!/bin/bash
# Directory with the mail server certificates
CERTSDIR=/etc/ssl/fetchmaild
# Path of fetchmailrc
FETCHMAILRC=/etc/fetchmailrc
# Lock file
LOCKFILE=/var/tmp/fetchmaild_ssl_update.lock
###################################################################
# NORMALLY THERE IS NO NEED TO CHANGE ANYTHING BELOW THIS COMMENT #
###################################################################
function log()
{
echo `date +%d.%m.%Y%t%H:%M:%S` " LOG:" $1
}
function error()
{
echo `date +%d.%m.%Y%t%H:%M:%S` " ERROR:" $1
}
# Check if POP3/IMAP server address was specified
if [ -z $1 ] ; then
error "Please specify POP3/IMAP server."
exit 1
else
SERVER=$1
fi
# Check if POP3/IMAP port was specified
if [ -z $2 ] ; then
error "Please specify POP3/IMAP port."
exit 1
else
SERVERPORT=$2
fi
# Check if local certificate exists
if [ ! -f ${CERTSDIR}/${SERVER}.pem ] ; then
error "No local certificate for ${SERVER} found."
exit 1
fi
if [ -f ${LOCKFILE} ] ; then
kill -0 $(cat ${LOCKFILE}) >/dev/null 2>&1
if [ $? -eq 0 ] ; then
error "Previous process still running."
exit 1
else
log "Deprecated lock file found. Remove lock file."
rm -f ${LOCKFILE}
fi
fi
echo $$ >${LOCKFILE}
# Generate fingerprint of local old certificate
OLDFINGERPRINT=$(openssl x509 -in ${CERTSDIR}/${SERVER}.pem -fingerprint -noout -md5 | cut -d= -f2)
# Download current certificate
echo "quit" | openssl s_client -connect ${SERVER}:${SERVERPORT} -showcerts 2>/dev/null | sed -ne '/BEGIN/,/END/p' > ${CERTSDIR}/${SERVER}.pem
# Generate fingerprint of local new certificate
NEWFINGERPRINT=$(openssl x509 -in ${CERTSDIR}/${SERVER}.pem -fingerprint -noout -md5 | cut -d= -f2)
# Print old and new fingerprint
log "Old fingerprint: ${OLDFINGERPRINT}"
log "New fingerprint: ${NEWFINGERPRINT}"
# Update fingerprint in fetchmailrc
sed -i "s/${OLDFINGERPRINT}/${NEWFINGERPRINT}/g" ${FETCHMAILRC}
rm -f ${LOCKFILE}
exit 0
Bevor Sie das Skript ausführen, sollten Sie den Fetchmail-Daemon beenden.
[root@centos6 ~]# service fetchmaild stop
Übergeben Sie dem Skript beim Aufruf die Adresse des Mailservers (hier pop.gmx.net) und die Portnummer (hier 995 für POP3s).
[root@centos6 ~]# ./fetchmaild_ssl_update.sh pop.gmx.net 995
Nachdem das Server-Zertifikat und der Fingerprint aktualisiert wurde, können Sie den Fetchmail-Daemon wieder starten.
[root@centos6 ~]# service fetchmaild start
Indem Sie die Logdatei überprüfen, können Sie feststellen, ob das Problem nach der Aktualisierung des Server-Zertifikats und des Fingerprints behoben ist.
[root@centos6 ~]# tail -f /var/log/maillog
Weiterführende Tutorials
CentOS 6: Benachrichtigung wenn Fetchmail-Fingerabdrücke nicht stimmen
Dieser Eintrag wurde am 16.09.2011 erstellt und zuletzt am 24.01.2016 bearbeitet.
Direkter Link zu dieser Seite: http://www.gtkdb.de/index_33_1371.html
[ Zur Startseite ] [ Zur Kategorie ]
© 2004-2021 by Georg Kainzbauer