3 TC: A Tor control protocol (Version 1)
7 This document describes an implementation-specific protocol that is used
8 for other programs (such as frontend user-interfaces) to communicate with a
9 locally running Tor process. It is not part of the Tor onion routing
12 This protocol replaces version 0 of TC, which is now deprecated. For
13 reference, TC is described in "control-spec-v0.txt". Implementors are
14 recommended to avoid using TC directly, but instead to use a library that
15 can easily be updated to use the newer protocol.
19 TC is a bidirectional message-based protocol. It assumes an underlying
20 stream for communication between a controlling process (the "client"
21 or "controller") and a Tor process (or "server"). The stream may be
22 implemented via TCP, TLS-over-TCP, a Unix-domain socket, or so on,
23 but it must provide reliable in-order delivery. For security, the
24 stream should not be accessible by untrusted parties.
26 In TC, the client and server send typed messages to each other over the
27 underlying stream. The client sends "commands" and the server sends
30 By default, all messages from the server are in response to messages from
31 the client. Some client requests, however, will cause the server to send
32 messages to the client indefinitely far into the future. Such
33 "asynchronous" replies are marked as such.
35 Servers respond to messages in the order messages are received.
39 2.1. Description format
41 The message formats listed below use ABNF as described in RFC2234.
42 The protocol itself is loosely based on SMTP (see RFC 2821).
44 We use the following nonterminals from RFC2822: atom, qcontent
46 We define the following general-use nonterminals:
48 String = DQUOTE *qcontent DQUOTE
50 There are explicitly no limits on line length. All 8-bit characters are
51 permitted unless explicitly disallowed.
53 2.2. Commands from controller to Tor
55 Command = Keyword Arguments CRLF / "+" Keyword Arguments CRLF Data
57 Arguments = *(SP / VCHAR)
59 Specific commands and their arguments are described below in section 3.
61 2.3. Replies from Tor to the controller
63 Reply = *(MidReplyLine / DataReplyLine) EndReplyLine
65 MidReplyLine = "-" ReplyLine
66 DataReplyLine = "+" ReplyLine Data
67 EndReplyLine = SP ReplyLine
68 ReplyLine = StatusCode [ SP ReplyText ] CRLF
72 Specific replies are mentioned below in section 3, and described more fully
75 2.4. General-use tokens
77 ; Identifiers for servers.
78 ServerID = Nickname / Fingerprint
79 Nickname = 1*19 NicknameChar
80 NicknameChar = "a"-"z" / "A"-"Z" / "0" - "9"
81 Fingerprint = "$" 40*HEXDIG
83 ; Unique identifiers for streams or circuits. Currently, Tor only
84 ; uses digits, but this may change
85 StreamID = 1*16 IDChar
86 CircuitID = 1*16 IDChar
87 IDChar = ALPHA / DIGIT
89 Address = ip4-address / ip6-address / hostname (XXXX Define these)
92 ; A "Data" section is a sequence of octets concluded by the terminating
93 ; sequence CRLF "." CRLF. The terminating sequence may not appear in the
94 ; body of the data. Leading periods on lines in the data are escaped with
95 ; an additional leading period as in RFC2821 section 4.5.2
96 Data = *DataLine "." CRLF
97 DataLine = CRLF / "." 1*LineItem CRLF / NonDotItem *LineItem CRLF
98 LineItem = NonCR / 1*CR NonCRLF
99 NonDotItem = NonDotCR / 1*CR NonCRLF
103 All commands and other keywords are case-insensitive.
107 Change the value of one or more configuration variables. The syntax is:
109 "SETCONF" 1*(SP keyword ["=" String]) CRLF
111 Tor behaves as though it had just read each of the key-value pairs
112 from its configuration file. Keywords with no corresponding values have
113 their configuration values reset to 0 or NULL (use RESETCONF if you want
114 to set it back to its default). SETCONF is all-or-nothing: if there
115 is an error in any of the configuration settings, Tor sets none of them.
117 Tor responds with a "250 configuration values set" reply on success.
118 If some of the listed keywords can't be found, Tor replies with a
119 "552 Unrecognized option" message. Otherwise, Tor responds with a
120 "513 syntax error in configuration values" reply on syntax error, or a
121 "553 impossible configuration setting" reply on a semantic error.
123 When a configuration option takes multiple values, or when multiple
124 configuration keys form a context-sensitive group (see GETCONF below), then
125 setting _any_ of the options in a SETCONF command is taken to reset all of
126 the others. For example, if two ORBindAddress values are configured, and a
127 SETCONF command arrives containing a single ORBindAddress value, the new
128 command's value replaces the two old values.
132 Remove all settings for a given configuration option entirely, assign
133 its default value (if any), and then assign the String provided.
134 Typically the String is left empty, to simply set an option back to
135 its default. The syntax is:
137 "RESETCONF" 1*(SP keyword ["=" String]) CRLF
139 Otherwise it behaves like SETCONF above.
143 Request the value of a configuration variable. The syntax is:
145 "GETCONF" 1*(SP keyword) CRLF
147 If all of the listed keywords exist in the Tor configuration, Tor replies
148 with a series of reply lines of the form:
150 If any option is set to a 'default' value semantically different from an
151 empty string, Tor may reply with a reply line of the form:
154 If some of the listed keywords can't be found, Tor replies with a
155 "552 unknown configuration keyword" message.
157 If an option appears multiple times in the configuration, all of its
158 key-value pairs are returned in order.
160 Some options are context-sensitive, and depend on other options with
161 different keywords. These cannot be fetched directly. Currently there
162 is only one such option: clients should use the "HiddenServiceOptions"
163 virtual keyword to get all HiddenServiceDir, HiddenServicePort,
164 HiddenServiceNodes, and HiddenServiceExcludeNodes option settings.
168 Request the server to inform the client about interesting events. The
171 "SETEVENTS" [SP "EXTENDED"] *(SP EventCode) CRLF
173 EventCode = "CIRC" / "STREAM" / "ORCONN" / "BW" / "DEBUG" /
174 "INFO" / "NOTICE" / "WARN" / "ERR" / "NEWDESC" / "ADDRMAP" /
177 Any events *not* listed in the SETEVENTS line are turned off; thus, sending
178 SETEVENTS with an empty body turns off all event reporting.
180 The server responds with a "250 OK" reply on success, and a "552
181 Unrecognized event" reply if one of the event codes isn't recognized. (On
182 error, the list of active event codes isn't changed.)
184 If the flag string "EXTENDED" is provided, Tor may provide extra
185 information with events for this connection; see 4.1 for more information.
186 NOTE: All events on a given connection will be provided in extended format,
188 NOTE: "EXTENDED" is only supported in Tor 0.1.1.9-alpha or later.
192 Sent from the client to the server. The syntax is:
193 "AUTHENTICATE" [ SP 1*HEXDIG / QuotedString ] CRLF
195 The server responds with "250 OK" on success or "515 Bad authentication" if
196 the authentication cookie is incorrect.
198 The format of the 'cookie' is implementation-dependent; see 5.1 below for
199 information on how the standard Tor implementation handles it.
201 If Tor requires authentication and the controller has not yet sent an
202 AUTHENTICATE message, Tor sends a "514 authentication required" reply to
203 any other kind of message.
207 Sent from the client to the server. The syntax is:
210 Instructs the server to write out its config options into its torrc. Server
211 returns "250 OK" if successful, or "551 Unable to write configuration
212 to disk" if it can't write the file or some other error occurs.
216 Sent from the client to the server. The syntax is:
218 "SIGNAL" SP Signal CRLF
220 Signal = "RELOAD" / "SHUTDOWN" / "DUMP" / "DEBUG" / "HALT" /
221 "HUP" / "INT" / "USR1" / "USR2" / "TERM"
223 The meaning of the signals are:
225 RELOAD -- Reload: reload config items, refetch directory. (like HUP)
226 SHUTDOWN -- Controlled shutdown: if server is an OP, exit immediately.
227 If it's an OR, close listeners and exit after 30 seconds.
229 DUMP -- Dump stats: log information about open connections and
230 circuits. (like USR1)
231 DEBUG -- Debug: switch all open logs to loglevel debug. (like USR2)
232 HALT -- Immediate shutdown: clean up and exit now. (like TERM)
234 The server responds with "250 OK" if the signal is recognized (or simply
235 closes the socket if it was asked to close immediately), or "552
236 Unrecognized signal" if the signal is unrecognized.
240 Sent from the client to the server. The syntax is:
242 "MAPADDRESS" 1*(Address "=" Address SP) CRLF
244 The first address in each pair is an "original" address; the second is a
245 "replacement" address. The client sends this message to the server in
246 order to tell it that future SOCKS requests for connections to the original
247 address should be replaced with connections to the specified replacement
248 address. If the addresses are well-formed, and the server is able to
249 fulfill the request, the server replies with a 250 message:
250 250-OldAddress1=NewAddress1
251 250 OldAddress2=NewAddress2
253 containing the source and destination addresses. If request is malformed,
254 the server replies with "512 syntax error in command argument". If the server
255 can't fulfill the request, it replies with "451 resource exhausted."
257 The client may decline to provide a body for the original address, and
258 instead send a special null address ("0.0.0.0" for IPv4, "::0" for IPv6, or
259 "." for hostname), signifying that the server should choose the original
260 address itself, and return that address in the reply. The server
261 should ensure that it returns an element of address space that is unlikely
262 to be in actual use. If there is already an address mapped to the
263 destination address, the server may reuse that mapping.
265 If the original address is already mapped to a different address, the old
266 mapping is removed. If the original address and the destination address
267 are the same, the server removes any mapping in place for the original
271 C: MAPADDRESS 0.0.0.0=tor.eff.org 1.2.3.4=tor.freehaven.net
272 S: 250-127.192.10.10=tor.eff.org
273 S: 250 1.2.3.4=tor.freehaven.net
275 {Note: This feature is designed to be used to help Tor-ify applications
276 that need to use SOCKS4 or hostname-less SOCKS5. There are three
277 approaches to doing this:
278 1. Somehow make them use SOCKS4a or SOCKS5-with-hostnames instead.
279 2. Use tor-resolve (or another interface to Tor's resolve-over-SOCKS
280 feature) to resolve the hostname remotely. This doesn't work
281 with special addresses like x.onion or x.y.exit.
282 3. Use MAPADDRESS to map an IP address to the desired hostname, and then
283 arrange to fool the application into thinking that the hostname
284 has resolved to that IP.
285 This functionality is designed to help implement the 3rd approach.}
287 Mappings set by the controller last until the Tor process exits:
288 they never expire. If the controller wants the mapping to last only
289 a certain time, then it must explicitly un-map the address when that
294 Sent from the client to the server. The syntax is as for GETCONF:
295 "GETINFO" 1*(SP keyword) CRLF
296 one or more NL-terminated strings. The server replies with an INFOVALUE
299 Unlike GETCONF, this message is used for data that are not stored in the Tor
300 configuration file, and that may be longer than a single line. On success,
301 one ReplyLine is sent for each requested value, followed by a final 250 OK
302 ReplyLine. If a value fits on a single line, the format is:
304 If a value must be split over multiple lines, the format is:
308 Recognized keys and their values include:
310 "version" -- The version of the server's software, including the name
311 of the software. (example: "Tor 0.0.9.4")
313 "config-file" -- The location of Tor's configuration file ("torrc").
315 "desc/id/<OR identity>" or "desc/name/<OR nickname>" -- the latest server
316 descriptor for a given OR, NUL-terminated. If no such OR is known, the
317 corresponding value is an empty string.
319 "network-status" -- a space-separated list of all known OR identities.
320 This is in the same format as the router-status line in directories;
321 see tor-spec.txt for details.
324 "addr-mappings/config"
325 "addr-mappings/cache"
326 "addr-mappings/control" -- a space-separated list of address mappings, each
327 in the form of "from-address=to-address". The 'config' key
328 returns those address mappings set in the configuration; the 'cache'
329 key returns the mappings in the client-side DNS cache; the 'control'
330 key returns the mappings set via the control interface; the 'all'
331 target returns the mappings set through any mechanism.
334 A series of lines as for a circuit status event. Each line is of the form:
335 CircuitID SP CircStatus SP Path CRLF
338 A series of lines as for a stream status event. Each is of the form:
339 StreamID SP StreamStatus SP CircID SP Target CRLF
342 A series of lines as for an OR connection status event. Each is of the
344 ServerID SP ORStatus CRLF
347 A series of lines listing the currently chosen helper nodes, if any.
349 ServerID SP ((("down" / "unlisted") ISOTime) / "up") CRLF
352 "accounting/hibernating"
354 "accounting/bytes-left"
355 "accounting/interval-start"
356 "accounting/interval-wake"
357 "accounting/interval-end"
358 Information about accounting status. If accounting is enabled,
359 "enabled" is 1; otherwise it is 0. The "hibernating" field is "hard"
360 if we are accepting no data; "soft" if we're accepting no new
361 connections, and "awake" if we're not hibernating at all. The "bytes"
362 and "bytes-left" fields contain (read-bytes SP write-bytes), for the
363 start and the rest of the interval respectively. The 'interval-start'
364 and 'interval-end' fields are the borders of the current interval; the
365 'interval-wake' field is the time within the current interval (if any)
366 where we plan[ned] to start being active.
369 A series of lines listing the available configuration options. Each is
371 OptionName SP OptionType [ SP Documentation ] CRLF
373 OptionType = "Integer" / "TimeInterval" / "DataSize" / "Float" /
374 "Boolean" / "Time" / "CommaList" / "Dependant" / "Virtual" /
375 "String" / "LineList"
379 A series of lines listing the available GETINFO options. Each is of
381 OptionName SP Documentation CRLF
382 OptionPrefix SP Documentation CRLF
383 OptionPrefix = OptionName "/*"
386 C: GETINFO version desc/name/moria1
387 S: 250+desc/name/moria=
388 S: [Descriptor for moria]
390 S: 250-version=Tor 0.1.1.0-alpha-cvs
395 Sent from the client to the server. The format is:
396 "EXTENDCIRCUIT" SP CircuitID SP ServerID *("," ServerID) CRLF
398 This request takes one of two forms: either the Circuit ID is zero, in
399 which case it is a request for the server to build a new circuit according
400 to the specified path, or the Circuit ID is nonzero, in which case it is a
401 request for the server to extend an existing circuit with that ID according
402 to the specified path.
404 If the request is successful, the server sends a reply containing a message
405 body consisting of the Circuit ID of the (maybe newly created) circuit.
406 The syntax is "250" SP "EXTENDED" SP CircuitID CRLF.
410 Sent from the client to the server. The syntax is:
411 "ATTACHSTREAM" SP StreamID SP CircuitID CRLF
413 This message informs the server that the specified stream should be
414 associated with the specified circuit. Each stream may be associated with
415 at most one circuit, and multiple streams may share the same circuit.
416 Streams can only be attached to completed circuits (that is, circuits that
417 have sent a circuit status 'BUILT' event or are listed as built in a
418 GETINFO circuit-status request).
420 If the circuit ID is 0, responsibility for attaching the given stream is
423 Tor responds with "250 OK" if it can attach the stream, 552 if the circuit
424 or stream didn't exist, or 551 if the stream couldn't be attached for
427 {Implementation note: By default, Tor automatically attaches streams to
428 circuits itself, unless the configuration variable
429 "__LeaveStreamsUnattached" is set to "1". Attempting to attach streams
430 via TC when "__LeaveStreamsUnattached" is false may cause a race between
431 Tor and the controller, as both attempt to attach streams to circuits.}
435 Sent from the client to the server. The syntax is:
436 "+POSTDESCRIPTOR" CRLF Descriptor CRLF "." CRLF
438 This message informs the server about a new descriptor.
440 The descriptor, when parsed, must contain a number of well-specified
441 fields, including fields for its nickname and identity.
443 If there is an error in parsing the descriptor, the server must send a "554
444 Invalid descriptor" reply. If the descriptor is well-formed but the server
445 chooses not to add it, it must reply with a 251 message whose body explains
446 why the server was not added. If the descriptor is added, Tor replies with
451 Sent from the client to the server. The syntax is:
452 "REDIRECTSTREAM" SP StreamID SP Address (Port) CRLF
454 Tells the server to change the exit address on the specified stream. If
455 Port is specified, changes the destination port as well. No remapping
456 is performed on the new provided address.
458 To be sure that the modified address will be used, this event must be sent
459 after a new stream event is received, and before attaching this stream to
462 Tor replies with "250 OK" on success.
466 Sent from the client to the server. The syntax is:
468 "CLOSESTREAM" SP StreamID SP Reason *(SP Flag) CRLF
470 Tells the server to close the specified stream. The reason should be one
471 of the Tor RELAY_END reasons given in tor-spec.txt, as a decimal. Flags is
472 not used currently; Tor servers SHOULD ignore unrecognized flags. Tor may
473 hold the stream open for a while to flush any data that is pending.
475 Tor replies with "250 OK" on success, or a 512 if there aren't enough
476 arguments, or a 552 if it doesn't recognize the StreamID or reason.
481 CLOSECIRCUIT SP CircuitID *(SP Flag) CRLF
484 Tells the server to close the specified circuit. If "IfUnused" is
485 provided, do not close the circuit unless it is unused.
487 Other flags may be defined in the future; Tor SHOULD ignore unrecognized
490 Tor replies with "250 OK" on success, or a 512 if there aren't enough
491 arguments, or a 552 if it doesn't recognize the CircuitID.
495 Tells the server to hang up on this controller connection. This command
496 can be used before authenticating.
500 Reply codes follow the same 3-character format as used by SMTP, with the
501 first character defining a status, the second character defining a
502 subsystem, and the third designating fine-grained information.
504 The TC protocol currently uses the following first characters:
506 2yz Positive Completion Reply
507 The command was successful; a new request can be started.
509 4yz Temporary Negative Completion reply
510 The command was unsuccessful but might be reattempted later.
512 5yz Permanent Negative Completion Reply
513 The command was unsuccessful; the client should not try exactly
514 that sequence of commands again.
516 6yz Asynchronous Reply
517 Sent out-of-order in response to an earlier SETEVENTS command.
519 The following second characters are used:
522 Sent in response to ill-formed or nonsensical commands.
525 Refers to operations of the Tor Control protocol.
528 Refers to actual operations of Tor system.
530 The following codes are defined:
533 251 Operation was unnecessary
534 [Tor has declined to perform the operation, but no harm was done.]
536 451 Resource exhausted
538 500 Syntax error: protocol
540 510 Unrecognized command
541 511 Unimplemented command
542 512 Syntax error in command argument
543 513 Unrecognized command argument
544 514 Authentication required
545 515 Bad authentication
547 550 Unspecified Tor error
550 [Something went wrong inside Tor, so that the client's
551 request couldn't be fulfilled.]
553 552 Unrecognized entity
554 [A configuration key, a stream ID, circuit ID, event,
555 mentioned in the command did not actually exist.]
557 553 Invalid configuration value
558 [The client tried to set a configuration option to an
559 incorrect, ill-formed, or impossible value.]
561 554 Invalid descriptor
565 650 Asynchronous event notification
567 Unless specified to have specific contents, the human-readable messages
568 in error replies should not be relied upon to match those in this document.
570 4.1. Asynchronous events
572 These replies can be sent after a corresponding SETEVENTS command has been
573 received. They will not be interleaved with other Reply elements, but they
574 can appear between a command and its corresponding reply. For example,
575 this sequence is possible:
579 C: GETCONF SOCKSPORT ORPORT
580 S: 650 CIRC 1000 EXTENDED moria1,moria2
581 S: 250-SOCKSPORT=9050
584 But this sequence is disallowed:
587 C: GETCONF SOCKSPORT ORPORT
588 S: 250-SOCKSPORT=9050
589 S: 650 CIRC 1000 EXTENDED moria1,moria2
592 Clients SHOULD tolerate more arguments in an asynchonous reply than
593 expected, and SHOULD tolerate more lines in an asynchronous reply than
594 expected. For instance, a client that expects a CIRC message like:
595 650 CIRC 1000 EXTENDED moria1,moria2
597 650-CIRC 1000 EXTENDED moria1,moria2 0xBEEF
601 If clients ask for extended events, then each event line as specified below
602 will be followed by additional extensions. Clients that do so MUST
603 tolerate additional arguments and lines. Additional lines will be of the
605 "650" ("-"/" ") KEYWORD ["=" ARGUMENTS] CRLF
606 Additional arguments will be of the form
607 SP KEYWORD ["=" ( QuotedString / * NonSpDquote ) ]
608 Such clients MUST tolerate lines with keywords they do not recognize.
610 4.1.1. Circuit status changed
614 "650" SP "CIRC" SP CircuitID SP CircStatus SP Path
617 "LAUNCHED" / ; circuit ID assigned to new circuit
618 "BUILT" / ; all hops finished, can now accept streams
619 "EXTENDED" / ; one more hop has been completed
620 "FAILED" / ; circuit closed (was not built)
621 "CLOSED" ; circuit closed (was built)
623 Path = ServerID *("," ServerID)
625 4.1.2. Stream status changed
629 "650" SP "STREAM" SP StreamID SP StreamStatus SP CircID SP Target SP
632 "NEW" / ; New request to connect
633 "NEWRESOLVE" / ; New request to resolve an address
634 "SENTCONNECT" / ; Sent a connect cell along a circuit
635 "SENTRESOLVE" / ; Sent a resolve cell along a circuit
636 "SUCCEEDED" / ; Received a reply; stream established
637 "FAILED" / ; Stream failed and not retriable.
638 "CLOSED" / ; Stream closed
639 "DETACHED" ; Detached from circuit; still retriable.
641 Target = Address ":" Port
643 The circuit ID designates which circuit this stream is attached to. If
644 the stream is unattached, the circuit ID "0" is given.
646 4.1.3. OR Connection status changed
649 "650" SP "ORCONN" SP ServerID SP ORStatus
651 ORStatus = "LAUNCHED" / "CONNECTED" / "FAILED" / "CLOSED"
653 4.1.4. Bandwidth used in the last second
656 "650" SP "BW" SP BytesRead SP BytesWritten
658 BytesWritten = 1*DIGIT
663 "650" SP Severity SP ReplyText
665 "650+" Severity CRLF Data
667 Severity = "DEBUG" / "INFO" / "NOTICE" / "WARN"/ "ERR"
669 4.1.6. New descriptors available
672 "650" SP "NEWDESC" 1*(SP ServerID)
674 4.1.7. New Address mapping
677 "650" SP "ADDRMAP" SP Address SP Address SP Expiry
678 Expiry = DQOUTE ISOTime DQUOTE / "NEVER"
680 4.1.8. Descriptors uploaded to us in our role as authoritative dirserver
683 "650" "+" "AUTHDIR_NEWDESCS" CRLF Action CRLF Message CRLF Descriptor CRLF "." CRLF
684 Action = "ACCEPTED" / "DROPPED" / "REJECTED"
687 5. Implementation notes
691 By default, the current Tor implementation trusts all local users.
693 If the 'CookieAuthentication' option is true, Tor writes a "magic cookie"
694 file named "control_auth_cookie" into its data directory. To authenticate,
695 the controller must send the contents of this file.
697 If the 'HashedControlPassword' option is set, it must contain the salted
698 hash of a secret password. The salted hash is computed according to the
699 S2K algorithm in RFC 2440 (OpenPGP), and prefixed with the s2k specifier.
700 This is then encoded in hexadecimal, prefixed by the indicator sequence
701 "16:". Thus, for example, the password 'foo' could encode to:
702 16:660537E3E1CD49996044A3BF558097A981F539FEA2F9DA662B4626C1C2
703 ++++++++++++++++**^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
706 You can generate the salt of a password by calling
707 'tor --hash-password <password>'
708 or by using the example code in the Python and Java controller libraries.
709 To authenticate under this scheme, the controller sends Tor the original
710 secret that was used to generate the password.
712 5.2. Don't let the buffer get too big.
714 If you ask for lots of events, and 16MB of them queue up on the buffer,
715 the Tor process will close the socket.
717 5.3. Backward compatibility
719 For backward compatibility with the "version 0" control protocol, Tor checks
720 whether the third octet the first command is zero. If it is, Tor
721 assumes that version 0 is in use. This feature is deprecated, and will be
722 removed in the 0.1.2.x Tor development series.
724 In order to detect which version of the protocol is supported controllers
725 should send the sequence [00 00 0D 0A]. This is a valid and unrecognized
726 command in both protocol versions, and implementations can detect which
727 error they have received.