Faztek's unnofficial Blog

My first blog is dedicated to Internet hosting software.

domingo, novembro 18, 2007

Configure your email client for Gmail

Configuring your incoming email client for Gmail: fetchmail

Gmail uses a nice POP3S email (POP-3 over SSL) you can use.

1. Enable POP in your Gmail account.

2. Find out where X.509/“privacy-enhanced-mail (PEM)” certificates live on your system, e.g., in the /usr/share/ssl/certs/ directory. The “locate .pem” command may help you figure this out, or you can just create a new world-readable directory exclusively for this.

3. The Gmail POP3-over-SSL (pop3s) server presents a server certificate at every secure-socket-layer (SSL) connection establishment; we will want to be able to verify its authenticity.

(A new server certificate was rolled out by Gmail on 2005-12-13 when the old one expired on that same day with a few minutes of POP service unavailability.)

That server certificate is itself signed by a certificate authority (CA), Equifax Secure (now GeoTrust), using a self-signed root certificate having the “Equifax Secure Certificate Authority” organizational unit name (OU) and no common name (CN). You need to download, install in its own file, and index this root certificate.

sh# cd /usr/share/ssl/certs
sh# wget -O Equifax_Secure_Certificate_Authority.pem \
         https://www.geotrust.com/resources/root_certificates/certificates/Equifax_Secure_Certificate_Authority.cer
sh# chmod 644 Equifax_Secure_Certificate_Authority.pem
sh# openssl x509 -in Equifax_Secure_Certificate_Authority.pem \
                 -fingerprint -subject -issuer -serial -hash -noout
MD5 Fingerprint=67:CB:9D:C0:13:24:8A:82:9B:B2:17:1E:D1:1B:EC:D4
subject= /C=US/O=Equifax/OU=Equifax Secure Certificate Authority
issuer= /C=US/O=Equifax/OU=Equifax Secure Certificate Authority
serial=35DEF4CF
594f1775
sh# c_rehash .
sh# file 594f1775.*
594f1775.0: symbolic link to `Equifax_Secure_Certificate_Authority.pem'

The c_rehash command is a Perl script that comes with the OpenSSL toolkit; it creates symbolic links to certificate files (with a “.pem” extension) using symlink names based on a hash of each certificate's whole subject name. Fetchmail uses the OpenSSL libraries and will only try to open the installed file by looking it up under the 594f1775.0 (or 594f1775.1 and so on) file name in the end.

The server certificate itself does not need to be stored anywhere.

4. The fetchmail client does not need to present a client certificate. Instead, client authentication is performed using the USER and PASS post-office-protocol version 3 (POP3) commands within the SSL connection, once it has been properly established.

5. Edit the appropriate .fetchmailrc file, depending on how you run fetchmail (i.e., as root or as a lesser-privileged local user). The contents of this file are documented by the fetchmail(1) man page, which can be consulted using the “man fetchmail” command. You will need an entry such as this one:

poll pop.gmail.com with proto POP3
    user 'eric.schmidt@gmail.com' there with password 'xxxxxxxx' is eric here
        options keep ssl sslfingerprint '59:51:61:89:CD:DD:B2:35:94:BB:44:97:A0:39:D5:B4'
            sslcertck sslcertpath /usr/share/ssl/certs

Add any other option according to your preferences. If other family members also have a Gmail account and this is root's .fetchmailrc file, you can add similar three-line user subsections under this same poll section; the last two lines will redundantly be identical for every Gmail account.

The specified password is that of the Gmail account, not the local user's password. Since this configuration file contain passwords, it must be non-world-readable:

sh# chmod 600 $HOME/.fetchmailrc

The MD5 fingerprint is that of the “pop.gmail.com” server certificate delivered by the Gmail POP3-over-SSL server, not that of the “Equifax Secure Certificate Authority” root certificate.

Note that this will not be enough to perform certificate-revocation-list (CRL) verifications, which fetchmail/OpenSSL does not support; however, this shortcoming is somewhat mitigated by the MD5 fingerprint verification, at the price of a loss in unattended flexibility (should Gmail wish to change its server certificate for some unlikely reason).

There is no need to inform fetchmail that the POP3-over-SSL (pop3s) TCP port is 995; it's smart enough to figure it out on its own.

Note that POP3-over-SSL is not the same as regular (non-SSL) POP3 with use of the STLS command and capability (i.e., RFC 2595's POP3 STARTTLS extension), which Gmail does not support.

6. You should be able to test this with

sh# fetchmail -d0 -v pop.gmail.com

once you complete the email-forwarding/email-delivery part of fetchmail's configuration and integration (which is beyond the email-retrieval scope of this help document).

7. The Gmail POP3-over-SSL server specifies that it does not want to be polled more than once every five minutes (i.e., 300 seconds), as can be verified by executing the following command:

sh$ openssl s_client -connect pop.gmail.com:995 -CApath /usr/share/ssl/certs -quiet
depth=1 /C=US/O=Equifax/OU=Equifax Secure Certificate Authority
verify return:1
depth=0 /C=US/ST=California/L=Mountain View/O=Google Inc./CN=pop.gmail.com
verify return:1
+OK Gpop x99xx9999xxx ready.
CAPA
+OK Capability list follows
USER
RESP-CODES
EXPIRE 0
LOGIN-DELAY 300
X-GOOGLE-VERHOEVEN
.
USER eric.schmidt@gmail.com
+OK send PASS
PASS xxxxxxxx
+OK Welcome.
CAPA
+OK Capability list follows
USER
RESP-CODES
PIPELINING
EXPIRE 0
LOGIN-DELAY 300
TOP
UIDL
X-GOOGLE-VERHOEVEN
.
QUIT
+OK Farewell.
read:errno=0

(Authenticating is not strictly necessary for this test. It was done to show how Gmail's POP3 server presents a different list of capabilities before and after login.)

Make sure to respect this delay if automatic polling is configured. This can be achieved by specifying “set daemon 300” in the .fetchmailrc file, or by specifying “-d 300” on the fetchmail command line, where 300 can be replaced by a greater number if desired.

* Did you click ‘Save Changes’ after enabling POP in Gmail? To ensure that Gmail can communicate with your mail client, be sure to click ‘Save Changes’ on the Gmail ‘Mail Settings’ page.




Using Outlook

On a windowzed POP3 client (like Outlook), do not select "Secure Password Authentication", unless you know what you are doing. On the "incoming mail (POP3)", select: "this server requires a secure connection (SSL)"; port selected should be 995 (means POP-3 over SSL).

sábado, novembro 17, 2007

HOW TO install a pop3s server

There are two basic options on Debian: courier-pop-ssl and dovecot; the first is older, I prefer the latter program.
% apt-get install dovecot-common dovecot-pop3d
% vi /etc/dovecot/dovecot.conf
Edit configuration and choose:
protocols = pop3 pop3s
Default configuration avoids plain text passwords; to allow it (usually on POP3, i.e. on port 110), insert
disable_plaintext_auth = no
instead of default commented line:
#disable_plaintext_auth = yes
Debian Sarge package does not come with logging; use, for instance:
log_path = /var/log/dovecot.log
info_log_path = /var/log/dovecot-info.log
On a windowzed POP3 client (like Outlook), do not select "Secure Password Authentication", unless you know what you are doing. On the "incoming mail (POP3)", select: "this server requires a secure connection (SSL)"; port selected should be 995 (means POP-3 over SSL).

Dozens HOW TOs, most of them for Debian distros:

quarta-feira, novembro 14, 2007

A Freesco box running an intranet MTA for outbound email

With Exim4 you can use "local_interfaces" configuration to restrict the interfaces it listens port 25 (the SMTP connection port), or even change the listening port.
Restricting the interface to your local intranet is easy:
  • local_interfaces = <; 127.0.0.1.25 ; 10.0.0.20.25
In this case only the local loop interface (aka lo) and one of the networks (in my case the Freesco box has it's local intranet interface, eth1, at 10.0.0.20).
It is possible to combine this Exim (let's call it the intranet-MTA) with another instance of Exim running for inbound email (the most usual usage of Exim in Freesco boxes... let's call it internet-MTA), as follow:
  • local_interfaces = <; 85.2.3.4.25
85.2.3.4 is just an example to illustrate the fact you can only select an IP interface by it's IP address, not an ethernet device (like ppp0, or any other.)
Usually people running Freesco boxes use dynamic IP addresses, so this IP is not fixed at all.

It is possible to tackle this problem as follow.
There is a special argument that is passed to the /rc/rc_user when an IP changes: it's the 'newip' part of this script; I have chosen to restart Exim in this situation, to allow a new configuration (with updated IP) to be taken for the internet-MTA.
Starting Exim in a Freesco box: there is usually an associated starting script (/pkg/rc/rc_exim) that should be able to launch both intranet and internet-MTAs. For the internet-MTA there is a teak: the configuration is generated due to the nature of the dynamic IP.
Refer to the following excerpt:
MY_IP=`ifconfig ppp0 | grep inet.addr: | sed 's/.* addr:\([^ ]*\) .*/\1/'`
MY_A=/usr/exim/conf-autogen
echo "local_interfaces = <; ${MY_IP}.25" > $MY_A
cat /usr/exim/conf-init >> $MY_A
/bin/exim -C /usr/exim/intra.conf -bd -q30m -om
/bin/exim -bd -q30m -om
This will depend on how you have installed Exim. The version I actually use takes the configuration file at: /usr/exim/configure. The first Exim call chooses the fixed configuration (for the intranet-MTA), whilst the second call executes the usual internet-MTA.

The first is used for all my intranet outbound messages, the second for all inbound messages.
The port is always the standard (25, i.e. SMTP).

Naturally the inbound configuration is much more strict: should not allow any relay, contains some spam-blocking, etc. On the other hand, the outbound configuration is totally relaxed, allowing relay to any host (foreign MTAs, usually on the internet.) I assume thereby all intranet insiders behave well, do not send spam, etc.

The motivation for achieving this scheme: if I used a single Exim instance, and since I run greylist, all mails sent to the outside world would be stalled for around 1 hour (until the greylist expires), or eventually have an error on the MUA, something like: "your message could not be sent". It is also possible to costumize the inbound and outbound Exim instances, in a much easier way.