home *** CD-ROM | disk | FTP | other *** search
/ PC World 1999 August / PCWorld_1999-08_cd.bin / doc / HOWTO / mini / Secure-POP+SSH < prev    next >
Text File  |  1998-10-24  |  12KB  |  397 lines

  1.   Secure POP via SSH mini-HOWTO
  2.   Manish Singh, <yosh@gimp.org>
  3.   v1.0, 30 September 1998
  4.  
  5.   This document explains how to set up secure POP connections using ssh.
  6.   ______________________________________________________________________
  7.  
  8.   Table of Contents
  9.  
  10.  
  11.   1. Introduction
  12.  
  13.   2. The Basic Technique
  14.  
  15.      2.1 Setting up Port Forwarding
  16.      2.2 Testing it out
  17.  
  18.   3. Using it With Your Mail Software
  19.  
  20.      3.1 Setting up fetchmail
  21.      3.2 Automating it all
  22.      3.3 Not using fetchmail
  23.  
  24.   4. Miscellany
  25.  
  26.      4.1 Disclaimer
  27.      4.2 Copyright
  28.      4.3 Acknowledgements
  29.  
  30.  
  31.   ______________________________________________________________________
  32.  
  33.   1.  Introduction
  34.  
  35.  
  36.   Normal POP mail sessions, by their very nature, are insecure. The
  37.   password goes across the network in cleartext for everyone to see.
  38.   Now, this may be perfectly acceptable in a trusted or firewalled
  39.   environment. But on a public network, such as a university or your
  40.   run-of-the-mill ISP, anyone armed with a simple network sniffer can
  41.   grab your password right off the wire. This is compounded by the fact
  42.   that many people set their computers to check for mail at regular
  43.   intervals, so the password is sent out quite frequently, which makes
  44.   it easy to sniff.
  45.  
  46.   With this password, an attacker can now access your email account,
  47.   which may have sensitive or private information. It is also quite
  48.   common that this password is the same as the user's shell account, so
  49.   there is the possibility for more damage.
  50.  
  51.   By doing all POP traffic using an encrypted channel, nothing goes in
  52.   cleartext over the network. We can use ssh's diverse methods of
  53.   authentication, instead of a simple plaintext password. That is the
  54.   real point of using this method: not because we get encrypted content
  55.   (which is futile at this point, since it's probably gone unencrypted
  56.   over several networks already before reaching your mailbox; securing
  57.   those communications is the job of GNU Privacy Guard or PGP, not ssh),
  58.   but the secure authentication.
  59.  
  60.   There are other methods of achieving secure authentication already,
  61.   such as APOP, KPOP, and IMAP. However, using ssh has the advantage
  62.   that it works with normal POP configurations, without requiring
  63.   special client (not all mail clients support advanced protocols) or
  64.   server support (except for sshd running on the server). You mail
  65.   provider may be unable or unwilling to use a more secure protocol.
  66.   Besides, by using ssh you can compress the traffic too, which is a
  67.   nice little extra for people with slow connections.
  68.  
  69.  
  70.   2.  The Basic Technique
  71.  
  72.  
  73.   This technique relies on a fundamental feature of ssh: port forwarding
  74.  
  75.   There are many variations on this theme, which depend on your desired
  76.   mail setup. They all require ssh, which is available from
  77.   http://www.ssh.fi/ and mirrors.  RPMs are available at
  78.   ftp://ftp.replay.com/pub/crypto/ and Debian packages are available at
  79.   ftp://non-us.debian.org/debian-non-US/ (and their respective mirrors).
  80.  
  81.  
  82.   2.1.  Setting up Port Forwarding
  83.  
  84.  
  85.   To start port forwarding, run the following command:
  86.  
  87.  
  88.  
  89.        ssh -C -f popserver -L 11110:popserver:110 sleep 5
  90.  
  91.  
  92.  
  93.  
  94.   Let's take a closer look at that command:
  95.  
  96.  
  97.  
  98.      ssh
  99.         The ssh binary itself, the magic program that does it all.
  100.  
  101.  
  102.      -C This enables compression of the datastream. It's optional, but
  103.         usually useful, especially for dialup users.
  104.  
  105.  
  106.      -f Once ssh has done authentication and established port
  107.         forwarding, fork to background so other programs can be run.
  108.         Since we're just using the port forwarding features of ssh, we
  109.         don't need a tty attached to it.
  110.  
  111.  
  112.      popserver
  113.         The POP server we're connecting to.
  114.  
  115.  
  116.      -L 11110:popserver:110
  117.         Forward local port 11110 to port 110 on the remote server
  118.         popserver. We use a high local port (11110) so any user can
  119.         create forwardings.
  120.  
  121.  
  122.      sleep 5
  123.         After ssh has forked itself into the background, it runs a
  124.         command. We use sleep so that the connection is maintained for
  125.         enough time for our mail client to setup a connection to the
  126.         server. 5 seconds is usually sufficient time for this to happen.
  127.  
  128.  
  129.   You can use most other options to ssh when appropriate. A common
  130.   setting may be a username, since it might be different on the POP
  131.   server.
  132.  
  133.   This requires sshd running on the remote server popserver. However,
  134.   you do not need to have an active shell account there. The time it
  135.   takes to print a message ``You cannot telnet here'' is enough to setup
  136.   a connection.
  137.  
  138.  
  139.   2.2.  Testing it out
  140.  
  141.  
  142.   Once you've figured out the details command to run to establish port
  143.   forwarding, you can try it. For example:
  144.  
  145.  
  146.  
  147.        $ ssh -C -f msingh@popserver -L 11110:popserver:110 sleep 1000
  148.  
  149.  
  150.  
  151.  
  152.   popserver is the ol' POP server. My username on my local machine is
  153.   manish so I need to explicitly specify the username msingh. (If your
  154.   local and remote usernames are the same the msingh@ part is
  155.   unnecessary.
  156.  
  157.   Then it prints:
  158.  
  159.  
  160.  
  161.        msingh@popserver's password:
  162.  
  163.  
  164.  
  165.  
  166.   And I type in my POP password (you may have different shell and POP
  167.   passwords though, so use your shell one). Now we're done! So we can
  168.   try:
  169.  
  170.  
  171.  
  172.        $ telnet localhost 11110
  173.  
  174.  
  175.  
  176.  
  177.   which should print something like:
  178.  
  179.  
  180.  
  181.        QUALCOMM POP v3.33 ready.
  182.  
  183.  
  184.  
  185.  
  186.   Woohoo! It works! The data is sent out over the network encrypted, so
  187.   the only cleartext is over the loopback interfaces of my local box and
  188.   the POP server.
  189.  
  190.  
  191.   3.  Using it With Your Mail Software
  192.  
  193.  
  194.   This section describes setting up your POP client software to use the
  195.   ssh forwarded connection. It's primary focus is fetchmail (ESR's
  196.   excellent mail-retrieval and forwarding utility), since that is the
  197.   most flexible software I have found for dealing with POP. fetchmail
  198.   can be found at http://www.tuxedo.org/~esr/fetchmail/.  It will do you
  199.   a great service to read the excellent documentation that comes with
  200.   fetchmail.
  201.  
  202.  
  203.   3.1.  Setting up fetchmail
  204.  
  205.  
  206.   The following is my .fetchmailrc
  207.  
  208.  
  209.  
  210.        ______________________________________________________________________
  211.        defaults
  212.                user msingh is manish
  213.                no rewrite
  214.  
  215.        poll localhost with protocol pop3 and port 11110:
  216.                preconnect "ssh -C -f msingh@popserver -L 11110:popserver:110 sleep 5"
  217.                password foobar;
  218.        ______________________________________________________________________
  219.  
  220.  
  221.  
  222.  
  223.   Pretty simple, huh? fetchmail has a wealth of commands, but the key
  224.   ones are the preconnect line and the poll option.
  225.  
  226.   We're not connecting directly to the POP server, but instead localhost
  227.   and port 11110. The preconnect does the forwarding each time fetchmail
  228.   is run, leaving open the connection for 5 seconds, so fetchmail can
  229.   make it's own connect. The rest fetchmail does itself.
  230.  
  231.   So each time you run fetchmail, you're prompted for your ssh password
  232.   for authentication. If you run fetchmail in the background (like I
  233.   do), it's inconvenient to have to do that. Which brings us to the next
  234.   section.
  235.  
  236.  
  237.   3.2.  Automating it all
  238.  
  239.  
  240.   ssh can authenticate using many methods. One of these is an RSA
  241.   public/private key pair. You can generate an authentication key for
  242.   your account using ssh-keygen. An authetication key can have a
  243.   passphrase associated with it, or the passphase can be blank. Whether
  244.   you want a passphrase depends on how secure you think the account you
  245.   are using locally is.
  246.  
  247.   If you think your machine is secure, go ahead and have a blank
  248.   passpharase.  Then the above .fetchmailrc works just by running
  249.   fetchmail. You can then run fetchmail in daemon mode when you dial up
  250.   and mail is fetched automatically. You're done.
  251.  
  252.   However, if you think you need a passphrase, things get more complex.
  253.   ssh can run under control of an agent, which can register keys and
  254.   authenticate whatever ssh connections are made under it. So I have
  255.   this script getmail.sh:
  256.  
  257.  
  258.  
  259.        ______________________________________________________________________
  260.        #!/bin/sh
  261.        ssh-add
  262.        while true; do fetchmail --syslog --invisible; sleep 5m; done
  263.        ______________________________________________________________________
  264.  
  265.   When I dialup, I run:
  266.  
  267.  
  268.  
  269.        $ ssh-agent getmail.sh
  270.  
  271.  
  272.  
  273.  
  274.   This prompts me for my passphrase once, then checks mail every 5
  275.   minutes. When the dialup connection is closed, I terminate ssh-agent.
  276.   (This is automated in my ip-up and ip-down scripts)
  277.  
  278.  
  279.   3.3.  Not using fetchmail
  280.  
  281.  
  282.   What if I can't/don't want to use fetchmail? Pine, Netscape, and some
  283.   other clients have their own POP mechanisms. First, consider using
  284.   fetchmail! It's far more flexible, and mail clients shouldn't be doing
  285.   that kind of stuff anyway. Both Pine and Netscape can be configured to
  286.   use local mail systems.
  287.  
  288.   But if you must, unless your client has a preconnect feature like
  289.   fetchmail, you're going to have to keep the ssh port forward active
  290.   for the entire time you're connected. Which means using sleep
  291.   100000000 to keep the connection alive. This might not go over well
  292.   with your network admins.
  293.  
  294.   Secondly, some clients (like Netscape) have the port number hardcoded
  295.   to 110.  So you need to be root to do port forwarding from privledged
  296.   ports. This is also annoying. But it should work.
  297.  
  298.  
  299.   4.  Miscellany
  300.  
  301.   4.1.  Disclaimer
  302.  
  303.  
  304.   There is no guarantee that this document lives up to its intended
  305.   purpose. This is simply provided as a free resource. As such, the
  306.   author of the information provided within cannot make any guarentee
  307.   that the information is even accurate. Use at your own risk.
  308.  
  309.   Cryptographic software such as ssh may be subject to certain
  310.   restrictions, depending on where you live. In some countries, you must
  311.   have a license to use such software. If you are unsure of your local
  312.   laws, please consult someone who is familiar with your situation for
  313.   more information.
  314.  
  315.   The use of the information provided in this document is most likely
  316.   not anticipated by your mail service provider. The author does not
  317.   encourage the abuse and misuse of network services, and provides this
  318.   document for informational purposes only. If you are in doubt about
  319.   whether the use of these techniques falls within the service agreement
  320.   of your mail provider, please clear that up beforehand.
  321.  
  322.  
  323.   4.2.  Copyright
  324.  
  325.  
  326.   This document is copyright ⌐ 1998 Manish Singh <yosh@gimp.org>
  327.  
  328.   Permission is granted to make and distribute verbatim copies of this
  329.   manual provided the copyright notice and this permission notice are
  330.   preserved on all copies.
  331.   Permission is granted to copy and distribute modified versions of this
  332.   document under the conditions for verbatim copying, provided that this
  333.   copyright notice is included exactly as in the original, and that the
  334.   entire resulting derived work is distributed under the terms of a
  335.   permission notice identical to this one.
  336.  
  337.   Permission is granted to copy and distribute translations of this
  338.   document into another language, under the above conditions for
  339.   modified versions.
  340.  
  341.   Commercial redistribution is allowed and encouraged; however, the
  342.   author would like to be notified of any such distributions.
  343.  
  344.   All trademarks used in this document are acknowledged as being owned
  345.   by their respective owners.
  346.  
  347.  
  348.   4.3.  Acknowledgements
  349.  
  350.  
  351.   Special thanks goes to Seth David Schoen
  352.   <schoen@uclink4.berkeley.edu>, who enlightened me in the ways of ssh
  353.   port forwarding.
  354.  
  355.  
  356.  
  357.  
  358.  
  359.  
  360.  
  361.  
  362.  
  363.  
  364.  
  365.  
  366.  
  367.  
  368.  
  369.  
  370.  
  371.  
  372.  
  373.  
  374.  
  375.  
  376.  
  377.  
  378.  
  379.  
  380.  
  381.  
  382.  
  383.  
  384.  
  385.  
  386.  
  387.  
  388.  
  389.  
  390.  
  391.  
  392.  
  393.  
  394.  
  395.  
  396.  
  397.