Courier IMAP SSL Server Certificate Installtion and Configuration

last updated in Categories FreeBSD, Howto, Linux, Networking, Postfix, RedHat/Fedora Linux, Security, Sys admin, UNIX

The Courier mail server is a mail transfer agent (MTA) server that provides ESMTP, IMAP, POP3, webmail, and mailing list services with individual components. But, it is best known for its IMAP / IMAPs and POP3 / POP3s (secure version) server component.

Advertisements

Courier can provides support for both regular UNIX operating system account (stored in /etc/passwd) and virtual mail account managed by third party backends such as OpenLDAP, MySQL and so on.

In this quick tutorial, you will learn about installing Courier IMAP SSL digital certificate.

Out setup is as follows:

  • SMTP Server: smtp.theos.in
  • Courier IMAP / POP3 Server: smtp.theos.in

Generating a CSR and private key for Courier IMAP SSL Server

Type the command to create a SSL CSR for a mail server called smtp.theos.in:
# mkdir -p /usr/local/ssl
# cd /usr/local/ssl
# openssl req -new -nodes -keyout smtp.theos.in.key -out smtp.theos.in.csr

Most important is Common Name, in our example it is set to smtp.theos.in. For the common name, you should enter the full Courier IMAP server address of your site.

Submit CSR to CA

Next logical step is copy and paste the contents of the CSR file into the SSL certificate providers (aka CA) account and get final certificate.

Install your SSL certificate

Unzip file and upload certificates to /usr/local/ssl directory. You also need to upload your CA’s intermediate certificate. Now, you should have 4 file as follows:

  1. /usr/local/ssl/intermediate.crt
  2. /usr/local/ssl/smtp.theos.in.crt
  3. /usr/local/ssl/smtp.theos.in.csr
  4. /usr/local/ssl/smtp.theos.in.key

Now create /usr/local/ssl/smtp.theos.in.pem a combined .pem certificate file:
# cat /usr/local/ssl/smtp.theos.in.crt /usr/local/ssl/smtp.theos.in.key > /usr/local/ssl/smtp.theos.in.pem

Configure Courier IMAP SSL Certificate

Open your courier IMAP configuration file such as /usr/local/etc/courier-imap/imapd-ssl and make set directives as follows:
TLS_CERTFILE=/usr/local/ssl/smtp.theos.in.pem
TLS_TRUSTCERTS=/usr/local/ssl/intermediate.crt

Save and close the file. Make sure that the file permissions are set correct and only root can read all files located in /usr/local/ssl directory. Restart Courier IMAP server:
# /usr/local/etc/rc.d/courier-imap-imapd-ssl restart

Test your installation

Use openssl utility to test configuration:
$ openssl s_client -connect smtp.theos.in:993
You should not see any error or warning message regarding SSL certificate.

ADVERTISEMENTS

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.

6 comment

  1. You may want to add a -CApath parameter to the check command, otherwise openssl will complain about “self signed certificate in certificate chain”.
    It took me several hours and lots of downloads of RapidSSL/Geotrust intermediate and CA certs to figure this one out.

    Example:

    openssl s_client -connect -CApath /etc/ssl/certs smtp.theos.in:993

  2. Hey Bob – You just saved me hours thanks mate for -CApath patch. Taa saves me from the RapidSSL / Geotrust Cheers mate

  3. After the following steps, you also need to move the generated .pem file to the /etc/courier folder and rename it as imapd.pem and pop3d.pem

    Have a question? Post it on our forum!