SMTP AUTH and STARTTLS

SMTP AUTH and STARTTLS | Problems with SMTP | “Users Good, Spammers Bad” — Solutions | SMTP AUTH | SMTP AUTH - Mechanisms | STARTTLS | STARTTLS - Bad News, Good News | Mail Headers Showing TLS | SMTP AUTH versus STARTTLS | Small Workgroup Implementation | Design Overview | Sendmail Protocol Support | OpenSSL Overview | TLS Certificates | Compiling Cyrus SASL | Cyrus SASL Configuration | SASL Database Setup (Optional) | pwcheck Daemon (Optional) | Sendmail 8.12 Compile Overview | Compile support for Cyrus SASL | Compile support for OpenSSL | Sendmail Config File Locations | Sendmail 8.12 Runtime Changes | Custom Mailer Compile Tips | Sendmail Configuration Overview | Configuration for STARTTLS | STARTTLS Configuration Tips | Configuration for SMTP AUTH | SMTP AUTH Tips | Client Setup Caveats | Real World Issues - draconian ISPs | Real World Issues - stunnel | References and Related Material

SMTP AUTH and STARTTLS

Standards-based protocols that add authentication and encryption to SMTP.

Problems with SMTP

Need to support roaming users without becoming open relay.

ESMTP allows extensions to solve such problems.

“Users Good, Spammers Bad” — Solutions

Various approaches, no best solution.

SMTP AUTH

$ telnet localhost 25

EHLO localhost

250-AUTH DIGEST-MD5 CRAM-MD5 PLAIN
AUTH cram-md5
334 SGVsbG8sIFdvcmxk…

SMTP AUTH - Mechanisms

STARTTLS

Also (disfavored) smtps protocol, equivalent of https— the Internet Engineering Steering Group (IESG) recommends protocol designers to use upwards negotiation over alternate ports.

STARTTLS - Bad News, Good News

Mail Headers Showing TLS

Received: from mail.example.edu (IDENT:smmsp@mail.example.edu [10.0.0.11])
by example.org (8.12.1/8.12.1) with ESMTP id fBA0M7gU038106
(using TLSv1/SSLv3 with cipher EDH-RSA-DES-CBC3-SHA (168 bits) verified FAIL)
for <user@example.org>; Sun, 9 Dec 2001 16:22:10 -0800 (PST)
Received: from grue.example.edu (sender@grue.example.edu [10.0.0.13])
(authenticated bits=0)
by mail.example.edu (8.12.1/8.12.1) with ESMTP id fBA0M3rD003797
(version=TLSv1/SSLv3 cipher=RC4-MD5 bits=128 verify=NOT)
for <user@example.org>; Sun, 9 Dec 2001 16:22:07 -0800
Sender: sender@example.edu
Message-ID: <3C14002A.FAB442A3@example.edu>
Date: Sun, 09 Dec 2001 16:22:02 -0800
From: Sender <sender@example.edu>
To: user@example.org
Subject: test

SMTP AUTH versus STARTTLS

Some degree of overlap between the two standards.

SMTP AUTH for users, STARTTLS for machines.

Determine your needs and requirements before implementation!

Small Workgroup Implementation

Design Overview

Sendmail Protocol Support

Use the following command to determine your sendmail version and compile features.

$ sendmail -d0 < /dev/null

OpenSSL Overview

TLS Certificates

# openssl genrsa 1024 > host.key
# chmod 400 host.key
# openssl req -new -key host.key > host.csr

Common Name (eg, YOUR name) []:mail.example.edu

host.key and host.cert (from Certificate Authority) used later.

Self-signed certificate or own Certificate Authority may be an alternative (but client support for custom certificates varies, and may be insecure).

Compiling Cyrus SASL

Sendmail uses cyrus sasl 1.5 at time of writing.

Cyrus SASL Configuration

Setup the /usr/lib/sasl/Sendmail.conf for Sendmail.

Example Sendmail.conf from production Linux system:

$ cat /usr/lib/sasl/Sendmail.conf
pwcheck_method: shadow

SASL Database Setup (Optional)

pwcheck Daemon (Optional)

Sendmail 8.12 Compile Overview

$ sendmail -d0.12 < /dev/null
Version 8.12.3
Compiled with: DNSMAP LOG MAP_REGEX MATCHGECOS MILTER MIME7TO8 MIME8TO7
NAMED_BIND NETINET NETUNIX NEWDB PIPELINING SASL SCANF STARTTLS
USERDB XDEBUG

Compile support for Cyrus SASL

Add the following to your site.config.m4.

APPENDDEF(`confENVDEF', `-DSASL')
APPENDDEF(`confLIBS', `-lsasl -lcrypt')

dnl allows AUTH_OPTIONS to prevent LOGIN/PLAIN over non-TLS link
APPENDDEF(`confENVDEF', `-D_FFR_SASL_OPTS')
define(`confAUTH_OPTIONS', `p')

May need Cyrus SASL defines (-lcrypt) above OpenSSL’s (-lcrypto) to prevent function name conflicts.

Compile support for OpenSSL

Add the following to your site.config.m4.

APPENDDEF(`confENVDEF', `-DSTARTTLS')
APPENDDEF(`confLIBS', `-lssl -lcrypto')

APPENDDEF(`confLIBDIRS', `-L/usr/local/ssl/lib')
APPENDDEF(`confINCDIRS', `-I/usr/local/ssl/include')

Sendmail Config File Locations

Files under cf/ are used to help build sendmail.cf.

Sendmail 8.12 Runtime Changes

Different due to non-suid operation; see sendmail/SECURITY for details.

Custom Mailer Compile Tips

Sendmail Configuration Overview

Configuration for STARTTLS

Place following in sendmail.mc, rebuild sendmail.cf.

define(`CERT_DIR', `/etc/mail/certs')
define(`confCACERT', `CERT_DIR/cacert.pem')
define(`confCACERT_PATH', `CERT_DIR/CA')

define(`confSERVER_CERT', `CERT_DIR/host.cert')
define(`confSERVER_KEY', `CERT_DIR/host.key')
define(`confCLIENT_CERT', `CERT_DIR/host.cert')
define(`confCLIENT_KEY', `CERT_DIR/host.key')

STARTTLS Configuration Tips

Disable client certificates if not using them:

  1. Place following into /etc/mail/access map.
  2. Srv_Features: V

  3. Rebuild access map using makemap(8).
  4. # makemap hash access < access

Additionally, can disable TLS for client connections made by the server in access map:

Try_TLS:example.net NO

Configuration for SMTP AUTH

Place following in sendmail.mc, rebuild sendmail.cf.

define(`confAUTH_MECHANISMS', `DIGEST-MD5 CRAM-MD5 PLAIN LOGIN')
TRUST_AUTH_MECH(`DIGEST-MD5 CRAM-MD5 PLAIN LOGIN')

Could also build custom rulesets for more control.

SMTP AUTH Tips

Custom sendmail.mc ruleset to only allow EXPN/VRFY to work for authenticated users:

LOCAL_CONFIG
F{trusty}/etc/mail/trusted-domains

LOCAL_RULESETS
Scheck_expn
R$* $@ $>check_expn_and_vrfy $1

Scheck_vrfy
R$* $@ $>check_expn_and_vrfy $1

Scheck_expn_and_vrfy
R$* $: < $&{client_name} >
R< $={trusty} > $@ OK
R< $+ $={trusty} > $@ OK
R$* $: $&{auth_type}
R$={TrustAuthMech} $@ OK
R$* $#error $@ 5.7.1 $: 550 EXPN/VRFY failed for $&{client_name}

Client Setup Caveats

Straightforward for common GUI clients, but test first.

Real World Issues - draconian ISPs

Some ISPs are now blocking outbound SMTP connections to inhibit spread of Microsoft Malware (Sircam, Nimda).

Real World Issues - stunnel

stunnel(1) could be used to support clients with poor TLS support.

Stunnel can create an open relay if used on the server side.

References and Related Material