<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div dir="ltr"><div>Hi Haxxpop,</div><div><br></div></div><div dir="ltr">On 15 Aug 2019, at 16:53, Pop Chunhapanya <<a href="mailto:pop@cloudflare.com">pop@cloudflare.com</a>> wrote:<br><br></div><blockquote type="cite"><div dir="ltr"><div dir="ltr"><div dir="ltr"><br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="auto"><blockquote type="cite"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div>So I'm thinking putting the tor daemon behind some third party TCP proxy that will protect me from this kind of DDoS attack.</div><div><br></div><div>What
 do you think if I want to implement a feature that forward all the 
onion service traffic to the TCP proxy before going to the Tor network?</div><div><br></div><div>The protocol that I'm thinking is TCP Proxy Protocol [1]</div><div><br></div><div>[1] <a href="https://www.haproxy.org/download/1.8/doc/proxy-protocol.txt" target="_blank">https://www.haproxy.org/download/1.8/doc/proxy-protocol.txt</a></div></div></div></div></blockquote><br><div>You could try the existing HTTPSProxy torrc option?</div><div><br></div><div><dl><dt class="gmail-m_-2116091595766822615hdlist1" style="margin:0px 0px 10px;padding:0px;border:0px none;outline:currentcolor none 0px;font-weight:bold;vertical-align:baseline;line-height:28px"><span style="background-color:rgba(255,255,255,0)"><b style="margin:0px;padding:0px;border:0px none;outline:currentcolor none 0px;font-style:inherit;vertical-align:baseline">HTTPSProxy</b> <span style="margin:0px;padding:0px;border:0px none;outline:currentcolor none 0px;font-weight:inherit;font-style:italic;vertical-align:baseline">host</span>[:<span style="margin:0px;padding:0px;border:0px none;outline:currentcolor none 0px;font-weight:inherit;font-style:italic;vertical-align:baseline">port</span>]</span></dt><dd style="margin:0px 0px 18px;padding:0px;border:0px none;outline:currentcolor none 0px;vertical-align:baseline;line-height:20px"><p style="margin:0px 0px 18px;padding:0px;border:0px none;outline:currentcolor none 0px;font-style:inherit;vertical-align:baseline;line-height:20px"><span style="background-color:rgba(255,255,255,0)">Tor will make all its OR (SSL) connections through this host:port (or host:443 if port is not specified), via HTTP CONNECT rather than connecting directly to servers. You may want to set <b style="margin:0px;padding:0px;border:0px none;outline:currentcolor none 0px;font-style:inherit;vertical-align:baseline">FascistFirewall</b> to restrict the set of ports you might try to connect to, if your HTTPS proxy only allows connecting to certain ports.</span></p><p style="margin:0px 0px 18px;padding:0px;border:0px none;outline:currentcolor none 0px;font-style:inherit;vertical-align:baseline;line-height:20px"><span style="background-color:rgba(255,255,255,0)"><br></span></p><p style="margin:0px 0px 18px;padding:0px;border:0px none;outline:currentcolor none 0px;font-style:inherit;vertical-align:baseline;line-height:20px">Tor also allows an intelligent firewall to filter circuits using a field in haproxy protocol format, see <b style="margin:0px;padding:0px;border:0px none;outline:currentcolor none 0px;vertical-align:baseline;background-color:rgba(255,255,255,0)">HiddenServiceExportCircuitID</b><span style="background-color:rgba(255,255,255,0)"> for details. But you probably won't need this advanced feature.</span></p></dd></dl></div></div></blockquote><div><br></div><div>I feel that HTTPSProxy is too expensive. As far as I know, it needs to do (1) tcp handshake, (2) tls handshake, and (3) http connect. If I can use haproxy, it would be just one tcp handshake.</div><div><br></div><div>Could I propose another option for haproxy?</div><div>I can do it myself. You just review and merge :)</div></div></div></div></blockquote><br><div>Sure, I suggest you use this torrc option format:</div><div><br></div><div><p style="margin: 0px; font-stretch: normal; font-size: 12px; line-height: normal; font-family: Helvetica;"><span style="font-size: 12pt;">TCPProxy protocol host:port</span></p><p style="margin: 0px; font-stretch: normal; font-size: 12px; line-height: normal; font-family: Helvetica;"><span style="font-size: 12pt;"><br></span></p><p style="margin: 0px; font-stretch: normal; font-size: 12px; line-height: normal; font-family: Helvetica;"><span style="font-size: 12pt;">Tor will use the given protocol to make all its OR (SSL) connections through a TCP proxy on host:port, rather than connecting directly to servers. You may want to set FascistFirewall to restrict the set of ports you might try to connect to, if your proxy only allows connecting to certain ports. There is no equivalent option for directory connections, because all Tor client versions that support this option download directory documents via OR connections.</span></p><p style="margin: 0px; font-stretch: normal; font-size: 12px; line-height: normal; font-family: Helvetica;"><span style="font-size: 12pt;"><br></span></p><p style="margin: 0px; font-stretch: normal; font-size: 12px; line-height: normal; font-family: Helvetica;"><span style="font-size: 12pt;">The only protocol supported right now 'haproxy'. This option is only for clients. (Default: none)</span></p><p style="margin: 0px; font-stretch: normal; font-size: 12px; line-height: normal; font-family: Helvetica;"><span style="font-size: 12pt;"><br></span></p><p style="margin: 0px; font-stretch: normal; font-size: 12px; line-height: normal; font-family: Helvetica;"><span style="font-size: 12pt;">The haproxy protocol works in the following way: when the feature is enabled, the Tor process will write a header line on every outbound connection. The header is in the following format:</span></p><p style="margin: 0px; font-stretch: normal; font-size: 12px; line-height: normal; font-family: Helvetica;"><span style="font-size: 12pt;">   "PROXY" [ "TCP4" | "TCP6" ] SourceIPAddress DestinationIPAddress SourcePort DestinationPort "\r\n"</span></p><p style="margin: 0px; font-stretch: normal; font-size: 12px; line-height: normal; font-family: Helvetica;"><span style="font-size: 12pt;">There is a single space after each item, except for the last item, which is followed by a CRLF.</span></p><p style="margin: 0px; font-stretch: normal; font-size: 12px; line-height: normal; font-family: Helvetica;"><span style="font-size: 12pt;"><br></span></p><p style="margin: 0px; font-stretch: normal; font-size: 12px; line-height: normal; font-family: Helvetica;"><span style="font-size: 12pt;">After parsing a correctly-formatted PROXY line, the haproxy connects to DestinationIPAddress:DestinationPort, and forwards all subsequent data to the destination. Any data sent by the destination is forwarded by haproxy to the Tor client.</span></p><p style="margin: 0px; font-stretch: normal; font-size: 12px; line-height: normal; font-family: Helvetica;"><span style="font-size: 12pt;"><br></span></p><p style="margin: 0px; font-stretch: normal; font-size: 12px; line-height: normal; font-family: Helvetica;"><span style="font-size: 12pt;">The HAProxy version 1 proxy protocol is described in detail at <a href="https://www.haproxy.org/download/1.8/doc/proxy-protocol.txt">https://www.haproxy.org/download/1.8/doc/proxy-protocol.txt</a></span></p></div><div><br></div><div><p style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Helvetica;"><span style="font-size: 16px;">I don't think you'll need to implement a TCPProxyAuthenticator option.</span></p><p style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Helvetica;"><span style="font-size: 16px;"><br></span></p><p style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Helvetica;"><span style="font-size: 16px;">T</span></p></div></body></html>