control-spec.txt 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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 protocol.
  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 pipe, or so on. For security, the stream should not be
  16. 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. 3.2. DONE (Type 0x0001)
  45. Sent from server to client in response to a request that was successfully
  46. completed, with no more information needed. The body is empty.
  47. 3.3. SETCONF (Type 0x0002)
  48. Change the value of a configuration variable. The body contains
  49. two nul-terminated strings: a configuration key and a configuration value.
  50. The server behaves as though it had just read the key-value pair in its
  51. configuration file. The server responds with a DONE message on success,
  52. or an ERROR message on failure.
  53. 3.4. GETCONF (Type 0x0003)
  54. Request the value of a configuration variable. The body contains a
  55. nul-terminated string for a configuration key. The server replies with a
  56. CONFVALUE message
  57. 3.5. CONFVALUE (Type 0x0004)
  58. Sent in response to a GETCONF message; contains a nul-terminated key string
  59. and a nul-terminated value string.
  60. 3.6. SETEVENTS (Type 0x0005)
  61. Request the server to inform the client about interesting events.
  62. The body contains a list of 2-byte event codes (see "event" below).
  63. Sending SETEVENTS with an empty body turns off all event reporting.
  64. The server responds with a DONE message on success, and an ERROR message
  65. if one of the event codes isn't recognized. (On error, the list of active
  66. event codes isn't changed.)
  67. 3.7. EVENT (Type 0x0006)
  68. Sent from the server to the client when an event has occurred, and the
  69. client has requested that kind of event. The body contains a 2-byte
  70. event code, followed by additional event-dependent information. Event
  71. codes are:
  72. 0x0001 -- Circuit status changed
  73. Status [1 octet]
  74. (Launched=0,Built=1,Extended=2,Failed=3,Closed=4)
  75. Circuit ID [4 octets]
  76. (Must be unique to Tor process/time)
  77. Path [NUL-terminated comma-separated string]
  78. (For extended/failed, is the portion of the path that is
  79. built)
  80. 0x0002 -- Stream status changed
  81. Status [1 octet]
  82. (Sent connect=0,sent resolve=1,succeeded=2,failed=3,
  83. closed=4)
  84. Stream ID [4 octets]
  85. (Must be unique to Tor process/time)
  86. Target (NUL-terminated address-port string]
  87. 0x0003 -- OR Connection status changed
  88. Status [1 octet]
  89. (Launched=0,connected=1,failed=2,closed=3)
  90. OR nickname/identity [NUL-terminated]
  91. 0x0004 -- Bandwidth used in last N seconds. (N=1? 5?)
  92. Bytes read [4 octets]
  93. Bytes written [4 octets]
  94. 0x0005 -- Warning/error occurred
  95. Message [NUL-terminated]
  96. 3.8. AUTHENTICATE (Type 0x0007)
  97. Sent from the client to the server. Contains a 'magic cookie' to prove
  98. that client is really the admin for this Tor process. The server responds
  99. with DONE or ERROR.
  100. 4. Implementation notes
  101. On Unix, we should use a named pipe on the fs and use filesystem privileges
  102. to authenticate. On Win32, a password/magic cookie may be in order.
  103. -----------
  104. (for emacs)
  105. Local Variables:
  106. mode:text
  107. indent-tabs-mode:nil
  108. fill-column:77
  109. End: