<?xml version="1.0" encoding="utf-8" ?>
<?xml-stylesheet href="/templates/default/atom.css" type="text/css" ?>

<feed 
   xmlns="http://www.w3.org/2005/Atom"
   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
   xmlns:dc="http://purl.org/dc/elements/1.1/"
   xmlns:admin="http://webns.net/mvcb/"
   xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
   xmlns:wfw="http://wellformedweb.org/CommentAPI/">
    
    <link href="http://freebsd.munk.me.uk/feeds/atom.xml" rel="self" title="freebsd.munk.me.uk" type="application/atom+xml" />
    <link href="http://freebsd.munk.me.uk/"                        rel="alternate"    title="freebsd.munk.me.uk" type="text/html" />
    <link href="http://freebsd.munk.me.uk/rss.php?version=2.0"     rel="alternate"    title="freebsd.munk.me.uk" type="application/rss+xml" />
    <title type="html">freebsd.munk.me.uk</title>
    <subtitle type="html">FreeBSD System Administration</subtitle>
    <icon>http://freebsd.munk.me.uk/templates/default/img/s9y_banner_small.png</icon>
    <id>http://freebsd.munk.me.uk/</id>
    <updated>2011-11-11T19:59:28Z</updated>
    <generator uri="http://www.s9y.org/" version="1.6">Serendipity 1.6 - http://www.s9y.org/</generator>
    <dc:language>en</dc:language>

    <entry>
        <link href="http://freebsd.munk.me.uk/archives/227-Exim-TLS-Configuration-On-FreeBSD.html" rel="alternate" title="Exim TLS Configuration On FreeBSD" />
        <author>
            <name>munk</name>
                    </author>
    
        <published>2011-11-11T19:32:42Z</published>
        <updated>2011-11-11T19:59:28Z</updated>
        <wfw:comment>http://freebsd.munk.me.uk/wfwcomment.php?cid=227</wfw:comment>
    
        <slash:comments>0</slash:comments>
        <wfw:commentRss>http://freebsd.munk.me.uk/rss.php?version=atom1.0&amp;type=comments&amp;cid=227</wfw:commentRss>
    
            <category scheme="http://freebsd.munk.me.uk/categories/7-Email" label="Email" term="Email" />
            <category scheme="http://freebsd.munk.me.uk/categories/14-Security" label="Security" term="Security" />
    
        <id>http://freebsd.munk.me.uk/archives/227-guid.html</id>
        <title type="html">Exim TLS Configuration On FreeBSD</title>
        <content type="xhtml" xml:base="http://freebsd.munk.me.uk/">
            <div xmlns="http://www.w3.org/1999/xhtml">
                Configured Exim to work with Transport Layer Security (TLS) a few days ago.  Really I should have done this at the time I <a href="http://freebsd.munk.me.uk/archives/212-Installing-Exim,-SASLAuthd,-ClamAV-and-SpamAssassin-on-FreeBSD-6.2.html">set up Exim, SASLauthd, ClamAV and SpamAssassin</a> but hey ho.  Instead I've endured years of bots trying to brute force passwords via SMTP (for which I ended up using various means to block them by detecting hits in the logfiles, another entry completely!).<br />
<br />
Anyway yes finally got around to it so this is how I did it (this should work out of the box on a fresh installation of Exim on FreeBSD):<br />
<br />
<strong>Create A Self Certified SSL Certificate</strong><br />
First of all I created a self signed ssl certificate using this command:<br />
<div class="bb-code-title">CODE:</div><div class="bb-code">openssl&#160;req&#160;-x509&#160;-newkey&#160;rsa&#58;1024&#160;-keyout&#160;/etc/mail/exim.crt&#160;-out&#160;/etc/mail/exim.crt&#160;-days&#160;9999&#160;-nodes</div><br />
After issuing that command you're prompted for a few details like company details, organizational role, etc etc, no big deal.  Really if you're running a 'proper' email server (ie one used by a lot of people) then you need to get your certificate signed properly by a Certificate Authority (CA) - using a self certified certificate you will be prompted when you go to login to the server with a warning about how the certificate is not valid - but since there's only me using the server nowadays it doesn't really matter and I can just add an exception into my email client to allow the certificate even though it's not valid.<br />
<br />
<strong>Modify Exim Configuration</strong><br />
Next go on to modify the exim config so it uses TLS.  With each of the following items of config you probably want to check to see if they're already in teh default config but commented out, I know most of it is in there:<br />
<br />
<div class="bb-code-title">CODE:</div><div class="bb-code">tls_advertise_hosts&#160;=&#160;&#42;<br />
tls_certificate&#160;=&#160;/etc/mail/exim.crt<br />
tls_privatekey&#160;=&#160;/etc/mail/exim.crt<br />
auth_advertise_hosts&#160;=&#160;${if&#160;eq{$tls_cipher}{}{}{&#42;}}</div><br />
<br />
I think the last setting 'auth_advertise_hosts' is probably not in by default - that option basically says 'only advertise authentication if a connection is using TLS'.  I must admit I don't fully understand the mechanics of it all but as I understand it, it's this that is key to cutting down on brute force attacks, because brute force attackers generally just blindly use the basic AUTH commands via SMTP and don't ever bother trying to use TLS.<br />
<br />
With that added to the configuration file it's just left to restart the exim server and you should be good to go.<br />
<br />
<strong>Notes</strong><br />
When you login via telnet now to test it out you should see that AUTH isn't available unless you've already started a TLS session (which you have to do with the STARTTLS command).  You won't be able to test the authentication out after issuing STARTTLS via telnet because the conversation has to be encrypted after that point.  I think I read somewhere you can use openssl to test it out though I didn't try.<br />
<br />
Another thing to watch out for, briefly mentioned above, is that you must set up your email client to allow the invalid/self certified certificate that the server uses.  If you don't do that then you won't be able to send email using authentication via the server.  The first time you try and send an email using auth via the server from your email client, it should pop up a dialog box that allows you to allow the cert even though it's invalid. 
            </div>
        </content>
        
    </entry>

</feed>
