10.07.2015 Views

Pine, IMAP, and SSH (SSH, The Secure Shell: The Definitive Gu...

Pine, IMAP, and SSH (SSH, The Secure Shell: The Definitive Gu...

Pine, IMAP, and SSH (SSH, The Secure Shell: The Definitive Gu...

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>Pine</strong>, <strong>IMAP</strong>, <strong>and</strong> <strong>SSH</strong> (<strong>SSH</strong>, <strong>The</strong> <strong>Secure</strong> <strong>Shell</strong>: <strong>The</strong> <strong>Definitive</strong> <strong>Gu</strong>ide)of 8http://www.hn.edu.cn/book/NetWork/NetworkingBookshelf_2ndEd/ssh...8/3/2005 2:16 PM11.3. <strong>Pine</strong>, <strong>IMAP</strong>, <strong>and</strong> <strong>SSH</strong><strong>Pine</strong> is a popular, Unix-based email program from the University of Washington(http://www.washington.edu/pine/). In addition to h<strong>and</strong>ling mail stored <strong>and</strong> delivered in local files, <strong>Pine</strong> alsosupports <strong>IMAP</strong>[136] for accessing remote mailboxes <strong>and</strong> SMTP[137] for posting mail.[136]Internet Message Access Protocol, RFC-2060.[137]Simple Mail Transfer Protocol, RFC-821.In this case study, we integrate <strong>Pine</strong> <strong>and</strong> <strong>SSH</strong> to solve two common problems:<strong>IMAP</strong> authenticationIn many cases, <strong>IMAP</strong> permits a password to be sent in the clear over the network. We discuss how toprotect your password using <strong>SSH</strong>, but (surprisingly) not by port forwarding.Restricted mail relayingMany ISPs permit their mail <strong>and</strong> news servers to be accessed only by their customers. In somecircumstances, this restriction may prevent you from legitimately relaying mail through your ISP. Onceagain, <strong>SSH</strong> comes to the rescue.We also discuss wrapping ssh in a script to avoid <strong>Pine</strong> connection delays <strong>and</strong> facilitate access to multiplemailboxes. This discussion will delve into more detail than the previous one on <strong>Pine</strong>/<strong>SSH</strong> integration.[Section 4.5.4, "<strong>Pine</strong>"]11.3.1. Securing <strong>IMAP</strong> AuthenticationLike <strong>SSH</strong>, <strong>IMAP</strong> is a client/server protocol. Your email program (e.g., <strong>Pine</strong>) is the client, <strong>and</strong> an <strong>IMAP</strong>server process (e.g., imapd ) runs on a remote machine, the <strong>IMAP</strong> host, to control access to your remotemailbox. Also like <strong>SSH</strong>, <strong>IMAP</strong> generally requires you to authenticate before accessing your mailbox,typically by password. Unfortunately, in many cases this password is sent to the <strong>IMAP</strong> host in the clear overthe network; this represents a security risk (see Figure 11-8).[138][138]<strong>IMAP</strong> does support more secure methods of authentication, but they aren't widelydeployed.Figure 11-8. A normal <strong>IMAP</strong> connection


<strong>Pine</strong>, <strong>IMAP</strong>, <strong>and</strong> <strong>SSH</strong> (<strong>SSH</strong>, <strong>The</strong> <strong>Secure</strong> <strong>Shell</strong>: <strong>The</strong> <strong>Definitive</strong> <strong>Gu</strong>ide)of 8http://www.hn.edu.cn/book/NetWork/NetworkingBookshelf_2ndEd/ssh...8/3/2005 2:16 PMFigure 11-10. <strong>Pine</strong>/<strong>IMAP</strong> over <strong>SSH</strong>, preauthenticatedHere's a sample session that invokes an <strong>IMAP</strong> server, imapd, through inetd so it runs as root:server% telnet localhost imap* OK localhost <strong>IMAP</strong>4rev1 v12.261 server ready0 login res password'1 select inbox* 3 EXISTS* 0 RECENT* OK [UIDVALIDITY 964209649] UID validity status* OK [UIDNEXT 4] Predicted next UID* FLAGS (\Answered \Flagged \Deleted \Draft \Seen)* OK [PERMANENTFLAGS (\* \Answered \Flagged \Deleted \Draft \Seen)] Permanent flags1 OK [READ-WRITE] SELECT completed2 logout* BYE imap.example.com <strong>IMAP</strong>4rev1 server terminating connection2 OK LOGOUT completedAlternatively, in preauthenticated mode, the <strong>IMAP</strong> server assumes that authentication has already been doneby the program that started the server <strong>and</strong> that it already has the necessary rights to access the user's mailbox.If you invoke imapd on the comm<strong>and</strong> line under a nonroot uid, imapd assumes you have alreadyauthenticated <strong>and</strong> opens your email inbox. You can then type <strong>IMAP</strong> comm<strong>and</strong>s <strong>and</strong> access your mailboxwithout authentication:server% /usr/local/sbin/imapd* PREAUTH imap.example.com <strong>IMAP</strong>4rev1 v12.261 server ready0 select inbox* 3 EXISTS* 0 RECENT* OK [UIDVALIDITY 964209649] UID validity status* OK [UIDNEXT 4] Predicted next UID* FLAGS (\Answered \Flagged \Deleted \Draft \Seen)* OK [PERMANENTFLAGS (\* \Answered \Flagged \Deleted \Draft \Seen)] Permanent flags0 OK [READ-WRITE] SELECT completed1 logout* BYE imap.example.com <strong>IMAP</strong>4rev1 server terminating connection1 OK LOGOUT completedNotice the PREAUTH response at the beginning of the session, indicating pre-authenticated mode. It is followedby the comm<strong>and</strong> select inbox, which causes the <strong>IMAP</strong> server implicitly to open the inbox of the currentuser without dem<strong>and</strong>ing authentication.Now, how does all this relate to <strong>Pine</strong>? When instructed to access an <strong>IMAP</strong> mailbox, <strong>Pine</strong> first attempts to loginto the <strong>IMAP</strong> host using rsh <strong>and</strong> to run a preauthenticated instance of imapd directly. If this succeeds, <strong>Pine</strong>then converses with the <strong>IMAP</strong> server over the pipe to rsh <strong>and</strong> has automatic access to the user's remote inboxwithout further authentication. This is a good idea <strong>and</strong> very convenient; the only problem is that rsh is veryinsecure. However, you can make <strong>Pine</strong> use <strong>SSH</strong> instead.


<strong>Pine</strong>, <strong>IMAP</strong>, <strong>and</strong> <strong>SSH</strong> (<strong>SSH</strong>, <strong>The</strong> <strong>Secure</strong> <strong>Shell</strong>: <strong>The</strong> <strong>Definitive</strong> <strong>Gu</strong>ide)of 8http://www.hn.edu.cn/book/NetWork/NetworkingBookshelf_2ndEd/ssh...8/3/2005 2:16 PM11.3.1.2. Making <strong>Pine</strong> use <strong>SSH</strong> instead of rsh<strong>Pine</strong>'s rsh feature is controlled by three configuration variables in the ~/.pinerc file: rsh-path, rsh-comm<strong>and</strong>,<strong>and</strong> rsh-open-timeout. rsh-path stores the program name for opening a Unix remote shell connection.Normally it is the fully qualified path to the rsh executable (e.g., /usr/ucb/rsh). To make <strong>Pine</strong> use <strong>SSH</strong>,instruct it to use the ssh client rather than rsh, setting rsh-path to the location of the <strong>SSH</strong> client:rsh-path=/usr/local/bin/sshrsh-comm<strong>and</strong> represents the Unix comm<strong>and</strong> line for opening the remote shell connection: in this case, the<strong>IMAP</strong> connection to the <strong>IMAP</strong> host. <strong>The</strong> value is a printf-style format string with four "%s" conversionspecifications that are automatically filled in at runtime. From first to last, these four specifications st<strong>and</strong> for:1.2.3.4.<strong>The</strong> value of rsh-path<strong>The</strong> remote hostname<strong>The</strong> username for accessing your remote mailbox<strong>The</strong> connection method; in this case, "imap"For example, the default value of rsh-comm<strong>and</strong>is:"%s %s -l %s exec /etc/r%sd"which can instantiate to:/usr/ucb/rsh imap.example.com -l smith exec /etc/rimapdTo make this work properly with ssh, modify the default format string slightly, adding the -q option for quietmode:rsh-comm<strong>and</strong>="%s %s -q -l %s exec /etc/r%sd"This instantiates to:/usr/local/bin/ssh imap.example.com -w -l smith exec /etc/rimapd<strong>The</strong> -q option is necessary so that ssh doesn't emit diagnostic messages that may confuse <strong>Pine</strong>, such as:Warning: Kerberos authentication disabled in SUID client.fwd connect from localhost to local port sshdfwd-2001<strong>Pine</strong> otherwise tries to interpret these as part of the <strong>IMAP</strong> protocol. <strong>The</strong> default <strong>IMAP</strong> server location of/etc/r %sd becomes /etc/rimapd.<strong>The</strong> third variable, rsh-open-timeout, sets the number of seconds for <strong>Pine</strong> to open the remote shellconnection. Leave this setting at its default value, 15, but any integer greater than or equal to 5 is permissible.So finally, the <strong>Pine</strong> configuration is:rsh-path=/usr/local/bin/sshrsh-comm<strong>and</strong>="%s %s -q -l %s exec /etc/r%sd"rsh-open-timeout=


<strong>Pine</strong>, <strong>IMAP</strong>, <strong>and</strong> <strong>SSH</strong> (<strong>SSH</strong>, <strong>The</strong> <strong>Secure</strong> <strong>Shell</strong>: <strong>The</strong> <strong>Definitive</strong> <strong>Gu</strong>ide)of 8http://www.hn.edu.cn/book/NetWork/NetworkingBookshelf_2ndEd/ssh...8/3/2005 2:16 PMRemote Usernames in <strong>Pine</strong>By the way, it's not mentioned in the <strong>Pine</strong> manpage or configuration file comments, but if youneed to specify a different username for connecting to a remote mailbox, the syntax is:{hostname/user=jane}mailboxThis causes <strong>Pine</strong> to call the rsh-comm<strong>and</strong> with "jane" as the remote username (i.e., the third%s substitution).Generally, you want to use an <strong>SSH</strong> authentication method that doesn't require typing a password orpassphrase, such as trusted-host or public-key with an agent. <strong>SSH</strong> is run behind the scenes by <strong>Pine</strong> <strong>and</strong>doesn't have access to the terminal to prompt you. If you're running the X Window System, ssh can pop upan X widget instead to get input, ssh-askpass, but you probably don't want that either. <strong>Pine</strong> may makeseveral separate <strong>IMAP</strong> connections in the course of reading your mail, even if it's all on the same server. Thisis just how the <strong>IMAP</strong> protocol works.With the previous settings in your ~/.pinerc file <strong>and</strong> the right kind of <strong>SSH</strong> authentication in place, you'reready to try <strong>Pine</strong> over <strong>SSH</strong>. Just start <strong>Pine</strong> <strong>and</strong> open your remote mailbox; if all goes well, it will openwithout prompting for a password.


<strong>Pine</strong>, <strong>IMAP</strong>, <strong>and</strong> <strong>SSH</strong> (<strong>SSH</strong>, <strong>The</strong> <strong>Secure</strong> <strong>Shell</strong>: <strong>The</strong> <strong>Definitive</strong> <strong>Gu</strong>ide)of 8http://www.hn.edu.cn/book/NetWork/NetworkingBookshelf_2ndEd/ssh...8/3/2005 2:16 PM11.3.2. Mail Relaying <strong>and</strong> News Access<strong>Pine</strong> uses <strong>IMAP</strong> to read mail but not to send it. For that, it can either call a local program (such as sendmail) or use an SMTP server. <strong>Pine</strong> can also be a newsreader <strong>and</strong> use NNTP (the Network News Transfer Protocol,RFC-977) to contact a news server.An ISP commonly provides NNTP <strong>and</strong> SMTP servers for its customers when connected to the ISP's network.However, for security <strong>and</strong> usage control reasons, the ISP generally restricts this access to connectionsoriginating within its own network (including its own dial-up connections). In other words, if you'reconnected to the Internet from elsewhere <strong>and</strong> try to use your ISP's services, the attempt will probably fail.Access to your usual servers can be blocked by a firewall, or if not, your outgoing mail can bounce with amessage about "no relaying," <strong>and</strong> the news server rejects you with a message about "unauthorized use."You are authorized to use the services, of course, so what do you do? Use <strong>SSH</strong> port forwarding! Byforwarding your SMTP <strong>and</strong> NNTP connections over an <strong>SSH</strong> session to a machine inside the ISP's network,your connections appear to come from that machine, thus bypassing the address-based restrictions. You canuse separate <strong>SSH</strong> comm<strong>and</strong>s to forward each port:$ ssh -L2025:localhost:25 smtp-server ...$ ssh -L2119:localhost:119 nntp-server ...Alternatively, if you have a shell account on one of the ISP's machines running <strong>SSH</strong> but can't log into themail or news servers directly, do this:$ ssh -L2025:smtp-server:25 -L2119:nntp-server:119 shell-server ...This is an off-host forwarding, <strong>and</strong> thus the last leg of the forwarded path isn't protected by <strong>SSH</strong>. Section9.2.4, "Forwarding Off-Host" But since the reason for this forwarding isn't so much protection as it isbypassing the source-address restriction, that's OK. Your mail messages <strong>and</strong> news postings are going to betransferred insecurely once you drop them off, anyway. (If you want security for them, you need to sign orencrypt them separately, e.g., with PGP or S/MIME.)In any case, now configure <strong>Pine</strong> to use the forwarded ports by setting the smtp-server <strong>and</strong> nntp-serverconfiguration options in your ~/.pinerc file:smtp-server=localhost:2025nntp-server=localhost:211911.3.3. Using a Connection Script<strong>The</strong> <strong>Pine</strong> configuration option rsh-path can point not only to rsh or ssh, but also to any other program: mostusefully, a script you've written providing any needed customizations. <strong>The</strong>re are a couple of reasons why youmight need to do this:<strong>The</strong> rsh-path setting is global, applying to every remote mailbox. That is, <strong>Pine</strong> tries to use this style ofaccess either for every remote mailbox or for none. If you have multiple remote mailboxes but onlysome of them are accessible via <strong>SSH</strong>/imapd, this leads to annoyance. <strong>Pine</strong> falls back to a direct TCPconnection if <strong>SSH</strong> fails to get an <strong>IMAP</strong> connection, but you have to wait for it to fail. If the server inquestion is behind a firewall silently blocking the <strong>SSH</strong> port, this can be a lengthy delay.


<strong>Pine</strong>, <strong>IMAP</strong>, <strong>and</strong> <strong>SSH</strong> (<strong>SSH</strong>, <strong>The</strong> <strong>Secure</strong> <strong>Shell</strong>: <strong>The</strong> <strong>Definitive</strong> <strong>Gu</strong>ide)of 8http://www.hn.edu.cn/book/NetWork/NetworkingBookshelf_2ndEd/ssh...8/3/2005 2:16 PM# your ISP's domain; a common <strong>and</strong> useful convention.@forward = ('-L',"$smtp_proxy:mail:$smtp",'-L',"$nntp_proxy:news:$nntp");if ($do_forwards);# prepare the arguments to ssh@ssh_argv = ('-a','-x','-q',@forward,"$remoteuser\@$server");# run sshexec $ssh, @ssh_argv, $comm<strong>and</strong>;11.2. FTP Forwarding 11.4. Kerberos <strong>and</strong> <strong>SSH</strong>Copyright © 2002 O'Reilly & Associates. All rights reserved.


ERROR: syntaxerrorOFFENDING COMMAND: --nostringval--STACK:/Title()/Subject(D:20050803141644)/ModDate()/Keywords(PDFCreator Version 0.8.0)/Creator(D:20050803141644)/CreationDate(sev)/Author-mark-

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!