broker-spec.txt 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. Snowflake broker protocol
  2. 0. Scope and Preliminaries
  3. The Snowflake broker is used to hand out Snowflake proxies to clients using the Snowflake pluggable transport. There are some similarities to the function of the broker and how BridgeDB hands out Tor bridges.
  4. This document specifies how the Snowflake broker interacts with other parts of the Tor ecosystem, starting with the metrics CollecTor module and to be expanded upon later.
  5. 1. Metrics Reporting (version 1.1)
  6. Metrics data from the Snowflake broker can be retrieved by sending an HTTP GET request to https://[Snowflake broker URL]/metrics and consists of the following items:
  7. "snowflake-stats-end" YYYY-MM-DD HH:MM:SS (NSEC s) NL
  8. [At start, exactly once.]
  9. YYYY-MM-DD HH:MM:SS defines the end of the included measurement
  10. interval of length NSEC seconds (86400 seconds by default).
  11. "snowflake-ips" [CC=NUM,CC=NUM,...,CC=NUM] NL
  12. [At most once.]
  13. List of mappings from two-letter country codes to the number of
  14. unique IP addresses of Snowflake proxies that have polled. Each
  15. country code only appears once.
  16. "snowflake-ips-total" NUM NL
  17. [At most once.]
  18. A count of the total number of unique IP addresses of Snowflake
  19. proxies that have polled.
  20. "snowflake-ips-standalone" NUM NL
  21. [At most once.]
  22. A count of the total number of unique IP addresses of snowflake
  23. proxies of type "standalone" that have polled.
  24. "snowflake-ips-badge" NUM NL
  25. [At most once.]
  26. A count of the total number of unique IP addresses of snowflake
  27. proxies of type "badge" that have polled.
  28. "snowflake-ips-webext" NUM NL
  29. [At most once.]
  30. A count of the total number of unique IP addresses of snowflake
  31. proxies of type "webext" that have polled.
  32. "snowflake-idle-count" NUM NL
  33. [At most once.]
  34. A count of the number of times a proxy has polled but received
  35. no client offer, rounded up to the nearest multiple of 8.
  36. "client-denied-count" NUM NL
  37. [At most once.]
  38. A count of the number of times a client has requested a proxy
  39. from the broker but no proxies were available, rounded up to
  40. the nearest multiple of 8.
  41. "client-restricted-denied-count" NUM NL
  42. [At most once.]
  43. A count of the number of times a client with a restricted or
  44. unknown NAT type has requested a proxy from the broker but no
  45. proxies were available, rounded up to the nearest multiple of 8.
  46. "client-unrestricted-denied-count" NUM NL
  47. [At most once.]
  48. A count of the number of times a client with an unrestricted NAT
  49. type has requested a proxy from the broker but no proxies were
  50. available, rounded up to the nearest multiple of 8.
  51. "client-snowflake-match-count" NUM NL
  52. [At most once.]
  53. A count of the number of times a client successfully received a
  54. proxy from the broker, rounded up to the nearest multiple of 8.
  55. "client-http-count" NUM NL
  56. [At most once.]
  57. A count of the number of times a client has requested a proxy using
  58. the HTTP rendezvous method from the broker, rounded up to the nearest
  59. multiple of 8.
  60. "client-http-ips" [CC=NUM,CC=NUM,...,CC=NUM] NL
  61. [At most once.]
  62. List of mappings from two-letter country codes to the number of
  63. times a client has requested a proxy using the HTTP rendezvous method,
  64. rounded up to the nearest multiple of 8. Each country code only appears
  65. once.
  66. "client-ampcache-count" NUM NL
  67. [At most once.]
  68. A count of the number of times a client has requested a proxy using
  69. the ampcache rendezvous method from the broker, rounded up to the
  70. nearest multiple of 8.
  71. "client-ampcache-ips" [CC=NUM,CC=NUM,...,CC=NUM] NL
  72. [At most once.]
  73. List of mappings from two-letter country codes to the number of
  74. times a client has requested a proxy using the ampcache rendezvous
  75. method, rounded up to the nearest multiple of 8. Each country code only
  76. appears once.
  77. "client-sqs-count" NUM NL
  78. [At most once.]
  79. A count of the number of times a client has requested a proxy using
  80. the sqs rendezvous method from the broker, rounded up to the nearest
  81. multiple of 8.
  82. "client-sqs-ips" [CC=NUM,CC=NUM,...,CC=NUM] NL
  83. [At most once.]
  84. List of mappings from two-letter country codes to the number of
  85. times a client has requested a proxy using the sqs rendezvous method,
  86. rounded up to the nearest multiple of 8. Each country code only appears
  87. once.
  88. "snowflake-ips-nat-restricted" NUM NL
  89. [At most once.]
  90. A count of the total number of unique IP addresses of snowflake
  91. proxies that have a restricted NAT type.
  92. "snowflake-ips-nat-unrestricted" NUM NL
  93. [At most once.]
  94. A count of the total number of unique IP addresses of snowflake
  95. proxies that have an unrestricted NAT type.
  96. "snowflake-ips-nat-unknown" NUM NL
  97. [At most once.]
  98. A count of the total number of unique IP addresses of snowflake
  99. proxies that have an unknown NAT type.
  100. "snowflake-proxy-poll-with-relay-url-count" NUM NL
  101. [At most once.]
  102. A count of snowflake proxy polls with relay url extension present.
  103. This means this proxy understands relay url, and is sending its
  104. allowed prefix.
  105. "snowflake-proxy-poll-without-relay-url-count" NUM NL
  106. [At most once.]
  107. A count of snowflake proxy polls with relay url extension absent.
  108. This means this proxy is not yet updated.
  109. "snowflake-proxy-rejected-for-relay-url-count" NUM NL
  110. [At most once.]
  111. A count of snowflake proxy polls with relay url extension rejected
  112. based on broker's relay url extension policy.
  113. This means an incompatible allowed relay pattern is included in the
  114. proxy poll message.
  115. 2. Broker messaging specification and endpoints
  116. The broker facilitates the connection of snowflake clients and snowflake proxies
  117. through the exchange of WebRTC SDP information with its endpoints.
  118. 2.1. Client interactions with the broker
  119. The broker offers multiple ways for clients to exchange registration
  120. messages.
  121. 2.1.1. HTTPS POST
  122. Clients interact with the broker by making a POST request to `/client` with the
  123. offer SDP in the request body:
  124. ```
  125. POST /client HTTP
  126. [offer SDP]
  127. ```
  128. If the broker is behind a domain-fronted connection, this request is accompanied
  129. with the necessary HOST information.
  130. If the client is matched up with a proxy, they receive a 200 OK response with
  131. the proxy's answer SDP in the request body:
  132. ```
  133. HTTP 200 OK
  134. [answer SDP]
  135. ```
  136. If no proxies were available, they receive a 503 status code:
  137. ```
  138. HTTP 503 Service Unavailable
  139. ```
  140. 2.1.2. AMP
  141. The broker's /amp/client endpoint receives client poll messages encoded
  142. into the URL path, and sends client poll responses encoded as HTML that
  143. conforms to the requirements of AMP (Accelerated Mobile Pages). This
  144. endpoint is intended to be accessed through an AMP cache, using the
  145. -ampcache option of snowflake-client.
  146. The client encodes its poll message into a GET request as follows:
  147. ```
  148. GET /amp/client/0[0 or more bytes]/[base64 of client poll message]
  149. ```
  150. The components of the path are as follows:
  151. * "/amp/client/", the root of the endpoint.
  152. * "0", a format version number, which controls the interpretation of the
  153. rest of the path. Only the first byte matters as a version indicator
  154. (not the whole first path component).
  155. * Any number of slash or non-slash bytes. These may be used as padding
  156. or to prevent cache collisions in the AMP cache.
  157. * A final slash.
  158. * base64 encoding of the client poll message, using the URL-safe
  159. alphabet (which does not include slash).
  160. The broker returns a client poll response message in the HTTP response.
  161. The message is encoded using AMP armor, an AMP-compatible HTML encoding.
  162. The data stream is notionally a "0" byte (a format version indicator)
  163. followed by the base64 encoding of the message (using the standard
  164. alphabet, with "=" padding). This stream is broken into
  165. whitespace-separated chunks, which are then bundled into HTML <pre>
  166. elements. The <pre> elements are then surrounded by AMP boilerplate. To
  167. decode, search the HTML for <pre> elements, concatenate their contents
  168. and join on whitespace, discard the "0" prefix, and base64 decode.
  169. 2.2 Proxy interactions with the broker
  170. Proxies poll the broker with a proxy poll request to `/proxy`:
  171. ```
  172. POST /proxy HTTP
  173. {
  174. Sid: [generated session id of proxy],
  175. Version: 1.3,
  176. Type: ["badge"|"webext"|"standalone"|"mobile"],
  177. NAT: ["unknown"|"restricted"|"unrestricted"],
  178. Clients: [number of current clients, rounded down to multiples of 8],
  179. AcceptedRelayPattern: [a pattern representing accepted set of relay domains]
  180. }
  181. ```
  182. If the request is well-formed, they receive a 200 OK response.
  183. If a client is matched:
  184. ```
  185. HTTP 200 OK
  186. {
  187. Status: "client match",
  188. {
  189. type: offer,
  190. sdp: [WebRTC SDP]
  191. },
  192. RelayURL: [the WebSocket URL proxy should connect to relay Snowflake traffic]
  193. }
  194. ```
  195. If a client is not matched:
  196. ```
  197. HTTP 200 OK
  198. {
  199. Status: "no match"
  200. }
  201. ```
  202. If the request is malformed:
  203. ```
  204. HTTP 400 BadRequest
  205. ```
  206. If they are matched with a client, they provide their SDP answer with a POST
  207. request to `/answer`:
  208. ```
  209. POST /answer HTTP
  210. {
  211. Sid: [generated session id of proxy],
  212. Version: 1.3,
  213. Answer:
  214. {
  215. type: answer,
  216. sdp: [WebRTC SDP]
  217. }
  218. }
  219. ```
  220. If the request is well-formed, they receive a 200 OK response.
  221. If the client retrieved the answer:
  222. ```
  223. HTTP 200 OK
  224. {
  225. Status: "success"
  226. }
  227. ```
  228. If the client left:
  229. ```
  230. HTTP 200 OK
  231. {
  232. Status: "client gone"
  233. }
  234. 3) If the request is malformed:
  235. HTTP 400 BadRequest
  236. ```