180-pluggable-transport.txt 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551
  1. Filename: 180-pluggable-transport.txt
  2. Title: Pluggable transports for circumvention
  3. Author: Jacob Appelbaum, Nick Mathewson
  4. Created: 15-Oct-2010
  5. Status: Closed
  6. Implemented-In: 0.2.3.x
  7. Overview
  8. This proposal describes a way to decouple protocol-level obfuscation
  9. from the core Tor protocol in order to better resist client-bridge
  10. censorship. Our approach is to specify a means to add pluggable
  11. transport implementations to Tor clients and bridges so that they can
  12. negotiate a superencipherment for the Tor protocol.
  13. Scope
  14. This is a document about transport plugins; it does not cover
  15. discovery improvements, or bridgedb improvements. While these
  16. requirements might be solved by a program that also functions as a
  17. transport plugin, this proposal only covers the requirements and
  18. operation of transport plugins.
  19. Motivation
  20. Frequently, people want to try a novel circumvention method to help
  21. users connect to Tor bridges. Some of these methods are already
  22. pretty easy to deploy: if the user knows an unblocked VPN or open
  23. SOCKS proxy, they can just use that with the Tor client today.
  24. Less easy to deploy are methods that require participation by both the
  25. client and the bridge. In order of increasing sophistication, we
  26. might want to support:
  27. 1. A protocol obfuscation tool that transforms the output of a TLS
  28. connection into something that looks like HTTP as it leaves the
  29. client, and back to TLS as it arrives at the bridge.
  30. 2. An additional authentication step that a client would need to
  31. perform for a given bridge before being allowed to connect.
  32. 3. An information passing system that uses a side-channel in some
  33. existing protocol to convey traffic between a client and a bridge
  34. without the two of them ever communicating directly.
  35. 4. A set of clients to tunnel client->bridge traffic over an existing
  36. large p2p network, such that the bridge is known by an identifier
  37. in that network rather than by an IP address.
  38. We could in theory support these almost fine with Tor as it stands
  39. today: every Tor client can take a SOCKS proxy to use for its outgoing
  40. traffic, so a suitable client proxy could handle the client's traffic
  41. and connections on its behalf, while a corresponding program on the
  42. bridge side could handle the bridge's side of the protocol
  43. transformation. Nevertheless, there are some reasons to add support
  44. for transportation plugins to Tor itself:
  45. 1. It would be good for bridges to have a standard way to advertise
  46. which transports they support, so that clients can have multiple
  47. local transport proxies, and automatically use the right one for
  48. the right bridge.
  49. 2. There are some changes to our architecture that we'll need for a
  50. system like this to work. For testing purposes, if a bridge blocks
  51. off its regular ORPort and instead has an obfuscated ORPort, the
  52. bridge authority has no way to test it. Also, unless the bridge
  53. has some way to tell that the bridge-side proxy at 127.0.0.1 is not
  54. the origin of all the connections it is relaying, it might decide
  55. that there are too many connections from 127.0.0.1, and start
  56. paring them down to avoid a DoS.
  57. 3. Censorship and anticensorship techniques often evolve faster than
  58. the typical Tor release cycle. As such, it's a good idea to
  59. provide ways to test out new anticensorship mechanisms on a more
  60. rapid basis.
  61. 4. Transport obfuscation is a relatively distinct problem
  62. from the other privacy problems that Tor tries to solve, and it
  63. requires a fairly distinct skill-set from hacking the rest of Tor.
  64. By decoupling transport obfuscation from the Tor core, we hope to
  65. encourage people working on transport obfuscation who would
  66. otherwise not be interested in hacking Tor.
  67. 5. Finally, we hope that defining a generic transport obfuscation plugin
  68. mechanism will be useful to other anticensorship projects.
  69. Non-Goals
  70. We're not going to talk about automatic verification of plugin
  71. correctness and safety via sandboxing, proof-carrying code, or
  72. whatever.
  73. We need to do more with discovery and distribution, but that's not
  74. what this proposal is about. We're pretty convinced that the problems
  75. are sufficiently orthogonal that we should be fine so long as we don't
  76. preclude a single program from implementing both transport and
  77. discovery extensions.
  78. This proposal is not about what transport plugins are the best ones
  79. for people to write. We do, however, make some general
  80. recommendations for plugin authors in an appendix.
  81. We've considered issues involved with completely replacing Tor's TLS
  82. with another encryption layer, rather than layering it inside the
  83. obfuscation layer. We describe how to do this in an appendix to the
  84. current proposal, though we are not currently sure whether it's a good
  85. idea to implement.
  86. We deliberately reject any design that would involve linking the
  87. transport plugins into Tor's process space.
  88. Design overview
  89. To write a new transport protocol, an implementer must provide two
  90. pieces: a "Client Proxy" to run at the initiator side, and a "Server
  91. Proxy" to run at the server side. These two pieces may or may not be
  92. implemented by the same program.
  93. Each client may run any number of Client Proxies. Each one acts like
  94. a SOCKS proxy that accepts connections on localhost. Each one
  95. runs on a different port, and implements one or more transport
  96. methods. If the protocol has any parameters, they are passed from Tor
  97. inside the regular username/password parts of the SOCKS protocol.
  98. Bridges (and maybe relays) may run any number of Server Proxies: these
  99. programs provide an interface like stunnel: they get connections from the
  100. network (typically by listening for connections on the network) and relay
  101. them to the Bridge's real ORPort.
  102. To configure one of these programs, it should be sufficient simply to
  103. list it in your torrc. The program tells Tor which transports it
  104. provides. The Tor consensus should carry a new approved version number that
  105. is specific for pluggable transport; this will allow Tor to know when a
  106. particular transport is known to be unsafe, safe, or non-functional.
  107. Bridges (and maybe relays) report in their descriptors which transport
  108. protocols they support. This information can be copied into bridge
  109. lines. Bridges using a transport protocol may have multiple bridge
  110. lines.
  111. Any methods that are wildly successful, we can bake into Tor.
  112. Specifications: Client behavior
  113. We extend the bridge line format to allow you to say which method
  114. to use to connect to a bridge.
  115. The new format is:
  116. Bridge method address:port [[keyid=]id-fingerprint] [k=v] [k=v] [k=v]
  117. To connect to such a bridge, the Tor program needs to know which
  118. SOCKS proxy will support the transport called "method". It
  119. then connects to this proxy, and asks it to connect to
  120. address:port. If [id-fingerprint] is provided, Tor should expect
  121. the public identity key on the TLS connection to match the digest
  122. provided in [id-fingerprint]. If any [k=v] items are provided,
  123. they are configuration parameters for the proxy: Tor should
  124. separate them with semicolons and put them in the user and
  125. password fields of the request, splitting them across the fields
  126. as necessary. If a key or value value must contain a semicolon or
  127. a backslash, it is escaped with a backslash.
  128. Method names must be C identifiers.
  129. For reference, the old bridge format was
  130. Bridge address[:port] [id-fingerprint]
  131. where port defaults to 443 and the id-fingerprint is optional. The
  132. new format can be distinguished from the old one by checking if the
  133. first argument has any non-C-identifier characters. (Looking for a
  134. period should be a simple way.) Also, while the id-fingerprint could
  135. optionally include whitespace in the old format, whitespace in the
  136. id-fingerprint is not permitted in the new format.
  137. Example: if the bridge line is "bridge trebuchet www.example.com:3333
  138. keyid=09F911029D74E35BD84156C5635688C009F909F9 rocks=20 height=5.6m"
  139. AND if the Tor client knows that the 'trebuchet' method is supported,
  140. the client should connect to the proxy that provides the 'trebuchet'
  141. method, ask it to connect to www.example.com, and provide the string
  142. "rocks=20;height=5.6m" as the username, the password, or split
  143. across the username and password.
  144. There are two ways to tell Tor clients about protocol proxies:
  145. external proxies and managed proxies. An external proxy is configured
  146. with
  147. ClientTransportPlugin <method> socks4 <address:port> [auth=X]
  148. or
  149. ClientTransportPlugin <method> socks5 <address:port> [username=X] [password=Y]
  150. as in
  151. "ClientTransportPlugin trebuchet socks5 127.0.0.1:9999".
  152. This example tells Tor that another program is already running to handle
  153. 'trubuchet' connections, and Tor doesn't need to worry about it.
  154. A managed proxy is configured with
  155. ClientTransportPlugin <methods> exec <path> [options]
  156. as in
  157. "ClientTransportPlugin trebuchet exec /usr/libexec/trebuchet --managed".
  158. This example tells Tor to launch an external program to provide a
  159. socks proxy for 'trebuchet' connections. The Tor client only
  160. launches one instance of each external program with a given set of
  161. options, even if the same executable and options are listed for
  162. more than one method.
  163. In managed proxies, <methods> can be a comma-separated list of
  164. pluggable transport method names, as in:
  165. "ClientTransportPlugin pawn,bishop,rook exec /bin/ptproxy --managed".
  166. If instead of a transport method, the torrc lists "*" for a managed
  167. proxy, Tor uses that proxy for all transport methods that the plugin
  168. supports. So "ClientTransportPlugin * exec /usr/libexec/tor/foobar"
  169. tells Tor that Tor should use the foobar plugin for every method that
  170. the proxy supports. See the "Managed proxy interface" section below
  171. for details on how Tor learns which methods a plugin supports.
  172. If two plugins support the same method, Tor should use whichever
  173. one is listed first.
  174. The same program can implement a managed or an external proxy: it just
  175. needs to take an argument saying which one to be.
  176. Server behavior
  177. Server proxies are configured similarly to client proxies. When
  178. launching a proxy, the server must tell it what ORPort it has
  179. configured, and what address (if any) it can listen on. The
  180. server must tell the proxy which (if any) methods it should
  181. provide if it can; the proxy needs to tell the server which
  182. methods it is actually providing, and on what ports.
  183. When a client connects to the proxy, the proxy may need a way to
  184. tell the server some identifier for the client address. It does
  185. this in-band.
  186. As before, the server lists proxies in its torrc. These can be
  187. external proxies that run on their own, or managed proxies that Tor
  188. launches.
  189. An external server proxy is configured as
  190. ServerTransportPlugin <method> proxy <address:port> <param=val> ...
  191. as in
  192. "ServerTransportPlugin trebuchet proxy 127.0.0.1:999 rocks=heavy".
  193. The param=val pairs and the address are used to make the bridge
  194. configuration information that we'll tell users.
  195. A managed proxy is configured as
  196. ServerTransportPlugin <methods> exec </path/to/binary> [options]
  197. or
  198. ServerTransportPlugin * exec </path/to/binary> [options]
  199. When possible, Tor should launch only one binary of each binary/option
  200. pair configured. So if the torrc contains
  201. ClientTransportPlugin foo exec /usr/bin/megaproxy --foo
  202. ClientTransportPlugin bar exec /usr/bin/megaproxy --bar
  203. ServerTransportPlugin * exec /usr/bin/megaproxy --foo
  204. then Tor will launch the megaproxy binary twice: once with the option
  205. --foo and once with the option --bar.
  206. Managed proxy interface
  207. When the Tor client or relay launches a managed proxy, it communicates
  208. via environment variables. At a minimum, it sets (in addition to the
  209. normal environment variables inherited from Tor):
  210. {Client and server}
  211. "TOR_PT_STATE_LOCATION" -- A filesystem directory path where the
  212. proxy should store state if it wants to. This directory is not
  213. required to exist, but the proxy SHOULD be able to create it if
  214. it doesn't. The proxy MUST NOT store state elsewhere.
  215. Example: TOR_PT_STATE_LOCATION=/var/lib/tor/pt_state/
  216. "TOR_PT_MANAGED_TRANSPORT_VER" -- To tell the proxy which
  217. versions of this configuration protocol Tor supports. Future
  218. versions will give a comma-separated list. Clients MUST accept
  219. comma-separated lists containing any version that they
  220. recognize, and MUST work correctly even if some of the versions
  221. they don't recognize are non-numeric. Valid version characters
  222. are non-space, non-comma printing ASCII characters.
  223. Example: TOR_PT_MANAGED_TRANSPORT_VER=1,1a,2,4B
  224. {Client only}
  225. "TOR_PT_CLIENT_TRANSPORTS" -- A comma-separated list of which
  226. methods this client should enable, or * if all methods should
  227. be enabled. The proxy SHOULD ignore methods that it doesn't
  228. recognize.
  229. Example: TOR_PT_CLIENT_TRANSPORTS=trebuchet,battering_ram,ballista
  230. {Server only}
  231. "TOR_PT_EXTENDED_SERVER_PORT" -- An <address>:<port> where tor
  232. should be listening for connections speaking the extended
  233. ORPort protocol (See the "The extended ORPort protocol" section
  234. below). If tor does not support the extended ORPort protocol,
  235. it MUST use the empty string as the value of this environment
  236. variable.
  237. Example: TOR_PT_EXTENDED_SERVER_PORT=127.0.0.1:4200
  238. "TOR_PT_ORPORT" -- Our regular ORPort in a form suitable
  239. for local connections, i.e. connections from the proxy to
  240. the ORPort.
  241. Example: TOR_PT_ORPORT=127.0.0.1:9001
  242. "TOR_PT_SERVER_BINDADDR" -- A comma seperated list of
  243. <key>-<value> pairs, where <key> is a transport name and
  244. <value> is the adress:port on which it should listen for client
  245. proxy connections.
  246. The keys holding transport names must appear on the same order
  247. as they appear on TOR_PT_SERVER_TRANSPORTS.
  248. This might be the advertised address, or might be a local
  249. address that Tor will forward ports to. It MUST be an address
  250. that will work with bind().
  251. Example:
  252. TOR_PT_SERVER_BINDADDR=trebuchet-127.0.0.1:1984,ballista-127.0.0.1:4891
  253. "TOR_PT_SERVER_TRANSPORTS" -- A comma-separated list of server
  254. methods that the proxy should support, or * if all methods
  255. should be enabled. The proxy SHOULD ignore methods that it
  256. doesn't recognize.
  257. Example: TOR_PT_SERVER_TRANSPORTS=trebuchet,ballista
  258. The transport proxy replies by writing NL-terminated lines to
  259. stdout. The line metaformat is
  260. <Line> ::= <Keyword> <OptArgs> <NL>
  261. <Keyword> ::= <KeywordChar> | <Keyword> <KeywordChar>
  262. <KeyWordChar> ::= <any US-ASCII alphanumeric, dash, and underscore>
  263. <OptArgs> ::= <Args>*
  264. <Args> ::= <SP> <ArgChar> | <Args> <ArgChar>
  265. <ArgChar> ::= <any US-ASCII character but NUL or NL>
  266. <SP> ::= <US-ASCII whitespace symbol (32)>
  267. <NL> ::= <US-ASCII newline (line feed) character (10)>
  268. Tor MUST ignore lines with keywords that it doesn't recognize.
  269. First, if there's an error parsing the environment variables, the
  270. proxy should write:
  271. ENV-ERROR <errormessage>
  272. and exit.
  273. If the environment variables were correctly formatted, the proxy
  274. should write:
  275. VERSION <configuration protocol version>
  276. to say that it supports this configuration protocol version (example
  277. "VERSION 1"). It must either pick a version that Tor told it about
  278. in TOR_PT_MANAGED_TRANSPORT_VER, or pick no version at all, say:
  279. VERSION-ERROR no-version
  280. and exit.
  281. The proxy should then open its ports. If running as a client
  282. proxy, it should not use fixed ports; instead it should autoselect
  283. ports to avoid conflicts. A client proxy should by default only
  284. listen on localhost for connections.
  285. A server proxy SHOULD try to listen at a consistent port, though it
  286. SHOULD pick a different one if the port it last used is now allocated.
  287. A client or server proxy then should tell which methods it has
  288. made available and how. It does this by printing zero or more
  289. CMETHOD and SMETHOD lines to its stdout. These lines look like:
  290. CMETHOD <methodname> socks4/socks5 <address:port> [ARGS=arglist] \
  291. [OPT-ARGS=arglist]
  292. as in
  293. CMETHOD trebuchet socks5 127.0.0.1:19999 ARGS=rocks,height \
  294. OPT-ARGS=tensile-strength
  295. The ARGS field lists mandatory parameters that must appear in
  296. every bridge line for this method. The OPT-ARGS field lists
  297. optional parameters. If no ARGS or OPT-ARGS field is provided,
  298. Tor should not check the parameters in bridge lines for this
  299. method.
  300. The proxy should print a single "CMETHODS DONE" line after it is
  301. finished telling Tor about the client methods it provides. If it
  302. tries to supply a client method but can't for some reason, it
  303. should say:
  304. CMETHOD-ERROR <methodname> <errormessage>
  305. A proxy should also tell Tor about the server methods it is providing
  306. by printing zero or more SMETHOD lines. These lines look like:
  307. SMETHOD <methodname> <address:port> [options]
  308. If there's an error setting up a configured server method, the
  309. proxy should say:
  310. SMETHOD-ERROR <methodname> <errormessage>
  311. as in
  312. SMETHOD-ERROR trebuchet could not setup 'trebuchet' method
  313. The 'address:port' part of an SMETHOD line is the address to put
  314. in the bridge line. The Options part is a list of space-separated
  315. K:V flags that Tor should know about. Recognized options are:
  316. - FORWARD:1
  317. If this option is set (for example, because address:port is not
  318. a publicly accessible address), then Tor needs to forward some
  319. other address:port to address:port via upnp-helper. Tor would
  320. then advertise that other address:port in the bridge line instead.
  321. - ARGS:K=V,K=V,K=V
  322. If this option is set, the K=V arguments are added to Tor's
  323. extrainfo document.
  324. - DECLARE:K=V,...
  325. If this option is set, the K=V options should be added as
  326. extension entries to the router descriptor, so clients and other
  327. relays can make use of it. See ideas/xxx-triangleboy-transport.txt
  328. for an example situation where the plugin would want to declare
  329. parameters to other Tors.
  330. - USE-EXTENDED-PORT:1
  331. If this option is set, the server plugin is planning to connect
  332. to Tor's extended server port.
  333. SMETHOD and CMETHOD lines may be interspersed, to allow the proxies to
  334. report methods as they become available, even when some methods may
  335. require probing your network, connecting to some kind of peers, etc
  336. before they are set up. After the final SMETHOD line, the proxy says
  337. "SMETHODS DONE".
  338. The proxy SHOULD NOT tell Tor about a server or client method
  339. unless it is actually open and ready to use.
  340. Tor clients SHOULD NOT use any method from a client proxy or
  341. advertise any method from a server proxy UNLESS it is listed as a
  342. possible method for that proxy in torrc, and it is listed by the
  343. proxy as a method it supports.
  344. Proxies should respond to a single INT signal by closing their
  345. listener ports and not accepting any new connections, but keeping
  346. all connections open, then terminating when connections are all
  347. closed. Proxies should respond to a second INT signal by shutting
  348. down cleanly.
  349. The managed proxy configuration protocol version defined in this
  350. section is "1".
  351. So, for example, if tor supports this configuration protocol it
  352. should set the environment variable:
  353. TOR_PT_MANAGED_TRANSPORT_VER=1
  354. The Extended ORPort protocol
  355. The Extended ORPort protocol is described in proposal 196.
  356. Advertising bridge methods
  357. Bridges put the 'method' lines in their extra-info documents.
  358. transport SP <transportname> SP <address:port> [SP arglist] NL
  359. The address:port are as returned from an SMETHOD line (unless they are
  360. replaced by the FORWARD: directive). The arglist is a K=V,... list as
  361. returned in the ARGS: part of the SMETHOD line's Options component.
  362. If the SMETHOD line includes a DECLARE: part, the router descriptor gets
  363. a new line:
  364. transport-info SP <transportname> [SP arglist] NL
  365. Bridge authority behavior
  366. We need to specify a way to test different transport methods that
  367. bridges claim to support. We should test as many as possible. We
  368. should NOT require that we have a way to test every possible
  369. transport method before we allow its use: the point of this design
  370. is to remove bottlenecks in transport deployment.
  371. Bridgedb behavior
  372. Bridgedb can, given a set of router descriptors and their
  373. corresponding extrainfo documents, generate a set of bridge lines
  374. for each bridge. Bridgedb may want to avoid handing out
  375. methods that seem to get bridges blocked quickly.
  376. Implementation plan
  377. First, we should implement per-bridge proxies via the "external
  378. proxy" method described in "Specifications: Client behavior". Also,
  379. we'll want to build the
  380. extended-server-port mechanism. This will let bridges run
  381. transport proxies such that they can generate bridge lines to
  382. give to clients for testing, so long as the user configures and
  383. launches their proxies on their own.
  384. Once that's done, we can see if we need any managed proxies, or if
  385. the whole idea there is silly.
  386. If we do, the next most important part seems to be getting
  387. the client-side automation part written. And once that's done, we
  388. can evaluate how much of the server side is easy for people to do
  389. and how much is hard.
  390. The "obfsproxy" obfuscating proxy is a likely candidate for an
  391. initial transport (trac entry #2760), as is Steven Murdoch's http
  392. thing (trac entry #2759) or something similar.
  393. Notes on plugins to write
  394. We should ship a couple of null plugin implementations in one or two
  395. popular, portable languages so that people get an idea of how to
  396. write the stuff.
  397. 1. We should have one that's just a proof of concept that does
  398. nothing but transfer bytes back and forth.
  399. 2. We should implement DNS or HTTP using other software (as Geoff Goodell
  400. did years ago with DNS) as an example of wrapping existing code into
  401. our plugin model.
  402. 3. The obfuscated-ssh superencipherment is pretty trivial and pretty
  403. useful. It makes the protocol stringwise unfingerprintable.
  404. 4. If we do a raw-traffic proxy, openssh tunnels would be the logical
  405. choice.
  406. Appendix: recommendations for transports
  407. Be free/open-source software. Also, if you think your code might
  408. someday do so well at circumvention that it should be implemented
  409. inside Tor, it should use the same license as Tor.
  410. Tor already uses OpenSSL, Libevent, and zlib. Before you go and decide
  411. to use crypto++ in your transport plugin, ask yourself whether OpenSSL
  412. wouldn't be a nicer choice.
  413. Be portable: most Tor users are on Windows, and most Tor developers
  414. are not, so designing your code for just one of these platforms will
  415. make it either get a small userbase, or poor auditing.
  416. Think secure: if your code is in a C-like language, and it's hard to
  417. read it and become convinced it's safe, then it's probably not safe.
  418. Think small: we want to minimize the bytes that a Windows user needs
  419. to download for a transport client.
  420. Avoid security-through-obscurity if possible. Specify.
  421. Resist trivial fingerprinting: There should be no good string or regex
  422. to search for to distinguish your protocol from protocols permitted by
  423. censors.
  424. Imitate a real profile: There are many ways to implement most
  425. protocols -- and in many cases, most possible variants of a given
  426. protocol won't actually exist in the wild.