491 Words

Fetchmail OpenSSL error, part 2

In the past, fetchmail only required the MD5 fingerprint of an SSL certificate for validation. Since Fedora 36, fetchmail requires the complete certificate chain and c_rehash links of the certificates.

You can set this up with the following steps.

Get the domain certificate

Save the domain certificate somewhere. In this example we create a folder inside the home folder and save it there.

(Replace sub.domain.tld:993 with your own server address, and sub_domain_tld.cert with a filename that works for you.)

mkdir -p ~/.fetchmail/ssl
openssl s_client -connect sub.domain.tld:993 </dev/null 2>/dev/null | openssl x509 > ~/.fetchmail/ssl/sub_domain_tld.cert

Add sslcertpath to your config

Fetchmail does not understand ~/ (home directory expansion), so you have to write out the full path to your home folder.

Add the following lines to your ~/.fetchmailrc file:

ssl
sslcertck
sslcertpath /home/USERNAME/.fetchmail/ssl

There are a few ways to create the rehash symbolic links.

Option 1: generate them with c_rehash

The easiest way is c_rehash, but it isn’t installed by default on Fedora 36. You can install it with:

# c_rehash comes with openssl-perl
sudo dnf install openssl-perl

Run c_rehash:

c_rehash ~/.fetchmail/ssl

Option 2: openssl rehash (built in, no extra package)

OpenSSL 1.1 and newer can do the same as c_rehash itself:

openssl rehash ~/.fetchmail/ssl

You can also create the links yourself by passing each file to OpenSSL:

# replace file.cert with the name of your certificate file
cd ~/.fetchmail/ssl
ln -s file.cert "$(openssl x509 -hash -noout -in file.cert)".0

Test fetchmail

Your ~/.fetchmailrc file should look something like this:

poll sub.domain.tld
protocol imap
port 993
user "username"
pass "pass"   # I do not recommend storing your password here
ssl
sslcertck
sslcertpath /home/USERNAME/.fetchmail/ssl
mda "/your/mda"

Now test fetchmail.

In my case I got this SSL error message, because a root certificate was needed:

fetchmail: Server certificate verification error: self-signed certificate in certificate chain
fetchmail: Missing trust anchor certificate: /C=US/O=Internet Security Research Group/CN=ISRG Root X1
fetchmail: This could mean that the root CA's signing certificate is not in the trusted CA certificate location, or that c_rehash needs to be run on the certificate directory. For details, please see the documentation of --sslcertpath and --sslcertfile in the manual page. See README.SSL for details.
fetchmail: OpenSSL reported: error:0A000086:SSL routines::certificate verify failed

This turned out to be a Let’s Encrypt issue. You can solve it by saving the root certificate in the new fetchmail SSL folder:

cd ~/.fetchmail/ssl
wget https://letsencrypt.org/certs/isrgrootx1.pem

Now create a rehash symbolic link for this file (option 1 or 2 above) and test again.

Easier: use the system’s certificate store

If your mail server uses a normal public certificate (like Let’s Encrypt), you don’t need your own certificate folder at all. Point fetchmail to the CA bundle that your distribution keeps up to date:

ssl
sslcertck
sslcertfile /etc/pki/tls/certs/ca-bundle.crt        # Fedora
# sslcertfile /etc/ssl/certs/ca-certificates.crt    # Debian/Ubuntu

Then you never have to download root certificates by hand again.