doc.go 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /*
  2. * Copyright (c) 2023, Psiphon Inc.
  3. * All rights reserved.
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. *
  18. */
  19. /*
  20. Package inproxy enables 3rd party, ephemeral proxies to help Psiphon clients
  21. connect to the Psiphon network.
  22. The in-proxy architecture is inspired by and similar to Tor's snowflake
  23. pluggable transport, https://snowflake.torproject.org/.
  24. With in-proxy, Psiphon clients are matched with proxies by brokers run by the
  25. Psiphon network.
  26. In addition to proxies in unblocked regions, proxies in blocked regions are
  27. supported, to facilitate the use cases such as a local region hop from a
  28. mobile ISP, where international traffic may be expensive and throttled, to a
  29. home ISP, which may be less restricted.
  30. The proxy/server hop uses the full range of Psiphon tunnel protocols,
  31. providing blocking circumvention on the 2nd hop.
  32. Proxies don't create Psiphon tunnels, they just relay either TCP or UDP flows
  33. from the client to the server, where those flows are Psiphon tunnel
  34. protocols. Proxies don't need to be upgraded in order to relay newer Psiphon
  35. tunnel protocols or protocol variants.
  36. Proxies cannot see the client traffic within the relayed Psiphon tunnel.
  37. Brokers verify that client destinations are valid Psiphon servers only, so
  38. proxies cannot be misused for non-Psiphon relaying.
  39. To limit the set of Psiphon servers that proxies can observe and enumerate,
  40. client destinations are limited to the set of servers specifically designated
  41. with in-proxy capabilities. This is enforced by the broker.
  42. Proxies are compartmentalized in two ways; (1) personal proxies will use a
  43. personal compartment ID to limit access to clients run by users with whom the
  44. proxy operator has shared, out-of-band, a personal compartment ID, or access
  45. token; (2) common proxies will be assigned a common compartment ID by the
  46. Psiphon network to limit access to clients that have obtained the common
  47. compartment ID, or access token, from Psiphon through channels such as
  48. targeted tactics or embedded in OSLs.
  49. Proxies are expected to be run for longer periods, on desktop computers. The
  50. in-proxy design does not currently support browser extension or website
  51. widget proxies.
  52. The client/proxy hop uses WebRTC, with the broker playing the role of a WebRTC
  53. signaling server in addition to matching clients and proxies. Clients and
  54. proxies gather ICE candidates, including any host candidates, IPv4 or IPv6,
  55. as well as STUN server reflexive candidates. In addition, any available port
  56. mapping protocols -- UPnP-IGD, NAT-PMP, PCP -- are used to gather port
  57. mapping candidates, which are injected into ICE SDPs as host candidates. TURN
  58. candidates are not used.
  59. NAT topology discovery is performed and metrics sent to broker to optimize
  60. utility and matching of proxies to clients. Mobile networks may be assumed to
  61. be CGNAT in case NAT discovery fails or is skipped. And, for mobile networks,
  62. there is an option to skip discovery and STUN for a faster dial.
  63. The client-proxy is a WebRTC data channel; on the wire, it is DTLS, preceded
  64. by an ICE STUN packet. By default, WebRTC DTLS is configured to look like
  65. common browsers. In addition, the DTLS ClientHello can be randomized. Proxy
  66. endpoints are ephemeral, but if they were to be scanned or probed, the
  67. response should look like common WebRTC stacks that receive packets from
  68. invalid peers.
  69. Clients and proxies connect to brokers via a domain fronting transport; the
  70. transport is abstracted and other channels may be provided. Within that
  71. transport, a Noise protocol framework session is established between
  72. clients/proxies and a broker, to ensure privacy, authentication, and replay
  73. defense between the end points; not even a domain fronting CDN can observe
  74. the transactions within a session. The session has an additional obfuscation
  75. layer that renders the messages as fully random, which may be suitable for
  76. encapsulating in plaintext transports; adds random padding; and detects
  77. replay of any message.
  78. For clients and proxies, all broker and WebRTC dial parameters, including
  79. domain fronting, STUN server selection, NAT discovery behavior, timeouts, and
  80. so on are remotely configurable via Psiphon tactics. Callbacks facilitate
  81. replay of successful dial parameters for individual stages of a dial,
  82. including a successful broker connection, or a working STUN server.
  83. For each proxied client tunnel, brokers use secure sessions to send the
  84. destination Psiphon server a message indicating the proxy ID that's relaying
  85. the client's traffic, the original client IP, and additional metrics to be
  86. logged with the server_tunnel log for the tunnel. Neither a client nor a
  87. proxy is trusted to report the original client IP or the proxy ID.
  88. Instead of having the broker connect out to Psiphon servers, and trying to
  89. synchronize reliable arrival of these messages, the broker uses the client to
  90. relay secure session packets -- the message, preceded by a session handshake
  91. if required -- inline, in the client/broker and client/server tunnel
  92. connections. These session packets piggyback on top of client/broker and
  93. client/server round trips that happen anyway, including the Psiphon API
  94. handshake.
  95. Psiphon servers with in-proxy capabilities should be configured, on in-proxy
  96. listeners, to require receipt of this broker message before finalizing
  97. traffic rules, issuing tactics, issuing OSL progress, or allowing traffic
  98. tunneling. The original client IP reported by the broker should be used for
  99. all client GeoIP policy decisions and logging.
  100. The proxy ID corresponds to the proxy's secure session public key; the proxy
  101. proves possession of the corresponding private key in the session handshake.
  102. Proxy IDs are not revealed to clients; only to brokers and Psiphon servers. A
  103. proxy may maintain a long-term key pair and corresponding proxy ID, and that
  104. may be used by Psiphon to assign reputation to well-performing proxies or to
  105. issue rewards for proxies.
  106. Each secure session public key is an Ed25519 public key. This public key is
  107. used for signatures, including the session reset token in the session
  108. protocol. This signing key may also be used, externally, in a
  109. challenge/response registration process where a proxy operator can
  110. demonstrate ownership of a proxy public key and its corresponding proxy ID.
  111. For use in ECDH in the Noise protocol, the Ed25519 public key is converted to
  112. the corresponding, unique Curve25519 public key.
  113. Logged proxy ID values will be the Curve25519 representation of the public
  114. key. Since Curve25519 public keys don't uniquely map back to Ed25519 public
  115. keys, any external proxy registration system should store the Ed25519 public
  116. key and derive the corresponding Curve25519 when mapping server tunnel proxy
  117. IDs back to the Ed25519 proxy public key.
  118. The proxy is designed to be bundled with the tunnel-core client, run
  119. optionally, and integrated with its tactics, data store, and logging. The
  120. broker is designed to be bundled with the Psiphon server, psiphond, and, like
  121. tactics requests, run under MeekServer; and use the tactics, psinet database,
  122. GeoIP services, and logging services provided by psiphond.
  123. The build tag PSIPHON_ENABLE_INPROXY must be specified in order to enable
  124. in-proxy components. Without this build tag, the components are disabled and
  125. larger dependencies are not referenced and excluded from builds.
  126. */
  127. package inproxy