control-spec.txt 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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
  50. two nul-terminated strings: a configuration key and a configuration value.
  51. The server behaves as though it had just read the key-value pair in its
  52. configuration file. The server responds with a DONE message on success,
  53. or an ERROR message on failure.
  54. 3.4. GETCONF (Type 0x0003)
  55. Request the value of a configuration variable. The body contains one or
  56. more nul-terminated strings for configuration keys. The server replies
  57. with a CONFVALUE message.
  58. 3.5. CONFVALUE (Type 0x0004)
  59. Sent in response to a GETCONF message; contains a list of nul-terminated
  60. key strings followed by nul-terminated value strings.
  61. [XXXX note that you'll get more keys than you expect with things like
  62. loglevel.]
  63. 3.6. SETEVENTS (Type 0x0005)
  64. Request the server to inform the client about interesting events.
  65. The body contains a list of 2-byte event codes (see "event" below).
  66. Sending SETEVENTS with an empty body turns off all event reporting.
  67. The server responds with a DONE message on success, and an ERROR message
  68. if one of the event codes isn't recognized. (On error, the list of active
  69. event codes isn't changed.)
  70. 3.7. EVENT (Type 0x0006)
  71. Sent from the server to the client when an event has occurred, and the
  72. client has requested that kind of event. The body contains a 2-byte
  73. event code, followed by additional event-dependent information. Event
  74. codes are:
  75. 0x0001 -- Circuit status changed
  76. Status [1 octet]
  77. (Launched=0,Built=1,Extended=2,Failed=3,Closed=4)
  78. Circuit ID [4 octets]
  79. (Must be unique to Tor process/time)
  80. Path [NUL-terminated comma-separated string]
  81. (For extended/failed, is the portion of the path that is
  82. built)
  83. 0x0002 -- Stream status changed
  84. Status [1 octet]
  85. (Sent connect=0,sent resolve=1,succeeded=2,failed=3,
  86. closed=4)
  87. Stream ID [4 octets]
  88. (Must be unique to Tor process/time)
  89. Target (NUL-terminated address-port string]
  90. 0x0003 -- OR Connection status changed
  91. Status [1 octet]
  92. (Launched=0,connected=1,failed=2,closed=3)
  93. OR nickname/identity [NUL-terminated]
  94. 0x0004 -- Bandwidth used in last N seconds. (N=1? 5?)
  95. Bytes read [4 octets]
  96. Bytes written [4 octets]
  97. 0x0005 -- Warning/error occurred
  98. Message [NUL-terminated]
  99. 3.8. AUTHENTICATE (Type 0x0007)
  100. Sent from the client to the server. Contains a 'magic cookie' to prove
  101. that client is really the admin for this Tor process. The server responds
  102. with DONE or ERROR.
  103. 4. Implementation notes
  104. There are four ways we could authenticate, for now:
  105. 1) Listen on 127.0.0.1; trust all local users.
  106. 2) Write a named socket in tor's data-directory or in some other location;
  107. rely on the OS to ensure that only authorized users can open it. (NOTE:
  108. the Linux unix(7) man page suggests that some BSDs don't enforce
  109. authorization.) If the OS has named sockets, and implements
  110. authentication, trust all users who can read Tor's data directory.
  111. 3) Write a random magic cookie to the FS in Tor's data-directory; use that
  112. magic cookie for authentication. Trust all users who can read Tor's data
  113. directory.
  114. 4) Store a salted-and-hashed passphrase in Tor's configuration. Use the
  115. passphrase for authentication. Trust all users who know the passphrase.
  116. On Win32, our only options are 1, 3, and 4. Since the semantics for 2 and 3
  117. are so similar, I'm recommending that we not support 2, and just always bind
  118. on 127.0.0.1. I've implemented 3 and 4; 1 would be trivial. -NM
  119. -----------
  120. (for emacs)
  121. Local Variables:
  122. mode:text
  123. indent-tabs-mode:nil
  124. fill-column:77
  125. End: