CardiacPhase/Git/mingw64/share/doc/connect/manual.html

1421 lines
40 KiB
HTML

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="generator" content="AsciiDoc 8.5.2" />
<title>SSH Proxy Command&#8201;&#8212;&#8201;connect.c</title>
<style type="text/css">
/* Debug borders */
p, li, dt, dd, div, pre, h1, h2, h3, h4, h5, h6 {
/*
border: 1px solid red;
*/
}
body {
margin: 1em 5% 1em 5%;
}
a {
color: blue;
text-decoration: underline;
}
a:visited {
color: fuchsia;
}
em {
font-style: italic;
color: navy;
}
strong {
font-weight: bold;
color: #083194;
}
tt {
color: navy;
}
h1, h2, h3, h4, h5, h6 {
color: #527bbd;
font-family: sans-serif;
margin-top: 1.2em;
margin-bottom: 0.5em;
line-height: 1.3;
}
h1, h2, h3 {
border-bottom: 2px solid silver;
}
h2 {
padding-top: 0.5em;
}
h3 {
float: left;
}
h3 + * {
clear: left;
}
div.sectionbody {
font-family: serif;
margin-left: 0;
}
hr {
border: 1px solid silver;
}
p {
margin-top: 0.5em;
margin-bottom: 0.5em;
}
ul, ol, li > p {
margin-top: 0;
}
pre {
padding: 0;
margin: 0;
}
span#author {
color: #527bbd;
font-family: sans-serif;
font-weight: bold;
font-size: 1.1em;
}
span#email {
}
span#revnumber, span#revdate, span#revremark {
font-family: sans-serif;
}
div#footer {
font-family: sans-serif;
font-size: small;
border-top: 2px solid silver;
padding-top: 0.5em;
margin-top: 4.0em;
}
div#footer-text {
float: left;
padding-bottom: 0.5em;
}
div#footer-badges {
float: right;
padding-bottom: 0.5em;
}
div#preamble {
margin-top: 1.5em;
margin-bottom: 1.5em;
}
div.tableblock, div.imageblock, div.exampleblock, div.verseblock,
div.quoteblock, div.literalblock, div.listingblock, div.sidebarblock,
div.admonitionblock {
margin-top: 1.0em;
margin-bottom: 1.5em;
}
div.admonitionblock {
margin-top: 2.0em;
margin-bottom: 2.0em;
margin-right: 10%;
color: #606060;
}
div.content { /* Block element content. */
padding: 0;
}
/* Block element titles. */
div.title, caption.title {
color: #527bbd;
font-family: sans-serif;
font-weight: bold;
text-align: left;
margin-top: 1.0em;
margin-bottom: 0.5em;
}
div.title + * {
margin-top: 0;
}
td div.title:first-child {
margin-top: 0.0em;
}
div.content div.title:first-child {
margin-top: 0.0em;
}
div.content + div.title {
margin-top: 0.0em;
}
div.sidebarblock > div.content {
background: #ffffee;
border: 1px solid silver;
padding: 0.5em;
}
div.listingblock > div.content {
border: 1px solid silver;
background: #f4f4f4;
padding: 0.5em;
}
div.quoteblock, div.verseblock {
padding-left: 1.0em;
margin-left: 1.0em;
margin-right: 10%;
border-left: 5px solid #dddddd;
color: #777777;
}
div.quoteblock > div.attribution {
padding-top: 0.5em;
text-align: right;
}
div.verseblock > div.content {
white-space: pre;
}
div.verseblock > div.attribution {
padding-top: 0.75em;
text-align: left;
}
/* DEPRECATED: Pre version 8.2.7 verse style literal block. */
div.verseblock + div.attribution {
text-align: left;
}
div.admonitionblock .icon {
vertical-align: top;
font-size: 1.1em;
font-weight: bold;
text-decoration: underline;
color: #527bbd;
padding-right: 0.5em;
}
div.admonitionblock td.content {
padding-left: 0.5em;
border-left: 3px solid #dddddd;
}
div.exampleblock > div.content {
border-left: 3px solid #dddddd;
padding-left: 0.5em;
}
div.imageblock div.content { padding-left: 0; }
span.image img { border-style: none; }
a.image:visited { color: white; }
dl {
margin-top: 0.8em;
margin-bottom: 0.8em;
}
dt {
margin-top: 0.5em;
margin-bottom: 0;
font-style: normal;
color: navy;
}
dd > *:first-child {
margin-top: 0.1em;
}
ul, ol {
list-style-position: outside;
}
ol.arabic {
list-style-type: decimal;
}
ol.loweralpha {
list-style-type: lower-alpha;
}
ol.upperalpha {
list-style-type: upper-alpha;
}
ol.lowerroman {
list-style-type: lower-roman;
}
ol.upperroman {
list-style-type: upper-roman;
}
div.compact ul, div.compact ol,
div.compact p, div.compact p,
div.compact div, div.compact div {
margin-top: 0.1em;
margin-bottom: 0.1em;
}
div.tableblock > table {
border: 3px solid #527bbd;
}
thead, p.table.header {
font-family: sans-serif;
font-weight: bold;
}
tfoot {
font-weight: bold;
}
td > div.verse {
white-space: pre;
}
p.table {
margin-top: 0;
}
/* Because the table frame attribute is overriden by CSS in most browsers. */
div.tableblock > table[frame="void"] {
border-style: none;
}
div.tableblock > table[frame="hsides"] {
border-left-style: none;
border-right-style: none;
}
div.tableblock > table[frame="vsides"] {
border-top-style: none;
border-bottom-style: none;
}
div.hdlist {
margin-top: 0.8em;
margin-bottom: 0.8em;
}
div.hdlist tr {
padding-bottom: 15px;
}
dt.hdlist1.strong, td.hdlist1.strong {
font-weight: bold;
}
td.hdlist1 {
vertical-align: top;
font-style: normal;
padding-right: 0.8em;
color: navy;
}
td.hdlist2 {
vertical-align: top;
}
div.hdlist.compact tr {
margin: 0;
padding-bottom: 0;
}
.comment {
background: yellow;
}
.footnote, .footnoteref {
font-size: 0.8em;
}
span.footnote, span.footnoteref {
vertical-align: super;
}
#footnotes {
margin: 20px 0 20px 0;
padding: 7px 0 0 0;
}
#footnotes div.footnote {
margin: 0 0 5px 0;
}
#footnotes hr {
border: none;
border-top: 1px solid silver;
height: 1px;
text-align: left;
margin-left: 0;
width: 20%;
min-width: 100px;
}
@media print {
div#footer-badges { display: none; }
}
div#toc {
margin-bottom: 2.5em;
}
div#toctitle {
color: #527bbd;
font-family: sans-serif;
font-size: 1.1em;
font-weight: bold;
margin-top: 1.0em;
margin-bottom: 0.1em;
}
div.toclevel1, div.toclevel2, div.toclevel3, div.toclevel4 {
margin-top: 0;
margin-bottom: 0;
}
div.toclevel2 {
margin-left: 2em;
font-size: 0.9em;
}
div.toclevel3 {
margin-left: 4em;
font-size: 0.9em;
}
div.toclevel4 {
margin-left: 6em;
font-size: 0.9em;
}
/* Workarounds for IE6's broken and incomplete CSS2. */
div.sidebar-content {
background: #ffffee;
border: 1px solid silver;
padding: 0.5em;
}
div.sidebar-title, div.image-title {
color: #527bbd;
font-family: sans-serif;
font-weight: bold;
margin-top: 0.0em;
margin-bottom: 0.5em;
}
div.listingblock div.content {
border: 1px solid silver;
background: #f4f4f4;
padding: 0.5em;
}
div.quoteblock-attribution {
padding-top: 0.5em;
text-align: right;
}
div.verseblock-content {
white-space: pre;
}
div.verseblock-attribution {
padding-top: 0.75em;
text-align: left;
}
div.exampleblock-content {
border-left: 3px solid #dddddd;
padding-left: 0.5em;
}
/* IE6 sets dynamically generated links as visited. */
div#toc a:visited { color: blue; }
</style>
<script type="text/javascript">
/*<![CDATA[*/
window.onload = function(){asciidoc.footnotes();}
var asciidoc = { // Namespace.
/////////////////////////////////////////////////////////////////////
// Table Of Contents generator
/////////////////////////////////////////////////////////////////////
/* Author: Mihai Bazon, September 2002
* http://students.infoiasi.ro/~mishoo
*
* Table Of Content generator
* Version: 0.4
*
* Feel free to use this script under the terms of the GNU General Public
* License, as long as you do not remove or alter this notice.
*/
/* modified by Troy D. Hanson, September 2006. License: GPL */
/* modified by Stuart Rackham, 2006, 2009. License: GPL */
// toclevels = 1..4.
toc: function (toclevels) {
function getText(el) {
var text = "";
for (var i = el.firstChild; i != null; i = i.nextSibling) {
if (i.nodeType == 3 /* Node.TEXT_NODE */) // IE doesn't speak constants.
text += i.data;
else if (i.firstChild != null)
text += getText(i);
}
return text;
}
function TocEntry(el, text, toclevel) {
this.element = el;
this.text = text;
this.toclevel = toclevel;
}
function tocEntries(el, toclevels) {
var result = new Array;
var re = new RegExp('[hH]([2-'+(toclevels+1)+'])');
// Function that scans the DOM tree for header elements (the DOM2
// nodeIterator API would be a better technique but not supported by all
// browsers).
var iterate = function (el) {
for (var i = el.firstChild; i != null; i = i.nextSibling) {
if (i.nodeType == 1 /* Node.ELEMENT_NODE */) {
var mo = re.exec(i.tagName);
if (mo && (i.getAttribute("class") || i.getAttribute("className")) != "float") {
result[result.length] = new TocEntry(i, getText(i), mo[1]-1);
}
iterate(i);
}
}
}
iterate(el);
return result;
}
var toc = document.getElementById("toc");
var entries = tocEntries(document.getElementById("content"), toclevels);
for (var i = 0; i < entries.length; ++i) {
var entry = entries[i];
if (entry.element.id == "")
entry.element.id = "_toc_" + i;
var a = document.createElement("a");
a.href = "#" + entry.element.id;
a.appendChild(document.createTextNode(entry.text));
var div = document.createElement("div");
div.appendChild(a);
div.className = "toclevel" + entry.toclevel;
toc.appendChild(div);
}
if (entries.length == 0)
toc.parentNode.removeChild(toc);
},
/////////////////////////////////////////////////////////////////////
// Footnotes generator
/////////////////////////////////////////////////////////////////////
/* Based on footnote generation code from:
* http://www.brandspankingnew.net/archive/2005/07/format_footnote.html
*/
footnotes: function () {
var cont = document.getElementById("content");
var noteholder = document.getElementById("footnotes");
var spans = cont.getElementsByTagName("span");
var refs = {};
var n = 0;
for (i=0; i<spans.length; i++) {
if (spans[i].className == "footnote") {
n++;
// Use [\s\S] in place of . so multi-line matches work.
// Because JavaScript has no s (dotall) regex flag.
note = spans[i].innerHTML.match(/\s*\[([\s\S]*)]\s*/)[1];
noteholder.innerHTML +=
"<div class='footnote' id='_footnote_" + n + "'>" +
"<a href='#_footnoteref_" + n + "' title='Return to text'>" +
n + "</a>. " + note + "</div>";
spans[i].innerHTML =
"[<a id='_footnoteref_" + n + "' href='#_footnote_" + n +
"' title='View footnote' class='footnote'>" + n + "</a>]";
var id =spans[i].getAttribute("id");
if (id != null) refs["#"+id] = n;
}
}
if (n == 0)
noteholder.parentNode.removeChild(noteholder);
else {
// Process footnoterefs.
for (i=0; i<spans.length; i++) {
if (spans[i].className == "footnoteref") {
var href = spans[i].getElementsByTagName("a")[0].getAttribute("href");
href = href.match(/#.*/)[0]; // Because IE return full URL.
n = refs[href];
spans[i].innerHTML =
"[<a href='#_footnote_" + n +
"' title='View footnote' class='footnote'>" + n + "</a>]";
}
}
}
}
}
/*]]>*/
</script>
</head>
<body>
<div id="header">
<h1>SSH Proxy Command&#8201;&#8212;&#8201;connect.c</h1>
</div>
<div id="content">
<div id="preamble">
<div class="sectionbody">
<div class="paragraph"><p><tt>connect.c</tt> is a 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,</p></div>
<div class="paragraph"><p>Features of <tt>connect.c</tt> are:</p></div>
<div class="ulist"><ul>
<li>
<p>
Supports SOCKS (version 4/4a/5) and https CONNECT method.
</p>
</li>
<li>
<p>
Supports NO-AUTH and USERPASS authentication of SOCKS5
</p>
</li>
<li>
<p>
You can input password from tty, <tt>ssh-askpass</tt> or environment variable.
</p>
</li>
<li>
<p>
Run on UNIX or Windows platform.
</p>
</li>
<li>
<p>
You can compile with various C compiler (cc, gcc, Visual C, Borland C. etc.)
</p>
</li>
<li>
<p>
Simple and general program independent from OpenSSH.
</p>
</li>
<li>
<p>
You can also relay local socket stream instead of standard I/O.
</p>
</li>
</ul></div>
<div class="paragraph"><p>You can download source code
(<a href="http://bitbucket.org/gotoh/connect/raw/tip/connect.c">connect.c</a>)
on the <a href="http://bitbucket.org/gotoh/connect/">project page</a>.</p></div>
<div class="paragraph"><p>Pre-compiled binary for MS Windows is also available on
<a href="http://bitbucket.org/gotoh/connect/downloads/">download page</a>.</p></div>
</div>
</div>
<h2 id="_what_is_proxy_command">What is proxy command?</h2>
<div class="sectionbody">
<div class="paragraph"><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: ProxyCommand option instead.</p></div>
<div class="paragraph"><p>Proxy command mechanism is delegation of network stream
communication. If ProxyCommand 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></div>
<div class="paragraph"><p>The <tt>connect.c</tt> program was made for this purpose.</p></div>
</div>
<h2 id="_how_to_use">How to Use</h2>
<div class="sectionbody">
<h3 id="_get_source">Get Source</h3><div style="clear:left"></div>
<div class="paragraph"><p>You can get source code from <a href="http://bitbucket.org/gotoh/connect/downloads/">project download page</a>.
Pre-compiled MS Windows binary is also available there.</p></div>
<h3 id="_compile_and_install">Compile and Install</h3><div style="clear:left"></div>
<div class="paragraph"><p>In most environment, you can compile <tt>connect.c</tt> 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></div>
<div class="dlist"><dl>
<dt class="hdlist1">
UNIX cc
</dt>
<dd>
<p>
<tt>cc connect.c -o connect</tt>
</p>
</dd>
<dt class="hdlist1">
UNIX gcc
</dt>
<dd>
<p>
<tt>gcc connect.c -o connect</tt>
</p>
</dd>
<dt class="hdlist1">
Solaris
</dt>
<dd>
<p>
<tt>gcc connect.c -o connect -lnsl -lsocket -lresolv</tt>
</p>
</dd>
<dt class="hdlist1">
Microsoft Visual C/C++
</dt>
<dd>
<p>
<tt>cl connect.c wsock32.lib advapi32.lib</tt>
</p>
</dd>
<dt class="hdlist1">
Borland C
</dt>
<dd>
<p>
<tt>bcc32 connect.c wsock32.lib advapi32.lib</tt>
</p>
</dd>
<dt class="hdlist1">
Cygwin gcc
</dt>
<dd>
<p>
<tt>gcc connect.c -o connect</tt>
</p>
</dd>
<dt class="hdlist1">
Mac OS/Darwin
</dt>
<dd>
<p>
<tt>gcc connect.c -o connect -lresolv</tt>
</p>
</dd>
</dl></div>
<div class="paragraph"><p>To install connect command, simply copy compiled binary to directory
in your <tt>PATH</tt> (ex. <tt>/usr/local/bin</tt>). Like this:</p></div>
<div class="listingblock">
<div class="content">
<pre><tt>$ cp connect /usr/local/bin</tt></pre>
</div></div>
<h3 id="_modify_your_tt_ssh_config_tt">Modify your <tt>~/.ssh/config</tt></h3><div style="clear:left"></div>
<div class="paragraph"><p>Modify your <tt>~/.ssh/config</tt> file to use connect command as proxy
command. For the case of SOCKS server is running on firewall host
socks.local.net with port 1080, you can add <tt>ProxyCommand</tt> option in
<tt>~/.ssh/config</tt>, like this:</p></div>
<div class="listingblock">
<div class="content">
<pre><tt>Host remote.outside.net
ProxyCommand connect -S socks.local.net %h %p</tt></pre>
</div></div>
<div class="paragraph"><p><tt>%h</tt> and <tt>%p</tt> will be replaced on invoking proxy command with target
hostname and port specified to SSH command.</p></div>
<div class="paragraph"><p>If you hate writing many entries of remote hosts, following example
may help you.</p></div>
<div class="listingblock">
<div class="content">
<pre><tt>## Outside of the firewall, use connect command with SOCKS conenction.
Host *
ProxyCommand connect -S socks.local.net %h %p
## Inside of the firewall, use connect command with direct connection.
Host *.local.net
ProxyCommand connect %h %p</tt></pre>
</div></div>
<div class="paragraph"><p>If you want to use http proxy, use <tt>-H</tt> option instead of <tt>-S</tt> option
in examle above, like this:</p></div>
<div class="listingblock">
<div class="content">
<pre><tt>## Outside of the firewall, with HTTP proxy
Host *
ProxyCommand connect -H proxy.local.net:8080 %h %p
## Inside of the firewall, direct
Host *.local.net
ProxyCommand connect %h %p</tt></pre>
</div></div>
<h3 id="_use_ssh">Use SSH</h3><div style="clear:left"></div>
<div class="paragraph"><p>After editing your <tt>~/.ssh/config</tt> 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 hostname command on
host <tt>remote.outside.net</tt>.</p></div>
<div class="listingblock">
<div class="content">
<pre><tt>local$ ssh remote.outside.net hostname
Hello, this is remote.outside.net
remote$</tt></pre>
</div></div>
<h3 id="_have_trouble">Have trouble?</h3><div style="clear:left"></div>
<div class="paragraph"><p>If you have trouble, execute connect command from command line with <tt>-d</tt>
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></div>
<div class="listingblock">
<div class="content">
<pre><tt>$ 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.20 $
DEBUG: connecting to xxx.xxx.xxx.xxx:1080
DEBUG: begin_socks_relay()
DEBUG: atomic_out() [4 bytes]
DEBUG: &gt;&gt;&gt; 05 02 00 02
DEBUG: atomic_in() [2 bytes]
DEBUG: &lt;&lt;&lt; 05 02
DEBUG: auth method: USERPASS
DEBUG: atomic_out() [some bytes]
DEBUG: &gt;&gt;&gt; xx xx xx xx ...
DEBUG: atomic_in() [2 bytes]
DEBUG: &lt;&lt;&lt; 01 01
ERROR: Authentication faield.
FATAL: failed to begin relaying via SOCKS.</tt></pre>
</div></div>
</div>
<h2 id="_more_detail">More Detail</h2>
<div class="sectionbody">
<div class="paragraph"><p>Command line usage is here:</p></div>
<div class="listingblock">
<div class="content">
<pre><tt>usage: connect [-dnhs45] [-R resolve] [-p local-port] [-w sec]
[-H [user@]proxy-server[:port]]
[-S [user@]socks-server[:port]]
host port</tt></pre>
</div></div>
<div class="paragraph"><p>host and port is target hostname and port-number to connect.</p></div>
<div class="dlist"><dl>
<dt class="hdlist1">
<tt>-H</tt> [user@]server[:port]
</dt>
<dd>
<p>
Specify hostname and port number of http proxy server to
relay. If port is omitted, 80 is used.
</p>
</dd>
<dt class="hdlist1">
<tt>-h</tt>
</dt>
<dd>
<p>
Use HTTP proxy via proxy server sepcified by environment variable
<tt>HTTP_PROXY</tt>.
</p>
</dd>
<dt class="hdlist1">
<tt>-S</tt> [_user_@]<em>server</em>\[:_port_]
</dt>
<dd>
<p>
Specify hostname and port number of SOCKS server to
relay. Like <tt>-H</tt> option, port number can be omit and default is 1080.
</p>
</dd>
<dt class="hdlist1">
<tt>-s</tt>
</dt>
<dd>
<p>
Use SOCKS proxy via SOCKS server sepcified by environment variable
<tt>SOCKS5_SERVER</tt>.
</p>
</dd>
<dt class="hdlist1">
<tt>-4</tt>
</dt>
<dd>
<p>
Use SOCKS version 4 protocol.
This option must be used with <tt>-S</tt>.
</p>
</dd>
<dt class="hdlist1">
<tt>-5</tt>
</dt>
<dd>
<p>
Use SOCKS version 5 protocol.
This option must be used with <tt>-S</tt>.
</p>
</dd>
<dt class="hdlist1">
<tt>-R</tt> <em>method</em>
</dt>
<dd>
<p>
The method to resolve hostname. 3 keywords (<tt>local</tt>,
<tt>remote</tt>, <tt>both</tt>) or dot-notation IP address is allowed. Keyword
both means; <em>"Try local first, then remote"</em>. If dot-notation IP
address is specified, use this host as nameserver (UNIX
only). Default is remote for SOCKS5 or local for others. On SOCKS4
protocol, remote resolving method (remote and both) use protocol
version 4a.
</p>
</dd>
<dt class="hdlist1">
<tt>-p</tt> <em>port</em>
</dt>
<dd>
<p>
Accept on local TCP port and relay it instead of standard input
and output. With this option, program will terminate when remote or
local TCP session is closed.
</p>
</dd>
<dt class="hdlist1">
<tt>-w</tt> <em>timeout</em>
</dt>
<dd>
<p>
Timeout seconds for connecting to remote host.
</p>
</dd>
<dt class="hdlist1">
<tt>-a</tt> <em>auth</em>
</dt>
<dd>
<p>
option specifiys user intended authentication methods
separated by comma. Currently <tt>userpass</tt> and <tt>none</tt> are
supported. Default is userpass. You can also specifying this parameter
by the environment variable <tt>SOCKS5_AUTH</tt>.
</p>
</dd>
</dl></div>
<div class="paragraph"><p><tt>-d</tt>: Run with debug message output. If you fail to connect, use this
option to see what is done.</p></div>
<div class="paragraph"><p>As additional feature,
you can omit port argument when program name is special format
containing port number itself like "connect-25". For example:</p></div>
<div class="listingblock">
<div class="content">
<pre><tt>$ 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
$</tt></pre>
</div></div>
<div class="paragraph"><p>This example means that the command name "connect-25" indicates port
number 25 so you can omit 2nd argument (and used if specified
explicitly).
This is usefull for the application which invokes only with hostname
argument.</p></div>
<h3 id="_specifying_user_name_via_environment_variables">Specifying user name via environment variables</h3><div style="clear:left"></div>
<div class="paragraph"><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></div>
<div class="dlist"><dl>
<dt class="hdlist1">
<tt>SOCKS5_USER</tt>
</dt>
<dd>
<p>
Used for SOCKS v5 access.
</p>
</dd>
<dt class="hdlist1">
<tt>SOCKS4_USER</tt>
</dt>
<dd>
<p>
Used for SOCKS v4 access.
</p>
</dd>
<dt class="hdlist1">
<tt>SOCKS_USER</tt>
</dt>
<dd>
<p>
Used for SOCKS v5 or v4 access and varaibles above are not defined.
</p>
</dd>
<dt class="hdlist1">
<tt>HTTP_PROXY_USER</tt>
</dt>
<dd>
<p>
Used for HTTP proxy access.
</p>
</dd>
<dt class="hdlist1">
<tt>CONNECT_USER</tt>
</dt>
<dd>
<p>
Used for all type of access if all above are not defined.
</p>
</dd>
</dl></div>
<div class="paragraph"><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></div>
<div class="tableblock">
<table rules="all"
width="50%"
frame="border"
cellspacing="0" cellpadding="4">
<col width="25%" />
<col width="25%" />
<col width="25%" />
<col width="25%" />
<tbody>
<tr>
<td align="left" valign="top"><p class="table"></p></td>
<td align="left" valign="top"><p class="table">SOCKS v5</p></td>
<td align="left" valign="top"><p class="table">SOCKS v4</p></td>
<td align="left" valign="top"><p class="table">HTTP proxy</p></td>
</tr>
<tr>
<td align="left" valign="top"><p class="table">1</p></td>
<td align="left" valign="top"><p class="table"><tt>SOCKS5_USER</tt></p></td>
<td align="left" valign="top"><p class="table"><tt>SOCKS4_USER</tt></p></td>
<td rowspan="2" align="center" valign="top"><p class="table"><tt>HTTP_PROXY_USER</tt></p></td>
</tr>
<tr>
<td align="left" valign="top"><p class="table">2</p></td>
<td colspan="2" align="center" valign="top"><p class="table"><tt>SOCKS_USER</tt></p></td>
</tr>
<tr>
<td align="left" valign="top"><p class="table">3</p></td>
<td colspan="3" align="center" valign="top"><p class="table"><tt>CONNECT_USER</tt></p></td>
</tr>
<tr>
<td align="left" valign="top"><p class="table">4</p></td>
<td colspan="3" align="center" valign="top"><p class="table">(query user name to system)</p></td>
</tr>
</tbody>
</table>
</div>
<h3 id="_specifying_password_via_environment_variables">Specifying password via environment variables</h3><div style="clear:left"></div>
<div class="paragraph"><p>There are 5 environemnt variables to specify password. If you use this
feature, please note that it is not secure way.</p></div>
<div class="dlist"><dl>
<dt class="hdlist1">
<tt>SOCKS5_PASSWD</tt>
</dt>
<dd>
<p>
Used for SOCKS v5 access. This variables is compatible with NEC SOCKS implementation.
</p>
</dd>
<dt class="hdlist1">
<tt>SOCKS5_PASSWORD</tt>
</dt>
<dd>
<p>
Used for SOCKS v5 access if <tt>SOCKS5_PASSWD</tt> is not defined.
</p>
</dd>
<dt class="hdlist1">
<tt>SOCKS_PASSWORD</tt>
</dt>
<dd>
<p>
Used for SOCKS v5 (or v4) access all above is not defined.
</p>
</dd>
<dt class="hdlist1">
<tt>HTTP_PROXY_PASSWORD</tt>
</dt>
<dd>
<p>
Used for HTTP proxy access.
</p>
</dd>
<dt class="hdlist1">
<tt>CONNECT_PASSWORD</tt>
</dt>
<dd>
<p>
Used for all type of access if all above are not defined.
</p>
</dd>
</dl></div>
<div class="paragraph"><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></div>
<div class="tableblock">
<table rules="all"
width="50%"
frame="border"
cellspacing="0" cellpadding="4">
<col width="33%" />
<col width="33%" />
<col width="33%" />
<tbody>
<tr>
<td align="left" valign="top"><p class="table"></p></td>
<td align="left" valign="top"><p class="table">SOCKS v5</p></td>
<td align="left" valign="top"><p class="table">HTTP proxy</p></td>
</tr>
<tr>
<td align="left" valign="top"><p class="table">1</p></td>
<td align="left" valign="top"><p class="table"><tt>SOCKS5_PASSWD</tt></p></td>
<td rowspan="2" align="center" valign="top"><p class="table"><tt>HTTP_PROXY_PASSWORD</tt></p></td>
</tr>
<tr>
<td align="left" valign="top"><p class="table">2</p></td>
<td align="left" valign="top"><p class="table"><tt>SOCKS_PASSWORD</tt></p></td>
</tr>
<tr>
<td align="left" valign="top"><p class="table">3</p></td>
<td colspan="2" align="center" valign="top"><p class="table"><tt>CONNECT_PASSWORD</tt></p></td>
</tr>
<tr>
<td align="left" valign="top"><p class="table">4</p></td>
<td colspan="2" align="center" valign="top"><p class="table">(ask to user interactively)</p></td>
</tr>
</tbody>
</table>
</div>
</div>
<h2 id="_limitations">Limitations</h2>
<div class="sectionbody">
<h3 id="_socks5_authentication">SOCKS5 authentication</h3><div style="clear:left"></div>
<div class="paragraph"><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></div>
<h3 id="_http_authentication">HTTP authentication</h3><div style="clear:left"></div>
<div class="paragraph"><p>BASIC authentication is supported but DIGEST authentication is not.</p></div>
<h3 id="_switching_proxy_server_on_event">Switching proxy server on event</h3><div style="clear:left"></div>
<div class="paragraph"><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></div>
<div class="paragraph"><p>One tricky workaround exists. It is replacing <tt>~/.ssh/config</tt> file by
script on ppp up/down.</p></div>
<div class="paragraph"><p>There&#8217;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 that you should modify
addresses if you use it.</p></div>
<div class="listingblock">
<div class="content">
<pre><tt>#!/bin/sh
## ~/bin/myconnect --- Proxy server switching wrapper
if ifconfig eth0 |grep "inet addr:192\.168\.1" &gt;/dev/null; then
opts="-S 192.168.1.1:1080"
elif ifconfig eth0 |grep "inet addr:10\." &gt;/dev/null; then
opts="-H 10.1.1.1:80"
else
opts="-s"
fi
exec /usr/local/bin/connect $opts $@</tt></pre>
</div></div>
</div>
<h2 id="_tips">Tips</h2>
<div class="sectionbody">
<h3 id="_proxying_socket_connection">Proxying socket connection</h3><div style="clear:left"></div>
<div class="paragraph"><p>In usual, <tt>connect.c</tt> relays network connection to/from standard
input/output. By specifying -p option, however, <tt>connect.c</tt> relays local
network stream instead of standard input/output. With this option,
connect command waits connection from other program, then start
relaying between both network stream.</p></div>
<div class="paragraph"><p>This feature may be useful for the program which is hard to SOCKSify.</p></div>
<h3 id="_use_with_ssh_askpass_command">Use with ssh-askpass command</h3><div style="clear:left"></div>
<div class="paragraph"><p><tt>connect.c</tt> 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 ssh-askpass 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 <tt>SSH_ASKPASS</tt> is
specified, then <tt>connect.c</tt> invoke command specified by environment
variable SSH_ASKPASS to input password. ssh-askpass program might be
installed if you are using OpenSSH on UNIX environment. On Windows
environment, pre-compiled binary is available from here.</p></div>
<div class="paragraph"><p>This feature is limited on window system environment.</p></div>
<div class="paragraph"><p>And also useful on Emacs on MS Windows (NT Emacs or Meadow). It is
hard to send passphrase to connect 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></div>
<h3 id="_use_for_network_stream_of_emacs">Use for Network Stream of Emacs</h3><div style="clear:left"></div>
<div class="paragraph"><p>Although <tt>connect.c</tt> 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></div>
<div class="paragraph"><p>There is sample code:
<a href="http://bitbucket.org/gotoh/connect/src/tip/relay.el">http://bitbucket.org/gotoh/connect/src/tip/relay.el</a></p></div>
<div class="paragraph"><p>With this code, you can use <tt>relay-open-network-stream</tt> function instead
of <tt>open-network-stream</tt> to make network connection. See top comments of
the source for more detail.</p></div>
<h3 id="_remote_resolver">Remote resolver</h3><div style="clear:left"></div>
<div class="paragraph"><p>If you are SOCKS4 user on UNIX environment, you might want specify
nameserver to resolve remote hostname. You can do it specifying <tt>-R</tt>
option followed by IP address of resolver.</p></div>
<h3 id="_hopping_connection_via_ssh">Hopping Connection via SSH</h3><div style="clear:left"></div>
<div class="paragraph"><p>Conbination of ssh and connect command have more interesting
usage. Following command makes indirect connection to host2:port from
your current host via host1.</p></div>
<div class="listingblock">
<div class="content">
<pre><tt>$ ssh host1 connect host2 port</tt></pre>
</div></div>
<div class="paragraph"><p>This method is useful for the situations like:</p></div>
<div class="ulist"><ul>
<li>
<p>
You are outside of organizasion now, but you want to access an
internal host barriered by firewall.
</p>
</li>
<li>
<p>
You want to use some service which is allowed only from some limited hosts.
</p>
</li>
</ul></div>
<div class="paragraph"><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></div>
<div class="listingblock">
<div class="content">
<pre><tt>$ ssh host1 connect news 119
200 news.my-office.com InterNetNews NNRP server INN 2.3.2 ready (posting ok).
quit
205 .
$</tt></pre>
</div></div>
<div class="paragraph"><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></div>
<div class="listingblock">
<div class="content">
<pre><tt> |
External (internet) | Internal (office)
|
+------+ +----------+ +-------+ +-----------+
| HOME | | firewall | | host1 | | NNTP host |
+------+ +----------+ +-------+ +-----------+
emacs &lt;-------------- ssh ---------------&gt; sshd &lt;-- connect --&gt; nntpd
&lt;-- connect --&gt; socksd &lt;-- SOCKS --&gt;</tt></pre>
</div></div>
<div class="paragraph"><p>As an advanced example, you can use SSH hopping as fetchmail&#8217;s plug-in
program to access via secure tunnel. This method requires that connect
program is insatalled on remote host. There&#8217;s example of .fetchmailrc
bellow. When fetchmail access to mail-server, you will login to remote
host using SSH then execute connect program on remote host to relay
conversation with pop server. Thus fetchmail can retrieve mails in
secure.</p></div>
<div class="listingblock">
<div class="content">
<pre><tt>poll mail-server
protocol pop3
plugin "ssh %h connect localhost %p"
username "username"
password "password"</tt></pre>
</div></div>
</div>
<h2 id="_break_the_more_restricted_wall">Break The More Restricted Wall</h2>
<div class="sectionbody">
<div class="paragraph"><p>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:</p></div>
<div class="listingblock">
<div class="content">
<pre><tt>internal$ cat ~/.ssh/config
Host home
ProxyCommand connect -H firewall:8080 %h 443
Host server # internal
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$</tt></pre>
</div></div>
<div class="paragraph"><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></div>
<div class="listingblock">
<div class="content">
<pre><tt> |
Internal (office) | External (internet)
|
+--------+ +----------+ +------+ +--------+
| office | | firewall | | home | | server |
+--------+ +----------+ +------+ +--------+
&lt;------------------ ssh ---------------------&gt;sshd:443
&lt;-- connect --&gt; http-proxy &lt;-- https:443 --&gt; any
connect &lt;-- tcp --&gt; port</tt></pre>
</div></div>
<div class="admonitionblock">
<table><tr>
<td class="icon">
<div class="title">Note</div>
</td>
<td class="content">If you wanna use this, you should give up hosting https
service at port 443 on you external host <em>home</em>.</td>
</tr></table>
</div>
</div>
<h2 id="_f_y_i">F.Y.I.</h2>
<div class="sectionbody">
<h3 id="_difference_between_socks_versions">Difference between SOCKS versions</h3><div style="clear:left"></div>
<div class="paragraph"><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></div>
<div class="paragraph"><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&#8217;s some improvement: IPv6 support, request by
hostname, UDP proxying, etc.</p></div>
<h3 id="_configuration_to_use_https">Configuration to use HTTPS</h3><div style="clear:left"></div>
<div class="paragraph"><p>Many http proxy servers implementation supports https CONNECT 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 https to REMITTABLE parameter to allow HTTP-Proxy like
this:</p></div>
<div class="listingblock">
<div class="content">
<pre><tt>delegated -Pxxxx ...... REMITTABLE='+,https' ...</tt></pre>
</div></div>
<div class="paragraph"><p>For the case of Squid, you should allow target ports via https by ACL,
and so on.</p></div>
<h3 id="_socks5_servers">SOCKS5 Servers</h3><div style="clear:left"></div>
<div class="dlist"><dl>
<dt class="hdlist1">
<a href="http://www.socks.nec.com/refsoftware.html">NEC SOCKS Reference Implementation</a>
</dt>
<dd>
<p>
Reference implementation of SOKCS server and library.
</p>
</dd>
<dt class="hdlist1">
<a href="http://www.inet.no/dante/index.html">Dante</a>
</dt>
<dd>
<p>
Dante is free implementation of SOKCS server and library. Many
enhancements and modulalized.
</p>
</dd>
<dt class="hdlist1">
<a href="http://www.delegate.org/delegate/">DeleGate</a>
</dt>
<dd>
<p>
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.
</p>
</dd>
</dl></div>
<h3 id="_specifications">Specifications</h3><div style="clear:left"></div>
<div class="dlist"><dl>
<dt class="hdlist1">
<a href="http://www.socks.nec.com/protocol/socks4.protocol">socks4.protocol.txt</a>
</dt>
<dd>
<p>
SOCKS: A protocol for TCP proxy across firewalls
</p>
</dd>
<dt class="hdlist1">
<a href="http://www.socks.nec.com/protocol/socks4a.protocol">socks4a.protocol.txt</a>
</dt>
<dd>
<p>
SOCKS 4A: A Simple Extension to SOCKS 4 Protocol
</p>
</dd>
<dt class="hdlist1">
<a href="http://www.socks.nec.com/rfc/rfc1928.txt">RFC 1928</a>
</dt>
<dd>
<p>
SOCKS Protocol Version 5
</p>
</dd>
<dt class="hdlist1">
<a href="http://www.socks.nec.com/rfc/rfc1929.txt">RFC 1929</a>
</dt>
<dd>
<p>
Username/Password Authentication for SOCKS V5
</p>
</dd>
<dt class="hdlist1">
<a href="http://www.ietf.org/rfc/rfc2616.txt">RFC 2616</a>
</dt>
<dd>
<p>
Hypertext Transfer Protocol&#8201;&#8212;&#8201;HTTP/1.1
</p>
</dd>
<dt class="hdlist1">
<a href="http://www.ietf.org/rfc/rfc2617.txt">RFC 2617</a>
</dt>
<dd>
<p>
HTTP Authentication: Basic and Digest Access Authentication
</p>
</dd>
</dl></div>
<h3 id="_related_links">Related Links</h3><div style="clear:left"></div>
<div class="ulist"><ul>
<li>
<p>
<a href="http://www.openssh.org/">OpenSSH Home</a>
</p>
</li>
<li>
<p>
<a href="http://www.ssh.com/">Proprietary SSH</a>
</p>
</li>
<li>
<p>
<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)
</p>
</li>
</ul></div>
<h3 id="_similars">Similars</h3><div style="clear:left"></div>
<div class="dlist"><dl>
<dt class="hdlist1">
<a href="http://proxytunnel.sourceforge.net/">Proxy Tunnel</a>
</dt>
<dd>
<p>
Proxying command using https CONNECT.
</p>
</dd>
<dt class="hdlist1">
<a href="http://www.snurgle.org/~griffon/ssh-https-tunnel">stunnel</a>
</dt>
<dd>
<p>
Proxy through an https tunnel (Perl script)
</p>
</dd>
</dl></div>
</div>
</div>
<div id="footnotes"><hr /></div>
<div id="footer">
<div id="footer-text">
Last updated 2009-12-17 21:28:59 JST
</div>
</div>
</body>
</html>