syncthing-relay.7 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700
  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" "Jun 26, 2025" "v1.29.7" "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. .UNINDENT
  241. .sp
  242. 4. RelayFull \- Relay limits are too strict for you to be able to join the session.
  243. The relay immediately terminates the connection after sending this.
  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. .SS ConnectRequest message (Type = 5)
  473. .INDENT 0.0
  474. .INDENT 3.5
  475. .sp
  476. .EX
  477. 0 1 2 3
  478. 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
  479. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  480. | Length of ID |
  481. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  482. / /
  483. \e ID (variable length) \e
  484. / /
  485. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  486. struct ConnectRequest {
  487. opaque ID<32>;
  488. }
  489. .EE
  490. .UNINDENT
  491. .UNINDENT
  492. .INDENT 0.0
  493. .TP
  494. .B : ID
  495. Device ID to which the client would like to connect.
  496. .UNINDENT
  497. .SS SessionInvitation message (Type = 6)
  498. .INDENT 0.0
  499. .INDENT 3.5
  500. .sp
  501. .EX
  502. 0 1 2 3
  503. 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
  504. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  505. | Length of From |
  506. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  507. / /
  508. \e From (variable length) \e
  509. / /
  510. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  511. | Length of Key |
  512. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  513. / /
  514. \e Key (variable length) \e
  515. / /
  516. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  517. | Length of Address |
  518. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  519. / /
  520. \e Address (variable length) \e
  521. / /
  522. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  523. | 0x0000 | Port |
  524. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  525. | Server Socket (V=0 or 1) |V|
  526. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  527. struct SessionInvitation {
  528. opaque From<32>;
  529. opaque Key<32>;
  530. opaque Address<32>;
  531. unsigned int Port;
  532. bool ServerSocket;
  533. }
  534. .EE
  535. .UNINDENT
  536. .UNINDENT
  537. .INDENT 0.0
  538. .TP
  539. .B : From
  540. Device ID identifying who you will be connecting with.
  541. .TP
  542. .B : Key
  543. A unique random session key generated by the relay server. It is used to
  544. identify which session you are trying to connect to.
  545. .TP
  546. .B : Address
  547. An optional IP address on which the relay server is expecting you to
  548. connect, in order to start a connection in session mode.
  549. Empty/all zero IP should be replaced with the relay’s public IP address that
  550. was used when establishing the protocol mode connection.
  551. .TP
  552. .B : Port
  553. The port on which the relay server is expecting you to connect,
  554. in order to start a connection in session mode.
  555. .TP
  556. .B : Server Socket
  557. Because both sides connecting to the relay use the client side of the socket,
  558. and some protocols behave differently depending if the connection starts on
  559. the server side or the client side, this boolean indicates which side of the
  560. connection this client should assume it’s getting. The value is inverted in
  561. the invitation which is sent to the other device, so that there is always
  562. one client socket, and one server socket.
  563. .UNINDENT
  564. .SS RelayFull message (Type = 7)
  565. .INDENT 0.0
  566. .INDENT 3.5
  567. .sp
  568. .EX
  569. 0 1 2 3
  570. 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
  571. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  572. struct RelayFull {
  573. }
  574. .EE
  575. .UNINDENT
  576. .UNINDENT
  577. .SH HOW SYNCTHING USES RELAYS, AND GENERAL SECURITY
  578. .sp
  579. In the case of Syncthing and BEP, when two devices connect via relay, they
  580. start their standard TLS connection encapsulated within the relay’s plain\-text
  581. session connection, effectively upgrading the plain\-text connection to a TLS
  582. connection.
  583. .sp
  584. Even though the relay could be used for man\-in\-the\-middle attack, using TLS
  585. at the application/BEP level ensures that all the traffic is safely encrypted,
  586. and is completely meaningless to the relay. Furthermore, the secure suite of
  587. ciphers used by BEP provides forward secrecy, meaning that even if the relay
  588. did capture all the traffic, and even if the attacker did get their hands on the
  589. device keys, they would still not be able to recover/decrypt any traffic which
  590. was transported via the relay.
  591. .sp
  592. After establishing a relay session, Syncthing looks at the SessionInvitation
  593. message, and depending which side it has received, wraps the raw socket in
  594. either a TLS client socket or a TLS server socket depending on the ServerSocket
  595. boolean value in the SessionInvitation, and starts the TLS handshake.
  596. .sp
  597. From that point onwards it functions exactly the same way as if Syncthing was
  598. establishing a direct connection with the other device over the internet,
  599. performing device ID validation, and full TLS encryption, and provides the same
  600. security properties as it would provide when connecting over the internet.
  601. .SH EXAMPLES OF STRONG CIPHER SUITES
  602. .TS
  603. box center;
  604. l|l|l.
  605. T{
  606. ID
  607. T} T{
  608. Name
  609. T} T{
  610. Description
  611. T}
  612. _
  613. T{
  614. 0x009F
  615. T} T{
  616. DHE\-RSA\-AES256\-GCM\-SHA384
  617. T} T{
  618. TLSv1.2 DH RSA AESGCM(256) AEAD
  619. T}
  620. _
  621. T{
  622. 0x006B
  623. T} T{
  624. DHE\-RSA\-AES256\-SHA256
  625. T} T{
  626. TLSv1.2 DH RSA AES(256) SHA256
  627. T}
  628. _
  629. T{
  630. 0xC030
  631. T} T{
  632. ECDHE\-RSA\-AES256\-GCM\-SHA384
  633. T} T{
  634. TLSv1.2 ECDH RSA AESGCM(256) AEAD
  635. T}
  636. _
  637. T{
  638. 0xC028
  639. T} T{
  640. ECDHE\-RSA\-AES256\-SHA384
  641. T} T{
  642. TLSv1.2 ECDH RSA AES(256) SHA384
  643. T}
  644. _
  645. T{
  646. 0x009E
  647. T} T{
  648. DHE\-RSA\-AES128\-GCM\-SHA256
  649. T} T{
  650. TLSv1.2 DH RSA AESGCM(128) AEAD
  651. T}
  652. _
  653. T{
  654. 0x0067
  655. T} T{
  656. DHE\-RSA\-AES128\-SHA256
  657. T} T{
  658. TLSv1.2 DH RSA AES(128) SHA256
  659. T}
  660. _
  661. T{
  662. 0xC02F
  663. T} T{
  664. ECDHE\-RSA\-AES128\-GCM\-SHA256
  665. T} T{
  666. TLSv1.2 ECDH RSA AESGCM(128) AEAD
  667. T}
  668. _
  669. T{
  670. 0xC027
  671. T} T{
  672. ECDHE\-RSA\-AES128\-SHA256
  673. T} T{
  674. TLSv1.2 ECDH RSA AES(128) SHA256
  675. T}
  676. .TE
  677. .SH AUTHOR
  678. The Syncthing Authors
  679. .SH COPYRIGHT
  680. 2014-2019, The Syncthing Authors
  681. .\" Generated by docutils manpage writer.
  682. .