1 From: "Paul Makepeace" <Paul.Makepeace@realprogrammers.com>
2 Date: Sat, 16 Oct 1999 02:03:04 -0500
4 Quickstart: do everything following the # signs as root
6 This is an FYI to demonstrate how to have exim work with SSL using the
7 stunnel wrapper and its underlying OpenSSL libraries and toolkit. It's
8 intended as a recipe; there are plenty of explanations about the underlying
9 technology (start at http://mike.daewoo.com.pl/computer/stunnel/ ) but little
10 up-to-date cookbook info (that I could find) and the manpages left me
13 My goal was not to compile anything. This unfortunately required me moving to
14 Debian 2.2, the unstable branch that contained these new packages. This note
15 is thus Debian-oriented but not -specific.
17 Stunnel requires a X.509 certificate to operate and comes with one by default
18 in the Debian stunnel package. For my purposes though it was useless since
19 Outlook Express (and I'm sure many others) check the Common Name matched the
20 hostname it's connecting too.
22 The certificate generation can be done in this four step process in lieu of
23 obtaining a signed one from Thawte or Verisign (not sure why one would do
24 that in this instance):
28 ## mkdir -p /etc/ssl/certs
30 # cat > README < this-email; # :-)
32 # openssl genrsa 1024 > exim.rsa
34 Generate Diffie-Hellman parameters:
36 # openssl gendh -rand /dev/urandom > exim.dh
38 Generate certificate using the RSA key without a passphrase (explained in
41 # openssl req -new -x509 -nodes -key exim.rsa -out exim.x509
43 The important point here is to enter the hostname into the Common Name field
44 as it's entered into the mail client. Without this the mail client may
45 question you for every connection about this mismatch. The data to this and
46 other questions can be set up in /usr/local/openssl/openssl.cnf . The fields
47 can be given defaults by adding _default to the attribute name (examples
50 At this point create the stunnel-ready file by stringing those three
53 # cat exim.rsa exim.pem exim.x509 exim.dh > exim.pem
55 Run exim in daemon mode under stunnel on the ssmtp port (and imapd to
58 (suitably hack /etc/init.d/* as follows:)
60 # cp exim.pem imapd.pem
61 # chmod 600 exim.pem imapd.pem
63 # stunnel -d 465 -l /usr/sbin/exim -p exim.pem -- exim -bs
64 # stunnel -d 993 -l /usr/sbin/imapd -p imapd.pem -- imapd
66 The name given after the -- on the command line is the name the service is
67 run as so using say exim-ssl would, since stunnel can use libwrap (of TCP
68 Wrappers fame), allow a separately configured access policy in
69 /etc/hosts.(allow|deny)
71 To run exim in inetd mode (not recommended apparently because of the
72 connection cost) requires a adding 127.0.0.1 to the host_accept_relay
73 directive in /etc/exim.conf since stunnel invokes it through the loopback
74 interface. I suspect this actually would defeat the point of this directive
75 in practice if spammers ever figured out how to connect to an SSL MTA thus
78 The magic line in /etc/inetd.conf is (as a single line):
80 ssmtp stream tcp nowait mail /usr/sbin/stunnel exim -l /usr/sbin/exim -p
81 /etc/ssl/certs/exim.pem -- exim -bs
83 ...with in /etc/services:
85 ssmtp 465/tcp # SMTP over SSL
88 Corrections & improvements appreciated!