spec-3nweb-server 1.8.5 → 1.8.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (340) hide show
  1. package/.gitlab-ci-linux.yml +50 -0
  2. package/.gitlab-ci-mac.yml +29 -0
  3. package/.gitlab-ci-windows.yml +29 -0
  4. package/.gitlab-ci.yml +63 -0
  5. package/build/3nstorage/resources/store.d.ts +2 -2
  6. package/build/3nstorage/resources/store.js +1 -1
  7. package/build/3nstorage/resources/users.d.ts +3 -3
  8. package/build/3nstorage/resources/users.js +1 -1
  9. package/build/3nstorage/resources/utils.d.ts +6 -0
  10. package/build/3nstorage/resources/utils.js +41 -0
  11. package/build/3nstorage/routes/owner/archive-obj-version.js +8 -10
  12. package/build/3nstorage/routes/owner/cancel-trans.js +5 -4
  13. package/build/3nstorage/routes/owner/delete-obj.js +7 -8
  14. package/build/3nstorage/routes/owner/get-archived-obj-ver.js +11 -13
  15. package/build/3nstorage/routes/owner/get-current-obj.js +7 -6
  16. package/build/3nstorage/routes/owner/get-obj-status.js +8 -8
  17. package/build/3nstorage/routes/owner/put-current-obj.js +25 -55
  18. package/build/3nstorage/routes/owner/session-params.js +2 -0
  19. package/build/asmail/resources/utils.d.ts +6 -0
  20. package/build/asmail/resources/utils.js +36 -0
  21. package/build/asmail/routes/delivery/finalize-delivery.js +3 -2
  22. package/build/asmail/routes/delivery/pre-flight.js +9 -26
  23. package/build/asmail/routes/delivery/provide-recipient-pubkey.js +4 -3
  24. package/build/asmail/routes/delivery/put-metadata.js +13 -21
  25. package/build/asmail/routes/delivery/put-obj.js +19 -25
  26. package/build/asmail/routes/delivery/restart-session.d.ts +4 -8
  27. package/build/asmail/routes/delivery/restart-session.js +10 -23
  28. package/build/asmail/routes/delivery/sender-authorization.js +5 -5
  29. package/build/asmail/routes/delivery/start-session.js +9 -24
  30. package/build/asmail/routes/retrieval/get-message-meta.js +4 -7
  31. package/build/asmail/routes/retrieval/get-message-obj.js +10 -7
  32. package/build/asmail/routes/retrieval/list-messages.js +4 -4
  33. package/build/asmail/routes/retrieval/remove-message.js +3 -2
  34. package/build/mock/tls-options.js +46 -44
  35. package/build/tests/admin-proto/signup.d.ts +1 -0
  36. package/build/tests/admin-proto/signup.js +235 -0
  37. package/build/tests/jasmine.d.ts +1 -0
  38. package/build/tests/jasmine.js +32 -0
  39. package/build/tests/libs-for-tests/3nstorage.d.ts +22 -0
  40. package/build/tests/libs-for-tests/3nstorage.js +123 -0
  41. package/build/tests/libs-for-tests/asmail.d.ts +22 -0
  42. package/build/tests/libs-for-tests/asmail.js +179 -0
  43. package/build/tests/libs-for-tests/assert.d.ts +1 -0
  44. package/build/tests/libs-for-tests/assert.js +26 -0
  45. package/build/tests/libs-for-tests/async-jasmine.d.ts +7 -0
  46. package/build/tests/libs-for-tests/async-jasmine.js +77 -0
  47. package/build/tests/libs-for-tests/bytes-equal.d.ts +1 -0
  48. package/build/tests/libs-for-tests/bytes-equal.js +34 -0
  49. package/build/tests/libs-for-tests/json-copy.d.ts +1 -0
  50. package/build/tests/libs-for-tests/json-copy.js +45 -0
  51. package/build/tests/libs-for-tests/json-equal.d.ts +4 -0
  52. package/build/tests/libs-for-tests/json-equal.js +67 -0
  53. package/build/tests/libs-for-tests/mailerid.d.ts +13 -0
  54. package/build/tests/libs-for-tests/mailerid.js +114 -0
  55. package/build/tests/libs-for-tests/pkl.d.ts +28 -0
  56. package/build/tests/libs-for-tests/pkl.js +89 -0
  57. package/build/tests/libs-for-tests/server-components/3nstorage.d.ts +20 -0
  58. package/build/tests/libs-for-tests/server-components/3nstorage.js +200 -0
  59. package/build/tests/libs-for-tests/server-components/admin.d.ts +6 -0
  60. package/build/tests/libs-for-tests/server-components/admin.js +43 -0
  61. package/build/tests/libs-for-tests/server-components/asmail.d.ts +16 -0
  62. package/build/tests/libs-for-tests/server-components/asmail.js +143 -0
  63. package/build/tests/libs-for-tests/server-components/component.d.ts +13 -0
  64. package/build/tests/libs-for-tests/server-components/component.js +77 -0
  65. package/build/tests/libs-for-tests/server-components/mailerid.d.ts +10 -0
  66. package/build/tests/libs-for-tests/server-components/mailerid.js +103 -0
  67. package/build/tests/libs-for-tests/server-runner.d.ts +15 -0
  68. package/build/tests/libs-for-tests/server-runner.js +69 -0
  69. package/build/tests/libs-for-tests/spec-assembly.d.ts +6 -0
  70. package/build/tests/libs-for-tests/spec-assembly.js +55 -0
  71. package/build/tests/libs-for-tests/ws-utils.d.ts +3 -0
  72. package/build/tests/libs-for-tests/ws-utils.js +59 -0
  73. package/build/tests/libs-for-tests/xhr-utils.d.ts +61 -0
  74. package/build/tests/libs-for-tests/xhr-utils.js +154 -0
  75. package/build/tests/protocols/3nstorage/owner/specs/archive-obj-ver.d.ts +2 -0
  76. package/build/tests/protocols/3nstorage/owner/specs/archive-obj-ver.js +84 -0
  77. package/build/tests/protocols/3nstorage/owner/specs/archive-root-ver.d.ts +2 -0
  78. package/build/tests/protocols/3nstorage/owner/specs/archive-root-ver.js +78 -0
  79. package/build/tests/protocols/3nstorage/owner/specs/delete-archive-obj-ver.d.ts +2 -0
  80. package/build/tests/protocols/3nstorage/owner/specs/delete-archive-obj-ver.js +83 -0
  81. package/build/tests/protocols/3nstorage/owner/specs/delete-archive-root-ver.d.ts +2 -0
  82. package/build/tests/protocols/3nstorage/owner/specs/delete-archive-root-ver.js +77 -0
  83. package/build/tests/protocols/3nstorage/owner/specs/delete-obj.d.ts +2 -0
  84. package/build/tests/protocols/3nstorage/owner/specs/delete-obj.js +75 -0
  85. package/build/tests/protocols/3nstorage/owner/specs/events.d.ts +2 -0
  86. package/build/tests/protocols/3nstorage/owner/specs/events.js +91 -0
  87. package/build/tests/protocols/3nstorage/owner/specs/get-current-obj.d.ts +2 -0
  88. package/build/tests/protocols/3nstorage/owner/specs/get-current-obj.js +269 -0
  89. package/build/tests/protocols/3nstorage/owner/specs/get-current-root.d.ts +2 -0
  90. package/build/tests/protocols/3nstorage/owner/specs/get-current-root.js +262 -0
  91. package/build/tests/protocols/3nstorage/owner/specs/get-obj-status.d.ts +2 -0
  92. package/build/tests/protocols/3nstorage/owner/specs/get-obj-status.js +79 -0
  93. package/build/tests/protocols/3nstorage/owner/specs/get-root-status.d.ts +2 -0
  94. package/build/tests/protocols/3nstorage/owner/specs/get-root-status.js +72 -0
  95. package/build/tests/protocols/3nstorage/owner/specs/put-current-obj.d.ts +2 -0
  96. package/build/tests/protocols/3nstorage/owner/specs/put-current-obj.js +287 -0
  97. package/build/tests/protocols/3nstorage/owner/specs/put-current-root.d.ts +2 -0
  98. package/build/tests/protocols/3nstorage/owner/specs/put-current-root.js +274 -0
  99. package/build/tests/protocols/3nstorage/owner/specs/trans-cancel-root.d.ts +2 -0
  100. package/build/tests/protocols/3nstorage/owner/specs/trans-cancel-root.js +73 -0
  101. package/build/tests/protocols/3nstorage/owner/specs/trans-cancel.d.ts +2 -0
  102. package/build/tests/protocols/3nstorage/owner/specs/trans-cancel.js +72 -0
  103. package/build/tests/protocols/3nstorage/owner/test-utils.d.ts +14 -0
  104. package/build/tests/protocols/3nstorage/owner/test-utils.js +54 -0
  105. package/build/tests/protocols/3nstorage/owner.d.ts +1 -0
  106. package/build/tests/protocols/3nstorage/owner.js +138 -0
  107. package/build/tests/protocols/asmail/config.d.ts +1 -0
  108. package/build/tests/protocols/asmail/config.js +117 -0
  109. package/build/tests/protocols/asmail/delivery/specs/finalize-delivery.d.ts +2 -0
  110. package/build/tests/protocols/asmail/delivery/specs/finalize-delivery.js +60 -0
  111. package/build/tests/protocols/asmail/delivery/specs/provide-recipient-pubkey.d.ts +2 -0
  112. package/build/tests/protocols/asmail/delivery/specs/provide-recipient-pubkey.js +68 -0
  113. package/build/tests/protocols/asmail/delivery/specs/put-metadata.d.ts +2 -0
  114. package/build/tests/protocols/asmail/delivery/specs/put-metadata.js +83 -0
  115. package/build/tests/protocols/asmail/delivery/specs/put-obj.d.ts +2 -0
  116. package/build/tests/protocols/asmail/delivery/specs/put-obj.js +123 -0
  117. package/build/tests/protocols/asmail/delivery/specs/restart-session.d.ts +2 -0
  118. package/build/tests/protocols/asmail/delivery/specs/restart-session.js +79 -0
  119. package/build/tests/protocols/asmail/delivery/specs/start-session.d.ts +2 -0
  120. package/build/tests/protocols/asmail/delivery/specs/start-session.js +64 -0
  121. package/build/tests/protocols/asmail/delivery/test-utils.d.ts +16 -0
  122. package/build/tests/protocols/asmail/delivery/test-utils.js +46 -0
  123. package/build/tests/protocols/asmail/delivery.d.ts +1 -0
  124. package/build/tests/protocols/asmail/delivery.js +46 -0
  125. package/build/tests/protocols/asmail/retrieval/specs/events.d.ts +2 -0
  126. package/build/tests/protocols/asmail/retrieval/specs/events.js +62 -0
  127. package/build/tests/protocols/asmail/retrieval/specs/get-message-meta.d.ts +2 -0
  128. package/build/tests/protocols/asmail/retrieval/specs/get-message-meta.js +70 -0
  129. package/build/tests/protocols/asmail/retrieval/specs/get-message-obj.d.ts +2 -0
  130. package/build/tests/protocols/asmail/retrieval/specs/get-message-obj.js +166 -0
  131. package/build/tests/protocols/asmail/retrieval/specs/list-messages.d.ts +2 -0
  132. package/build/tests/protocols/asmail/retrieval/specs/list-messages.js +96 -0
  133. package/build/tests/protocols/asmail/retrieval/specs/remove-message.d.ts +2 -0
  134. package/build/tests/protocols/asmail/retrieval/specs/remove-message.js +66 -0
  135. package/build/tests/protocols/asmail/retrieval/test-utils.d.ts +17 -0
  136. package/build/tests/protocols/asmail/retrieval/test-utils.js +46 -0
  137. package/build/tests/protocols/asmail/retrieval.d.ts +1 -0
  138. package/build/tests/protocols/asmail/retrieval.js +92 -0
  139. package/build/tests/protocols/mailerid.d.ts +1 -0
  140. package/build/tests/protocols/mailerid.js +210 -0
  141. package/build/tests/shared-checks/check-mid-login.d.ts +2 -0
  142. package/build/tests/shared-checks/check-mid-login.js +131 -0
  143. package/build/tests/shared-checks/requests.d.ts +20 -0
  144. package/build/tests/shared-checks/requests.js +123 -0
  145. package/package.json +1 -1
  146. package/packing/create-deb.sh +57 -0
  147. package/packing/deb/lib/systemd/system/3nweb.service +11 -0
  148. package/packing/deb/postinst +44 -0
  149. package/packing/deb/usr/share/doc/3nweb-server/conf-for-postinstall.yaml +19 -0
  150. package/packing/deb/usr/share/doc/3nweb-server/copyright +22 -0
  151. package/publish-task.sh +10 -0
  152. package/push-to-github.sh +105 -0
  153. package/ts-code/3nstorage/3nstorage-app.ts +99 -0
  154. package/ts-code/3nstorage/owner.ts +178 -0
  155. package/ts-code/3nstorage/resources/sessions.ts +37 -0
  156. package/ts-code/3nstorage/resources/store.ts +896 -0
  157. package/ts-code/3nstorage/resources/users.ts +258 -0
  158. package/ts-code/3nstorage/resources/utils.ts +45 -0
  159. package/ts-code/3nstorage/routes/owner/archive-obj-version.ts +71 -0
  160. package/ts-code/3nstorage/routes/owner/cancel-trans.ts +60 -0
  161. package/ts-code/3nstorage/routes/owner/delete-obj.ts +99 -0
  162. package/ts-code/3nstorage/routes/owner/get-archived-obj-ver.ts +109 -0
  163. package/ts-code/3nstorage/routes/owner/get-current-obj.ts +124 -0
  164. package/ts-code/3nstorage/routes/owner/get-obj-status.ts +55 -0
  165. package/ts-code/3nstorage/routes/owner/param-getter.ts +51 -0
  166. package/ts-code/3nstorage/routes/owner/param-setter.ts +50 -0
  167. package/ts-code/3nstorage/routes/owner/put-current-obj.ts +257 -0
  168. package/ts-code/3nstorage/routes/owner/session-params.ts +50 -0
  169. package/ts-code/3nstorage/shared.ts +43 -0
  170. package/ts-code/asmail/asmail-app.ts +91 -0
  171. package/ts-code/asmail/config.ts +96 -0
  172. package/ts-code/asmail/delivery.ts +94 -0
  173. package/ts-code/asmail/resources/delivery-sessions.ts +118 -0
  174. package/ts-code/asmail/resources/inbox.ts +696 -0
  175. package/ts-code/asmail/resources/recipients.ts +495 -0
  176. package/ts-code/asmail/resources/sessions.ts +37 -0
  177. package/ts-code/asmail/resources/utils.ts +41 -0
  178. package/ts-code/asmail/retrieval.ts +96 -0
  179. package/ts-code/asmail/routes/config/param-getter.ts +49 -0
  180. package/ts-code/asmail/routes/config/param-setter.ts +49 -0
  181. package/ts-code/asmail/routes/delivery/finalize-delivery.ts +51 -0
  182. package/ts-code/asmail/routes/delivery/pre-flight.ts +118 -0
  183. package/ts-code/asmail/routes/delivery/provide-recipient-pubkey.ts +58 -0
  184. package/ts-code/asmail/routes/delivery/put-metadata.ts +85 -0
  185. package/ts-code/asmail/routes/delivery/put-obj.ts +152 -0
  186. package/ts-code/asmail/routes/delivery/restart-session.ts +117 -0
  187. package/ts-code/asmail/routes/delivery/sender-authorization.ts +81 -0
  188. package/ts-code/asmail/routes/delivery/start-session.ts +136 -0
  189. package/ts-code/asmail/routes/retrieval/get-message-meta.ts +50 -0
  190. package/ts-code/asmail/routes/retrieval/get-message-obj.ts +106 -0
  191. package/ts-code/asmail/routes/retrieval/list-messages.ts +68 -0
  192. package/ts-code/asmail/routes/retrieval/remove-message.ts +48 -0
  193. package/ts-code/cli/index.ts +82 -0
  194. package/ts-code/cli/run-cmd.ts +81 -0
  195. package/ts-code/cli/show-sample-config.ts +78 -0
  196. package/ts-code/cli/signup-cmd.ts +229 -0
  197. package/ts-code/cli/user-cmd.ts +68 -0
  198. package/ts-code/cli/utils.ts +105 -0
  199. package/ts-code/config/default-confs.ts +22 -0
  200. package/ts-code/config/from-yaml.ts +35 -0
  201. package/ts-code/config/letsencrypt.ts +77 -0
  202. package/ts-code/config/signup.ts +137 -0
  203. package/ts-code/lib-common/admin-api/signup.ts +120 -0
  204. package/ts-code/lib-common/assert.ts +22 -0
  205. package/ts-code/lib-common/async-fs-node.ts +656 -0
  206. package/ts-code/lib-common/buffer-utils.ts +124 -0
  207. package/ts-code/lib-common/byte-streaming/common.ts +166 -0
  208. package/ts-code/lib-common/bytes-equal.ts +25 -0
  209. package/ts-code/lib-common/canonical-address.ts +92 -0
  210. package/ts-code/lib-common/exceptions/error.ts +44 -0
  211. package/ts-code/lib-common/exceptions/file.ts +84 -0
  212. package/ts-code/lib-common/exceptions/http.ts +69 -0
  213. package/ts-code/lib-common/ipc/generic-ipc.ts +750 -0
  214. package/ts-code/lib-common/ipc/ws-ipc.ts +117 -0
  215. package/ts-code/lib-common/json-equal.ts +55 -0
  216. package/ts-code/lib-common/json-utils.ts +130 -0
  217. package/ts-code/lib-common/jwkeys.ts +246 -0
  218. package/ts-code/lib-common/map-of-sets.ts +60 -0
  219. package/ts-code/lib-common/mid-sigs-NaCl-Ed.ts +677 -0
  220. package/ts-code/lib-common/objs-on-disk/file-layout.ts +480 -0
  221. package/ts-code/lib-common/objs-on-disk/obj-file.ts +325 -0
  222. package/ts-code/lib-common/objs-on-disk/utils.ts +201 -0
  223. package/ts-code/lib-common/objs-on-disk/v1-obj-file-format.ts +329 -0
  224. package/ts-code/lib-common/processes.ts +501 -0
  225. package/ts-code/lib-common/random-node.ts +79 -0
  226. package/ts-code/lib-common/service-api/3nstorage/owner.ts +559 -0
  227. package/ts-code/lib-common/service-api/3nstorage/root-route.ts +22 -0
  228. package/ts-code/lib-common/service-api/asmail/config.ts +144 -0
  229. package/ts-code/lib-common/service-api/asmail/delivery.ts +250 -0
  230. package/ts-code/lib-common/service-api/asmail/retrieval.ts +238 -0
  231. package/ts-code/lib-common/service-api/asmail/root-route.ts +22 -0
  232. package/ts-code/lib-common/service-api/ipc-api.ts +44 -0
  233. package/ts-code/lib-common/service-api/locker.ts +44 -0
  234. package/ts-code/lib-common/service-api/mailer-id/login.ts +80 -0
  235. package/ts-code/lib-common/service-api/mailer-id/provisioning.ts +64 -0
  236. package/ts-code/lib-common/service-api/mailer-id/root-route.ts +25 -0
  237. package/ts-code/lib-common/service-api/pub-key-login.ts +75 -0
  238. package/ts-code/lib-common/service-api/web-socket-base.ts +87 -0
  239. package/ts-code/lib-common/session-encryptor.ts +54 -0
  240. package/ts-code/lib-common/time-window-cache.ts +74 -0
  241. package/ts-code/lib-common/transferable.d.ts +30 -0
  242. package/ts-code/lib-server/conf-util.ts +35 -0
  243. package/ts-code/lib-server/mid-access.ts +45 -0
  244. package/ts-code/lib-server/middleware/body-parsers.ts +248 -0
  245. package/ts-code/lib-server/middleware/error-handler.ts +79 -0
  246. package/ts-code/lib-server/pkl-access.ts +46 -0
  247. package/ts-code/lib-server/resources/dns.ts +151 -0
  248. package/ts-code/lib-server/resources/mailerid-authorizer.ts +115 -0
  249. package/ts-code/lib-server/resources/mem-backed-sessions-factory.ts +132 -0
  250. package/ts-code/lib-server/resources/server-data-folders.ts +160 -0
  251. package/ts-code/lib-server/resources/server-key-for-pkl-challenge.ts +41 -0
  252. package/ts-code/lib-server/resources/sessions.ts +232 -0
  253. package/ts-code/lib-server/resources/user-files.ts +147 -0
  254. package/ts-code/lib-server/routes/pub-key-login/complete-exchange.ts +63 -0
  255. package/ts-code/lib-server/routes/pub-key-login/start-exchange.ts +189 -0
  256. package/ts-code/lib-server/routes/sessions/close.ts +27 -0
  257. package/ts-code/lib-server/routes/sessions/mid-auth.ts +77 -0
  258. package/ts-code/lib-server/routes/sessions/start.ts +116 -0
  259. package/ts-code/lib-server/web-sockets/app.ts +339 -0
  260. package/ts-code/lib-server/web-sockets/server-events.ts +63 -0
  261. package/ts-code/lib.ts +29 -0
  262. package/ts-code/locker/locker-app.ts +60 -0
  263. package/ts-code/locker/resources/lockers.ts +17 -0
  264. package/ts-code/locker/resources/sessions.ts +37 -0
  265. package/ts-code/locker/routes/create-locker.ts +47 -0
  266. package/ts-code/mailerId/mailerId-app.ts +107 -0
  267. package/ts-code/mailerId/resources/certifier.ts +181 -0
  268. package/ts-code/mailerId/resources/sessions.ts +44 -0
  269. package/ts-code/mailerId/resources/users.ts +88 -0
  270. package/ts-code/mailerId/routes/certify.ts +68 -0
  271. package/ts-code/main.ts +304 -0
  272. package/ts-code/mock/dns.ts +106 -0
  273. package/ts-code/mock/mock-as-child-proc.ts +130 -0
  274. package/ts-code/mock/node-child-ipc.ts +69 -0
  275. package/ts-code/mock/run-in-proc.ts +111 -0
  276. package/ts-code/mock/tls-options.ts +73 -0
  277. package/ts-code/services.ts +138 -0
  278. package/ts-code/signup/resources/users.ts +429 -0
  279. package/ts-code/signup/routes/add.ts +65 -0
  280. package/ts-code/signup/routes/get-available-addresses.ts +49 -0
  281. package/ts-code/signup/routes/get-available-domains.ts +45 -0
  282. package/ts-code/signup/signup-app.ts +54 -0
  283. package/ts-code/signup/signup-tokens.ts +148 -0
  284. package/ts-code/tests/admin-proto/signup.ts +277 -0
  285. package/ts-code/tests/jasmine.ts +37 -0
  286. package/ts-code/tests/libs-for-tests/3nstorage.ts +144 -0
  287. package/ts-code/tests/libs-for-tests/asmail.ts +220 -0
  288. package/ts-code/tests/libs-for-tests/assert.ts +22 -0
  289. package/ts-code/tests/libs-for-tests/async-jasmine.ts +89 -0
  290. package/ts-code/tests/libs-for-tests/bytes-equal.ts +25 -0
  291. package/ts-code/tests/libs-for-tests/json-copy.ts +38 -0
  292. package/ts-code/tests/libs-for-tests/json-equal.ts +55 -0
  293. package/ts-code/tests/libs-for-tests/mailerid.ts +123 -0
  294. package/ts-code/tests/libs-for-tests/pkl.ts +127 -0
  295. package/ts-code/tests/libs-for-tests/server-components/3nstorage.ts +206 -0
  296. package/ts-code/tests/libs-for-tests/server-components/admin.ts +49 -0
  297. package/ts-code/tests/libs-for-tests/server-components/asmail.ts +152 -0
  298. package/ts-code/tests/libs-for-tests/server-components/component.ts +90 -0
  299. package/ts-code/tests/libs-for-tests/server-components/mailerid.ts +114 -0
  300. package/ts-code/tests/libs-for-tests/server-runner.ts +82 -0
  301. package/ts-code/tests/libs-for-tests/spec-assembly.ts +60 -0
  302. package/ts-code/tests/libs-for-tests/ws-utils.ts +61 -0
  303. package/ts-code/tests/libs-for-tests/xhr-utils.ts +179 -0
  304. package/ts-code/tests/protocols/3nstorage/owner/specs/archive-obj-ver.ts +100 -0
  305. package/ts-code/tests/protocols/3nstorage/owner/specs/archive-root-ver.ts +91 -0
  306. package/ts-code/tests/protocols/3nstorage/owner/specs/delete-archive-obj-ver.ts +99 -0
  307. package/ts-code/tests/protocols/3nstorage/owner/specs/delete-archive-root-ver.ts +90 -0
  308. package/ts-code/tests/protocols/3nstorage/owner/specs/delete-obj.ts +84 -0
  309. package/ts-code/tests/protocols/3nstorage/owner/specs/events.ts +125 -0
  310. package/ts-code/tests/protocols/3nstorage/owner/specs/get-current-obj.ts +298 -0
  311. package/ts-code/tests/protocols/3nstorage/owner/specs/get-current-root.ts +290 -0
  312. package/ts-code/tests/protocols/3nstorage/owner/specs/get-obj-status.ts +88 -0
  313. package/ts-code/tests/protocols/3nstorage/owner/specs/get-root-status.ts +80 -0
  314. package/ts-code/tests/protocols/3nstorage/owner/specs/put-current-obj.ts +366 -0
  315. package/ts-code/tests/protocols/3nstorage/owner/specs/put-current-root.ts +329 -0
  316. package/ts-code/tests/protocols/3nstorage/owner/specs/trans-cancel-root.ts +86 -0
  317. package/ts-code/tests/protocols/3nstorage/owner/specs/trans-cancel.ts +86 -0
  318. package/ts-code/tests/protocols/3nstorage/owner/test-utils.ts +72 -0
  319. package/ts-code/tests/protocols/3nstorage/owner.ts +198 -0
  320. package/ts-code/tests/protocols/asmail/config.ts +172 -0
  321. package/ts-code/tests/protocols/asmail/delivery/specs/finalize-delivery.ts +69 -0
  322. package/ts-code/tests/protocols/asmail/delivery/specs/provide-recipient-pubkey.ts +88 -0
  323. package/ts-code/tests/protocols/asmail/delivery/specs/put-metadata.ts +102 -0
  324. package/ts-code/tests/protocols/asmail/delivery/specs/put-obj.ts +156 -0
  325. package/ts-code/tests/protocols/asmail/delivery/specs/restart-session.ts +97 -0
  326. package/ts-code/tests/protocols/asmail/delivery/specs/start-session.ts +79 -0
  327. package/ts-code/tests/protocols/asmail/delivery/test-utils.ts +64 -0
  328. package/ts-code/tests/protocols/asmail/delivery.ts +56 -0
  329. package/ts-code/tests/protocols/asmail/retrieval/specs/events.ts +78 -0
  330. package/ts-code/tests/protocols/asmail/retrieval/specs/get-message-meta.ts +80 -0
  331. package/ts-code/tests/protocols/asmail/retrieval/specs/get-message-obj.ts +197 -0
  332. package/ts-code/tests/protocols/asmail/retrieval/specs/list-messages.ts +110 -0
  333. package/ts-code/tests/protocols/asmail/retrieval/specs/remove-message.ts +74 -0
  334. package/ts-code/tests/protocols/asmail/retrieval/test-utils.ts +60 -0
  335. package/ts-code/tests/protocols/asmail/retrieval.ts +115 -0
  336. package/ts-code/tests/protocols/mailerid.ts +271 -0
  337. package/ts-code/tests/shared-checks/check-mid-login.ts +164 -0
  338. package/ts-code/tests/shared-checks/requests.ts +135 -0
  339. package/ts-code/tsconfig.json +11 -0
  340. package/ts-code/web3n.d.ts +1068 -0
@@ -0,0 +1,220 @@
1
+ /*
2
+ Copyright (C) 2016, 2019, 2022 3NSoft Inc.
3
+
4
+ This program is free software: you can redistribute it and/or modify it under
5
+ the terms of the GNU General Public License as published by the Free Software
6
+ Foundation, either version 3 of the License, or (at your option) any later
7
+ version.
8
+
9
+ This program is distributed in the hope that it will be useful, but
10
+ WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
+ See the GNU General Public License for more details.
13
+
14
+ You should have received a copy of the GNU General Public License along with
15
+ this program. If not, see <http://www.gnu.org/licenses/>.
16
+ */
17
+
18
+ import { User, doMailerIdLogin, provisionMidSigner } from './mailerid';
19
+ import { doJsonRequest, RequestOpts, doBodylessRequest, doBinaryRequest } from './xhr-utils';
20
+ import { resolve as resolveUrl } from 'url';
21
+ import { midLogin, PARAM_SC, p } from '../../lib-common/service-api/asmail/config';
22
+ import * as random from '../../lib-common/random-node';
23
+ import { base64 } from '../../lib-common/buffer-utils';
24
+ import { JsonKey } from '../../lib-common/jwkeys';
25
+ import { box } from 'ecma-nacl';
26
+ import * as deliveryApi from '../../lib-common/service-api/asmail/delivery';
27
+ import { BaseObj as Obj } from './3nstorage';
28
+ import { assert } from './assert';
29
+
30
+ export { BaseObj as Obj } from './3nstorage';
31
+
32
+ export async function getASMailServiceUrl(
33
+ asmailUrl: string, service: 'delivery'|'retrieval'|'config'
34
+ ): Promise<string> {
35
+ const reqOpts: RequestOpts= {
36
+ url: asmailUrl,
37
+ method: 'GET',
38
+ responseType: 'json'
39
+ };
40
+ const rep = await doBodylessRequest<any>(reqOpts);
41
+ expect(rep.status).toBe(200);
42
+ const serviceUrl: string = rep.data[service];
43
+ expect(typeof serviceUrl).toBe('string');
44
+ return resolveUrl(asmailUrl, serviceUrl);
45
+ }
46
+
47
+ export async function setInboxParams(
48
+ asmailUrl: string, user: User, params: { [pUrl: string]: any; }
49
+ ): Promise<void> {
50
+ const confUrl = await getASMailServiceUrl(asmailUrl, 'config');
51
+ const sessionId = await doMailerIdLogin(
52
+ resolveUrl(confUrl, midLogin.URL_PART), user
53
+ );
54
+ for (const pUrl of Object.keys(params)) {
55
+ const reqOpts: RequestOpts= {
56
+ url: resolveUrl(confUrl, pUrl),
57
+ method: 'PUT',
58
+ sessionId
59
+ };
60
+ const rep = await doJsonRequest<void>(reqOpts, params[pUrl]);
61
+ expect(rep.status).toBe(PARAM_SC.ok);
62
+ }
63
+ }
64
+
65
+ export const PUBLIC_KEY_USE = 'asmail-pub-key';
66
+
67
+ export async function generateInitPubKey(
68
+ midUrl: string, user: User
69
+ ): Promise<p.initPubKey.Certs> {
70
+ const midSigner = await provisionMidSigner(midUrl, user);
71
+ const skeyBytes = await random.bytes(box.KEY_LENGTH);
72
+ const pkeyBytes = box.generate_pubkey(skeyBytes);
73
+ const pkey: JsonKey = {
74
+ use: PUBLIC_KEY_USE,
75
+ alg: box.JWK_ALG_NAME,
76
+ kid: await random.stringOfB64Chars(10),
77
+ k: base64.pack(pkeyBytes)
78
+ };
79
+ const pkeyCert = midSigner.certifyPublicKey(pkey, 30*24*60*60);
80
+ const certs: p.initPubKey.Certs = {
81
+ pkeyCert,
82
+ provCert: midSigner.providerCert,
83
+ userCert: midSigner.userCert
84
+ };
85
+ return certs;
86
+ }
87
+
88
+ export async function startMsgDeliverySession(
89
+ deliveryUrl: string, req: deliveryApi.sessionStart.Request
90
+ ): Promise<deliveryApi.sessionStart.Reply> {
91
+ const reqOpts: RequestOpts = {
92
+ url: resolveUrl(deliveryUrl, deliveryApi.sessionStart.URL_END),
93
+ method: 'POST',
94
+ responseType: 'json'
95
+ };
96
+ const rep = await doJsonRequest<deliveryApi.sessionStart.Reply>(
97
+ reqOpts, req
98
+ );
99
+ expect(rep.status).toBe(deliveryApi.sessionStart.SC.ok);
100
+ return rep.data;
101
+ }
102
+
103
+ export interface DeliveryInfo extends
104
+ deliveryApi.msgMeta.Reply, deliveryApi.sessionStart.Reply {}
105
+
106
+ export async function startMsgDelivery(
107
+ deliveryUrl: string, firstReq: deliveryApi.sessionStart.Request,
108
+ metaReq: deliveryApi.msgMeta.Request
109
+ ): Promise<DeliveryInfo> {
110
+ const info = (await startMsgDeliverySession(
111
+ deliveryUrl, firstReq
112
+ )) as DeliveryInfo;
113
+ const reqOpts: RequestOpts = {
114
+ url: resolveUrl(deliveryUrl, deliveryApi.msgMeta.URL_END),
115
+ method: 'PUT',
116
+ responseType: 'json',
117
+ sessionId: info.sessionId
118
+ };
119
+ const rep = await doJsonRequest<deliveryApi.msgMeta.Reply>(reqOpts, metaReq);
120
+ expect(rep.status).toBe(deliveryApi.msgMeta.SC.ok);
121
+ for (const field of Object.keys(rep.data)) {
122
+ info[field] = rep.data[field];
123
+ }
124
+ return info;
125
+ }
126
+
127
+ export async function sendMsgObj(
128
+ deliveryUrl: string, sessionId: string, obj: Obj,
129
+ chunkLimit: number|undefined
130
+ ): Promise<void> {
131
+ if (!obj.objId) { throw new Error(`Message object doesn't have an id`); }
132
+ if (!chunkLimit) {
133
+ chunkLimit = 512*1024;
134
+ }
135
+
136
+ let ofs = 0;
137
+ const segsLen = obj.segs.length;
138
+ while (ofs < segsLen) {
139
+ const reqOpts: RequestOpts = { url: '', method: 'PUT', sessionId };
140
+ let bytesToSend: Uint8Array | Uint8Array[];
141
+
142
+ if (ofs === 0) {
143
+ // first request starts with header
144
+ const header = obj.header.length;
145
+ const segsChunk = obj.segs.subarray(0, chunkLimit - header);
146
+ const last = (segsChunk.length === obj.segs.length);
147
+ bytesToSend = [ obj.header, segsChunk ];
148
+ reqOpts.url = resolveUrl(deliveryUrl,
149
+ deliveryApi.msgObj.firstPutReqUrlEnd(obj.objId, { header, last }));
150
+ ofs += segsChunk.length;
151
+ } else {
152
+ // second request(s) send bytes
153
+ bytesToSend = obj.segs.subarray(ofs, ofs+chunkLimit);
154
+ const last = ((ofs + bytesToSend.length) === obj.segs.length);
155
+ reqOpts.url = resolveUrl(deliveryUrl,
156
+ deliveryApi.msgObj.secondPutReqUrlEnd(obj.objId, { ofs, last }));
157
+ ofs += bytesToSend.length;
158
+ }
159
+ const rep = await doBinaryRequest<void>(reqOpts, bytesToSend);
160
+ assert(rep.status === deliveryApi.msgObj.SC.ok, `Msg obj isn't saved: server status ${rep.status} instead of expected ${deliveryApi.msgObj.SC.ok}`);
161
+ }
162
+ }
163
+
164
+ export interface Msg {
165
+ cryptoMeta: deliveryApi.msgMeta.CryptoInfo,
166
+ msgObjs: Obj[]
167
+ }
168
+
169
+ export async function sendMsg(
170
+ deliveryUrl: string, recipient: string, msg: Msg
171
+ ): Promise<string> {
172
+ const stepsIter = msgSendingSteps(deliveryUrl, recipient, msg);
173
+ const fstStep = await stepsIter.next();
174
+ expect(fstStep.done).toBeFalsy();
175
+ expect(fstStep.value).toBeDefined();
176
+ const msgId = fstStep.value;
177
+ let done: boolean;
178
+ do {
179
+ done = !!(await stepsIter.next()).done;
180
+ } while (!done);
181
+ return msgId;
182
+ }
183
+
184
+ export async function* msgSendingSteps(
185
+ deliveryUrl: string, recipient: string, msg: Msg
186
+ ): AsyncGenerator<string, string, unknown> {
187
+ const meta = makeMetaFor(msg);
188
+ const sessInfo = await startMsgDelivery(deliveryUrl, { recipient }, meta);
189
+ yield sessInfo.msgId;
190
+ for (const msgObj of msg.msgObjs) {
191
+ await sendMsgObj(
192
+ deliveryUrl, sessInfo.sessionId, msgObj, sessInfo.maxChunkSize
193
+ );
194
+ yield sessInfo.msgId;
195
+ }
196
+ const reqOpts: RequestOpts = {
197
+ url: resolveUrl(deliveryUrl, deliveryApi.completion.URL_END),
198
+ method: 'POST',
199
+ sessionId: sessInfo.sessionId
200
+ };
201
+ const rep = await doBodylessRequest<void>(reqOpts);
202
+ expect(rep.status).toBe(deliveryApi.completion.SC.ok);
203
+ return sessInfo.msgId;
204
+ }
205
+
206
+ function makeMetaFor(msg: Msg): deliveryApi.msgMeta.Request {
207
+ const meta = msg.cryptoMeta as deliveryApi.msgMeta.Request;
208
+ meta.objIds = [];
209
+ for (let i=0; i < msg.msgObjs.length; i+=1) {
210
+ const objId = msg.msgObjs[i].objId;
211
+ if (!objId) {
212
+ throw new Error(`Message object #${i} doesn't have an id`);
213
+ }
214
+ meta.objIds[i] = objId;
215
+ }
216
+ return meta;
217
+ }
218
+
219
+
220
+ Object.freeze(exports);
@@ -0,0 +1,22 @@
1
+ /*
2
+ Copyright(c) 2018 3NSoft Inc.
3
+
4
+ This program is free software: you can redistribute it and/or modify it under
5
+ the terms of the GNU General Public License as published by the Free Software
6
+ Foundation, either version 3 of the License, or (at your option) any later
7
+ version.
8
+
9
+ This program is distributed in the hope that it will be useful, but
10
+ WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
+ See the GNU General Public License for more details.
13
+
14
+ You should have received a copy of the GNU General Public License along with
15
+ this program. If not, see <http://www.gnu.org/licenses/>.
16
+ */
17
+
18
+ export function assert(ok: boolean, errMsg?: string): void {
19
+ if (!ok) { throw new Error(errMsg); }
20
+ }
21
+
22
+ Object.freeze(exports);
@@ -0,0 +1,89 @@
1
+ /*
2
+ Copyright (C) 2016 - 2017 3NSoft Inc.
3
+
4
+ This program is free software: you can redistribute it and/or modify it under
5
+ the terms of the GNU General Public License as published by the Free Software
6
+ Foundation, either version 3 of the License, or (at your option) any later
7
+ version.
8
+
9
+ This program is distributed in the hope that it will be useful, but
10
+ WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
+ See the GNU General Public License for more details.
13
+
14
+ You should have received a copy of the GNU General Public License along with
15
+ this program. If not, see <http://www.gnu.org/licenses/>.
16
+ */
17
+
18
+ export function itAsync(expectation: string,
19
+ assertion?: () => Promise<void>, timeout?: number): void {
20
+ if (assertion) {
21
+ it(expectation, done => {
22
+ assertion().then(
23
+ () => done(),
24
+ err => done.fail(err));
25
+ }, timeout);
26
+ } else {
27
+ it(expectation);
28
+ }
29
+ }
30
+
31
+ export function xitAsync(expectation: string,
32
+ assertion?: () => Promise<void>, timeout?: number): void {
33
+ if (assertion) {
34
+ xit(expectation, done => {
35
+ assertion().then(
36
+ () => done(),
37
+ err => done.fail(err));
38
+ }, timeout);
39
+ } else {
40
+ xit(expectation);
41
+ }
42
+ }
43
+
44
+ export function fitAsync(expectation: string,
45
+ assertion?: () => Promise<void>, timeout?: number): void {
46
+ if (assertion) {
47
+ fit(expectation, done => {
48
+ assertion().then(
49
+ () => done(),
50
+ err => done.fail(err));
51
+ }, timeout);
52
+ } else {
53
+ fit(expectation);
54
+ }
55
+ }
56
+
57
+ export function beforeAllAsync(action: () => Promise<void>, timeout?: number) {
58
+ beforeAll(done => {
59
+ action().then(
60
+ () => done(),
61
+ err => done.fail(err));
62
+ }, timeout);
63
+ }
64
+
65
+ export function afterAllAsync(action: () => Promise<void>, timeout?: number) {
66
+ afterAll(done => {
67
+ action().then(
68
+ () => done(),
69
+ err => done.fail(err));
70
+ }, timeout);
71
+ }
72
+
73
+ export function beforeEachAsync(action: () => Promise<void>, timeout?: number) {
74
+ beforeEach(done => {
75
+ action().then(
76
+ () => done(),
77
+ err => done.fail(err));
78
+ }, timeout);
79
+ }
80
+
81
+ export function afterEachAsync(action: () => Promise<void>, timeout?: number) {
82
+ afterEach(done => {
83
+ action().then(
84
+ () => done(),
85
+ err => done.fail(err));
86
+ }, timeout);
87
+ }
88
+
89
+ Object.freeze(exports);
@@ -0,0 +1,25 @@
1
+ /*
2
+ Copyright (C) 2016 3NSoft Inc.
3
+
4
+ This program is free software: you can redistribute it and/or modify it under
5
+ the terms of the GNU General Public License as published by the Free Software
6
+ Foundation, either version 3 of the License, or (at your option) any later
7
+ version.
8
+
9
+ This program is distributed in the hope that it will be useful, but
10
+ WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
+ See the GNU General Public License for more details.
13
+
14
+ You should have received a copy of the GNU General Public License along with
15
+ this program. If not, see <http://www.gnu.org/licenses/>.
16
+ */
17
+
18
+ export function bytesEqual(a: Uint8Array, b: Uint8Array): boolean {
19
+ if (a.BYTES_PER_ELEMENT !== b.BYTES_PER_ELEMENT) { return false; }
20
+ if (a.length !== b.length) { return false; }
21
+ for (let i=0; i<a.length; i+=1) {
22
+ if (a[i] !== b[i]) { return false; }
23
+ }
24
+ return true;
25
+ }
@@ -0,0 +1,38 @@
1
+ /*
2
+ Copyright (C) 2016 3NSoft Inc.
3
+
4
+ This program is free software: you can redistribute it and/or modify it under
5
+ the terms of the GNU General Public License as published by the Free Software
6
+ Foundation, either version 3 of the License, or (at your option) any later
7
+ version.
8
+
9
+ This program is distributed in the hope that it will be useful, but
10
+ WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
+ See the GNU General Public License for more details.
13
+
14
+ You should have received a copy of the GNU General Public License along with
15
+ this program. If not, see <http://www.gnu.org/licenses/>.
16
+ */
17
+
18
+ export function copy<T>(orig: T): T {
19
+ if (typeof orig !== 'object') { return orig; }
20
+ if (orig === null) { return (null as any); }
21
+ if (Array.isArray(orig)) {
22
+ let arr: any[] = orig;
23
+ let c: any[] = [];
24
+ for (let i=0; i < arr.length; i+=1) {
25
+ c[i] = copy(arr[i]);
26
+ }
27
+ return (c as any);
28
+ } else {
29
+ let c = ({} as T);
30
+ let fields = Object.keys(orig);
31
+ for (let f of fields) {
32
+ c[f] = copy<any>(orig[f]);
33
+ }
34
+ return c;
35
+ }
36
+ }
37
+
38
+ Object.freeze(exports);
@@ -0,0 +1,55 @@
1
+ /*
2
+ Copyright (C) 2015 3NSoft Inc.
3
+
4
+ This program is free software: you can redistribute it and/or modify it under
5
+ the terms of the GNU General Public License as published by the Free Software
6
+ Foundation, either version 3 of the License, or (at your option) any later
7
+ version.
8
+
9
+ This program is distributed in the hope that it will be useful, but
10
+ WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
+ See the GNU General Public License for more details.
13
+
14
+ You should have received a copy of the GNU General Public License along with
15
+ this program. If not, see <http://www.gnu.org/licenses/>.
16
+ */
17
+
18
+ /**
19
+ * This module provides hex encoding of binary array into a string.
20
+ */
21
+
22
+ export function deepEqual(a: any, b: any): boolean {
23
+
24
+ let t = typeof a;
25
+
26
+ if (t !== typeof b) { return false; }
27
+
28
+ if (t !== 'object') {
29
+ return (a === b);
30
+ }
31
+
32
+ if (a === b) { return true; }
33
+ if ((a === null) || (b === null)) { return false; }
34
+
35
+ if (Array.isArray(a)) {
36
+ if (!Array.isArray(b)) { return false; }
37
+ let aArr = <Array<any>> a;
38
+ let bArr = <Array<any>> b;
39
+ if (aArr.length !== bArr.length) { return false; }
40
+ for (let i=0; i<aArr.length; i+=1) {
41
+ if (!deepEqual(aArr[i], bArr[i])) { return false; }
42
+ }
43
+ } else {
44
+ let keys = Object.keys(a);
45
+ if (keys.length !== Object.keys(b).length) { return false; }
46
+ for (let i=0; i<keys.length; i+=1) {
47
+ let key = keys[i];
48
+ if (!deepEqual(a[key], b[key])) { return false; }
49
+ }
50
+ }
51
+
52
+ return true;
53
+ }
54
+
55
+ Object.freeze(exports);
@@ -0,0 +1,123 @@
1
+ /*
2
+ Copyright (C) 2016 3NSoft Inc.
3
+
4
+ This program is free software: you can redistribute it and/or modify it under
5
+ the terms of the GNU General Public License as published by the Free Software
6
+ Foundation, either version 3 of the License, or (at your option) any later
7
+ version.
8
+
9
+ This program is distributed in the hope that it will be useful, but
10
+ WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
+ See the GNU General Public License for more details.
13
+
14
+ You should have received a copy of the GNU General Public License along with
15
+ this program. If not, see <http://www.gnu.org/licenses/>.
16
+ */
17
+
18
+ import { isLikeSignedKeyCert, SignedLoad } from '../../lib-common/jwkeys';
19
+ import { doJsonRequest, RequestOpts, doBodylessRequest, doBinaryRequest }
20
+ from './xhr-utils';
21
+ import { authSession, startSession }
22
+ from '../../lib-common/service-api/mailer-id/login';
23
+ import { certify as certApi }
24
+ from '../../lib-common/service-api/mailer-id/provisioning';
25
+ import { user as midUser } from '../../lib-common/mid-sigs-NaCl-Ed';
26
+ import { doPubKeyLogin, User } from './pkl';
27
+ import { bytesSync as randomBytes } from '../../lib-common/random-node';
28
+ import { parse as parseUrl } from 'url';
29
+
30
+ export { User } from './pkl';
31
+
32
+ async function getMidData(midUrl: string): Promise<any> {
33
+ let reqOpts: RequestOpts= {
34
+ url: midUrl,
35
+ method: 'GET',
36
+ responseType: 'json'
37
+ };
38
+ let rep = await doBodylessRequest<any>(reqOpts);
39
+ expect(rep.status).toBe(200);
40
+ return rep.data;
41
+ }
42
+
43
+ /**
44
+ * @param midUrl
45
+ * @return a promise, resolvable to MailerId service's provisioning url.
46
+ */
47
+ export async function getProvPath(midUrl: string): Promise<any> {
48
+ let midData = await getMidData(midUrl);
49
+ let prov: string = midData['provisioning']
50
+ expect(typeof prov).toBe('string');
51
+ // return url with provision path
52
+ let pathStarts = midUrl.indexOf('/', midUrl.indexOf('://')+3);
53
+ return midUrl.substring(0, pathStarts) + prov;
54
+ }
55
+
56
+ export async function getMidRoot(midUrl: string): Promise<SignedLoad> {
57
+ let midData = await getMidData(midUrl);
58
+ let rootCert = midData["current-cert"];
59
+ expect(isLikeSignedKeyCert(rootCert)).toBe(true);
60
+ return rootCert;
61
+ }
62
+
63
+ export async function startMidSession(loginUrl: string, userId: string):
64
+ Promise<string> {
65
+ let reqOpts: RequestOpts= {
66
+ url: loginUrl + startSession.URL_END,
67
+ method: 'POST',
68
+ responseType: 'json'
69
+ };
70
+ let req: startSession.Request = { userId };
71
+ let rep = await doJsonRequest<startSession.Reply>(reqOpts, req);
72
+ expect(rep.status).toBe(startSession.SC.ok);
73
+ return rep.data.sessionId;
74
+ }
75
+
76
+ export async function provisionMidSigner(midServiceUrl: string, user: User):
77
+ Promise<midUser.MailerIdSigner> {
78
+ let provUrl = await getProvPath(midServiceUrl);
79
+ let sessParams = await doPubKeyLogin(provUrl, user);
80
+ let reqOpts: RequestOpts= {
81
+ url: provUrl + certApi.URL_END,
82
+ method: 'POST',
83
+ sessionId: sessParams.sessionId,
84
+ responseType: 'arraybuffer'
85
+ };
86
+ let midSigningPair = midUser.generateSigningKeyPair(randomBytes);
87
+ let reqData: certApi.Request = {
88
+ pkey: midSigningPair.pkey,
89
+ duration: 12*60*60
90
+ };
91
+ let encrBody = sessParams.sessEncr.packJSON(reqData);
92
+ let rep = await doBinaryRequest<Uint8Array>(reqOpts, encrBody);
93
+ expect(rep.status).toBe(certApi.SC.ok);
94
+ let repData: certApi.Reply = sessParams.sessEncr.openJSON(rep.data);
95
+ return midUser.makeMailerIdSigner(
96
+ midSigningPair.skey, repData.userCert, repData.provCert);
97
+ }
98
+
99
+ export async function doMailerIdLogin(loginUrl: string, user: User):
100
+ Promise<string> {
101
+ let sessionId = await startMidSession(loginUrl, user.id);
102
+ let midSigner = await provisionMidSigner(user.midUrl, user);
103
+ let reqOpts: RequestOpts= {
104
+ url: loginUrl + authSession.URL_END,
105
+ method: 'POST',
106
+ responseType: 'json',
107
+ sessionId
108
+ };
109
+ let serviceDomain = parseUrl(loginUrl).hostname;
110
+ if (!serviceDomain) { throw new Error(
111
+ `Cannot parse hostname from login url ${loginUrl}`); }
112
+ let req: authSession.Request = {
113
+ assertion: midSigner.generateAssertionFor(
114
+ serviceDomain, sessionId),
115
+ provCert: midSigner.providerCert,
116
+ userCert: midSigner.userCert
117
+ };
118
+ let rep = await doJsonRequest<void>(reqOpts, req);
119
+ expect(rep.status).toBe(authSession.SC.ok);
120
+ return sessionId;
121
+ }
122
+
123
+ Object.freeze(exports);
@@ -0,0 +1,127 @@
1
+ /*
2
+ Copyright (C) 2016 3NSoft Inc.
3
+
4
+ This program is free software: you can redistribute it and/or modify it under
5
+ the terms of the GNU General Public License as published by the Free Software
6
+ Foundation, either version 3 of the License, or (at your option) any later
7
+ version.
8
+
9
+ This program is distributed in the hope that it will be useful, but
10
+ WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
+ See the GNU General Public License for more details.
13
+
14
+ You should have received a copy of the GNU General Public License along with
15
+ this program. If not, see <http://www.gnu.org/licenses/>.
16
+ */
17
+
18
+ import * as pklApi from '../../lib-common/service-api/pub-key-login';
19
+ import { base64 } from '../../lib-common/buffer-utils';
20
+ import { box, secret_box as sbox, nonce as nonceMod, arrays }
21
+ from 'ecma-nacl';
22
+ import { makeSessionEncryptor, SessionEncryptor }
23
+ from '../../lib-common/session-encryptor';
24
+ import { doJsonRequest, RequestOpts, doBinaryRequest }
25
+ from './xhr-utils';
26
+ import { parse as parseUrl, resolve as resolveUrl } from 'url';
27
+ import { bytesEqual } from './bytes-equal';
28
+
29
+ export interface User {
30
+ id: string;
31
+ loginDefaultSKey: Uint8Array;
32
+ loginLabeledSKey: {
33
+ kid: string;
34
+ k: Uint8Array;
35
+ };
36
+ midUrl: string;
37
+ storageOwnerUrl: string;
38
+ }
39
+
40
+ export interface ExchangeCrypto {
41
+ sessEncr: SessionEncryptor;
42
+ serverVerificationBytes: Uint8Array;
43
+ encResponse: Uint8Array;
44
+ }
45
+
46
+ export function decryptSessionParamsForCurve25519(r: pklApi.start.Reply,
47
+ loginSKey: Uint8Array): ExchangeCrypto {
48
+ let serverPKey = base64.open(r.serverPubKey);
49
+ expect(serverPKey.length).toBe(box.KEY_LENGTH);
50
+ let sharedKey = box.calc_dhshared_key(serverPKey, loginSKey);
51
+ let encChallenge = base64.open(r.sessionKey);
52
+ expect(encChallenge.length).toBe(
53
+ sbox.NONCE_LENGTH + sbox.KEY_LENGTH);
54
+ let nonce = encChallenge.subarray(0, sbox.NONCE_LENGTH);
55
+ let zeros = new Uint8Array(sbox.KEY_LENGTH);
56
+ let stream = sbox.pack(zeros, nonce, sharedKey).subarray(sbox.POLY_LENGTH);
57
+ let sessionKey = new Uint8Array(
58
+ encChallenge.subarray(sbox.NONCE_LENGTH));
59
+ for (var i=0; i < sbox.KEY_LENGTH; i+=1) {
60
+ sessionKey[i] ^= stream[i];
61
+ }
62
+ let serverVerificationBytes =
63
+ sbox.pack(sessionKey, nonce, sharedKey)
64
+ .subarray(0, sbox.POLY_LENGTH);
65
+ nonceMod.advanceOddly(nonce);
66
+ let sessEncr = makeSessionEncryptor(sessionKey, nonce);
67
+ let encResponse = sessEncr.pack(sessionKey);
68
+ arrays.wipe(sessionKey);
69
+ return { sessEncr, serverVerificationBytes, encResponse };
70
+ }
71
+
72
+ export interface ExchangeParams {
73
+ crypto: ExchangeCrypto;
74
+ sessionId: string;
75
+ }
76
+
77
+ export async function startPKLSession(loginUrl: string, user: User,
78
+ useDefaultKey: boolean): Promise<ExchangeParams> {
79
+ let reqOpts: RequestOpts= {
80
+ url: resolveUrl(loginUrl, pklApi.start.URL_END),
81
+ method: 'POST',
82
+ responseType: 'json'
83
+ };
84
+ let req: pklApi.start.Request = (useDefaultKey ?
85
+ { userId: user.id } :
86
+ { userId: user.id, kid: user.loginLabeledSKey.kid });
87
+ let rep = await doJsonRequest<pklApi.start.Reply>(reqOpts, req);
88
+ expect(rep.status).toBe(pklApi.start.SC.ok);
89
+ let skey = (useDefaultKey ? user.loginDefaultSKey : user.loginLabeledSKey.k)
90
+ return {
91
+ sessionId: rep.data.sessionId,
92
+ crypto: decryptSessionParamsForCurve25519(rep.data, skey)
93
+ };
94
+ }
95
+
96
+ export interface SessionParams {
97
+ sessEncr: SessionEncryptor;
98
+ sessionId: string;
99
+ }
100
+
101
+ async function validatePKLSession(loginUrl: string,
102
+ exchangeParams: ExchangeParams): Promise<SessionParams> {
103
+ let reqOpts: RequestOpts= {
104
+ url: resolveUrl(loginUrl, pklApi.complete.URL_END),
105
+ method: 'POST',
106
+ sessionId: exchangeParams.sessionId,
107
+ responseType: 'arraybuffer'
108
+ };
109
+ let rep = await doBinaryRequest<Uint8Array>(
110
+ reqOpts, exchangeParams.crypto.encResponse);
111
+ expect(rep.status).toBe(pklApi.complete.SC.ok);
112
+ expect(rep.data.length).toBe(sbox.POLY_LENGTH);
113
+ expect(bytesEqual(rep.data, exchangeParams.crypto.serverVerificationBytes))
114
+ .toBe(true);
115
+ return {
116
+ sessionId: exchangeParams.sessionId,
117
+ sessEncr: exchangeParams.crypto.sessEncr
118
+ };
119
+ }
120
+
121
+ export async function doPubKeyLogin(loginUrl: string, user: User):
122
+ Promise<SessionParams> {
123
+ let exchangeParams = await startPKLSession(loginUrl, user, false);
124
+ return validatePKLSession(loginUrl, exchangeParams);
125
+ }
126
+
127
+ Object.freeze(exports);