control-spec.txt 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. $Id$
  2. TC: A Tor control protocol
  3. 0. Scope
  4. (8 Aug 2004) This document describes an implementation-specific protocol to
  5. be implemented in a future version of Tor. It is not part of the Tor onion
  6. routing protocol.
  7. The protocol described in this document is used for other programs (such as
  8. frontend user-interfaces) to communicate with a locally running Tor process.
  9. We're trying to be pretty extensible here, but not infinitely
  10. forward-compatible.
  11. 1. Protocol outline
  12. TC is a bidirectional message-based protocol. It assumes an underlying
  13. stream for communication between a controlling process (the "client") and
  14. a Tor process (the "server"). The stream may be implemented via TCP,
  15. TLS-over-TCP, a Unix-domain socket, or so on. For security, the stream
  16. should not be observable by untrusted parties.
  17. In TC, the client and server send typed variable-length messages to one
  18. another over the underlying stream. By default, all messages from the server
  19. are in response to messages from the client. Some client requests, however,
  20. will cause the server to send messages to the client indefinitely far into
  21. the future.
  22. Servers respond to messages in the order they're received.
  23. 2. Message format
  24. The messages take the following format:
  25. Length [2 octets; big-endian]
  26. Type [2 octets; big-endian]
  27. Body [Length octets]
  28. Upon encountering a recognized Type, implementations behave as described in
  29. section 3 below. If the type is not recognized, servers respond with an
  30. "STAT" message (code UNRECOGNIZED; see 3.1 below), and clients simply ignore
  31. the message.
  32. 3. Message types
  33. 3.1. ERROR (Type 0x0000)
  34. Sent in response to a message that could not be processed as requested.
  35. The body of the message begins with a 2-byte error code. The following
  36. values are defined:
  37. 0x0000 Unspecified error
  38. 0x0001 Unrecognized message type
  39. 0x0002 Unrecognized configuration key
  40. 0x0003 Invalid configuration value
  41. 0x0004 Unrecognized event code
  42. 0x0005 Unauthorized user
  43. 0x0006 Failed authentication attempt
  44. The rest of the body should be a human-readable description of the error.
  45. 3.2. DONE (Type 0x0001)
  46. Sent from server to client in response to a request that was successfully
  47. completed, with no more information needed. The body is empty.
  48. 3.3. SETCONF (Type 0x0002)
  49. Change the value of a configuration variable. The body contains a list of
  50. newline-terminated key-value configuration lines.
  51. The server behaves as though it had just read the key-value pair in its
  52. configuration file.
  53. The server responds with a DONE message on success, or an ERROR message on
  54. failure.
  55. When a configuration options takes multiple values, or when multiple
  56. configuration keys form a context-sensitive group (see below), then
  57. setting _any_ of the options in a SETCONF command is taken to reset all of
  58. the others. For example, if two ORBindAddress values are provided,
  59. and a SETCONF command arrives containing a single ORBindAddress value, the
  60. new command's value replaces the two old values.
  61. To _remove_ all settings for a given option entirely, send a single line
  62. containing the key and no value.
  63. 3.4. GETCONF (Type 0x0003)
  64. Request the value of a configuration variable. The body contains one or
  65. more NL-terminated strings for configuration keys. The server replies
  66. with a CONFVALUE message.
  67. If an option appears multiple times in the configuration, all of its
  68. key-value pairs are returned in order.
  69. Some options are context-sensitive, and depend on other options with
  70. different keywords. These cannot be fetched directly. Instead, clients
  71. should use the "LogOptions" virtual keyword to get all LogFile, LogLevel,
  72. and SysLog option settings; and "HiddenServiceOptions" to get all
  73. HiddenServiceDir, HiddenServicePort, HiddenServiceNodes, and
  74. HiddenServiceExcludeNodes options.
  75. 3.5. CONFVALUE (Type 0x0004)
  76. Sent in response to a GETCONF message; contains a list of list of "Key
  77. Value\n" (A non-whitespace keyword, a single space, a non-NL value, a NL)
  78. strings.
  79. [XXXX note that you'll get more keys than you expect with things like
  80. loglevel.]
  81. 3.6. SETEVENTS (Type 0x0005)
  82. Request the server to inform the client about interesting events.
  83. The body contains a list of 2-byte event codes (see "event" below).
  84. Sending SETEVENTS with an empty body turns off all event reporting.
  85. The server responds with a DONE message on success, and an ERROR message
  86. if one of the event codes isn't recognized. (On error, the list of active
  87. event codes isn't changed.)
  88. 3.7. EVENT (Type 0x0006)
  89. Sent from the server to the client when an event has occurred, and the
  90. client has requested that kind of event. The body contains a 2-byte
  91. event code, followed by additional event-dependent information. Event
  92. codes are:
  93. 0x0001 -- Circuit status changed
  94. Status [1 octet]
  95. (Launched=0,Built=1,Extended=2,Failed=3,Closed=4)
  96. Circuit ID [4 octets]
  97. (Must be unique to Tor process/time)
  98. Path [NUL-terminated comma-separated string]
  99. (For extended/failed, is the portion of the path that is
  100. built)
  101. 0x0002 -- Stream status changed
  102. Status [1 octet]
  103. (Sent connect=0,sent resolve=1,succeeded=2,failed=3,
  104. closed=4)
  105. Stream ID [4 octets]
  106. (Must be unique to Tor process/time)
  107. Target (NUL-terminated address-port string]
  108. 0x0003 -- OR Connection status changed
  109. Status [1 octet]
  110. (Launched=0,connected=1,failed=2,closed=3)
  111. OR nickname/identity [NUL-terminated]
  112. 0x0004 -- Bandwidth used in last N seconds. (N=1? 5?)
  113. Bytes read [4 octets]
  114. Bytes written [4 octets]
  115. 0x0005 -- Warning/error occurred
  116. Message [NUL-terminated]
  117. 3.8. AUTHENTICATE (Type 0x0007)
  118. Sent from the client to the server. Contains a 'magic cookie' to prove
  119. that client is really the admin for this Tor process. The server responds
  120. with DONE or ERROR.
  121. 4. Implementation notes
  122. There are four ways we could authenticate, for now:
  123. 1) Listen on 127.0.0.1; trust all local users.
  124. 2) Write a named socket in tor's data-directory or in some other location;
  125. rely on the OS to ensure that only authorized users can open it. (NOTE:
  126. the Linux unix(7) man page suggests that some BSDs don't enforce
  127. authorization.) If the OS has named sockets, and implements
  128. authentication, trust all users who can read Tor's data directory.
  129. 3) Write a random magic cookie to the FS in Tor's data-directory; use that
  130. magic cookie for authentication. Trust all users who can read Tor's data
  131. directory.
  132. 4) Store a salted-and-hashed passphrase in Tor's configuration. Use the
  133. passphrase for authentication. Trust all users who know the passphrase.
  134. On Win32, our only options are 1, 3, and 4. Since the semantics for 2 and 3
  135. are so similar, I'm recommending that we not support 2, and just always bind
  136. on 127.0.0.1. I've implemented 3 and 4; 1 would be trivial. -NM
  137. -----------
  138. (for emacs)
  139. Local Variables:
  140. mode:text
  141. indent-tabs-mode:nil
  142. fill-column:77
  143. End: