1
0

syncthing-relay.7 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701
  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" "Sep 14, 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. .UNINDENT
  243. .sp
  244. The relay immediately terminates the connection after sending this.
  245. .sp
  246. After the successful response, all the bytes written and received will be
  247. relayed between the two devices in the session directly.
  248. .SS Example Exchange
  249. .sp
  250. Client A is the first to join the session.
  251. .sp
  252. Client B is the second to join the session.
  253. .sp
  254. Both are in session mode.
  255. .TS
  256. box center;
  257. l|l|l|l.
  258. T{
  259. #
  260. T} T{
  261. Client (A)
  262. T} T{
  263. Relay
  264. T} T{
  265. Client (B)
  266. T}
  267. _
  268. T{
  269. 1
  270. T} T{
  271. JoinSessionRequest(A)\->
  272. T} T{
  273. T} T{
  274. T}
  275. _
  276. T{
  277. 2
  278. T} T{
  279. T} T{
  280. <\-ResponseSuccess
  281. T} T{
  282. T}
  283. _
  284. T{
  285. 3
  286. T} T{
  287. Data\->
  288. T} T{
  289. (Buffers data)
  290. T} T{
  291. T}
  292. _
  293. T{
  294. 4
  295. T} T{
  296. Data\->
  297. T} T{
  298. (Buffers data)
  299. T} T{
  300. T}
  301. _
  302. T{
  303. 5
  304. T} T{
  305. T} T{
  306. T} T{
  307. <\-JoinSessionRequest(B)
  308. T}
  309. _
  310. T{
  311. 6
  312. T} T{
  313. T} T{
  314. ResponseSuccess\->
  315. T} T{
  316. T}
  317. _
  318. T{
  319. 7
  320. T} T{
  321. T} T{
  322. Relays data \->
  323. T} T{
  324. T}
  325. _
  326. T{
  327. 8
  328. T} T{
  329. T} T{
  330. Relays data \->
  331. T} T{
  332. T}
  333. _
  334. T{
  335. 9
  336. T} T{
  337. T} T{
  338. <\-Relays data
  339. T} T{
  340. <\-Data
  341. T}
  342. .TE
  343. .SH MESSAGES
  344. .sp
  345. All messages are preceded by a header message. Header message contains the
  346. magic value 0x9E79BC40, message type integer, and message length.
  347. .sp
  348. \fBWARNING:\fP
  349. .INDENT 0.0
  350. .INDENT 3.5
  351. Some messages have no content, apart from the implied header which allows
  352. us to identify what type of message it is.
  353. .UNINDENT
  354. .UNINDENT
  355. .SS Header structure
  356. .INDENT 0.0
  357. .INDENT 3.5
  358. .sp
  359. .EX
  360. 0 1 2 3
  361. 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
  362. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  363. | Magic |
  364. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  365. | Message Type |
  366. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  367. | Message Length |
  368. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  369. struct Header {
  370. unsigned int Magic;
  371. int MessageType;
  372. int MessageLength;
  373. }
  374. .EE
  375. .UNINDENT
  376. .UNINDENT
  377. .SS Ping message (Type = 0)
  378. .INDENT 0.0
  379. .INDENT 3.5
  380. .sp
  381. .EX
  382. 0 1 2 3
  383. 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
  384. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  385. struct Ping {
  386. }
  387. .EE
  388. .UNINDENT
  389. .UNINDENT
  390. .SS Pong message (Type = 1)
  391. .INDENT 0.0
  392. .INDENT 3.5
  393. .sp
  394. .EX
  395. 0 1 2 3
  396. 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
  397. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  398. struct Pong {
  399. }
  400. .EE
  401. .UNINDENT
  402. .UNINDENT
  403. .SS JoinRelayRequest message (Type = 2)
  404. .INDENT 0.0
  405. .INDENT 3.5
  406. .sp
  407. .EX
  408. 0 1 2 3
  409. 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
  410. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  411. struct JoinRelayRequest {
  412. }
  413. .EE
  414. .UNINDENT
  415. .UNINDENT
  416. .SS JoinSessionRequest message (Type = 3)
  417. .INDENT 0.0
  418. .INDENT 3.5
  419. .sp
  420. .EX
  421. 0 1 2 3
  422. 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
  423. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  424. | Length of Key |
  425. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  426. / /
  427. \e Key (variable length) \e
  428. / /
  429. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  430. struct JoinSessionRequest {
  431. opaque Key<32>;
  432. }
  433. .EE
  434. .UNINDENT
  435. .UNINDENT
  436. .INDENT 0.0
  437. .TP
  438. .B : Key
  439. This is a unique random session key generated by the relay server. It is
  440. used to identify which session you are trying to connect to.
  441. .UNINDENT
  442. .SS Response message (Type = 4)
  443. .INDENT 0.0
  444. .INDENT 3.5
  445. .sp
  446. .EX
  447. 0 1 2 3
  448. 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
  449. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  450. | Code |
  451. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  452. | Length of Message |
  453. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  454. / /
  455. \e Message (variable length) \e
  456. / /
  457. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  458. struct Response {
  459. int Code;
  460. string Message<>;
  461. }
  462. .EE
  463. .UNINDENT
  464. .UNINDENT
  465. .INDENT 0.0
  466. .TP
  467. .B : Code
  468. An integer representing the status code.
  469. .TP
  470. .B : Message
  471. Message associated with the code.
  472. .UNINDENT
  473. .SS ConnectRequest message (Type = 5)
  474. .INDENT 0.0
  475. .INDENT 3.5
  476. .sp
  477. .EX
  478. 0 1 2 3
  479. 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
  480. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  481. | Length of ID |
  482. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  483. / /
  484. \e ID (variable length) \e
  485. / /
  486. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  487. struct ConnectRequest {
  488. opaque ID<32>;
  489. }
  490. .EE
  491. .UNINDENT
  492. .UNINDENT
  493. .INDENT 0.0
  494. .TP
  495. .B : ID
  496. Device ID to which the client would like to connect.
  497. .UNINDENT
  498. .SS SessionInvitation message (Type = 6)
  499. .INDENT 0.0
  500. .INDENT 3.5
  501. .sp
  502. .EX
  503. 0 1 2 3
  504. 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
  505. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  506. | Length of From |
  507. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  508. / /
  509. \e From (variable length) \e
  510. / /
  511. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  512. | Length of Key |
  513. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  514. / /
  515. \e Key (variable length) \e
  516. / /
  517. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  518. | Length of Address |
  519. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  520. / /
  521. \e Address (variable length) \e
  522. / /
  523. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  524. | 0x0000 | Port |
  525. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  526. | Server Socket (V=0 or 1) |V|
  527. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  528. struct SessionInvitation {
  529. opaque From<32>;
  530. opaque Key<32>;
  531. opaque Address<32>;
  532. unsigned int Port;
  533. bool ServerSocket;
  534. }
  535. .EE
  536. .UNINDENT
  537. .UNINDENT
  538. .INDENT 0.0
  539. .TP
  540. .B : From
  541. Device ID identifying who you will be connecting with.
  542. .TP
  543. .B : Key
  544. A unique random session key generated by the relay server. It is used to
  545. identify which session you are trying to connect to.
  546. .TP
  547. .B : Address
  548. An optional IP address on which the relay server is expecting you to
  549. connect, in order to start a connection in session mode.
  550. Empty/all zero IP should be replaced with the relay’s public IP address that
  551. was used when establishing the protocol mode connection.
  552. .TP
  553. .B : Port
  554. The port on which the relay server is expecting you to connect,
  555. in order to start a connection in session mode.
  556. .TP
  557. .B : Server Socket
  558. Because both sides connecting to the relay use the client side of the socket,
  559. and some protocols behave differently depending if the connection starts on
  560. the server side or the client side, this boolean indicates which side of the
  561. connection this client should assume it’s getting. The value is inverted in
  562. the invitation which is sent to the other device, so that there is always
  563. one client socket, and one server socket.
  564. .UNINDENT
  565. .SS RelayFull message (Type = 7)
  566. .INDENT 0.0
  567. .INDENT 3.5
  568. .sp
  569. .EX
  570. 0 1 2 3
  571. 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
  572. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  573. struct RelayFull {
  574. }
  575. .EE
  576. .UNINDENT
  577. .UNINDENT
  578. .SH HOW SYNCTHING USES RELAYS, AND GENERAL SECURITY
  579. .sp
  580. In the case of Syncthing and BEP, when two devices connect via relay, they
  581. start their standard TLS connection encapsulated within the relay’s plain\-text
  582. session connection, effectively upgrading the plain\-text connection to a TLS
  583. connection.
  584. .sp
  585. Even though the relay could be used for man\-in\-the\-middle attack, using TLS
  586. at the application/BEP level ensures that all the traffic is safely encrypted,
  587. and is completely meaningless to the relay. Furthermore, the secure suite of
  588. ciphers used by BEP provides forward secrecy, meaning that even if the relay
  589. did capture all the traffic, and even if the attacker did get their hands on the
  590. device keys, they would still not be able to recover/decrypt any traffic which
  591. was transported via the relay.
  592. .sp
  593. After establishing a relay session, Syncthing looks at the SessionInvitation
  594. message, and depending which side it has received, wraps the raw socket in
  595. either a TLS client socket or a TLS server socket depending on the ServerSocket
  596. boolean value in the SessionInvitation, and starts the TLS handshake.
  597. .sp
  598. From that point onwards it functions exactly the same way as if Syncthing was
  599. establishing a direct connection with the other device over the internet,
  600. performing device ID validation, and full TLS encryption, and provides the same
  601. security properties as it would provide when connecting over the internet.
  602. .SH EXAMPLES OF STRONG CIPHER SUITES
  603. .TS
  604. box center;
  605. l|l|l.
  606. T{
  607. ID
  608. T} T{
  609. Name
  610. T} T{
  611. Description
  612. T}
  613. _
  614. T{
  615. 0x009F
  616. T} T{
  617. DHE\-RSA\-AES256\-GCM\-SHA384
  618. T} T{
  619. TLSv1.2 DH RSA AESGCM(256) AEAD
  620. T}
  621. _
  622. T{
  623. 0x006B
  624. T} T{
  625. DHE\-RSA\-AES256\-SHA256
  626. T} T{
  627. TLSv1.2 DH RSA AES(256) SHA256
  628. T}
  629. _
  630. T{
  631. 0xC030
  632. T} T{
  633. ECDHE\-RSA\-AES256\-GCM\-SHA384
  634. T} T{
  635. TLSv1.2 ECDH RSA AESGCM(256) AEAD
  636. T}
  637. _
  638. T{
  639. 0xC028
  640. T} T{
  641. ECDHE\-RSA\-AES256\-SHA384
  642. T} T{
  643. TLSv1.2 ECDH RSA AES(256) SHA384
  644. T}
  645. _
  646. T{
  647. 0x009E
  648. T} T{
  649. DHE\-RSA\-AES128\-GCM\-SHA256
  650. T} T{
  651. TLSv1.2 DH RSA AESGCM(128) AEAD
  652. T}
  653. _
  654. T{
  655. 0x0067
  656. T} T{
  657. DHE\-RSA\-AES128\-SHA256
  658. T} T{
  659. TLSv1.2 DH RSA AES(128) SHA256
  660. T}
  661. _
  662. T{
  663. 0xC02F
  664. T} T{
  665. ECDHE\-RSA\-AES128\-GCM\-SHA256
  666. T} T{
  667. TLSv1.2 ECDH RSA AESGCM(128) AEAD
  668. T}
  669. _
  670. T{
  671. 0xC027
  672. T} T{
  673. ECDHE\-RSA\-AES128\-SHA256
  674. T} T{
  675. TLSv1.2 ECDH RSA AES(128) SHA256
  676. T}
  677. .TE
  678. .SH AUTHOR
  679. The Syncthing Authors
  680. .SH COPYRIGHT
  681. 2014-2025, The Syncthing Authors
  682. .\" Generated by docutils manpage writer.
  683. .