Problem
- Retrieve/view mail: I keep all of my mail on a server at home and provide access via IMAP(S). I extended this by using dovecot as an IMAP proxy on the bastion host. This allows you to view your mail.
- Sending mail: Sendmail is the base MTA I’m using (it’s part of the base install of OpenBSD) and to get the secure authenticated connection for remotely sending mail, two different things are needed.
- TLS: For my purposes, this encrypts the connection via starttls(8)
- Authentication: This provides the ability to authenticate users and allow authenticated users to relay mail through the server. This is done via cyrus-sasl.
Dovecot/IMAP Configuration
- Install dovecot. Either build it from source via ports or install the package. See the OpenBSD FAQ for how to do this.
- In /etc/dovecot.conf, find the section specifying the password database as a passwd-file and uncomment it such that you end up with the following. See AuthDatabase/PasswdFile section of the dovecot wiki for more details.
# passwd-like file with specified location# passdb passwd-file {# [scheme=] [username_format=]# args = username_format=%n /etc/dovecot.passwd} - Create the passwd file, /etc/dovecot.passwd, in your favorite editor filling in the fields as described in the Passwd-file documentation. You should end up with something that looks like the following:
fred:{PLAIN-MD5}b40ac4fe40284c9de587b992c08f167::::::proxy=y host=my.proxy.domain.tld port=143The last fields, the extra fields, are the ones that make the proxy actually work. Note that the TLS/SSL options discussed in the dovecot documentation are only available in newer versions (1.2.rc4+) and not in the stable versions. That means I’m stuck with an un-encrypted connection between my bastion host/proxy and my real mail server. This isn’t the perfect solution, but I prefer using the proxy to just allowing a direct connection from anywhere on the internet to my internal servers. Create the md5 passphrase hash with the md5(1) command:
md5 -s password
- Configure dovecot to start at boot (if you didn’t when you installed it) and start up dovecot. In /etc/rc.local add:
if [ -x /usr/local/sbin/dovecot ]; then echo -n ' dovecot'; /usr/local/sbin/dovecotfi
Sendmail TLS Configuration
- Install cyrus-sasl. Either build it from source via ports or install the package. See theOpenBSD FAQ for how to do this.
- Configure the sasl auth daemon for authentication from sendmail:
echo pwcheck_method: saslauthd > /usr/local/lib/sasl2/Sendmail.conf
- Create users (these are the users and passwords for sending mail) with saslpasswd2(8) with the following command (you’ll be prompted for a password). This will create /etc/sasldb2.db. You will use username@domain as the username for authentication.
saslpasswd2 -c -u domain username
- Configure saslauthd to start at boot by adding the following to /etc/rc.local :
if [ -x /usr/local/sbin/saslauthd ]; then echo -n ' saslauthd'; /usr/local/sbin/saslauthd -a getpwentfi - Start saslauthd with /usr/local/sbin/saslauthd -a getpwent
- Rebuild sendmail with sasl support:
- Add WANT_SMTPAUTH=YES to /etc/mk.conf
- If you don’t have the OpenBSD source code installed, install it. See the OpenBSD FAQ for details on doing so if needed.
- cd to /usr/src/gnu/usr.sbin/sendmail/ and build and install sendmail with make clean obj depend && make && make install
- Configure sendmail for all of the new options. Edit /usr/share/sendmail/cf/openbsd-proto.mc as follows:
- Uncomment (remove the “dnl” from the beginning of the line) the section for TSL/SSL support.
dnldnl TLS/SSL support; uncomment and read starttls(8) to use.dnldefine(`CERT_DIR', `MAIL_SETTINGS_DIR`'certs')dnldefine(`confCACERT_PATH', `CERT_DIR')dnldefine(`confCACERT', `CERT_DIR/mycert.pem')dnldefine(`confSERVER_CERT', `CERT_DIR/mycert.pem')dnldefine(`confSERVER_KEY', `CERT_DIR/mykey.pem')dnldefine(`confCLIENT_CERT', `CERT_DIR/mycert.pem')dnldefine(`confCLIENT_KEY', `CERT_DIR/mykey.pem')dnl
- Add the following options for SMTP AUTH.
dnldnl Set SMTP AUTH optionsdnldefine(`confAUTH_MECHANISMS',`PLAIN LOGIN CRAM-MD5 DIGEST-MD5')dnlTRUST_AUTH_MECH(`PLAIN LOGIN CRAM-MD5 DIGEST-MD5')dnldefine(`confAUTH_OPTIONS',`p,y')dnldefine(`confPRIVACY_FLAGS',`authwarnings,goaway')dnl
- Uncomment (remove the “dnl” from the beginning of the line) the section for TSL/SSL support.
- Rebuild the cf files and install them by:
- cd /usr/share/sendmail/cf
- make distribution
- Configure sendmail to listen for connections over the network (default configuration is to listen only on localhost) by adding sendmail_flags="-L sm-mta -bd -q30m" to /etc/rc.conf.local
- Kill the running sendmail, source the new configuration options and restart sendmail:
kill `head -n1 /var/run/sendmail.pid`. /etc/rc.conf/usr/sbin/sendmail $sendmail_flags
That’s it! You should now have everything setup and working. In trouble shooting and testing my configuration, I found it very handy to watch traffic with tcpdump(8) with a command like tcpdump -n -s 1500 -vvvX port 25 .
Nice piece, but since many iphone owners are going to land here, maybe you should add a bit on installing certs and using compatible ciphers (RSA and not DSA for example).
Also I'm not sure a 'make install' is enough to rebuild sendmail (step 6).
Thanks for the comment on the "make install". I fixed that — was late when I started putting this all together and obviously missed that.As for the part about installing certs, can you provide some more details about what you'd like to see? I'm happy to put together something more that people would find useful.
Actually you documented that part in your 'getting mail on my iphone' post, it was a bit late too when I checked it last night. Shame I didn't find your docs before I worked on something similar last week, would have spared me quite some time
Does this work for a smarthost forwarder config on 465 or 587? On my 4.6 box, it looks like sendmail is still trying to talk on 25 – maillog shows "no route to host"
Actually it now works. It was a case of:- needing to use the ISP SMTP- needing to masquerade as the ISP email user (which I never use)- changing the SASL and authinfo dbs over to the ISP settings- some changes in /etc/hostsother helpful pages:http://efflandt.freeshell.org/sbc-smtp-auth.htmlhttp://qiaoyang.blogspot.com/2008/09/at-yahoo-email-address-verification-and.html
Pingback: Dovecot IMAPS Proxy with OpenBSD 4.8 | theory14