packets.txt 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555
  1. Tarsnap client-server protocol packets
  2. ======================================
  3. Unless specified otherwise, all values are stored as big-endian integers.
  4. HMACW(X) = HMAC(<write access key>, X)
  5. HMACR(X) = HMAC(<read access key>, X)
  6. HMACD(X) = HMAC(<delete access key>, X)
  7. In any single connection, the following operation types cannot be mixed:
  8. * Registering a machine.
  9. * Reading files.
  10. * Listing files.
  11. * Transactions (start/commit/write file/delete file, etc.)
  12. In addition, a NETPACKET_WRITE_FEXIST_REQUEST may not be sent while any
  13. other requests are pending on the same connection.
  14. NETPACKET_REGISTER_REQUEST (0x00)
  15. ---------------------------------
  16. A new machine wants to register with the server.
  17. Packet contents:
  18. char user[]
  19. The string user[] must be no more than 255 bytes, and is not NUL terminated.
  20. The server will respond with a NETPACKET_REGISTER_CHALLENGE packet or
  21. a NETPACKET_REGISTER_RESPONSE packet specifying "no such user".
  22. NETPACKET_REGISTER_CHALLENGE (0x80)
  23. -----------------------------------
  24. As part of the machine registration process, the server needs to verify that
  25. the machine has the user password.
  26. Packet contents:
  27. uint8_t salt[32]
  28. uint8_t serverpub[CRYPTO_DH_PUBLEN]
  29. The client must compute DH parameters (priv, pub) from the salt and
  30. password, and then compute K = serverpub^priv. It must then send back a
  31. NETPACKET_REGISTER_CHA_RESPONSE packet.
  32. NOTE: The value serverpub[] expires when the network protocol connection is
  33. closed, so the NETPACKET_REGISTER_CHA_RESPONSE packet MUST be sent as part
  34. of the same connection.
  35. NETPACKET_REGISTER_CHA_RESPONSE (0x01)
  36. --------------------------------------
  37. As part of the machine registration process, the new machine needs to prove
  38. that it holds the user password, and send its access keys and user-friendly
  39. name.
  40. Packet contents:
  41. uint8_t key_put[32]
  42. uint8_t key_get[32]
  43. uint8_t key_delete[32]
  44. uint8_t namelen
  45. char name[namelen]
  46. uint8_t hmac[32]
  47. The string name[namelen] is not NUL terminated.
  48. The value hmac is HMAC(SHA256(K), 0x01 || [the packet minus the final hmac]),
  49. where K is as described under NETPACKET_REGISTER_CHALLENGE. The server will
  50. respond with a NETPACKET_REGISTER_RESPONSE packet.
  51. NETPACKET_REGISTER_RESPONSE (0x81)
  52. ----------------------------------
  53. As part of the machine registration process, the server needs to confirm
  54. that the machine is registered and provide the registration number; or
  55. inform the client that the user or password is incorrect.
  56. Packet contents:
  57. uint8_t status
  58. uint64_t machinenum
  59. uint8_t hmac[32]
  60. The value status is
  61. 0 Success; machinenum is the machine number
  62. 1 No such user
  63. 2 Incorrect hmac (i.e., password is wrong)
  64. 3 Account balance is not positive.
  65. The value machinenum is (uint64_t)(-1) if status is non-zero.
  66. The value hmac is HMAC(SHA256(K), 0x81 || [the packet minus the final hmac]),
  67. where K is as described under NETPACKET_REGISTER_CHALLENGE, if status is 0 or
  68. 3; or zero otherwise.
  69. The server will close the connection after sending this packet.
  70. NETPACKET_TRANSACTION_GETNONCE (0x10)
  71. -------------------------------------
  72. Packet contents:
  73. uint64_t machinenum
  74. NETPACKET_TRANSACTION_GETNONCE_RESPONSE (0x90)
  75. ----------------------------------------------
  76. Packet contents:
  77. uint8_t snonce[32]
  78. NOTE: This server nonce becomes invalid as soon as (a) the network protocol
  79. connection is closed, or (b) a transaction is started by the machine for
  80. which this nonce is being provided.
  81. NETPACKET_TRANSACTION_START (0x11)
  82. ----------------------------------
  83. Packet contents:
  84. uint64_t machinenum
  85. uint8_t operation
  86. uint8_t snonce[32]
  87. uint8_t cnonce[32]
  88. uint8_t state[32]
  89. uint8_t hmac[32]
  90. The value operation is
  91. 0 Write transaction (key = write access key)
  92. 1 Delete transaction (key = delete access key)
  93. 2 Fsck transaction (key = delete access key, state = 0)
  94. 3 Fsck transaction w/o pruning (key = write access key, state = 0).
  95. The value snonce is as provided by the server (see above); the value cnonce
  96. is a random client nonce; the value state is the transaction nonce of the
  97. last committed transaction, or 32 zero bytes if this is the first transaction
  98. by this machine or if this is a fsck transaction.
  99. The value hmac is HMAC(key, 0x11 || [packet minus final hmac]).
  100. The transaction nonce for the new transaction is SHA256(snonce || cnonce).
  101. NETPACKET_TRANSACTION_START_RESPONSE (0x91)
  102. -------------------------------------------
  103. Packet contents:
  104. uint8_t status
  105. uint8_t hmac[32]
  106. The value status is
  107. 0 Success
  108. 1 Bad state (run --fsck)
  109. 2 Account balance is not positive.
  110. A status value of 2 will only ever be sent in response to an attempt to start
  111. a write transaction.
  112. The value hmac is HMAC(key, 0x91 || nonce || status) where key is the write
  113. or delete key as in NETPACKET_TRANSACTION_START and nonce is the transaction
  114. nonce as described above.
  115. NETPACKET_TRANSACTION_COMMIT (0x12)
  116. -----------------------------------
  117. Packet contents:
  118. uint64_t machinenum
  119. uint8_t whichkey
  120. uint8_t nonce[32]
  121. uint8_t hmac[32]
  122. The value whichkey is
  123. 0 key = write access key
  124. 1 key = delete access key.
  125. The value nonce is the transaction nonce for the transaction which the
  126. client wants to have committed.
  127. The value hmac is HMAC(key, 0x12 || [packet minus final hmac]).
  128. NETPACKET_TRANSACTION_COMMIT_RESPONSE (0x92)
  129. --------------------------------------------
  130. Packet contents:
  131. uint8_t hmac[32]
  132. The value hmac is HMAC(key, 0x92 || nonce) where key is the write or delete
  133. key as in NETPACKET_TRANSACTION_COMMIT.
  134. Note that this packet does not indicate that the requested transaction was
  135. committed; only that IF the requested transaction was the most recent
  136. non-committed transaction, THEN it has been committed.
  137. NETPACKET_TRANSACTION_CHECKPOINT (0x13)
  138. ---------------------------------------
  139. Mark a "checkpoint" in a write transaction. When committing a write
  140. transaction, files are omitted from the transaction if (a) they were uploaded
  141. after the last checkpoint, or (b) they were uploaded prior to the penultimate
  142. checkpoint and have class 'i' or 'm'.
  143. Packet contents:
  144. uint64_t machinenum
  145. uint8_t whichkey
  146. uint8_t ckptnonce[32]
  147. uint8_t nonce[32]
  148. uint8_t hmac[32]
  149. The value whichkey is
  150. 0 key = write access key
  151. 1 key = delete access key.
  152. Note that while checkpoints only exist in write transactions, a checkpoint
  153. request can be signed with a delete access key in the "log checkpoint
  154. creation; crash; run tarsnap -d" case.
  155. The value ckptnonce is a random nonce; if a checkpoint request is replayed,
  156. the ckptnonce value must be identical.
  157. The value nonce is the transaction nonce of the current write transaction.
  158. The value hmac is HMAC(0x13 || [packet minute final hmac]).
  159. NETPACKET_TRANSACTION_CHECKPOINT_RESPONSE (0x93)
  160. ------------------------------------------------
  161. Packet contents:
  162. uint8_t status
  163. uint8_t ckptnonce[32]
  164. uint8_t hmac[32]
  165. The value status means:
  166. 0 Success
  167. 1 Transaction nonce is incorrect.
  168. The value hmac is HMAC(key, 0x93 || nonce || [packet minus final hmac]),
  169. where nonce is the nonce provided by the client (which may not be the nonce
  170. of the current transaction, if status == 1), and key is the write or delete
  171. key as in NETPACKET_TRANSACTION_CHECKPOINT.
  172. NETPACKET_TRANSACTION_CANCEL (0x14)
  173. -----------------------------------
  174. The client wants to cancel any pending transaction as with TRANSACTION_START,
  175. but not actually start a transaction (yet).
  176. Packet contents:
  177. uint64_t machinenum
  178. uint8_t whichkey
  179. uint8_t snonce[32]
  180. uint8_t cnonce[32]
  181. uint8_t state[32]
  182. uint8_t hmac[32]
  183. The value whichkey is
  184. 0 key = write access key
  185. 1 key = delete access key
  186. 2 key = delete access key and state = 0
  187. 3 key = write access key and state = 0.
  188. The value snonce is as provided by the server in response to a
  189. NETPACKET_TRANSACTION_GETNONCE request; the value cnonce is a random client
  190. nonce; the value state is the transaction nonce of the last committed
  191. transaction.
  192. The value hmac is HMAC(key, 0x14 || [packet minus final hmac]).
  193. NETPACKET_TRANSACTION_CANCEL_RESPONSE (0x94)
  194. -------------------------------------------
  195. Packet contents:
  196. uint8_t status
  197. uint8_t hmac[32]
  198. The value status is
  199. 0 Success
  200. 1 Try again later
  201. A "success" here means that *if* the client's state value was correct *then*
  202. there is currently no transaction in progress. A "try again later" does not
  203. guarantee anything except that the server is alive and responsive; in
  204. particular, the server may cancel the currently in-progress transaction but
  205. still respond "try again later".
  206. The value hmac is HMAC(key, 0x94 || nonce || status) where key is the write
  207. or delete key as in NETPACKET_TRANSACTION_CANCEL and nonce is SHA256(snonce
  208. || cnonce).
  209. NETPACKET_TRANSACTION_TRYCOMMIT (0x15)
  210. --------------------------------------
  211. Packet contents:
  212. uint64_t machinenum
  213. uint8_t whichkey
  214. uint8_t nonce[32]
  215. uint8_t hmac[32]
  216. The value whichkey is
  217. 0 key = write access key
  218. 1 key = delete access key.
  219. The value nonce is the transaction nonce for the transaction which the
  220. client wants to have committed.
  221. The value hmac is HMAC(key, 0x15 || [packet minus final hmac]).
  222. NETPACKET_TRANSACTION_TRYCOMMIT_RESPONSE (0x95)
  223. -----------------------------------------------
  224. Packet contents:
  225. uint8_t status
  226. uint8_t hmac[32]
  227. The value status is
  228. 0 Success
  229. 1 Try again later
  230. A "success" here means that *if* the specified transaction was the most
  231. recent non-committed transaction, *then* it has been committed. A "try again
  232. later" guarantees nothing except that the server is alive and responsive;
  233. in particular, the server may commit the transaction in question but still
  234. respond "try again later".
  235. The value hmac is HMAC(key, 0x95 || nonce || status) where key is the write
  236. or delete key as in NETPACKET_TRANSACTION_TRYCOMMIT.
  237. NETPACKET_TRANSACTION_ISCHECKPOINTED (0x16)
  238. -------------------------------------------
  239. Packet contents:
  240. uint64_t machinenum
  241. uint8_t whichkey
  242. uint8_t nonce[32]
  243. uint8_t hmac[32]
  244. The value whichkey is
  245. 0 key = write access key
  246. 1 key = delete access key.
  247. The value nonce is a random 256-bit operation nonce.
  248. The value hmac is HMAC(key, 0x16 || [packet minus final hmac]).
  249. NETPACKET_TRANSACTION_ISCHECKPOINTED_RESPONSE (0x96)
  250. ----------------------------------------------------
  251. Packet contents:
  252. uint8_t status
  253. uint8_t tnonce[32]
  254. uint8_t hmac[32]
  255. The value status is
  256. 0 No transaction is in progress, the transaction in progress is
  257. a delete transaction, or the write transaction in progress
  258. does not have any checkpoints.
  259. 1 A write transaction is in progress and has a checkpoint.
  260. 2 "Reply hazy, try again" -- Magic 8-Ball
  261. The value tnonce is the transaction nonce of the current transaction if
  262. status is 1; and zero otherwise.
  263. The value hmac is HMAC(key, 0x96 || nonce || [packet minus final hmac]) where
  264. key is the write or delete key as in NETPACKET_TRANSACTION_ISCHECKPOINTED.
  265. NETPACKET_WRITE_FEXIST (0x20)
  266. -----------------------------
  267. Packet contents:
  268. uint64_t machinenum
  269. uint8_t class
  270. uint8_t name[32]
  271. uint8_t nonce[32]
  272. uint8_t hmac[32]
  273. The value nonce is the transaction nonce of the current transaction.
  274. The value hmac is HMACW(0x20 || [packet minus final hmac]).
  275. NETPACKET_WRITE_FEXIST_RESPONSE (0xa0)
  276. --------------------------------------
  277. Packet contents:
  278. uint8_t status
  279. uint8_t class
  280. uint8_t name[32]
  281. uint8_t hmac[32]
  282. The value status means:
  283. 0 File 'name' does not exist in class 'class'.
  284. 1 File 'name' exists in class 'class'.
  285. 2 Transaction nonce is incorrect.
  286. The value hmac is HMACW(0xa0 || nonce || [packet minus final hmac]), where
  287. nonce is the nonce provided by the client (which may not be the nonce of the
  288. current transaction).
  289. NETPACKET_WRITE_FILE (0x21)
  290. ---------------------------
  291. Packet contents:
  292. uint64_t machinenum
  293. uint8_t class
  294. uint8_t name[32]
  295. uint8_t nonce[32]
  296. uint32_t filelen
  297. uint8_t data[filelen]
  298. uint8_t hmac[32]
  299. The value nonce is the transaction nonce of the current transaction.
  300. The value filelen is at most 262144 (2^18).
  301. The value hmac is HMACW(0x20 || [packet minus final hmac]).
  302. NETPACKET_WRITE_FILE_RESPONSE (0xa1)
  303. ------------------------------------
  304. Packet contents:
  305. uint8_t status
  306. uint8_t class
  307. uint8_t name[32]
  308. uint8_t hmac[32]
  309. The value status is
  310. 0 Success
  311. 1 The specified file already exists
  312. 2 Transaction nonce is incorrect.
  313. The value hmac is HMACW(0xa1 || nonce || [packet minus final hmac]), where
  314. nonce is the nonce provided by the client (which may not be the nonce of the
  315. current transaction).
  316. NETPACKET_DELETE_FILE (0x30)
  317. ----------------------------
  318. Packet contents:
  319. uint64_t machinenum
  320. uint8_t class
  321. uint8_t name[32]
  322. uint8_t nonce[32]
  323. uint8_t hmac[32]
  324. The value nonce is the transaction nonce of the current transaction.
  325. The value hmac is HMACD(0x30 || [packet minus final hmac]).
  326. NETPACKET_DELETE_FILE_RESPONSE (0xb0)
  327. -------------------------------------
  328. Packet contents:
  329. uint8_t status
  330. uint8_t class
  331. uint8_t name[32]
  332. uint8_t hmac[32]
  333. The value status is
  334. 0 Success
  335. 1 The specified file does not exist
  336. 2 Transaction nonce is incorrect.
  337. The value hmac is HMACD(0xb0 || nonce || [packet minus final hmac]), where
  338. nonce is the nonce provided by the client (which may not be the nonce of the
  339. current transaction).
  340. NETPACKET_READ_FILE (0x40)
  341. --------------------------
  342. Packet contents:
  343. uint64_t machinenum
  344. uint8_t class
  345. uint8_t name[32]
  346. uint32_t size
  347. uint8_t hmac[32]
  348. The value size is the expected file size (at most 262144), or (uint32_t)(-1)
  349. if the file size is unknown.
  350. The value hmac is HMACR(0x40 || [packet minus final hmac]).
  351. NETPACKET_READ_FILE_RESPONSE (0xc0)
  352. -----------------------------------
  353. Packet contents:
  354. uint8_t status
  355. uint8_t class
  356. uint8_t name[32]
  357. uint32_t filelen
  358. uint8_t data[filelen or 0]
  359. uint8_t hmac[32]
  360. The value status is
  361. 0 Success
  362. 1 File does not exist
  363. 2 File size is incorrect
  364. 3 Account balance is not positive.
  365. The value filelen is the actual size of the file (possibly not equal to the
  366. size field of the NETPACKET_READ_FILE packet); or 0 if status is 1 or 3.
  367. The field data[] contains the file if status is 0; otherwise, the field is
  368. omitted.
  369. The value hmac is HMACR(0xc0 || [packet minus final hmac]).
  370. NETPACKET_DIRECTORY (0x50)
  371. --------------------------
  372. Packet contents:
  373. uint64_t machinenum
  374. uint8_t class
  375. uint8_t start[32]
  376. uint8_t snonce[32]
  377. uint8_t cnonce[32]
  378. uint8_t hmac[32]
  379. The value class is the class for which a directory listing is desired.
  380. The value start is the least value which should be returned by the server.
  381. The value snonce is as provided by the server (as in transaction starting);
  382. the value cnonce is a random client nonce.
  383. The value hmac is HMACR(0x50 || [packet minus final hmac]).
  384. NOTE: The server will respond with one or more NETPACKET_DIRECTORY_RESPONSE
  385. packets.
  386. NETPACKET_DIRECTORY_D (0x51)
  387. ----------------------------
  388. This is identical to a NETPACKET_DIRECTORY packet, except that hmac is
  389. HMACD(0x51 || [packet minus final hmac]).
  390. NETPACKET_DIRECTORY_RESPONSE (0xd0)
  391. -----------------------------------
  392. Packet contents:
  393. uint8_t status
  394. uint8_t class
  395. uint8_t start[32]
  396. uint32_t nfiles
  397. uint8_t flist[nfiles * 32]
  398. uint8_t hmac[32]
  399. The value status is
  400. 0 There are no more files after this
  401. 1 More packets to come
  402. 2 There might be more files after this; send another
  403. NETPACKET_DIRECTORY packet to request them
  404. 3 Account balance is not positive.
  405. A status value of 3 will only ever be sent in response to a DIRECTORY
  406. request, not to a DIRECTORY_D request.
  407. The files returned are the first nfiles files after start in lexicographical
  408. order.
  409. The value hmac is HMACR(0xd0 || nonce || [packet minus final hmac]), where
  410. nonce is SHA256(snonce || cnonce); or HMACD(...) if the packet is being sent
  411. in response to a NETPACKET_DIRECTORY_D packet.