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,339 @@
1
+ /*
2
+ Copyright (C) 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
+ import * as http from 'http';
19
+ import * as https from 'https';
20
+ import * as express from 'express';
21
+ import * as WebSocket from 'ws';
22
+ import { MapOfSets } from '../../lib-common/map-of-sets';
23
+ import { CheckSession, BaseRequest as HttpRequest, SessionParams } from '../resources/sessions';
24
+ import { parse as parseUrl } from 'url';
25
+
26
+ export type HttpServer = http.Server | https.Server;
27
+
28
+ const MAX_MSG_PAYLOAD = 4*1024;
29
+
30
+
31
+ class UserSocketsServer {
32
+
33
+ /**
34
+ * This is a web socket server. It is undefined, when app hasn't started, or
35
+ * when it has already closed.
36
+ */
37
+ private wss: WebSocket.Server|undefined = undefined;
38
+
39
+ private socksByPath = new Map<string, UserSockets>();
40
+
41
+ prefixPathsWith(prefix: string): void {
42
+ if (this.wss) { throw new Error(`Already connected to an http server`); }
43
+ if (!prefix) { return; }
44
+ prefix = ensureSlashesOnFront(prefix);
45
+ const socksByPath = new Map<string, UserSockets>();
46
+ for (const socks of this.socksByPath.values()) {
47
+ socks.path = `${prefix}${socks.path}`;
48
+ socksByPath.set(socks.path, socks);
49
+ }
50
+ this.socksByPath = socksByPath;
51
+ }
52
+
53
+ connectTo(server: HttpServer): void {
54
+ if (this.wss) { throw new Error(`Already connected to an http server`); }
55
+
56
+ this.wss = new WebSocket.Server({
57
+ server,
58
+ clientTracking: true,
59
+ maxPayload: MAX_MSG_PAYLOAD,
60
+ verifyClient: this.verifyClient.bind(this)
61
+ } as WebSocket.ServerOptions)
62
+ .on('connection', this.handleConnection.bind(this))
63
+ .on('error', (err) => { console.error(err); });
64
+
65
+ }
66
+
67
+ disconnect(): void {
68
+ if (!this.wss) { return; }
69
+ this.wss.close();
70
+ this.wss = undefined;
71
+ for (const socks of this.socksByPath.values()) {
72
+ socks.disconnect();
73
+ }
74
+ this.socksByPath.clear();
75
+ }
76
+
77
+ private verifyClient(
78
+ info: { req: http.IncomingMessage },
79
+ cb: (res: boolean, code?: number, msg?: string) => void
80
+ ): void {
81
+ const path = parseUrl(info.req.url!).path!;
82
+ const socks = this.socksByPath.get(path);
83
+ if (!socks) {
84
+ cb(false, 405, `WebSocket upgrade is not provided on ${path}`);
85
+ return;
86
+ }
87
+ socks.checkSession(info.req as HttpRequest<SessionParams>)
88
+ .then((sessionOK) => {
89
+ cb(sessionOK);
90
+ }, (err) => {
91
+ console.error(err);
92
+ cb(false, 401, "Required to start new session.");
93
+ });
94
+ }
95
+
96
+ private handleConnection(
97
+ client: WebSocket, req: HttpRequest<SessionParams>
98
+ ): void {
99
+ const userId = req.session.params.userId;
100
+ const path = parseUrl(req.url!).path!;
101
+ const socks = this.socksByPath.get(path);
102
+ if (!socks) {
103
+ client.close();
104
+ return;
105
+ }
106
+ socks.handleConnection(userId, client);
107
+ }
108
+
109
+ addUserSockets(socks: UserSockets): void {
110
+ if (this.socksByPath.has(socks.path)) { throw new Error(
111
+ `Sockets component is already set on path ${socks.path}`); }
112
+ this.socksByPath.set(socks.path, socks);
113
+ }
114
+
115
+ addUserSocketsFrom(sockServer: UserSocketsServer, path?: string): void {
116
+ if (path) {
117
+ sockServer.prefixPathsWith(path);
118
+ }
119
+ for (const sock of sockServer.socksByPath.values()) {
120
+ this.addUserSockets(sock);
121
+ }
122
+ }
123
+
124
+ }
125
+ Object.freeze(UserSocketsServer.prototype);
126
+ Object.freeze(UserSocketsServer);
127
+
128
+ function ensureSlashesOnFront(path: string): string {
129
+ while (path.endsWith('/')) {
130
+ path = path.substring(0, path.length - 1);
131
+ }
132
+ if (!path.startsWith('/')) {
133
+ path = `/${path}`;
134
+ }
135
+ return path;
136
+ }
137
+
138
+ export class UserSockets {
139
+
140
+ /**
141
+ * Only connections that match this path are accepted.
142
+ */
143
+ public path = '';
144
+
145
+ private clients = new MapOfSets<string, WebSocket>();
146
+
147
+ private ipcs: SocketIPCs[] = [];
148
+
149
+ constructor(
150
+ public checkSession: CheckSession<SessionParams>,
151
+ private readonly pingMillis: number
152
+ ) {}
153
+
154
+ disconnect(): void {
155
+ this.clients.clear();
156
+ }
157
+
158
+ handleConnection(userId: string, client: WebSocket): void {
159
+ for (const ipc of this.ipcs) {
160
+ ipc.attachIPC(userId, client);
161
+ }
162
+ let pinger = new PingSender(client, this.pingMillis);
163
+ client.on('close', () => {
164
+ this.clients.remove(userId, client);
165
+ pinger.close();
166
+ });
167
+ client.on('pong', () => pinger.onPong());
168
+ this.clients.add(userId, client);
169
+ }
170
+
171
+ addSocketIPC(ipc: SocketIPCs): void {
172
+ if (this.ipcs.find(existingIPC => (existingIPC.ipcChannel === ipc.ipcChannel))) {
173
+ throw new Error(`IPC channel ${ipc.ipcChannel} on a web socket is already set.`);
174
+ }
175
+ this.ipcs.push(ipc);
176
+ }
177
+
178
+ get socketGetter(): (userId: string) => Set<WebSocket>|undefined {
179
+ return (userId => this.clients.get(userId));
180
+ }
181
+
182
+ }
183
+ Object.freeze(UserSockets.prototype);
184
+ Object.freeze(UserSockets);
185
+
186
+ class PingSender {
187
+
188
+ private outstandingPong = 0;
189
+ private client: WebSocket|undefined;
190
+ private fourMinCheck: NodeJS.Timer;
191
+ private readonly pongTimeoutMillis: number;
192
+
193
+ constructor(
194
+ client: WebSocket,
195
+ private readonly pingMillis: number
196
+ ) {
197
+ this.client = client;
198
+ this.pongTimeoutMillis = Math.round(this.pingMillis/2);
199
+ this.fourMinCheck = setInterval(() => this.recurrentPing(), this.pingMillis);
200
+ this.fourMinCheck.unref();
201
+ }
202
+
203
+ private recurrentPing(): void {
204
+ if (!this.client) { return this.close(); }
205
+ if (this.outstandingPong === 0) {
206
+ } else if (this.outstandingPong === 1) {
207
+ setTimeout(() => this.additionalPing(), this.pongTimeoutMillis).unref();
208
+ } else {
209
+ this.client.close();
210
+ return;
211
+ }
212
+ this.client.ping();
213
+ this.outstandingPong += 1;
214
+ }
215
+
216
+ additionalPing(): void {
217
+ if (!this.client) { return; }
218
+ if (this.outstandingPong === 0) { return; }
219
+ this.client.ping();
220
+ this.outstandingPong += 1;
221
+ }
222
+
223
+ onPong(): void {
224
+ this.outstandingPong = 0;
225
+ }
226
+
227
+ close(): void {
228
+ if (!this.client) { return; }
229
+ this.client = undefined;
230
+ clearInterval(this.fourMinCheck);
231
+ }
232
+ }
233
+ Object.freeze(PingSender.prototype);
234
+ Object.freeze(PingSender);
235
+
236
+ export interface SocketIPCs {
237
+ ipcChannel: string|undefined;
238
+ attachIPC(userId: string, ws: WebSocket): void;
239
+ }
240
+
241
+ export class AppWithWSs {
242
+
243
+ private server: HttpServer|undefined = undefined;
244
+ private closingProc: Promise<void>|undefined = undefined;
245
+ http: express.Express;
246
+
247
+ private socks: UserSocketsServer|undefined = undefined;
248
+ private get sockServer(): UserSocketsServer {
249
+ if (!this.socks) {
250
+ this.socks = new UserSocketsServer();
251
+ }
252
+ return this.socks;
253
+ }
254
+
255
+ constructor(httpApp?: express.Express) {
256
+ this.http = (httpApp ? httpApp : express());
257
+ Object.seal(this);
258
+ }
259
+
260
+ addWS(path: string, socks: UserSockets): void;
261
+ addWS(socks: UserSockets): void;
262
+ addWS(path: string|UserSockets, socks?: UserSockets): void {
263
+ if (typeof path === 'string') {
264
+ socks!.path = ensureSlashesOnFront(path);
265
+ } else {
266
+ socks = path;
267
+ }
268
+ this.sockServer.addUserSockets(socks!);
269
+ }
270
+
271
+ use(path: string, app: AppWithWSs): void;
272
+ use(app: AppWithWSs): void;
273
+ use(path: string|AppWithWSs, app?: AppWithWSs): void {
274
+ if (typeof path === 'string') {
275
+ if (!app) { throw new TypeError(`App argument is missing`); }
276
+ this.http.use(path, app.http);
277
+ if (app.socks) {
278
+ this.sockServer.addUserSocketsFrom(app.socks, path);
279
+ }
280
+ } else {
281
+ app = path;
282
+ this.http.use(app.http);
283
+ if (app.socks) {
284
+ this.sockServer.addUserSocketsFrom(app.socks);
285
+ }
286
+ }
287
+ }
288
+
289
+ start(
290
+ sslOts: https.ServerOptions|undefined, port: number, hostname?: string
291
+ ): Promise<void> {
292
+ if (this.server) { throw new Error(`Server is already set`); }
293
+
294
+ // setup server
295
+ this.server = (sslOts ?
296
+ https.createServer(sslOts, this.http) :
297
+ http.createServer(this.http));
298
+ if (this.socks) {
299
+ this.socks.connectTo(this.server);
300
+ }
301
+
302
+ // start listening
303
+ this.closingProc = undefined;
304
+ return new Promise<void>((resolve, reject) => {
305
+ const cb = (err?) => {
306
+ if (err) { reject(err); }
307
+ else { resolve(); }
308
+ };
309
+ if (hostname) {
310
+ this.server!.listen(port, hostname, cb);
311
+ } else {
312
+ this.server!.listen(port, cb);
313
+ }
314
+ });
315
+ }
316
+
317
+ async stop(): Promise<void> {
318
+ if (!this.server) { return; }
319
+ if (!this.closingProc) {
320
+ if (this.socks) {
321
+ this.socks.disconnect();
322
+ }
323
+ this.closingProc = new Promise<void>((resolve, reject) => {
324
+ const cb = (err) => {
325
+ if (err) { reject(err); }
326
+ else { resolve(); }
327
+ };
328
+ this.server!.close(cb);
329
+ this.server = undefined;
330
+ });
331
+ }
332
+ await this.closingProc;
333
+ }
334
+
335
+ }
336
+ Object.freeze(AppWithWSs.prototype);
337
+ Object.freeze(AppWithWSs);
338
+
339
+ Object.freeze(exports);
@@ -0,0 +1,63 @@
1
+ /*
2
+ Copyright (C) 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
+ import { EventfulServer, makeEventfulServer, makeJsonCommPoint } from '../../lib-common/ipc/ws-ipc';
19
+ import * as WebSocket from 'ws';
20
+ import { SocketIPCs } from './app';
21
+
22
+ export type EventsSink<T> = (userId: string, channel: string, event: T) => void;
23
+
24
+ export class ServerEvents<T> implements SocketIPCs {
25
+
26
+ private socketToIPC = new WeakMap<WebSocket, EventfulServer>();
27
+
28
+ constructor(
29
+ public ipcChannel: string|undefined,
30
+ private eventChannels: string[],
31
+ private getSocket: (userId: string) => Set<WebSocket>|undefined
32
+ ) {
33
+ Object.seal(this);
34
+ }
35
+
36
+ attachIPC(userId: string, ws: WebSocket): void {
37
+ const comm = makeJsonCommPoint(ws);
38
+ const ipc = makeEventfulServer(this.ipcChannel, comm);
39
+ for (const channel of this.eventChannels) {
40
+ ipc.addEventGroup(channel, async () => {});
41
+ }
42
+ this.socketToIPC.set(ws, ipc);
43
+ }
44
+
45
+ private sendEvent(userId: string, channel: string, event: T): void {
46
+ const sockets = this.getSocket(userId);
47
+ if (!sockets) { return; }
48
+ for (const ws of sockets) {
49
+ const ipc = this.socketToIPC.get(ws);
50
+ if (!ipc) { continue; }
51
+ ipc.sendEvent(channel, event);
52
+ }
53
+ }
54
+
55
+ get eventsSink(): EventsSink<T> {
56
+ return this.sendEvent.bind(this);
57
+ }
58
+
59
+ }
60
+ Object.freeze(ServerEvents.prototype);
61
+ Object.freeze(ServerEvents);
62
+
63
+ Object.freeze(exports);
package/ts-code/lib.ts ADDED
@@ -0,0 +1,29 @@
1
+ /*
2
+ Copyright (C) 2020, 2023 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 { AppWithWSs } from './lib-server/web-sockets/app';
19
+
20
+ export { Configurations, servicesApp, accountsApp } from './services';
21
+
22
+ export { addSingleUserSignup } from './config/signup';
23
+
24
+ export import errors = require('./lib-server/middleware/error-handler');
25
+
26
+ export * as mock from './mock/run-in-proc';
27
+
28
+
29
+ Object.freeze(exports);
@@ -0,0 +1,60 @@
1
+ /*
2
+ Copyright (C) 2024 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 { Express } from 'express';
19
+ import { json as parseJSON } from '../lib-server/middleware/body-parsers';
20
+ import { ErrLogger, makeErrHandler } from '../lib-server/middleware/error-handler';
21
+ import { AppWithWSs } from '../lib-server/web-sockets/app';
22
+ import { makeSessionFactory } from './resources/sessions';
23
+ import { makeStorageAppForLocker } from '../3nstorage/3nstorage-app';
24
+ import { createLocker } from './routes/create-locker';
25
+ import * as api from '../lib-common/service-api/locker';
26
+
27
+
28
+ function addLockerSetupRoutes(app: Express): void {
29
+
30
+ app.put('/'+api.createLocker.URL_END,
31
+ parseJSON('1kb'),
32
+ // createLocker()
33
+ );
34
+
35
+ }
36
+
37
+ export function makeLockerApp(
38
+ rootFolder: string, errLogger?: ErrLogger
39
+ ): AppWithWSs {
40
+ const ownersSessions = makeSessionFactory(20*60);
41
+ const sharingSessions = makeSessionFactory(20*60);
42
+
43
+ const app = new AppWithWSs();
44
+
45
+ app.http.disable('etag');
46
+
47
+ addLockerSetupRoutes(app.http);
48
+
49
+ const lockers = undefined as any;
50
+
51
+ app.use('/3nstorage', makeStorageAppForLocker(
52
+ lockers, ownersSessions, sharingSessions, errLogger
53
+ ));
54
+
55
+ app.http.use(makeErrHandler(errLogger));
56
+
57
+ return app;
58
+ }
59
+
60
+ Object.freeze(exports);
@@ -0,0 +1,17 @@
1
+ /*
2
+ Copyright (C) 2024 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
+
@@ -0,0 +1,37 @@
1
+ /*
2
+ Copyright (C) 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
+ import { InMemorySessions } from '../../lib-server/resources/mem-backed-sessions-factory';
19
+ import { Request as Req, SessionParams, Factory } from '../../lib-server/resources/sessions';
20
+
21
+ export type SessionsFactory = Factory<SessionParams>;
22
+ export type Request = Req<SessionParams>;
23
+
24
+ function makeSessionParams(): SessionParams {
25
+ return { userId: (undefined as any) };
26
+ }
27
+
28
+ /**
29
+ * This returns factory, that works properly in a single process application,
30
+ * clearing up sessions that past given timeout.
31
+ * @param timeout is a session timeout in seconds
32
+ */
33
+ export function makeSessionFactory(timeout: number): SessionsFactory {
34
+ return InMemorySessions.factory<SessionParams>(timeout, makeSessionParams);
35
+ }
36
+
37
+ Object.freeze(exports);
@@ -0,0 +1,47 @@
1
+ /*
2
+ Copyright (C) 2024 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 { RequestHandler } from 'express';
19
+ import { createLocker as api } from '../../lib-common/service-api/locker';
20
+
21
+ export type LockerCreator = (token: string|undefined) => Promise<api.Reply>;
22
+
23
+ export function createLocker(
24
+ createLocker: LockerCreator
25
+ ): RequestHandler {
26
+
27
+ if ('function' !== typeof createLocker) {
28
+ throw new TypeError(
29
+ "Given argument 'createLocker' must be function, but is not."
30
+ );
31
+ }
32
+
33
+ return async (req, res, next) => {
34
+
35
+ const { token } = req.body as api.Request;
36
+
37
+ try{
38
+ const lockerInfo = await createLocker(token);
39
+ res.status(api.SC.ok).json(lockerInfo);
40
+ } catch (err) {
41
+ next(err);
42
+ }
43
+
44
+ };
45
+
46
+ }
47
+ Object.freeze(exports);
@@ -0,0 +1,107 @@
1
+ /*
2
+ Copyright (C) 2015 - 2016, 2020, 2024 - 2025 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 gives a function that creates a mountable, or app.use()-able,
20
+ * express MailerId application.
21
+ */
22
+
23
+ import * as express from 'express';
24
+ import { binary as parseBinary } from '../lib-server/middleware/body-parsers';
25
+ import { ComputeDHSharedKey } from '../lib-server/routes/pub-key-login/start-exchange';
26
+ import { certify } from './routes/certify';
27
+ import { Certifier } from './resources/certifier';
28
+ import { makeSessionFactory, SessionsFactory } from './resources/sessions';
29
+ import { makeFactory as makeUserFactory, Factory as UserFactory } from './resources/users';
30
+ import { makeSingleProcCertifier } from './resources/certifier';
31
+ import { calcNaClBoxSharedKey } from '../lib-server/resources/server-key-for-pkl-challenge';
32
+ import { ErrLogger, makeErrHandler } from '../lib-server/middleware/error-handler';
33
+ import * as api from '../lib-common/service-api/mailer-id/provisioning';
34
+ import { addPKLLoginRoutes } from '../lib-server/pkl-access';
35
+ import { OwnMidService } from '../lib-server/resources/mailerid-authorizer';
36
+ import { MailerIdRootRoute } from '../lib-common/service-api/mailer-id/root-route';
37
+
38
+ // Constant url parts of MailerId provisioning requests
39
+ const PROVISIONING_PATH = '/prov/';
40
+
41
+ function provisioningApp(
42
+ sessions: SessionsFactory, users: UserFactory,
43
+ certifier: Certifier, computeDHSharedKey: ComputeDHSharedKey
44
+ ): express.Express {
45
+
46
+ const app = express();
47
+ app.disable('etag');
48
+
49
+ // Login
50
+ addPKLLoginRoutes(
51
+ app, '/', users.getUserParamsAndKey, sessions, computeDHSharedKey
52
+ );
53
+
54
+ // *** Require authorized session for everything below ***
55
+ app.use(sessions.ensureAuthorizedSession());
56
+
57
+ // MailerId certificate provisioning routes
58
+ app.post('/' + api.certify.URL_END,
59
+ parseBinary('16kb'),
60
+ certify(certifier.certify)
61
+ );
62
+
63
+ return app;
64
+ }
65
+
66
+ export function makeMailerIdApp(
67
+ rootFolder: string, domain: string, certFile: string,
68
+ errLogger?: ErrLogger
69
+ ): { app: express.Express; ownService: OwnMidService; } {
70
+
71
+ const app = express();
72
+ const certProvisSessions = makeSessionFactory(2*60);
73
+ const users = makeUserFactory(rootFolder);
74
+ const certifier = makeSingleProcCertifier(domain, certFile);
75
+
76
+ app.use(PROVISIONING_PATH,
77
+ provisioningApp(
78
+ certProvisSessions, users, certifier, calcNaClBoxSharedKey
79
+ )
80
+ );
81
+
82
+ // MailerId display of service parameters, as per protocol
83
+ app.get('/', (req: express.Request, res: express.Response) => {
84
+ let path = req.originalUrl;
85
+ if (path[path.length-1] !== '/') {
86
+ path = path+'/';
87
+ }
88
+ const json: MailerIdRootRoute = {
89
+ "current-cert": certifier.getRootCert(),
90
+ "previous-certs": certifier.getPrevCerts(),
91
+ provisioning: path+PROVISIONING_PATH.substring(1)
92
+ };
93
+ res.status(200).json(json); // content type application/json
94
+ });
95
+
96
+ app.use(makeErrHandler(errLogger));
97
+
98
+ return {
99
+ app,
100
+ ownService: {
101
+ domain,
102
+ getRoot: () => certifier.getRootCert()
103
+ }
104
+ };
105
+ }
106
+
107
+ Object.freeze(exports);