rpms/connect-proxy/devel connect-1.95.c, NONE, 1.1 connect-proxy-make-man.patch, NONE, 1.1 connect-proxy.spec, NONE, 1.1 connect.html, NONE, 1.1

Jarod Wilson (jwilson) fedora-extras-commits at redhat.com
Thu Jul 6 03:24:33 UTC 2006


Author: jwilson

Update of /cvs/extras/rpms/connect-proxy/devel
In directory cvs-int.fedora.redhat.com:/tmp/cvs-serv14111/devel

Added Files:
	connect-1.95.c connect-proxy-make-man.patch connect-proxy.spec 
	connect.html 
Log Message:
auto-import connect-proxy-1.95-4.fc6 on branch devel from connect-proxy-1.95-4.fc6.src.rpm


--- NEW FILE connect-1.95.c ---
/***********************************************************************
 * connect.c -- Make socket connection using SOCKS4/5 and HTTP tunnel.
 *
 * Copyright (c) 2000-2004 Shun-ichi Goto
 * Copyright (c) 2002, J. Grant (English Corrections)
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 * ---------------------------------------------------------
 * PROJECT:  My Test Program
 * AUTHOR:   Shun-ichi GOTO <gotoh at taiyo.co.jp>
 * CREATE:   Wed Jun 21, 2000
 * REVISION: $Revision: 1.96 $
 * ---------------------------------------------------------
 *
 * Getting Source
 * ==============
 *
 *   Recent version of 'connect.c' is available from
 *     http://www.taiyo.co.jp/~gotoh/ssh/connect.c
 *
 *   Related tool, ssh-askpass.exe (alternative ssh-askpass on UNIX)
 *   is available:
 *     http://www.taiyo.co.jp/~gotoh/ssh/ssh-askpass.exe.gz
 *
 *   See more detail:
 *     http://www.taiyo.co.jp/~gotoh/ssh/connect.html
 *
 * How To Compile
 * ==============
 *
 *  On UNIX environment:
 *      $ gcc connect.c -o connect
 *
 *  On SOLARIS:
 *      $ gcc -o connect -lresolv -lsocket -lnsl connect.c
 *
 *  on Win32 environment:
 *      $ cl connect.c wsock32.lib advapi32.lib
 *    or
 *      $ bcc32 connect.c wsock32.lib advapi32.lib
 *    or
 *      $ gcc connect.c -o connect
 *
 *  on Mac OS X environment:
 *      $ gcc connect.c -o connect -lresolv
 *    or
 *      $ gcc connect.c -o connect -DBIND_8_COMPAT=1
 *
 * How To Use
 * ==========
 *
 *   You can specify proxy method in an environment variable or in a
 *   command line option.
 *
 *   usage:  connect [-dnhst45] [-R resolve] [-p local-port] [-w sec]
 *                   [-H [user@]proxy-server[:port]]
 *                   [-S [user@]socks-server[:port]]
 *                   [-T proxy-server[:port]]
 *                   [-c telnet proxy command]
 *                   host port
 *
 *   "host" and "port" is for the target hostname and port-number to
 *   connect to.
 *
 *   The -H option specifys a hostname and port number of the http proxy
 *   server to relay. If port is omitted, 80 is used. You can specify this
 *   value in the environment variable HTTP_PROXY and pass the -h option
 *   to use it.
 *
 *   The -S option specifys the hostname and port number of the SOCKS
 *   server to relay.  Like -H, port number can be omitted and the default
 *   is 1080. You can also specify this value pair in the environment
 *   variable SOCKS5_SERVER and give the -s option to use it.
 *
 *   The '-4' and the '-5' options are for specifying SOCKS relaying and
 *   indicates protocol version to use. It is valid only when used with
 *   '-s' or '-S'. Default is '-5' (protocol version 5)
 *
 *   The '-R' option is for specifying method to resolve the
 *   hostname. Three keywords ("local", "remote", "both") or dot-notation
 *   IP address are acceptable.  The keyword "both" means, "Try local
 *   first, then remote". If a dot-notation IP address is specified, use
 *   this host as nameserver. The default is "remote" for SOCKS5 or
 *   "local" for others. On SOCKS4 protocol, remote resolving method
 *   ("remote" and "both") requires protocol 4a supported server.
 *
 *   The '-p' option will forward a local TCP port instead of using the
 *   standard input and output.
 *
 *   The '-P' option is same to '-p' except keep remote session. The
 *   program repeats waiting the port with holding remote session without
 *   disconnecting. To disconnect the remote session, send EOF to stdin or
 *   kill the program.
 *
 *   The '-w' option specifys timeout seconds for making connection with
 *   TARGET host.
 *
 *   The '-d' option is used for debug. If you fail to connect, use this
 *   and check request to and response from server.
 *
 *   You can omit the "port" argument when program name is special format
 *   containing port number itself. For example,
 *     $ ln -s connect connect-25
 *   means this connect-25 command is spcifying port number 25 already
 *   so you need not 2nd argument (and ignored if specified).
 *
 *   To use proxy, this example is for SOCKS5 connection to connect to
 *   'host' at port 25 via SOCKS5 server on 'firewall' host.
 *     $ connect -S firewall  host 25
 *   or
 *     $ SOCKS5_SERVER=firewall; export SOCKS5_SERVER
 *     $ connect -s host 25
 *
 *   For a HTTP-PROXY connection:
 *     $ connect -H proxy-server:8080  host 25
 *   or
 *     $ HTTP_PROXY=proxy-server:8080; export HTTP_PROXY
 *     $ connect -h host 25
 *   To forward a local port, for example to use ssh:
 *     $ connect -p 5550 -H proxy-server:8080  host 22
 *    ($ ssh -l user -p 5550 localhost )
 *
 * TIPS
 * ====
 *
 *   Connect.c doesn't have any configuration to specify the SOCKS server.
 *   If you are a mobile user, this limitation might bother you.  However,
 *   You can compile connect.c and link with other standard SOCKS library
 *   like the NEC SOCKS5 library or Dante. This means connect.c is
 *   socksified and uses a configration file like to other SOCKSified
 *   network commands and you can switch configuration file any time
 *   (ex. when ppp startup) that brings you switching of SOCKS server for
 *   connect.c in same way with other commands. For this case, you can
 *   write ~/.ssh/config like this:
 *
 *     ProxyCommand connect -n %h %p
 *
 * SOCKS5 authentication
 * =====================
 *
 *   Only USER/PASS authentication is supported.
 *
 * Proxy authentication
 * ====================
 *
 *   Only BASIC scheme is supported.
 *
 * Authentication informations
 * ===========================
 *
 *   User name for authentication is specifed by an environment variable
 *   or system login name.  And password is specified from environment
 *   variable or external program (specified in $SSH_ASKPASS) or tty.
 *
 *   Following environment variable is used for specifying user name.
 *     SOCKS: $SOCKS5_USER, $LOGNAME, $USER
 *     HTTP Proxy: $HTTP_PROXY_USER, $LOGNAME, $USER
 *
 * ssh-askpass support
 * ===================
  *
 *   You can use ssh-askpass (came from OpenSSH or else) to specify
 *   password on graphical environment (X-Window or MS Windows). To use
 *   this, set program name to environment variable SSH_ASKPASS. On UNIX,
 *   X-Window must be required, so $DISPLAY environment variable is also
 *   needed.  On Win32 environment, $DISPLAY is not mentioned.
 *
 * Related Informations
 * ====================
 *
 *   SOCKS5 -- RFC 1928, RFC 1929, RFC 1961
 *             NEC SOCKS Reference Implementation is available from:
 *               http://www.socks.nec.com
 *             DeleGate version 5 or earlier can be SOCKS4 server,
 *             and version 6 can be SOCKS5 and SOCKS4 server.
 *             and version 7.7.0 or later can be SOCKS5 and SOCKS4a server.
 *               http://www.delegate.org/delegate/
 *
 *   HTTP-Proxy --
 *             Many http proxy servers supports this, but https should
 *             be allowed as configuration on your host.
 *             For example on DeleGate, you should add "https" to the
 *             "REMITTABLE" parameter to allow HTTP-Proxy like this:
 *               delegated -Pxxxx ...... REMITTABLE="+,https" ...
 *
 *  Hypertext Transfer Protocol -- HTTP/1.1  -- RFC 2616
[...2489 lines suppressed...]
    int sockopt;

    /* Create the socket. */
    debug("Creating source port to forward.\n");
    sock = socket (PF_INET, SOCK_STREAM, 0);
    if (sock < 0)
        fatal("socket() failed, errno=%d\n", socket_errno());
    sockopt = 1;
    setsockopt (sock, SOL_SOCKET, SO_REUSEADDR,
                (void*)&sockopt, sizeof(sockopt));

    /* Give the socket a name. */
    name.sin_family = AF_INET;
    name.sin_port = htons (port);
    name.sin_addr.s_addr = htonl (INADDR_ANY);
    if (bind (sock, (struct sockaddr *) &name, sizeof (name)) < 0)
        fatal ("bind() failed, errno=%d\n", socket_errno());

    if (listen( sock, 1) < 0)
        fatal ("listen() failed, errno=%d\n", socket_errno());

    /* wait for new connection with watching EOF of stdin. */
    debug ("waiting new connection at port %d (socket=%d)\n", port, sock);
    nfds = sock + 1;
    do {
        int n;
        struct timeval *ptmo = NULL;
#ifdef _WIN32
        struct timeval tmo;
        tmo.tv_sec = 0;
        tmo.tv_usec = 100*1000;                 /* On Windows, 100ms timeout */
        ptmo = &tmo;
#endif /* _WIN32 */
        FD_ZERO (&ifds);
        FD_SET ((SOCKET)sock, &ifds);
#ifndef _WIN32
        FD_SET (0, &ifds);                      /* watch stdin */
#endif
        n = select (nfds, &ifds, NULL, NULL, ptmo);
        if (n == -1) {
            fatal ("select() failed, %d\n", socket_errno());
            exit (1);
        }
#ifdef _WIN32
        if (0 < stdindatalen()) {
            FD_SET (0, &ifds);          /* fake */
            n++;
        }
#endif
        if (0 < n) {
            if (FD_ISSET(0, &ifds) && (getchar() <= 0)) {
                /* EOF */
                debug ("Give-up waiting port because stdin is closed.");
                exit(0);
            }
            if (FD_ISSET(sock, &ifds))
                break;                          /* socket is stimulated */
        }
    } while (1);
    socklen = sizeof(client);
    connection = accept( sock, &client, &socklen);
    if ( connection < 0 )
        fatal ("accept() failed, errno=%d\n", socket_errno());
    return connection;
}



/** Main of program **/
int
main( int argc, char **argv )
{
    int ret;
    int remote;                                 /* socket */
    int local_in;                               /* Local input */
    int local_out;                              /* Local output */
    int reason;
#ifdef _WIN32
    WSADATA wsadata;
    WSAStartup( 0x101, &wsadata);
#endif /* _WIN32 */

    /* initialization */
    make_revstr();
    getarg( argc, argv );
    debug("Program is $Revision: 1.96 $\n");

    /* Open local_in and local_out if forwarding a port */
    if ( local_type == LOCAL_SOCKET ) {
        /* Relay between local port and destination */
        local_in = local_out = accept_connection( local_port );
    } else {
        /* Relay between stdin/stdout and desteination */
        local_in = 0;
        local_out = 1;
#ifdef _WIN32
        _setmode(local_in, O_BINARY);
        _setmode(local_out, O_BINARY);
#endif
    }

retry:
#ifndef _WIN32
    if (0 < connect_timeout)
        set_timeout (connect_timeout);
#endif /* not _WIN32 */

    /* make connection */
    if ( relay_method == METHOD_DIRECT ) {
        remote = open_connection (dest_host, dest_port);
        if ( remote == SOCKET_ERROR )
            fatal( "Unable to connect to destination host, errno=%d\n",
                   socket_errno());
    } else {
        remote = open_connection (relay_host, relay_port);
        if ( remote == SOCKET_ERROR )
            fatal( "Unable to connect to relay host, errno=%d\n",
                   socket_errno());
    }

    /** resolve destination host (SOCKS) **/
#if !defined(_WIN32) && !defined(__CYGWIN32__)
    if (socks_ns.sin_addr.s_addr != 0)
        switch_ns (&socks_ns);
#endif /* not _WIN32 && not __CYGWIN32__ */
    if (relay_method == METHOD_SOCKS &&
        socks_resolve == RESOLVE_LOCAL &&
        local_resolve (dest_host, &dest_addr) < 0) {
        fatal("Unknown host: %s", dest_host);
    }

    /** relay negociation **/
    switch ( relay_method ) {
    case METHOD_SOCKS:
        if ( ((socks_version == 5) && (begin_socks5_relay(remote) < 0)) ||
             ((socks_version == 4) && (begin_socks4_relay(remote) < 0)) )
            fatal( "failed to begin relaying via SOCKS.\n");
        break;

    case METHOD_HTTP:
        ret = begin_http_relay(remote);
        switch (ret) {
        case START_ERROR:
            close (remote);
            fatal("failed to begin relaying via HTTP.\n");
        case START_OK:
            break;
        case START_RETRY:
            /* retry with authentication */
            close (remote);
            goto retry;
        }
        break;
    case METHOD_TELNET:
        if (begin_telnet_relay(remote) < 0)
             fatal("failed to begin relaying via telnet.\n");
        break;
    }
    debug("connected\n");

#ifndef _WIN32
    if (0 < connect_timeout)
        set_timeout (0);
#endif /* not _WIN32 */

    /* main loop */
    debug ("start relaying.\n");
do_repeater:
    reason = do_repeater(local_in, local_out, remote);
    debug ("relaying done.\n");
    if (local_type == LOCAL_SOCKET &&
        reason == REASON_CLOSED_BY_LOCAL &&
        f_hold_session) {
        /* re-wait at local port without closing remote session */
        debug ("re-waiting at local port %d\n", local_port);
        local_in = local_out = accept_connection( local_port );
        debug ("re-start relaying\n");
        goto do_repeater;
    }
    closesocket(remote);
    if ( local_type == LOCAL_SOCKET)
        closesocket(local_in);
#ifdef _WIN32
    WSACleanup();
#endif /* _WIN32 */
    debug ("that's all, bye.\n");

    return 0;
}

/* ------------------------------------------------------------
   Local Variables:
   compile-command: "cc connect.c -o connect"
   tab-width: 8
   fill-column: 74
   comment-column: 48
   End:
   ------------------------------------------------------------ */

/*** end of connect.c ***/

connect-proxy-make-man.patch:

--- NEW FILE connect-proxy-make-man.patch ---
diff -urP connect-proxy-1.93.orig/connect-proxy.1 connect-proxy-1.93/connect-proxy.1
--- connect-proxy-1.93.orig/connect-proxy.1	1969-12-31 16:00:00.000000000 -0800
+++ connect-proxy-1.93/connect-proxy.1	2005-12-07 14:40:45.000000000 -0800
@@ -0,0 +1,95 @@
+.TH "CONNECT-PROXY" "1" 
+.SH "NAME" 
+connect-proxy \(em connect over SOCKS4/5 proxy 
+.SH "SYNOPSIS" 
+.PP 
+\fBconnect-proxy\fR [\fB-dnhst45\fP]  [\fB-R \fIresolve\fR \fP]  [\fB-p \fIlocal-port\fR \fP]  [\fB-w \fIsecs\fR \fP]  [\fB-H \fI[user@]proxy-server[:port]]\fR \fP]  [\fB-S \fI[user@]socks-server[:port]]\fR \fP]  [\fB-T \fIproxy-server[:port]\fR \fP]  [\fB-c \fItelnet-proxy-command\fR \fP]  [host]  [port]  
+.SH "DESCRIPTION" 
+.PP 
+\fBconnect-proxy\fR open connection over SOCKS4/5 proxies 
+.PP 
+Please, note that any HTTP-Proxy tunnel won't work with content-inspection firewall (unless using SSL). 
+.SH "OPTIONS" 
+.IP "\fB-H\fP" 10 
+specifies a hostname and port number of the http proxy  
+server to relay. If port is omitted, 80 is used. You can specify this 
+value in the environment variable HTTP_PROXY and pass the \-h option 
+to use it. 
+.IP "\fB-S\fP" 10 
+specifies the hostname and port number of the SOCKS 
+server to relay.  Like \-H, port number can be omitted and the default 
+is 1080. You can also specify this value pair in the environment 
+variable SOCKS5_SERVER and give the \-s option to use it. 
+.IP "\fB-4\fP" 10 
+specifies SOCKS relaying and indicates protocol version to use.  
+It is valid only when used with '\-s' or '\-S'.  
+Default is '\-5' (protocol version 5) 
+.IP "\fB-R\fP" 10 
+method to resolve the 
+hostname. Three keywords ("local", "remote", "both") or dot-notation 
+IP address are acceptable.  The keyword "both" means, "Try local 
+first, then remote". If a dot-notation IP address is specified, use 
+this host as nameserver. The default is "remote" for SOCKS5 or 
+"local" for others. On SOCKS4 protocol, remote resolving method 
+("remote" and "both") requires protocol 4a supported server. 
+.IP "\fB-p\fP" 10 
+will forward a local TCP port instead of using the 
+standard input and output. 
+.IP "\fB-P\fP" 10 
+same to '\-p' except keep remote session. The 
+program repeats waiting the port with holding remote session without 
+disconnecting. To connect the remote session, send EOF to stdin or 
+kill the program. 
+.IP "\fB-w\fP" 10 
+timeout in seconds for making connection with TARGET host. 
+.IP "\fB-d\fP" 10 
+used for debug. If you fail to connect, use this and check request to and response from server. 
+.SH "USAGE" 
+.PP 
+To use proxy, this example is for SOCKS5 connection to connect to 
+'host' at port 25 via SOCKS5 server on 'firewall' host. 
+ 
+\fBconnect-proxy \-S firewall host 25\fR  
+ 
+\fBSOCKS5_SERVER=firewall; export SOCKS5_SERVER;  
+connect-proxy \-s host 25\fR 
+.PP 
+For a HTTP-PROXY connection: 
+ 
+\fBconnect-proxy \-H proxy-server:8080  host 25\fR   
+ 
+\fBHTTP_PROXY=proxy-server:8080; export HTTP_PROXY;  
+connect-proxy \-h host 25\fR  
+.PP 
+To forward a local port, for example to use ssh: 
+ 
+\fBconnect-proxy \-H proxy-server:8080  host 22 \fR  
+\fBssh \-l user \-p 5550 localhost\fR 
+.PP 
+To use it along ssh transparently: 
+\fB # file://~/.ssh/config 
+Host * 
+ProxyCommand connect-proxy \-H proxy-server:8080  %h %p\fR 
+.SH "ENVIRONMENT" 
+.PP 
+SOCKS5_USER, LOGNAME, USER 
+HTTP_PROXY_USER, LOGNAME, USER 
+.SH "SEE ALSO" 
+.PP 
+ssh (1). 
+.SH "WWW" 
+.PP 
+http://www.taiyo.co.jp/~gotoh/ssh/connect.html 
+.SH "AUTHOR" 
+.PP 
+This manual page was written by Philippe COVAL Philippe.COVAL at laposte.net for 
+the \fBDebian\fP system (but may be used by others).  Permission is 
+granted to copy, distribute and/or modify this document under 
+the terms of the GNU General Public License, Version 2 any  
+later version published by the Free Software Foundation. 
+ 
+.PP 
+On Debian systems, the complete text of the GNU General Public 
+License can be found in /usr/share/common-licenses/GPL. 
+ 
+.\" created by instant / docbook-to-man, Wed 27 Apr 2005, 21:50 
diff -urP connect-proxy-1.93.orig/Makefile connect-proxy-1.93/Makefile
--- connect-proxy-1.93.orig/Makefile	1969-12-31 16:00:00.000000000 -0800
+++ connect-proxy-1.93/Makefile	2005-12-07 14:49:13.000000000 -0800
@@ -0,0 +1,23 @@
+#gmake
+PACKAGE ?= connect-proxy
+URL ?= http://www.taiyo.co.jp/~gotoh/ssh/connect.c
+INSTALL_DIR ?= ${DESTDIR}/usr
+
+OBJS ?= connect.o
+
+default: ${PACKAGE} 
+
+install: ${PACKAGE}
+	 -mkdir -p ${INSTALL_DIR}/bin/
+	 install ${PACKAGE} ${INSTALL_DIR}/bin/
+
+
+${PACKAGE}: ${OBJS}
+	    ${CC} -o $@ $^
+clean: 
+	${RM} ${PACKAGE} ${PACKAGE}.o *~ ${OBJS}
+
+LICENCE: /usr/share/apps/LICENSES/GPL_V2
+	ln -fs $^ $@
+
+# EOF


--- NEW FILE connect-proxy.spec ---
Name:           connect-proxy
Version:        1.95
Release:        4%{?dist}
Summary:        SSH Proxy command helper

Group:          Applications/System
License:        GPL
URL:            http://www.taiyo.co.jp/~gotoh/ssh/connect.html
Source0:        connect-%{version}.c
# Real source listed below, it was renamed for sanity's sake
#Source0:        http://www.taiyo.co.jp/~gotoh/ssh/connect.c
Source1:        http://www.taiyo.co.jp/~gotoh/ssh/connect.html
Patch0:         connect-proxy-make-man.patch
BuildRoot:      %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)

Requires:       openssh

%description
connect-proxy is the simple relaying command to make network connection via
SOCKS and https proxy. It is mainly intended to be used as proxy command
of OpenSSH. You can make SSH session beyond the firewall with this command.

Features of connect-proxy are:

    * Supports SOCKS (version 4/4a/5) and https CONNECT method.
    * Supports NO-AUTH and USERPASS authentication of SOCKS
    * Partially supports telnet proxy (experimental).
    * You can input password from tty, ssh-askpass or environment variable.
    * Simple and general program independent from OpenSSH.
    * You can also relay local socket stream instead of standard I/O.

%prep
#setup -q -T -c -n %{name}-%{version}
%setup -q -T -c
cp %{SOURCE0} connect.c
cp %{SOURCE1} .
%patch0 -p1

%build
make CFLAGS="$RPM_OPT_FLAGS" %{?_smp_mflags}

%install
rm -rf $RPM_BUILD_ROOT
mkdir -p $RPM_BUILD_ROOT
make DESTDIR=$RPM_BUILD_ROOT install
mkdir -p $RPM_BUILD_ROOT%{_mandir}/man1
cp -p %{name}.1 $RPM_BUILD_ROOT%{_mandir}/man1/

%clean
rm -rf $RPM_BUILD_ROOT

%files
%defattr(-,root,root,-)
%doc connect.html
%{_mandir}/man1/*
%{_bindir}/%{name}

%changelog
* Wed Jul 05 2006 Jarod Wilson <jwilson at redhat.com> 1.95-4
- Minor spec cleanups
- Add copy of html doc page

* Wed Jul 05 2006 Jarod Wilson <jwilson at redhat.com> 1.95-3
- Rename source file with version for sanity's sake

* Wed Jul 05 2006 Jarod Wilson <jwilson at redhat.com> 1.95-2
- Fix BuildRoot and enable CFLAGS

* Wed Jul 05 2006 Jarod Wilson <jwilson at redhat.com> 1.95-1
- Initial build for Fedora Extras

* Wed Dec 12 2005 Jarod Wilson <jarod at wilsonet.com> 1.93-1
- Initial build


--- NEW FILE connect.html ---
<?xml version="1.0" encoding="us-ascii"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  "http://www.w3.org/TR/xhtml1/DTD/strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  <head>
    <title>SSH Proxy Command -- connect.c</title>
    <meta name="generator" content="emacs-wiki.el" />
    <meta http-equiv="Content-Type"
	  content="us-ascii" />
    <link rev="made" href="mailto:gotoh at taiyo.co.jp" />
    <link rel="home" href="http://www.taiyo.co.jp/~gotoh/" />
    <link rel="index" href="http://www.taiyo.co.jp/~gotoh/SiteIndex.html" />
    <link rel="stylesheet" type="text/css" href="emacs-wiki.css" />
  </head>
  <body>
    <h1>SSH Proxy Command -- connect.c</h1>
    <!-- Page published by Emacs Wiki begins here -->
<p>
<strong>connect.c</strong> is the simple relaying command to make network
connection via SOCKS and https proxy. It is mainly intended to
be used as <strong>proxy command</strong> of OpenSSH.  You can make SSH session
beyond the firewall with this command,

</p>

<p>
Features of <strong>connect.c</strong> are:

</p>

<ul>
<li>Supports SOCKS (version 4/4a/5) and https CONNECT method.
</li>
<li>Supports NO-AUTH and USERPASS authentication of SOCKS
</li>
<li>Partially supports telnet proxy (experimental).
</li>
<li>You can input password from tty, ssh-askpass or
     environment variable.
</li>
<li>Run on UNIX or Windows platform.
</li>
<li>You can compile with various C compiler (cc, gcc, Visual C, Borland C. etc.)
</li>
<li>Simple and general program independent from OpenSSH.
</li>
<li>You can also relay local socket stream instead of standard I/O.
</li>
</ul>

<p>
Download source code from:
<a href="http://www.taiyo.co.jp/~gotoh/ssh/connect.c">http://www.taiyo.co.jp/~gotoh/ssh/connect.c</a>
<br/>
For windows user, pre-compiled binary is also available:
<a href="http://www.taiyo.co.jp/~gotoh/ssh/connect.exe">http://www.taiyo.co.jp/~gotoh/ssh/connect.exe</a> (compiled with MSVC)

</p>

<h2>Contents</h2>
<dl class="contents">
<dt class="contents">
<a href="#sec1">News</a>
</dt>
<dt class="contents">
<a href="#sec2">What is 'proxy command'</a>
</dt>
<dt class="contents">
<a href="#sec3">How to Use</a>
</dt>
<dd>
<dl class="contents">
<dt class="contents">
<a href="#sec4">Get Source</a>
</dt>
<dt class="contents">
<a href="#sec5">Compile and Install</a>
</dt>
<dt class="contents">
<a href="#sec6">Modify your ~/.ssh/config</a>
</dt>
<dt class="contents">
<a href="#sec7">Use SSH</a>
</dt>
<dt class="contents">
<a href="#sec8">Have trouble?</a>
</dt>
</dl>
</dd>
<dt class="contents">
<a href="#sec9">More Detail</a>
</dt>
<dt class="contents">
<a href="#sec10">Specifying user name via environment variables</a>
</dt>
<dt class="contents">
<a href="#sec11">Specifying password via environment variables</a>
</dt>
<dt class="contents">
<a href="#sec12">Limitations</a>
</dt>
<dd>
<dl class="contents">
<dt class="contents">
<a href="#sec13">SOCKS5 authentication</a>
</dt>
<dt class="contents">
<a href="#sec14">HTTP authentication</a>
</dt>
<dt class="contents">
<a href="#sec15">Switching proxy server</a>
</dt>
<dt class="contents">
<a href="#sec16">Telnet Proxy</a>
</dt>
</dl>
</dd>
<dt class="contents">
<a href="#sec17">Tips</a>
</dt>
<dd>
<dl class="contents">
<dt class="contents">
<a href="#sec18">Proxying socket connection</a>
</dt>
<dt class="contents">
<a href="#sec19">Use with ssh-askpass command</a>
</dt>
<dt class="contents">
<a href="#sec20">Use for Network Stream of Emacs</a>
</dt>
<dt class="contents">
<a href="#sec21">Remote resolver</a>
</dt>
<dt class="contents">
<a href="#sec22">Hopping Connection via SSH</a>
</dt>
</dl>
</dd>
<dt class="contents">
<a href="#sec23">Break The More Restricted Wall</a>
</dt>
<dt class="contents">
<a href="#sec24">F.Y.I.</a>
</dt>
<dd>
<dl class="contents">
<dt class="contents">
<a href="#sec25">Difference between SOCKS versions.</a>
</dt>
<dt class="contents">
<a href="#sec26">Configuration to use HTTPS</a>
</dt>
<dt class="contents">
<a href="#sec27">SOCKS5 Servers</a>
</dt>
<dt class="contents">
<a href="#sec28">Specifications</a>
</dt>
<dt class="contents">
<a href="#sec29">Related Links</a>
</dt>
<dt class="contents">
<a href="#sec30">Similars</a>
</dt>
</dl>
</dd>
<dt class="contents">
<a href="#sec31">hisotry</a>
</dt>
</dl>


<h2><a name="sec1" id="sec1"></a>News</h2>
<dl>
<dt>2005-07-08</dt>
<dd>
Rev. 1.95. Buf fix for previous change. The bug causes the fail of
  basic authentication. And also fixed bug of parameter file handling.
  Thanks reporting, Johannes Schindelin <Johannes.Schindelin at gmx.de>.
</dd>
<dt>2005-07-07</dt>
<dd>
Rev. 1.94. Changed to use snprintf()/vsnprintf() for security issue
  that gcc complained them on OpenBSD 3.7/x86. The features are not
  changed.
</dd>
<dt>2005-03-04</dt>
<dd>
Updated compile option for Mac OS X.
</dd>
<dt>2005-02-21</dt>
<dd>
Rev.1.92. Removed assertions which has no mean and worse for windows
  suggested by OZAWA Takahiro.
</dd>
<dt>2005-01-12</dt>
<dd>
Rev.1.90. Fixed not to cause seg-fault on accessing to non HTTP
  port. This problem is reported by Jason Armstrong <ja at riverdrums.com>.
</dd>
<dt>2004-10-30</dt>
<dd>
Rev.1.89. Partial support for telnet proxy.
  Thanks to Gregory Shimansky <gshimansky at mail dot ru>. 
  (Note: This is ad-hoc implementation, so it is not enough for
  various type of telnet proxies.
  And password interaction is not supported.)
</dd>
</dl>

<h2><a name="sec2" id="sec2"></a>What is 'proxy command'</h2>

<p>
OpenSSH development team decides to stop supporting SOCKS and any
other tunneling mechanism. It was aimed to separate complexity to
support various mechanism of proxying from core code.  And they
recommends more flexible mechanism: <strong>ProxyCommand</strong> option
instead.

</p>

<p>
Proxy command mechanism is delegation of network stream
communication.  If <strong>ProxyCommand</strong> options is specified, SSH
invoke specified external command and talk with standard I/O of thid
command.  Invoked command undertakes network communication with
relaying to/from standard input/output including iniitial
communication or negotiation for proxying.  Thus, ssh can split out
proxying code into external command.

</p>

<p>
The <strong>connect.c</strong> program was made for this purpose.

</p>

<h2><a name="sec3" id="sec3"></a>How to Use</h2>

<h3><a name="sec4" id="sec4"></a>Get Source</h3>

<p>
Download source code from <a href="http://www.taiyo.co.jp/~gotoh/ssh/connect.c">here</a>.
<br/>
If you are MS Windows user, you can get pre-compiled binary from
<a href="http://www.taiyo.co.jp/~gotoh/ssh/connect.exe">here</a>.

</p>

<h3><a name="sec5" id="sec5"></a>Compile and Install</h3>

<p>
In most environment, you can compile <strong>connect.c</strong> simply.
On UNIX environment, you can use cc or gcc.
On Windows environment, you can use Microsoft Visual C, Borland C or Cygwin gcc.

</p>

<table border="2" cellpadding="5">
<thead>
<tr>
<th>Compiler</th><th>command line to compile</th>
</tr>
</thead>
<tbody>
<tr>
<td>UNIX cc</td><td>cc connect.c -o connect</td>
</tr>
<tr>
<td>UNIX gcc</td><td>gcc connect.c -o connect</td>
</tr>
<tr>
<td>Solaris</td><td>gcc connect.c -o connect -lnsl -lsocket -lresolv</td>
</tr>
<tr>
<td>Microsoft Visual C/C++</td><td>cl connect.c wsock32.lib advapi32.lib</td>
</tr>
<tr>
<td>Borland C</td><td>bcc32 connect.c wsock32.lib advapi32.lib</td>
</tr>
<tr>
<td>Cygwin gcc</td><td>gcc connect.c -o connect</td>
</tr>
<tr>
<td>Mac OS X</td><td>gcc connect.c -o connect -lresolv<br/>or<br/>gcc connect.c -o connect -DBIND_8_COMPAT=1</td>
</tr>
</tbody>
</table>

<p>
To install <strong>connect</strong> command, simply copy compiled binary to directory
in your PATH (ex. /usr/local/bin).  Like this:

</p>

<pre class="example">
$ cp connect /usr/local/bin
</pre>

<h3><a name="sec6" id="sec6"></a>Modify your ~/.ssh/config</h3>

<p>
Modify your <code>~/.ssh/config</code> file to use <strong>connect</strong> command as
<strong>proxy command</strong>.  For the case of SOCKS server is running on
firewall host <code>socks.local.net</code> with port 1080, you can add
<strong>ProxyCommand</strong> option in <code>~/.ssh/config</code>, like this:

</p>

<pre class="example">
Host remote.outside.net
  ProxyCommand connect -S socks.local.net %h %p
</pre>

<p>
<code>%h</code> and <code>%p</code> will be replaced on invoking proxy command with
target hostname and port specified to SSH command.

</p>

<p>
If you hate writing many entries of remote hosts, following example
may help you.

</p>

<pre class="example">
## Inside of the firewall, use connect command with direct connection.
Host *.local.net
  ProxyCommand connect %h %p

## Outside of the firewall, use connect command with SOCKS conenction.
Host *
  ProxyCommand connect -S socks.local.net %h %p
</pre>

<p>
If you want to use http proxy, use <strong>-H</strong> option instead of <strong>-S</strong>
option in examle above, like this:

</p>

<pre class="example">
## Inside of the firewall, direct
Host *.local.net
  ProxyCommand connect %h %p

## Outside of the firewall, with HTTP proxy
Host *
  ProxyCommand connect -H proxy.local.net:8080 %h %p
</pre>

<h3><a name="sec7" id="sec7"></a>Use SSH</h3>

<p>
After editing your <code>~/.ssh/config</code> file, you are ready to use ssh.
You can execute ssh without any special options as if remote host is
IP reachable host.  Following is an example to execute <code>hostname</code>
command on host <code>remote.outside.net</code>.

</p>

<pre class="example">
$ ssh remote.outside.net hostname
remote.outside.net
$
</pre>

<h3><a name="sec8" id="sec8"></a>Have trouble?</h3>

<p>
If you have trouble, execute <strong>connect</strong> command from command line
with <code>-d</code> option to see what is happened. Some debug message may
appear and reports progress. This information may tell you what is
wrong. In this example, error has occurred on authentication stage of
SOCKS5 protocol.

</p>

<pre class="example">
$ connect -d -S socks.local.net unknown.remote.outside.net 110
DEBUG: relay_method = SOCKS (2)
DEBUG: relay_host=socks.local.net
DEBUG: relay_port=1080
DEBUG: relay_user=gotoh
DEBUG: socks_version=5
DEBUG: socks_resolve=REMOTE (2)
DEBUG: local_type=stdio
DEBUG: dest_host=unknown.remote.outside.net
DEBUG: dest_port=110
DEBUG: Program is $Revision: 1.35 $
DEBUG: connecting to xxx.xxx.xxx.xxx:1080
DEBUG: begin_socks_relay()
DEBUG: atomic_out()  [4 bytes]
DEBUG: >>> 05 02 00 02
DEBUG: atomic_in() [2 bytes]
DEBUG: <<< 05 02
DEBUG: auth method: USERPASS
DEBUG: atomic_out()  [some bytes]
DEBUG: >>> xx xx xx xx ...
DEBUG: atomic_in() [2 bytes]
DEBUG: <<< 01 01
ERROR: Authentication faield.
FATAL: failed to begin relaying via SOCKS.
</pre>

<h2><a name="sec9" id="sec9"></a>More Detail</h2>

<p>
Command line usage is here:

</p>

<pre class="example">
usage:  connect [-dnhst45] [-R resolve] [-p local-port] [-w sec]
		[-H [user@]proxy-server[:port]]
		[-S [user@]socks-server[:port]]
		[-T socks-server:[port]]
                [-c telnet-proxy-command]
		host port
</pre>

<p>
<strong><em>host</em></strong> and <strong><em>port</em></strong> is target hostname and port-number to connect.

</p>

<p>
<strong>-H</strong> option specify hostname and port number of http proxy server to
relay. If port is omitted, 80 is used. You can specify this value by
environment variable <code>HTTP_PROXY</code> and give <strong>-h</strong> option to use it.

</p>

<p>
<strong>-S</strong> option specify hostname and port number of SOCKS server to
relay.  Like <strong>-H</strong> option, port number can be omit and default is 1080. 
You can also specify this value pair by environment variable
<code>SOCKS5_SERVER</code> and give <strong>-s</strong> option to use it.

</p>

<p>
<strong>-T</strong> option specify hostname and port number of telnet proxy to
relay. The port number can be omit and default is 23.
You can also specify this value pair by environment variable
<code>TELNET_PROXY</code> and give <strong>-t</strong> option to use it.

</p>

<p>
<strong>-4</strong> and <strong>-5</strong> is for specifying SOCKS protocol version. It is
valid only using with <strong>-s</strong> or <strong>-S</strong>. Default is <strong>-5</strong>
(protocol version 5)

</p>

<p>
<strong>-R</strong> is for specifying method to resolve hostname. 3 keywords
(<code>local</code>, <code>remote</code>, <code>both</code>) or dot-notation IP address is
allowed.  Keyword <code>both</code> means; "Try local first, then
remote". If dot-notation IP address is specified, use this host as
nameserver (UNIX only). Default is <code>remote</code> for SOCKS5 or <code>local</code>
for others. On SOCKS4 protocol, remote resolving method (<code>remote</code>
and <code>both</code>) use protocol version 4a.

</p>

<p>
The <strong>-p</strong> option specifys to wait a local TCP port and make relaying
with it instead of standard input and output.

</p>

<p>
The <strong>-w</strong> option specifys timeout seconds on making connection with
target host.

</p>

<p>
The <strong>-c</strong> option specifys request string against telnet
proxy server. The special word '%h' and '%p' in this string are replaced
as hostname and port number before sending. 
For telnet proxy by <a class="nonexistent" href="mailto:gotoh at taiyo.co.jp">DeleGate</a>, both "telnet %h %p" and "%h:%p"
are acceptable.
Default is "telnet %h %p".

</p>

<p>
The <strong>-a</strong> option specifiys user intended authentication methods
separated by comma.  Currently <code>userpass</code> and <code>none</code> are
supported. Default is <code>userpass</code>. You can also specifying this
parameter by the environment variable <code>SOCKS5_AUTH</code>.

</p>

<p>
The <strong>-d</strong> option is used for debug. If you fail to connect, use this
and check request to and response from server.

</p>

<p>
You can omit <strong><em>port</em></strong> argument when program name is special format
containing port number itself. For example, 

</p>

<pre class="example">
$ ln -s connect connect-25
$ ./connect-25 smtphost.outside.net
220 smtphost.outside.net ESMTP Sendmail
QUIT
221 2.0.0 smtphost.remote.net closing connection
$
</pre>

<p>
This example means that the command name "<code>connect-25</code>" contains port number
25 so you can omit 2nd argument (and used if specified explicitly).

</p>

<h2><a name="sec10" id="sec10"></a>Specifying user name via environment variables</h2>

<p>
There are 5 environemnt variables to specify
user name without command line option. This mechanism is usefull
for the user who using another user name different from system account.

</p>

<dl>
<dt>SOCKS5_USER</dt>
<dd>
Used for SOCKS v5 access.
</dd>
<dt>SOCKS4_USER</dt>
<dd>
Used for SOCKS v4 access.
</dd>
<dt>SOCKS_USER</dt>
<dd>
Used for SOCKS v5 or v4 access and varaibles above are not defined.
</dd>
<dt>HTTP_PROXY_USER</dt>
<dd>
Used for HTTP proxy access.
</dd>
<dt>CONNECT_USER</dt>
<dd>
Used for all type of access if all above are not defined.
</dd>
</dl>

<p>
Following table describes how user name is determined.
Left most number is order to check. If variable is not defined,
check next variable, and so on.

</p>

<table border=1>
<tr align=center><th></th><th>SOCKS v5</th><th>SOCKS v4</th><th>HTTP proxy</th></tr>
<tr align=center><td>1</td><td>SOCKS5_USER</td><td>SOCKS4_USER</td><td rowspan=2>HTTP_PROXY_USER</td></tr>
<tr align=center><td>2</td><td colspan=2>SOCKS_USER</td></tr>
<tr align=center><td>3</td><td colspan=3>CONNECT_USER</td></tr>
<tr align=center><td>4</td><td colspan=3><i>(query user name to system)</i></td></tr>
</table>

<h2><a name="sec11" id="sec11"></a>Specifying password via environment variables</h2>

<p>
There are 5 environemnt variables to specify
password. If you use this feature, please note that it is
not secure way.

</p>

<dl>
<dt>SOCKS5_PASSWD</dt>
<dd>
Used for SOCKS v5 access. This variables is compatible
  with NEC SOCKS implementation.
</dd>
<dt>SOCKS5_PASSWORD</dt>
<dd>
Used for SOCKS v5 access if SOCKS5_PASSWD is not defined.
</dd>
<dt>SOCKS_PASSWORD</dt>
<dd>
Used for SOCKS v5 (or v4) access all above is not defined.
</dd>
<dt>HTTP_PROXY_PASSWORD</dt>
<dd>
Used for HTTP proxy access.
</dd>
<dt>CONNECT_PASSWORD</dt>
<dd>
Used for all type of access if all above are not defined.
</dd>
</dl>

<p>
Following table describes how password is determined.
Left most number is order to check. If variable is not defined,
check next variable, and so on. Finally ask to user interactively
using external program or tty input.

</p>

<table border=1>
<tr align=center><th></th><th>SOCKS v5</th><th>HTTP proxy</th></tr>
<tr align=center><td>1</td><td>SOCKS5_PASSWD</td><td rowspan=2>HTTP_PROXY_PASSWORD</td></tr>
<tr align=center><td>2</td><td>SOCKS_PASSWORD</td></tr>
<tr align=center><td>3</td><td colspan=2>CONNECT_PASSWORD</td></tr>
<tr align=center><td>4</td><td colspan=2><i>(ask to user interactively)</i></td></tr>
</table>

<h2><a name="sec12" id="sec12"></a>Limitations</h2>

<h3><a name="sec13" id="sec13"></a>SOCKS5 authentication</h3>

<p>
Only NO-AUTH and USER/PASSWORD authentications are supported.
GSSAPI authentication (RFC 1961) and other draft authentications (CHAP,
EAP, MAF, etc.) is not supported.

</p>

<h3><a name="sec14" id="sec14"></a>HTTP authentication</h3>

<p>
BASIC authentication is supported but DIGEST authentication is not.

</p>

<h3><a name="sec15" id="sec15"></a>Switching proxy server</h3>

<p>
There is no mechanism to switch proxy server regarding to PC environment.
This limitation might be bad news for mobile user.
Since I do not want to make this program complex, I do not want to
support although this feature is already requested.  Please advice me
if there is good idea of detecting environment to swich and simple way
to specify conditioned directive of servers.

</p>

<p>
One tricky workaround exists. It is replacing ~/.ssh/config file
by script on ppp up/down.

</p>

<p>
There's another example of wrapper script (contributed by Darren Tucker).
This script costs executing ifconfig and grep to detect
current environment, but it works. (NOTE: you should modify addresses
if you use it.)

</p>

<pre class="example">
#!/bin/sh
## ~/bin/myconnect --- Proxy server switching wrapper

if ifconfig eth0 |grep "inet addr:192\.168\.1" >/dev/null; then
	opts="-S 192.168.1.1:1080"  
elif ifconfig eth0 |grep "inet addr:10\." >/dev/null; then
	opts="-H 10.1.1.1:80"
else
	opts="-s"
fi
exec /usr/local/bin/connect $opts $@
</pre>

<h3><a name="sec16" id="sec16"></a>Telnet Proxy</h3>

<p>
At first, note that the telnet proxy support is an partial feature.
In this implementation, <strong>connect</strong> single requestinting and proxy
returns some success/error detective in talked back lines including
greeting, prompt and connected messages.

</p>

<p>
The <strong>connect</strong> simply send request after connection to proxy is
established before any response reading, then repeat reading response
strings from proxy to decide remote connection request is succeeded or
not by checking pre-defined phrase in each lines. There are
pre-defined phrases which are good-phrase and bad-phrases.  First
good-phrase is checked and change state as relaying if exist.
<strong>connect</strong> treat this line as final response from proxy before
starting acutal communication with remote host.  Or if good-phrase is
not matched, bad-phrases will be checked.  If one of bad-phrase
matched, it cause connection error immediately.

</p>

<p>
The pre-defined phrases are currently fixed string so you cannot
change without modifying and compiling.  The good-phrase is:
"connected to".  The bad-phrases are: " failed", " refused", "
rejected", " closed".

</p>

<h2><a name="sec17" id="sec17"></a>Tips</h2>

<h3><a name="sec18" id="sec18"></a>Proxying socket connection</h3>

<p>
In usual, <strong>connect.c</strong> relays network connection to/from standard
input/output. By specifying <strong>-p</strong> option, however, <strong>connect.c</strong>
relays local network stream instead of standard input/output.
With this option, <strong>connect</strong> command waits connection
from other program, then start relaying between both network stream.

</p>

<p>
This feature may be useful for the program which is hard to SOCKSify.

</p>

<h3><a name="sec19" id="sec19"></a>Use with ssh-askpass command</h3>

<p>
<strong>connect.c</strong> ask you password when authentication is required.  If
you are using on tty/pty terminal, connect can input from terminal
with prompt. But you can also use <code>ssh-askpass</code> program to input
password.  If you are graphical environment like X Window or MS
Windows, and program does not have tty/pty, and environment variable
SSH_ASKPASS is specified, then <strong>connect.c</strong> invoke command
specified by environment variable <code>SSH_ASKPASS</code> to input password.
<code>ssh-askpass</code> program might be installed if you are using OpenSSH on
UNIX environment. On Windows environment, pre-compiled binary is
available from
<a href="http://www.taiyo.co.jp/~gotoh/ssh/ssh-askpass.exe">here</a>.

</p>

<p>
This feature is limited on window system environment.

</p>

<p>
And also useful on Emacs on MS Windows (NT Emacs or Meadow).  It is
hard to send passphrase to <strong>connect</strong> command (and also ssh)
because external command is invoked on hidden terminal and do I/O with
this terminal.  Using ssh-askpass avoids this problem.

</p>

<h3><a name="sec20" id="sec20"></a>Use for Network Stream of Emacs</h3>

<p>
Although <strong>connect.c</strong> is made for OpenSSH, it is generic and
independent from OpenSSH. So we can use this for other purpose.  For
example, you can use this command in Emacs to open network connection
with remote host over the firewall via SOCKS or HTTP proxy without
SOCKSifying Emacs itself.

</p>

<p>
There is sample code: 
<a href="http://www.taiyo.co.jp/~gotoh/lisp/relay.el">http://www.taiyo.co.jp/~gotoh/lisp/relay.el</a>

</p>

<p>
With this code, you can use <code>relay-open-network-stream</code> function
instead of <code>open-network-stream</code> to make network connection. See top
comments of source for more detail.

</p>

<h3><a name="sec21" id="sec21"></a>Remote resolver</h3>

<p>
If you are SOCKS4 user on UNIX environment, you might want specify
nameserver to resolve remote hostname.  You can do it specifying
<strong>-R</strong> option followed by IP address of resolver.

</p>

<h3><a name="sec22" id="sec22"></a>Hopping Connection via SSH</h3>

<p>
Conbination of ssh and <strong>connect</strong> command have more interesting usage.
Following command makes indirect connection to host2:port from your
current host via host1.

</p>

<pre class="example">
ssh host1 connect host2 port
</pre>

<p>
This method is useful for the situations like:

</p>

<ul>
<li>You are outside of organizasion now, but you want to access an
    internal host barriered by firewall.
</li>
<li>You want to use some service which is allowed only from some
    limited hosts.
</li>
</ul>

<p>
For example, I want to use local NetNews service in my office
from home.  I cannot make NNTP session directly because NNTP host is
barriered by firewall.  Fortunately, I have ssh account on internal
host and allowed using SOCKS5 on firewall from outside.  So I use
following command to connect to NNTP service.

</p>

<pre class="example">
$ ssh host1 connect news 119
200 news.my-office.com InterNetNews NNRP server INN 2.3.2 ready (posting ok).
quit
205 .
$
</pre>

<p>
By combinating hopping connection and relay.el, I can read NetNews
using <a href="http://www.gohome.org/wl/">Wanderlust</a> on Emacs at home.

</p>

<pre class="example">
                        |
    External (internet) | Internal (office)
                        |
+------+           +----------+          +-------+           +-----------+
| HOME |           | firewall |          | host1 |           | NNTP host |
+------+           +----------+          +-------+           +-----------+
 emacs <-------------- ssh ---------------> sshd <-- connect --> nntpd
       <-- connect --> socksd <-- SOCKS -->
</pre>

<p>
As an advanced example, you can use SSH hopping as fetchmail's plug-in
program to access via secure tunnel. This method requires that
<strong>connect</strong> program is insatalled on remote host.  There's example
of .fetchmailrc bellow. When fetchmail access to mail-server, you will
login to remote host using SSH then execute <strong>connect</strong> program on
remote host to relay conversation with pop server. Thus fetchmail can
retrieve mails in secure.

</p>

<pre class="example">
poll mail-server
  protocol pop3
  plugin "ssh %h connect localhost %p"
  username "username"
  password "password"
</exmaple>

* <a name="sec23" id="sec23"></a>Break The More Restricted Wall

If firewall does not provide SOCKS nor HTTPS other than port 443, you
cannot break the wall in usual way.  But if you have you own host
which is accessible from internet, you can make ssh connection to your
own host by configuring sshd as waiting at port 443 instead of
standard 22. By this, you can login to your own host via port 443.
Once you have logged-in to extenal home machine, you can execute
**connect** as second hop to make connection from your own host to
final target host, like this:

<example>
$ cat ~/.ssh/config
Host home
  ProxyCommand connect -H firewall:8080 %h 443

Host server
  ProxyCommand ssh home connect %h %p
...
internal$ ssh home
You are logged in to home!
home# exit
internal$ ssh server
You are logged in to server!
server# exit
internal$
</pre>

<p>
This way is similar to "Hopping connection via SSH" except configuring
outer sshd as waiting at port 443 (https).  This means that you have a
capability to break the strongly restricted wall if you have own host
out side of the wall.

</p>

<pre class="example">
                        |
      Internal (office) | External (internet)
                        |
+--------+         +----------+                 +------+          +--------+
| office |         | firewall |                 | home |          | server |
+--------+         +----------+                 +------+          +--------+
   <------------------ ssh --------------------->sshd:443
    <-- connect --> http-proxy <-- https:443 -->                      any
                                                 connect <-- tcp -->  port
</pre>

<p>
NOTE: If you wanna use this, you should give up hosting https service
at port 443 on you external host 'home'.

</p>

<h2><a name="sec24" id="sec24"></a>F.Y.I.</h2>

<h3><a name="sec25" id="sec25"></a>Difference between SOCKS versions.</h3>

<p>
SOCKS version 4 is first popular implementation which is documented
<a href="http://www.socks.nec.com/protocol/socks4.protocol">here</a>. Since
this protocol provide IP address based requesting, client program
should resolve name of outer host by itself. Version 4a (documented
<a href="http://www.socks.nec.com/protocol/socks4a.protocol">here</a>) is
enhanced to allow request by hostname instead of IP address.

</p>

<p>
SOCKS version 5 is re-designed protocol stands on experience of
version 4 and 4a.  There is no compativility with previous
versions. Instead, there's some improvement: IPv6 support, request by
hostname, UDP proxying, etc.

</p>

<h3><a name="sec26" id="sec26"></a>Configuration to use HTTPS</h3>

<p>
Many http proxy servers implementation supports https <code>CONNECT</code> method
(SLL).  You might add configuration to allow using https.  For the
example of <a href="http://www.delegate.org/delegate/">DeleGate</a> (
DeleGate is a multi-purpose application level gateway, or a proxy
server) , you should add <code>https</code> to <code>REMITTABLE</code> parameter to
allow HTTP-Proxy like this:

</p>

<pre class="example">
delegated -Pxxxx ...... REMITTABLE='+,https' ...
</pre>

<p>
For the case of Squid, you should allow target ports via https by ACL,
and so on.

</p>

<h3><a name="sec27" id="sec27"></a>SOCKS5 Servers</h3>

<dl>
<dt><a href="http://www.socks.nec.com/refsoftware.html">NEC SOCKS Reference Implementation</a></dt>
<dd>
Reference implementation of SOKCS server and library.
</dd>
<dt><a href="http://www.inet.no/dante/index.html">Dante</a></dt>
<dd>
Dante is free implementation of SOKCS server and library.
  Many enhancements and modulalized.
</dd>
<dt><a href="http://www.delegate.org/delegate/">DeleGate</a></dt>
<dd>
DeleGate is multi function proxy service provider.
  DeleGate 5.x.x or earlier can be SOCKS4 server,
  and 6.x.x can be SOCKS5 and SOCKS4 server.
  and 7.7.0 or later can be SOCKS5 and SOCKS4a server.
</dd>
</dl>

<h3><a name="sec28" id="sec28"></a>Specifications</h3>

<dl>
<dt><a href="http://www.socks.nec.com/protocol/socks4.protocol">socks4.protocol.txt</a></dt>
<dd>
SOCKS: A protocol for TCP proxy across firewalls
</dd>
<dt><a href="http://www.socks.nec.com/protocol/socks4a.protocol">socks4a.protocol.txt</a></dt>
<dd>
SOCKS 4A: A  Simple Extension to SOCKS 4 Protocol
</dd>
<dt><a href="http://www.socks.nec.com/rfc/rfc1928.txt">RFC 1928</a></dt>
<dd>
SOCKS Protocol Version 5
</dd>
<dt><a href="http://www.socks.nec.com/rfc/rfc1929.txt">RFC 1929</a></dt>
<dd>
Username/Password Authentication for SOCKS V5
</dd>
<dt><a href="http://www.ietf.org/rfc/rfc2616.txt">RFC 2616</a></dt>
<dd>
Hypertext Transfer Protocol -- HTTP/1.1
</dd>
<dt><a href="http://www.ietf.org/rfc/rfc2617.txt">RFC 2617</a></dt>
<dd>
HTTP Authentication: Basic and Digest Access Authentication
</dd>
</dl>

<h3><a name="sec29" id="sec29"></a>Related Links</h3>

<ul>
<li><a href="http://www.openssh.org">OpenSSH Home</a>
</li>
<li><a href="http://www.ssh.com/">Proprietary SSH</a>
</li>
<li><a href="http://www.taiyo.co.jp/~gotoh/ssh/openssh-socks.html">Using OpenSSH through a SOCKS compatible PROXY on your LAN</a> (J. Grant)
</li>
</ul>

<h3><a name="sec30" id="sec30"></a>Similars</h3>

<ul>
<li><a href="http://proxytunnel.sourceforge.net/">Proxy Tunnel</a> -- Proxying command using https CONNECT.
</li>
<li><a href="http://www.snurgle.org/~griffon/ssh-https-tunnel">stunnel</a> -- Proxy through an https tunnel (Perl script)
</li>
</ul>

<h2><a name="sec31" id="sec31"></a>hisotry</h2>

<dl>
<dt>2004-07-21</dt>
<dd>
Rev.1.84. Fixed some typo.
</dd>
<dt>2004-05-18</dt>
<dd>
Rev.1.83. Fixed problem not work on Solaris.
</dd>
<dt>2004-04-27</dt>
<dd>
Rev.1.82. Bug fix of memory clear on http proxying.
</dd>
<dt>2004-04-22</dt>
<dd>
Rev. 1.81. Fixed memory violation and memory leak bug. New environment
  variable SOCKS5_PASSWD for sharing value with NEC SOCKS implementation.
  And document (this page) is updated.
</dd>
<dt>2004-03-30</dt>
<dd>
Rev. 1.76. Fixed to accept multiple 'Proxy-Authorization' response.
</dd>
<dt>2003-01-07</dt>
<dd>
Rev. 1.68. Fixed a trouble around timeout support.
</dd>
<dt>2002-11-21</dt>
<dd>
Rev. 1.64 supports reading parameters from file /etc/connectrc or
  ~/.connectrc instead of specifying via environment variables. For
  examle, you can use this feature to switch setting by replacing file
  when network environment is changed. And added SOCKS_DIRECT,
  SOCKS5_DIRECT, SOCKS4_DIRECT, HTTP_DIRECT, SOCKS5_AUTH, environment
  parameters. (Thanks Masatoshi TSUCHIYA)
</dd>
<dt>2002-11-20</dt>
<dd>
Rev. 1.63 supports some old proxies which make response 401 with
  WWW-Authenticate: header. And fixed to use username specified in
  proxy host by -H option correctly. (contributed from Des Herriott, thanks)
</dd>
<dt>2002-10-14</dt>
<dd>
Rev. 1.61 with New option -w for specifying connection timeout.
  Currently, it works on UNIX only. (contributed from Darren Tucker, thanks)
</dd>
<dt>2002-09-29</dt>
<dd>
Add sample script for switching proxy server
  advised from Darren Tucker, thanks.
</dd>
<dt>2002-08-27</dt>
<dd>
connect.c is updataed to rev. 1.60.
</dd>
<dt>2002-04-08</dt>
<dd>
Updated <a href="http://www.taiyo.co.jp/~gotoh/ssh/openssh-socks.html">"Using OpenSSH through a SOCKS compatible PROXY on your LAN"</a> written by  J. Grant. (version 0.8)
</dd>
<dt>2002-02-20</dt>
<dd>
Add link of new document "Using OpenSSH through a SOCKS compatible PROXY on your LAN"
  written by J. Grant.
</dd>
<dt>2002-01-31</dt>
<dd>
Rev. 1.53 -- On Win32 and with MSVC, handle password
  input from console correctly.
</dd>
<dt>2002-01-30</dt>
<dd>
Rev. 1.50 -- [Security Fix] Do not print secure info in debug mode.
</dd>
<dt>2002-01-09</dt>
<dd>
Web page was made.
  connect.c is rev. 1.48.
</dd>
</dl>
<br>

    <!-- Page published by Emacs Wiki ends here -->
    <div class="navfoot">
      <hr/>
      <table width="100%" border="0" summary="Footer navigation">
       <tbody><tr>
	  <td width="50%" align="left">
	    <span class="footdate">Last Updated: 2005-07-18</span><br/>
	  </td>
	  <td width="50%" align="right">
            This page is authored by <a href="mailto:gotoh at taiyo.co.jp">Shun-ichi GOTO</a>
	    using <a href="http://repose.cx/emacs/wiki">emacs-wiki.el</a><br/>
	  </td>
	</tr></tbody>
      </table>
    </div>
  </body>
</html>




More information about the fedora-extras-commits mailing list