syncthing-relay.7 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712
  1. '\" t
  2. .\" Man page generated from reStructuredText.
  3. .
  4. .
  5. .nr rst2man-indent-level 0
  6. .
  7. .de1 rstReportMargin
  8. \\$1 \\n[an-margin]
  9. level \\n[rst2man-indent-level]
  10. level margin: \\n[rst2man-indent\\n[rst2man-indent-level]]
  11. -
  12. \\n[rst2man-indent0]
  13. \\n[rst2man-indent1]
  14. \\n[rst2man-indent2]
  15. ..
  16. .de1 INDENT
  17. .\" .rstReportMargin pre:
  18. . RS \\$1
  19. . nr rst2man-indent\\n[rst2man-indent-level] \\n[an-margin]
  20. . nr rst2man-indent-level +1
  21. .\" .rstReportMargin post:
  22. ..
  23. .de UNINDENT
  24. . RE
  25. .\" indent \\n[an-margin]
  26. .\" old: \\n[rst2man-indent\\n[rst2man-indent-level]]
  27. .nr rst2man-indent-level -1
  28. .\" new: \\n[rst2man-indent\\n[rst2man-indent-level]]
  29. .in \\n[rst2man-indent\\n[rst2man-indent-level]]u
  30. ..
  31. .TH "SYNCTHING-RELAY" "7" "Nov 27, 2025" "v2.0.0" "Syncthing"
  32. .SH NAME
  33. syncthing-relay \- Relay Protocol v1
  34. .SH WHAT IS A RELAY?
  35. .sp
  36. Relay is a service which relays data between two \fIdevices\fP which are not able to
  37. connect to each other directly otherwise. This is usually due to both devices
  38. being behind a NAT and neither side being able to open a port which would
  39. be directly accessible from the internet.
  40. .sp
  41. A relay was designed to relay BEP protocol, hence the reliance on device ID’s
  42. in the protocol spec, but at the same time it is general enough that could be
  43. reused by other protocols or applications, as the data transferred between two
  44. devices which use a relay is completely obscure and does not affect the
  45. relaying.
  46. .SH OPERATION MODES
  47. .sp
  48. Relay listens on a single TCP socket, but has two different connection modes,
  49. where a connection mode is a predefined set of messages which the relay and
  50. the device are expecting to exchange.
  51. .sp
  52. The first mode is the \fIprotocol\fP mode which allows a client to interact
  53. with the relay, for example join the relay, or request to connect to a device,
  54. given it is available on the relay. Similarly to BEP, protocol mode requires
  55. the device to connect via TLS using a strong suite of ciphers (same as BEP),
  56. which allows the relay to verify and derive the identity (Device ID) of the
  57. device.
  58. .sp
  59. The second mode is the \fIsession\fP mode which after a few initial messages
  60. connects two devices directly to each other via the relay, and is a plain\-text
  61. protocol, which for every byte written by one device, sends the same set of
  62. bytes to the other device and vica versa.
  63. .SH IDENTIFYING THE CONNECTION MODE
  64. .sp
  65. Because both connection modes operate over the same single socket, a method
  66. of detecting the connection mode is required.
  67. .sp
  68. When a new client connects to the relay, the relay checks the first byte
  69. that the client has sent, and if that matches 0x16, that implies to us that
  70. the connection is a protocol mode connection, due to 0x16 being the first byte
  71. in the TLS handshake, and only protocol mode connections use TLS.
  72. .sp
  73. If the first byte is not 0x16, then we assume that the connection is a session
  74. mode connection.
  75. .SH PROTOCOL MODE
  76. .sp
  77. Protocol mode uses TLS and protocol name defined by the TLS header should be
  78. \fIbep\-relay\fP\&.
  79. .sp
  80. Protocol mode has two submodes:
  81. 1. Permanent protocol submode \- Joining the relay, and waiting for messages from
  82. the relay asking to connect to some device which is interested in having a
  83. session with you.
  84. 2. Temporary protocol submode \- Only used to request a session with a device
  85. which is connected to the relay using the permanent protocol submode.
  86. .SS Permanent protocol submode
  87. .sp
  88. A permanent protocol submode begins with the client sending a JoinRelayRequest
  89. message, which the relay responds to with either a ResponseSuccess or
  90. ResponseAlreadyConnected message if a client with the same device ID already
  91. exists.
  92. .sp
  93. After the client has joined, no more messages are exchanged apart from
  94. Ping/Pong messages for general connection keep alive checking.
  95. .sp
  96. From this point onwards, the client stand\-by’s and waits for SessionInvitation
  97. messages from the relay, which implies that some other device is trying to
  98. connect with you. SessionInvitation message contains the unique session key
  99. which then can be used to establish a connection in session mode.
  100. .sp
  101. If the client fails to send a JoinSessionRequest message within the first ping
  102. interval, the connection is terminated.
  103. If the client fails to send a message (even if it’s a ping message) every minute
  104. (by default), the connection is terminated.
  105. .SS Temporary protocol submode
  106. .sp
  107. A temporary protocol submode begins with ConnectRequest message, to which the
  108. relay responds with ResponseNotFound if the device the client it is after
  109. is not available, with a RelayFull if the relay has reached its limits,
  110. or with a SessionInvitation, which contains the unique session
  111. key which then can be used to establish a connection in session mode.
  112. .sp
  113. The connection is terminated immediately after that.
  114. .SS Example Exchange
  115. .sp
  116. Client A \- Permanent protocol submode
  117. Client B \- Temporary protocol submode
  118. .TS
  119. box center;
  120. l|l|l|l.
  121. T{
  122. #
  123. T} T{
  124. Client (A)
  125. T} T{
  126. Relay
  127. T} T{
  128. Client (B)
  129. T}
  130. _
  131. T{
  132. 1
  133. T} T{
  134. JoinRelayRequest\->
  135. T} T{
  136. T} T{
  137. T}
  138. _
  139. T{
  140. 2
  141. T} T{
  142. T} T{
  143. <\-ResponseSuccess
  144. T} T{
  145. T}
  146. _
  147. T{
  148. 3
  149. T} T{
  150. Ping\->
  151. T} T{
  152. T} T{
  153. T}
  154. _
  155. T{
  156. 4
  157. T} T{
  158. T} T{
  159. <\-Pong
  160. T} T{
  161. T}
  162. _
  163. T{
  164. 5
  165. T} T{
  166. T} T{
  167. T} T{
  168. <\-ConnectRequest(A)
  169. T}
  170. _
  171. T{
  172. 6
  173. T} T{
  174. T} T{
  175. SessionInvitation(A)\->
  176. T} T{
  177. T}
  178. _
  179. T{
  180. 7
  181. T} T{
  182. T} T{
  183. <\-SessionInvitation(B)
  184. T} T{
  185. T}
  186. _
  187. T{
  188. 8
  189. T} T{
  190. T} T{
  191. T} T{
  192. (Disconnects)
  193. T}
  194. _
  195. T{
  196. 9
  197. T} T{
  198. Ping\->
  199. T} T{
  200. T} T{
  201. T}
  202. _
  203. T{
  204. 10
  205. T} T{
  206. T} T{
  207. <\-Pong
  208. T} T{
  209. T}
  210. _
  211. T{
  212. 11
  213. T} T{
  214. Ping\->
  215. T} T{
  216. T} T{
  217. T}
  218. _
  219. T{
  220. 12
  221. T} T{
  222. T} T{
  223. <\-Pong
  224. T} T{
  225. T}
  226. .TE
  227. .SH SESSION MODE
  228. .sp
  229. The first and only message the client sends in the session mode is the
  230. JoinSessionRequest message which contains the session key identifying which
  231. session you are trying to join. The relay responds with one of the following
  232. messages:
  233. .INDENT 0.0
  234. .IP 1. 3
  235. ResponseNotFound \- Session key is invalid
  236. .IP 2. 3
  237. ResponseAlreadyConnected \- Session is full (both sides already connected)
  238. .IP 3. 3
  239. ResponseSuccess \- You have successfully joined the session
  240. .IP 4. 3
  241. RelayFull \- Relay limits are too strict for you to be able to join the session.
  242. The relay immediately terminates the connection after sending this.
  243. .UNINDENT
  244. .sp
  245. After the successful response, all the bytes written and received will be
  246. relayed between the two devices in the session directly.
  247. .SS Example Exchange
  248. .sp
  249. Client A is the first to join the session.
  250. .sp
  251. Client B is the second to join the session.
  252. .sp
  253. Both are in session mode.
  254. .TS
  255. box center;
  256. l|l|l|l.
  257. T{
  258. #
  259. T} T{
  260. Client (A)
  261. T} T{
  262. Relay
  263. T} T{
  264. Client (B)
  265. T}
  266. _
  267. T{
  268. 1
  269. T} T{
  270. JoinSessionRequest(A)\->
  271. T} T{
  272. T} T{
  273. T}
  274. _
  275. T{
  276. 2
  277. T} T{
  278. T} T{
  279. <\-ResponseSuccess
  280. T} T{
  281. T}
  282. _
  283. T{
  284. 3
  285. T} T{
  286. Data\->
  287. T} T{
  288. (Buffers data)
  289. T} T{
  290. T}
  291. _
  292. T{
  293. 4
  294. T} T{
  295. Data\->
  296. T} T{
  297. (Buffers data)
  298. T} T{
  299. T}
  300. _
  301. T{
  302. 5
  303. T} T{
  304. T} T{
  305. T} T{
  306. <\-JoinSessionRequest(B)
  307. T}
  308. _
  309. T{
  310. 6
  311. T} T{
  312. T} T{
  313. ResponseSuccess\->
  314. T} T{
  315. T}
  316. _
  317. T{
  318. 7
  319. T} T{
  320. T} T{
  321. Relays data \->
  322. T} T{
  323. T}
  324. _
  325. T{
  326. 8
  327. T} T{
  328. T} T{
  329. Relays data \->
  330. T} T{
  331. T}
  332. _
  333. T{
  334. 9
  335. T} T{
  336. T} T{
  337. <\-Relays data
  338. T} T{
  339. <\-Data
  340. T}
  341. .TE
  342. .SH MESSAGES
  343. .sp
  344. All messages are preceded by a header message. Header message contains the
  345. magic value 0x9E79BC40, message type integer, and message length.
  346. .sp
  347. \fBWARNING:\fP
  348. .INDENT 0.0
  349. .INDENT 3.5
  350. Some messages have no content, apart from the implied header which allows
  351. us to identify what type of message it is.
  352. .UNINDENT
  353. .UNINDENT
  354. .SS Header structure
  355. .INDENT 0.0
  356. .INDENT 3.5
  357. .sp
  358. .EX
  359. 0 1 2 3
  360. 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
  361. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  362. | Magic |
  363. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  364. | Message Type |
  365. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  366. | Message Length |
  367. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  368. struct Header {
  369. unsigned int Magic;
  370. int MessageType;
  371. int MessageLength;
  372. }
  373. .EE
  374. .UNINDENT
  375. .UNINDENT
  376. .SS Ping message (Type = 0)
  377. .INDENT 0.0
  378. .INDENT 3.5
  379. .sp
  380. .EX
  381. 0 1 2 3
  382. 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
  383. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  384. struct Ping {
  385. }
  386. .EE
  387. .UNINDENT
  388. .UNINDENT
  389. .SS Pong message (Type = 1)
  390. .INDENT 0.0
  391. .INDENT 3.5
  392. .sp
  393. .EX
  394. 0 1 2 3
  395. 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
  396. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  397. struct Pong {
  398. }
  399. .EE
  400. .UNINDENT
  401. .UNINDENT
  402. .SS JoinRelayRequest message (Type = 2)
  403. .INDENT 0.0
  404. .INDENT 3.5
  405. .sp
  406. .EX
  407. 0 1 2 3
  408. 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
  409. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  410. struct JoinRelayRequest {
  411. }
  412. .EE
  413. .UNINDENT
  414. .UNINDENT
  415. .SS JoinSessionRequest message (Type = 3)
  416. .INDENT 0.0
  417. .INDENT 3.5
  418. .sp
  419. .EX
  420. 0 1 2 3
  421. 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
  422. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  423. | Length of Key |
  424. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  425. / /
  426. \e Key (variable length) \e
  427. / /
  428. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  429. struct JoinSessionRequest {
  430. opaque Key<32>;
  431. }
  432. .EE
  433. .UNINDENT
  434. .UNINDENT
  435. .INDENT 0.0
  436. .TP
  437. .B : Key
  438. This is a unique random session key generated by the relay server. It is
  439. used to identify which session you are trying to connect to.
  440. .UNINDENT
  441. .SS Response message (Type = 4)
  442. .INDENT 0.0
  443. .INDENT 3.5
  444. .sp
  445. .EX
  446. 0 1 2 3
  447. 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
  448. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  449. | Code |
  450. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  451. | Length of Message |
  452. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  453. / /
  454. \e Message (variable length) \e
  455. / /
  456. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  457. struct Response {
  458. int Code;
  459. string Message<>;
  460. }
  461. .EE
  462. .UNINDENT
  463. .UNINDENT
  464. .INDENT 0.0
  465. .TP
  466. .B : Code
  467. An integer representing the status code.
  468. .TP
  469. .B : Message
  470. Message associated with the code.
  471. .UNINDENT
  472. .INDENT 0.0
  473. .INDENT 3.5
  474. .sp
  475. .EX
  476. ResponseSuccess = Response{0, \(dqsuccess\(dq}
  477. ResponseNotFound = Response{1, \(dqnot found\(dq}
  478. ResponseAlreadyConnected = Response{2, \(dqalready connected\(dq}
  479. ResponseInternalError = Response{99, \(dqinternal error\(dq}
  480. ResponseUnexpectedMessage = Response{100, \(dqunexpected message\(dq}
  481. .EE
  482. .UNINDENT
  483. .UNINDENT
  484. .SS ConnectRequest message (Type = 5)
  485. .INDENT 0.0
  486. .INDENT 3.5
  487. .sp
  488. .EX
  489. 0 1 2 3
  490. 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
  491. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  492. | Length of ID |
  493. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  494. / /
  495. \e ID (variable length) \e
  496. / /
  497. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  498. struct ConnectRequest {
  499. opaque ID<32>;
  500. }
  501. .EE
  502. .UNINDENT
  503. .UNINDENT
  504. .INDENT 0.0
  505. .TP
  506. .B : ID
  507. Device ID to which the client would like to connect.
  508. .UNINDENT
  509. .SS SessionInvitation message (Type = 6)
  510. .INDENT 0.0
  511. .INDENT 3.5
  512. .sp
  513. .EX
  514. 0 1 2 3
  515. 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
  516. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  517. | Length of From |
  518. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  519. / /
  520. \e From (variable length) \e
  521. / /
  522. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  523. | Length of Key |
  524. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  525. / /
  526. \e Key (variable length) \e
  527. / /
  528. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  529. | Length of Address |
  530. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  531. / /
  532. \e Address (variable length) \e
  533. / /
  534. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  535. | 0x0000 | Port |
  536. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  537. | Server Socket (V=0 or 1) |V|
  538. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  539. struct SessionInvitation {
  540. opaque From<32>;
  541. opaque Key<32>;
  542. opaque Address<32>;
  543. unsigned int Port;
  544. bool ServerSocket;
  545. }
  546. .EE
  547. .UNINDENT
  548. .UNINDENT
  549. .INDENT 0.0
  550. .TP
  551. .B : From
  552. Device ID identifying who you will be connecting with.
  553. .TP
  554. .B : Key
  555. A unique random session key generated by the relay server. It is used to
  556. identify which session you are trying to connect to.
  557. .TP
  558. .B : Address
  559. An optional IP address on which the relay server is expecting you to
  560. connect, in order to start a connection in session mode.
  561. Empty/all zero IP should be replaced with the relay’s public IP address that
  562. was used when establishing the protocol mode connection.
  563. .TP
  564. .B : Port
  565. The port on which the relay server is expecting you to connect,
  566. in order to start a connection in session mode.
  567. .TP
  568. .B : Server Socket
  569. Because both sides connecting to the relay use the client side of the socket,
  570. and some protocols behave differently depending if the connection starts on
  571. the server side or the client side, this boolean indicates which side of the
  572. connection this client should assume it’s getting. The value is inverted in
  573. the invitation which is sent to the other device, so that there is always
  574. one client socket, and one server socket.
  575. .UNINDENT
  576. .SS RelayFull message (Type = 7)
  577. .INDENT 0.0
  578. .INDENT 3.5
  579. .sp
  580. .EX
  581. 0 1 2 3
  582. 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
  583. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  584. struct RelayFull {
  585. }
  586. .EE
  587. .UNINDENT
  588. .UNINDENT
  589. .SH HOW SYNCTHING USES RELAYS, AND GENERAL SECURITY
  590. .sp
  591. In the case of Syncthing and BEP, when two devices connect via relay, they
  592. start their standard TLS connection encapsulated within the relay’s plain\-text
  593. session connection, effectively upgrading the plain\-text connection to a TLS
  594. connection.
  595. .sp
  596. Even though the relay could be used for man\-in\-the\-middle attack, using TLS
  597. at the application/BEP level ensures that all the traffic is safely encrypted,
  598. and is completely meaningless to the relay. Furthermore, the secure suite of
  599. ciphers used by BEP provides forward secrecy, meaning that even if the relay
  600. did capture all the traffic, and even if the attacker did get their hands on the
  601. device keys, they would still not be able to recover/decrypt any traffic which
  602. was transported via the relay.
  603. .sp
  604. After establishing a relay session, Syncthing looks at the SessionInvitation
  605. message, and depending which side it has received, wraps the raw socket in
  606. either a TLS client socket or a TLS server socket depending on the ServerSocket
  607. boolean value in the SessionInvitation, and starts the TLS handshake.
  608. .sp
  609. From that point onwards it functions exactly the same way as if Syncthing was
  610. establishing a direct connection with the other device over the internet,
  611. performing device ID validation, and full TLS encryption, and provides the same
  612. security properties as it would provide when connecting over the internet.
  613. .SH EXAMPLES OF STRONG CIPHER SUITES
  614. .TS
  615. box center;
  616. l|l|l.
  617. T{
  618. ID
  619. T} T{
  620. Name
  621. T} T{
  622. Description
  623. T}
  624. _
  625. T{
  626. 0x009F
  627. T} T{
  628. DHE\-RSA\-AES256\-GCM\-SHA384
  629. T} T{
  630. TLSv1.2 DH RSA AESGCM(256) AEAD
  631. T}
  632. _
  633. T{
  634. 0x006B
  635. T} T{
  636. DHE\-RSA\-AES256\-SHA256
  637. T} T{
  638. TLSv1.2 DH RSA AES(256) SHA256
  639. T}
  640. _
  641. T{
  642. 0xC030
  643. T} T{
  644. ECDHE\-RSA\-AES256\-GCM\-SHA384
  645. T} T{
  646. TLSv1.2 ECDH RSA AESGCM(256) AEAD
  647. T}
  648. _
  649. T{
  650. 0xC028
  651. T} T{
  652. ECDHE\-RSA\-AES256\-SHA384
  653. T} T{
  654. TLSv1.2 ECDH RSA AES(256) SHA384
  655. T}
  656. _
  657. T{
  658. 0x009E
  659. T} T{
  660. DHE\-RSA\-AES128\-GCM\-SHA256
  661. T} T{
  662. TLSv1.2 DH RSA AESGCM(128) AEAD
  663. T}
  664. _
  665. T{
  666. 0x0067
  667. T} T{
  668. DHE\-RSA\-AES128\-SHA256
  669. T} T{
  670. TLSv1.2 DH RSA AES(128) SHA256
  671. T}
  672. _
  673. T{
  674. 0xC02F
  675. T} T{
  676. ECDHE\-RSA\-AES128\-GCM\-SHA256
  677. T} T{
  678. TLSv1.2 ECDH RSA AESGCM(128) AEAD
  679. T}
  680. _
  681. T{
  682. 0xC027
  683. T} T{
  684. ECDHE\-RSA\-AES128\-SHA256
  685. T} T{
  686. TLSv1.2 ECDH RSA AES(128) SHA256
  687. T}
  688. .TE
  689. .SH AUTHOR
  690. The Syncthing Authors
  691. .SH COPYRIGHT
  692. 2014-2025, The Syncthing Authors
  693. .\" Generated by docutils manpage writer.
  694. .