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.
- package/.gitlab-ci-linux.yml +50 -0
- package/.gitlab-ci-mac.yml +29 -0
- package/.gitlab-ci-windows.yml +29 -0
- package/.gitlab-ci.yml +63 -0
- package/build/3nstorage/resources/store.d.ts +2 -2
- package/build/3nstorage/resources/store.js +1 -1
- package/build/3nstorage/resources/users.d.ts +3 -3
- package/build/3nstorage/resources/users.js +1 -1
- package/build/3nstorage/resources/utils.d.ts +6 -0
- package/build/3nstorage/resources/utils.js +41 -0
- package/build/3nstorage/routes/owner/archive-obj-version.js +8 -10
- package/build/3nstorage/routes/owner/cancel-trans.js +5 -4
- package/build/3nstorage/routes/owner/delete-obj.js +7 -8
- package/build/3nstorage/routes/owner/get-archived-obj-ver.js +11 -13
- package/build/3nstorage/routes/owner/get-current-obj.js +7 -6
- package/build/3nstorage/routes/owner/get-obj-status.js +8 -8
- package/build/3nstorage/routes/owner/put-current-obj.js +25 -55
- package/build/3nstorage/routes/owner/session-params.js +2 -0
- package/build/asmail/resources/utils.d.ts +6 -0
- package/build/asmail/resources/utils.js +36 -0
- package/build/asmail/routes/delivery/finalize-delivery.js +3 -2
- package/build/asmail/routes/delivery/pre-flight.js +9 -26
- package/build/asmail/routes/delivery/provide-recipient-pubkey.js +4 -3
- package/build/asmail/routes/delivery/put-metadata.js +13 -21
- package/build/asmail/routes/delivery/put-obj.js +19 -25
- package/build/asmail/routes/delivery/restart-session.d.ts +4 -8
- package/build/asmail/routes/delivery/restart-session.js +10 -23
- package/build/asmail/routes/delivery/sender-authorization.js +5 -5
- package/build/asmail/routes/delivery/start-session.js +9 -24
- package/build/asmail/routes/retrieval/get-message-meta.js +4 -7
- package/build/asmail/routes/retrieval/get-message-obj.js +10 -7
- package/build/asmail/routes/retrieval/list-messages.js +4 -4
- package/build/asmail/routes/retrieval/remove-message.js +3 -2
- package/build/mock/tls-options.js +46 -44
- package/build/tests/admin-proto/signup.d.ts +1 -0
- package/build/tests/admin-proto/signup.js +235 -0
- package/build/tests/jasmine.d.ts +1 -0
- package/build/tests/jasmine.js +32 -0
- package/build/tests/libs-for-tests/3nstorage.d.ts +22 -0
- package/build/tests/libs-for-tests/3nstorage.js +123 -0
- package/build/tests/libs-for-tests/asmail.d.ts +22 -0
- package/build/tests/libs-for-tests/asmail.js +179 -0
- package/build/tests/libs-for-tests/assert.d.ts +1 -0
- package/build/tests/libs-for-tests/assert.js +26 -0
- package/build/tests/libs-for-tests/async-jasmine.d.ts +7 -0
- package/build/tests/libs-for-tests/async-jasmine.js +77 -0
- package/build/tests/libs-for-tests/bytes-equal.d.ts +1 -0
- package/build/tests/libs-for-tests/bytes-equal.js +34 -0
- package/build/tests/libs-for-tests/json-copy.d.ts +1 -0
- package/build/tests/libs-for-tests/json-copy.js +45 -0
- package/build/tests/libs-for-tests/json-equal.d.ts +4 -0
- package/build/tests/libs-for-tests/json-equal.js +67 -0
- package/build/tests/libs-for-tests/mailerid.d.ts +13 -0
- package/build/tests/libs-for-tests/mailerid.js +114 -0
- package/build/tests/libs-for-tests/pkl.d.ts +28 -0
- package/build/tests/libs-for-tests/pkl.js +89 -0
- package/build/tests/libs-for-tests/server-components/3nstorage.d.ts +20 -0
- package/build/tests/libs-for-tests/server-components/3nstorage.js +200 -0
- package/build/tests/libs-for-tests/server-components/admin.d.ts +6 -0
- package/build/tests/libs-for-tests/server-components/admin.js +43 -0
- package/build/tests/libs-for-tests/server-components/asmail.d.ts +16 -0
- package/build/tests/libs-for-tests/server-components/asmail.js +143 -0
- package/build/tests/libs-for-tests/server-components/component.d.ts +13 -0
- package/build/tests/libs-for-tests/server-components/component.js +77 -0
- package/build/tests/libs-for-tests/server-components/mailerid.d.ts +10 -0
- package/build/tests/libs-for-tests/server-components/mailerid.js +103 -0
- package/build/tests/libs-for-tests/server-runner.d.ts +15 -0
- package/build/tests/libs-for-tests/server-runner.js +69 -0
- package/build/tests/libs-for-tests/spec-assembly.d.ts +6 -0
- package/build/tests/libs-for-tests/spec-assembly.js +55 -0
- package/build/tests/libs-for-tests/ws-utils.d.ts +3 -0
- package/build/tests/libs-for-tests/ws-utils.js +59 -0
- package/build/tests/libs-for-tests/xhr-utils.d.ts +61 -0
- package/build/tests/libs-for-tests/xhr-utils.js +154 -0
- package/build/tests/protocols/3nstorage/owner/specs/archive-obj-ver.d.ts +2 -0
- package/build/tests/protocols/3nstorage/owner/specs/archive-obj-ver.js +84 -0
- package/build/tests/protocols/3nstorage/owner/specs/archive-root-ver.d.ts +2 -0
- package/build/tests/protocols/3nstorage/owner/specs/archive-root-ver.js +78 -0
- package/build/tests/protocols/3nstorage/owner/specs/delete-archive-obj-ver.d.ts +2 -0
- package/build/tests/protocols/3nstorage/owner/specs/delete-archive-obj-ver.js +83 -0
- package/build/tests/protocols/3nstorage/owner/specs/delete-archive-root-ver.d.ts +2 -0
- package/build/tests/protocols/3nstorage/owner/specs/delete-archive-root-ver.js +77 -0
- package/build/tests/protocols/3nstorage/owner/specs/delete-obj.d.ts +2 -0
- package/build/tests/protocols/3nstorage/owner/specs/delete-obj.js +75 -0
- package/build/tests/protocols/3nstorage/owner/specs/events.d.ts +2 -0
- package/build/tests/protocols/3nstorage/owner/specs/events.js +91 -0
- package/build/tests/protocols/3nstorage/owner/specs/get-current-obj.d.ts +2 -0
- package/build/tests/protocols/3nstorage/owner/specs/get-current-obj.js +269 -0
- package/build/tests/protocols/3nstorage/owner/specs/get-current-root.d.ts +2 -0
- package/build/tests/protocols/3nstorage/owner/specs/get-current-root.js +262 -0
- package/build/tests/protocols/3nstorage/owner/specs/get-obj-status.d.ts +2 -0
- package/build/tests/protocols/3nstorage/owner/specs/get-obj-status.js +79 -0
- package/build/tests/protocols/3nstorage/owner/specs/get-root-status.d.ts +2 -0
- package/build/tests/protocols/3nstorage/owner/specs/get-root-status.js +72 -0
- package/build/tests/protocols/3nstorage/owner/specs/put-current-obj.d.ts +2 -0
- package/build/tests/protocols/3nstorage/owner/specs/put-current-obj.js +287 -0
- package/build/tests/protocols/3nstorage/owner/specs/put-current-root.d.ts +2 -0
- package/build/tests/protocols/3nstorage/owner/specs/put-current-root.js +274 -0
- package/build/tests/protocols/3nstorage/owner/specs/trans-cancel-root.d.ts +2 -0
- package/build/tests/protocols/3nstorage/owner/specs/trans-cancel-root.js +73 -0
- package/build/tests/protocols/3nstorage/owner/specs/trans-cancel.d.ts +2 -0
- package/build/tests/protocols/3nstorage/owner/specs/trans-cancel.js +72 -0
- package/build/tests/protocols/3nstorage/owner/test-utils.d.ts +14 -0
- package/build/tests/protocols/3nstorage/owner/test-utils.js +54 -0
- package/build/tests/protocols/3nstorage/owner.d.ts +1 -0
- package/build/tests/protocols/3nstorage/owner.js +138 -0
- package/build/tests/protocols/asmail/config.d.ts +1 -0
- package/build/tests/protocols/asmail/config.js +117 -0
- package/build/tests/protocols/asmail/delivery/specs/finalize-delivery.d.ts +2 -0
- package/build/tests/protocols/asmail/delivery/specs/finalize-delivery.js +60 -0
- package/build/tests/protocols/asmail/delivery/specs/provide-recipient-pubkey.d.ts +2 -0
- package/build/tests/protocols/asmail/delivery/specs/provide-recipient-pubkey.js +68 -0
- package/build/tests/protocols/asmail/delivery/specs/put-metadata.d.ts +2 -0
- package/build/tests/protocols/asmail/delivery/specs/put-metadata.js +83 -0
- package/build/tests/protocols/asmail/delivery/specs/put-obj.d.ts +2 -0
- package/build/tests/protocols/asmail/delivery/specs/put-obj.js +123 -0
- package/build/tests/protocols/asmail/delivery/specs/restart-session.d.ts +2 -0
- package/build/tests/protocols/asmail/delivery/specs/restart-session.js +79 -0
- package/build/tests/protocols/asmail/delivery/specs/start-session.d.ts +2 -0
- package/build/tests/protocols/asmail/delivery/specs/start-session.js +64 -0
- package/build/tests/protocols/asmail/delivery/test-utils.d.ts +16 -0
- package/build/tests/protocols/asmail/delivery/test-utils.js +46 -0
- package/build/tests/protocols/asmail/delivery.d.ts +1 -0
- package/build/tests/protocols/asmail/delivery.js +46 -0
- package/build/tests/protocols/asmail/retrieval/specs/events.d.ts +2 -0
- package/build/tests/protocols/asmail/retrieval/specs/events.js +62 -0
- package/build/tests/protocols/asmail/retrieval/specs/get-message-meta.d.ts +2 -0
- package/build/tests/protocols/asmail/retrieval/specs/get-message-meta.js +70 -0
- package/build/tests/protocols/asmail/retrieval/specs/get-message-obj.d.ts +2 -0
- package/build/tests/protocols/asmail/retrieval/specs/get-message-obj.js +166 -0
- package/build/tests/protocols/asmail/retrieval/specs/list-messages.d.ts +2 -0
- package/build/tests/protocols/asmail/retrieval/specs/list-messages.js +96 -0
- package/build/tests/protocols/asmail/retrieval/specs/remove-message.d.ts +2 -0
- package/build/tests/protocols/asmail/retrieval/specs/remove-message.js +66 -0
- package/build/tests/protocols/asmail/retrieval/test-utils.d.ts +17 -0
- package/build/tests/protocols/asmail/retrieval/test-utils.js +46 -0
- package/build/tests/protocols/asmail/retrieval.d.ts +1 -0
- package/build/tests/protocols/asmail/retrieval.js +92 -0
- package/build/tests/protocols/mailerid.d.ts +1 -0
- package/build/tests/protocols/mailerid.js +210 -0
- package/build/tests/shared-checks/check-mid-login.d.ts +2 -0
- package/build/tests/shared-checks/check-mid-login.js +131 -0
- package/build/tests/shared-checks/requests.d.ts +20 -0
- package/build/tests/shared-checks/requests.js +123 -0
- package/package.json +1 -1
- package/packing/create-deb.sh +57 -0
- package/packing/deb/lib/systemd/system/3nweb.service +11 -0
- package/packing/deb/postinst +44 -0
- package/packing/deb/usr/share/doc/3nweb-server/conf-for-postinstall.yaml +19 -0
- package/packing/deb/usr/share/doc/3nweb-server/copyright +22 -0
- package/publish-task.sh +10 -0
- package/push-to-github.sh +105 -0
- package/ts-code/3nstorage/3nstorage-app.ts +99 -0
- package/ts-code/3nstorage/owner.ts +178 -0
- package/ts-code/3nstorage/resources/sessions.ts +37 -0
- package/ts-code/3nstorage/resources/store.ts +896 -0
- package/ts-code/3nstorage/resources/users.ts +258 -0
- package/ts-code/3nstorage/resources/utils.ts +45 -0
- package/ts-code/3nstorage/routes/owner/archive-obj-version.ts +71 -0
- package/ts-code/3nstorage/routes/owner/cancel-trans.ts +60 -0
- package/ts-code/3nstorage/routes/owner/delete-obj.ts +99 -0
- package/ts-code/3nstorage/routes/owner/get-archived-obj-ver.ts +109 -0
- package/ts-code/3nstorage/routes/owner/get-current-obj.ts +124 -0
- package/ts-code/3nstorage/routes/owner/get-obj-status.ts +55 -0
- package/ts-code/3nstorage/routes/owner/param-getter.ts +51 -0
- package/ts-code/3nstorage/routes/owner/param-setter.ts +50 -0
- package/ts-code/3nstorage/routes/owner/put-current-obj.ts +257 -0
- package/ts-code/3nstorage/routes/owner/session-params.ts +50 -0
- package/ts-code/3nstorage/shared.ts +43 -0
- package/ts-code/asmail/asmail-app.ts +91 -0
- package/ts-code/asmail/config.ts +96 -0
- package/ts-code/asmail/delivery.ts +94 -0
- package/ts-code/asmail/resources/delivery-sessions.ts +118 -0
- package/ts-code/asmail/resources/inbox.ts +696 -0
- package/ts-code/asmail/resources/recipients.ts +495 -0
- package/ts-code/asmail/resources/sessions.ts +37 -0
- package/ts-code/asmail/resources/utils.ts +41 -0
- package/ts-code/asmail/retrieval.ts +96 -0
- package/ts-code/asmail/routes/config/param-getter.ts +49 -0
- package/ts-code/asmail/routes/config/param-setter.ts +49 -0
- package/ts-code/asmail/routes/delivery/finalize-delivery.ts +51 -0
- package/ts-code/asmail/routes/delivery/pre-flight.ts +118 -0
- package/ts-code/asmail/routes/delivery/provide-recipient-pubkey.ts +58 -0
- package/ts-code/asmail/routes/delivery/put-metadata.ts +85 -0
- package/ts-code/asmail/routes/delivery/put-obj.ts +152 -0
- package/ts-code/asmail/routes/delivery/restart-session.ts +117 -0
- package/ts-code/asmail/routes/delivery/sender-authorization.ts +81 -0
- package/ts-code/asmail/routes/delivery/start-session.ts +136 -0
- package/ts-code/asmail/routes/retrieval/get-message-meta.ts +50 -0
- package/ts-code/asmail/routes/retrieval/get-message-obj.ts +106 -0
- package/ts-code/asmail/routes/retrieval/list-messages.ts +68 -0
- package/ts-code/asmail/routes/retrieval/remove-message.ts +48 -0
- package/ts-code/cli/index.ts +82 -0
- package/ts-code/cli/run-cmd.ts +81 -0
- package/ts-code/cli/show-sample-config.ts +78 -0
- package/ts-code/cli/signup-cmd.ts +229 -0
- package/ts-code/cli/user-cmd.ts +68 -0
- package/ts-code/cli/utils.ts +105 -0
- package/ts-code/config/default-confs.ts +22 -0
- package/ts-code/config/from-yaml.ts +35 -0
- package/ts-code/config/letsencrypt.ts +77 -0
- package/ts-code/config/signup.ts +137 -0
- package/ts-code/lib-common/admin-api/signup.ts +120 -0
- package/ts-code/lib-common/assert.ts +22 -0
- package/ts-code/lib-common/async-fs-node.ts +656 -0
- package/ts-code/lib-common/buffer-utils.ts +124 -0
- package/ts-code/lib-common/byte-streaming/common.ts +166 -0
- package/ts-code/lib-common/bytes-equal.ts +25 -0
- package/ts-code/lib-common/canonical-address.ts +92 -0
- package/ts-code/lib-common/exceptions/error.ts +44 -0
- package/ts-code/lib-common/exceptions/file.ts +84 -0
- package/ts-code/lib-common/exceptions/http.ts +69 -0
- package/ts-code/lib-common/ipc/generic-ipc.ts +750 -0
- package/ts-code/lib-common/ipc/ws-ipc.ts +117 -0
- package/ts-code/lib-common/json-equal.ts +55 -0
- package/ts-code/lib-common/json-utils.ts +130 -0
- package/ts-code/lib-common/jwkeys.ts +246 -0
- package/ts-code/lib-common/map-of-sets.ts +60 -0
- package/ts-code/lib-common/mid-sigs-NaCl-Ed.ts +677 -0
- package/ts-code/lib-common/objs-on-disk/file-layout.ts +480 -0
- package/ts-code/lib-common/objs-on-disk/obj-file.ts +325 -0
- package/ts-code/lib-common/objs-on-disk/utils.ts +201 -0
- package/ts-code/lib-common/objs-on-disk/v1-obj-file-format.ts +329 -0
- package/ts-code/lib-common/processes.ts +501 -0
- package/ts-code/lib-common/random-node.ts +79 -0
- package/ts-code/lib-common/service-api/3nstorage/owner.ts +559 -0
- package/ts-code/lib-common/service-api/3nstorage/root-route.ts +22 -0
- package/ts-code/lib-common/service-api/asmail/config.ts +144 -0
- package/ts-code/lib-common/service-api/asmail/delivery.ts +250 -0
- package/ts-code/lib-common/service-api/asmail/retrieval.ts +238 -0
- package/ts-code/lib-common/service-api/asmail/root-route.ts +22 -0
- package/ts-code/lib-common/service-api/ipc-api.ts +44 -0
- package/ts-code/lib-common/service-api/locker.ts +44 -0
- package/ts-code/lib-common/service-api/mailer-id/login.ts +80 -0
- package/ts-code/lib-common/service-api/mailer-id/provisioning.ts +64 -0
- package/ts-code/lib-common/service-api/mailer-id/root-route.ts +25 -0
- package/ts-code/lib-common/service-api/pub-key-login.ts +75 -0
- package/ts-code/lib-common/service-api/web-socket-base.ts +87 -0
- package/ts-code/lib-common/session-encryptor.ts +54 -0
- package/ts-code/lib-common/time-window-cache.ts +74 -0
- package/ts-code/lib-common/transferable.d.ts +30 -0
- package/ts-code/lib-server/conf-util.ts +35 -0
- package/ts-code/lib-server/mid-access.ts +45 -0
- package/ts-code/lib-server/middleware/body-parsers.ts +248 -0
- package/ts-code/lib-server/middleware/error-handler.ts +79 -0
- package/ts-code/lib-server/pkl-access.ts +46 -0
- package/ts-code/lib-server/resources/dns.ts +151 -0
- package/ts-code/lib-server/resources/mailerid-authorizer.ts +115 -0
- package/ts-code/lib-server/resources/mem-backed-sessions-factory.ts +132 -0
- package/ts-code/lib-server/resources/server-data-folders.ts +160 -0
- package/ts-code/lib-server/resources/server-key-for-pkl-challenge.ts +41 -0
- package/ts-code/lib-server/resources/sessions.ts +232 -0
- package/ts-code/lib-server/resources/user-files.ts +147 -0
- package/ts-code/lib-server/routes/pub-key-login/complete-exchange.ts +63 -0
- package/ts-code/lib-server/routes/pub-key-login/start-exchange.ts +189 -0
- package/ts-code/lib-server/routes/sessions/close.ts +27 -0
- package/ts-code/lib-server/routes/sessions/mid-auth.ts +77 -0
- package/ts-code/lib-server/routes/sessions/start.ts +116 -0
- package/ts-code/lib-server/web-sockets/app.ts +339 -0
- package/ts-code/lib-server/web-sockets/server-events.ts +63 -0
- package/ts-code/lib.ts +29 -0
- package/ts-code/locker/locker-app.ts +60 -0
- package/ts-code/locker/resources/lockers.ts +17 -0
- package/ts-code/locker/resources/sessions.ts +37 -0
- package/ts-code/locker/routes/create-locker.ts +47 -0
- package/ts-code/mailerId/mailerId-app.ts +107 -0
- package/ts-code/mailerId/resources/certifier.ts +181 -0
- package/ts-code/mailerId/resources/sessions.ts +44 -0
- package/ts-code/mailerId/resources/users.ts +88 -0
- package/ts-code/mailerId/routes/certify.ts +68 -0
- package/ts-code/main.ts +304 -0
- package/ts-code/mock/dns.ts +106 -0
- package/ts-code/mock/mock-as-child-proc.ts +130 -0
- package/ts-code/mock/node-child-ipc.ts +69 -0
- package/ts-code/mock/run-in-proc.ts +111 -0
- package/ts-code/mock/tls-options.ts +73 -0
- package/ts-code/services.ts +138 -0
- package/ts-code/signup/resources/users.ts +429 -0
- package/ts-code/signup/routes/add.ts +65 -0
- package/ts-code/signup/routes/get-available-addresses.ts +49 -0
- package/ts-code/signup/routes/get-available-domains.ts +45 -0
- package/ts-code/signup/signup-app.ts +54 -0
- package/ts-code/signup/signup-tokens.ts +148 -0
- package/ts-code/tests/admin-proto/signup.ts +277 -0
- package/ts-code/tests/jasmine.ts +37 -0
- package/ts-code/tests/libs-for-tests/3nstorage.ts +144 -0
- package/ts-code/tests/libs-for-tests/asmail.ts +220 -0
- package/ts-code/tests/libs-for-tests/assert.ts +22 -0
- package/ts-code/tests/libs-for-tests/async-jasmine.ts +89 -0
- package/ts-code/tests/libs-for-tests/bytes-equal.ts +25 -0
- package/ts-code/tests/libs-for-tests/json-copy.ts +38 -0
- package/ts-code/tests/libs-for-tests/json-equal.ts +55 -0
- package/ts-code/tests/libs-for-tests/mailerid.ts +123 -0
- package/ts-code/tests/libs-for-tests/pkl.ts +127 -0
- package/ts-code/tests/libs-for-tests/server-components/3nstorage.ts +206 -0
- package/ts-code/tests/libs-for-tests/server-components/admin.ts +49 -0
- package/ts-code/tests/libs-for-tests/server-components/asmail.ts +152 -0
- package/ts-code/tests/libs-for-tests/server-components/component.ts +90 -0
- package/ts-code/tests/libs-for-tests/server-components/mailerid.ts +114 -0
- package/ts-code/tests/libs-for-tests/server-runner.ts +82 -0
- package/ts-code/tests/libs-for-tests/spec-assembly.ts +60 -0
- package/ts-code/tests/libs-for-tests/ws-utils.ts +61 -0
- package/ts-code/tests/libs-for-tests/xhr-utils.ts +179 -0
- package/ts-code/tests/protocols/3nstorage/owner/specs/archive-obj-ver.ts +100 -0
- package/ts-code/tests/protocols/3nstorage/owner/specs/archive-root-ver.ts +91 -0
- package/ts-code/tests/protocols/3nstorage/owner/specs/delete-archive-obj-ver.ts +99 -0
- package/ts-code/tests/protocols/3nstorage/owner/specs/delete-archive-root-ver.ts +90 -0
- package/ts-code/tests/protocols/3nstorage/owner/specs/delete-obj.ts +84 -0
- package/ts-code/tests/protocols/3nstorage/owner/specs/events.ts +125 -0
- package/ts-code/tests/protocols/3nstorage/owner/specs/get-current-obj.ts +298 -0
- package/ts-code/tests/protocols/3nstorage/owner/specs/get-current-root.ts +290 -0
- package/ts-code/tests/protocols/3nstorage/owner/specs/get-obj-status.ts +88 -0
- package/ts-code/tests/protocols/3nstorage/owner/specs/get-root-status.ts +80 -0
- package/ts-code/tests/protocols/3nstorage/owner/specs/put-current-obj.ts +366 -0
- package/ts-code/tests/protocols/3nstorage/owner/specs/put-current-root.ts +329 -0
- package/ts-code/tests/protocols/3nstorage/owner/specs/trans-cancel-root.ts +86 -0
- package/ts-code/tests/protocols/3nstorage/owner/specs/trans-cancel.ts +86 -0
- package/ts-code/tests/protocols/3nstorage/owner/test-utils.ts +72 -0
- package/ts-code/tests/protocols/3nstorage/owner.ts +198 -0
- package/ts-code/tests/protocols/asmail/config.ts +172 -0
- package/ts-code/tests/protocols/asmail/delivery/specs/finalize-delivery.ts +69 -0
- package/ts-code/tests/protocols/asmail/delivery/specs/provide-recipient-pubkey.ts +88 -0
- package/ts-code/tests/protocols/asmail/delivery/specs/put-metadata.ts +102 -0
- package/ts-code/tests/protocols/asmail/delivery/specs/put-obj.ts +156 -0
- package/ts-code/tests/protocols/asmail/delivery/specs/restart-session.ts +97 -0
- package/ts-code/tests/protocols/asmail/delivery/specs/start-session.ts +79 -0
- package/ts-code/tests/protocols/asmail/delivery/test-utils.ts +64 -0
- package/ts-code/tests/protocols/asmail/delivery.ts +56 -0
- package/ts-code/tests/protocols/asmail/retrieval/specs/events.ts +78 -0
- package/ts-code/tests/protocols/asmail/retrieval/specs/get-message-meta.ts +80 -0
- package/ts-code/tests/protocols/asmail/retrieval/specs/get-message-obj.ts +197 -0
- package/ts-code/tests/protocols/asmail/retrieval/specs/list-messages.ts +110 -0
- package/ts-code/tests/protocols/asmail/retrieval/specs/remove-message.ts +74 -0
- package/ts-code/tests/protocols/asmail/retrieval/test-utils.ts +60 -0
- package/ts-code/tests/protocols/asmail/retrieval.ts +115 -0
- package/ts-code/tests/protocols/mailerid.ts +271 -0
- package/ts-code/tests/shared-checks/check-mid-login.ts +164 -0
- package/ts-code/tests/shared-checks/requests.ts +135 -0
- package/ts-code/tsconfig.json +11 -0
- package/ts-code/web3n.d.ts +1068 -0
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright (C) 2015 - 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
|
+
/**
|
|
19
|
+
* This creates a public key login 'complete-login-exchange' route handler
|
|
20
|
+
* for POST method.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
import { RequestHandler, Response, NextFunction } from 'express';
|
|
24
|
+
import { compareVectors, arrays } from 'ecma-nacl';
|
|
25
|
+
import { Request } from './start-exchange';
|
|
26
|
+
import { complete as api, ERR_SC, ErrorReply } from '../../../lib-common/service-api/pub-key-login';
|
|
27
|
+
import { toBuffer } from '../../../lib-common/buffer-utils';
|
|
28
|
+
|
|
29
|
+
export function completePKLogin(): RequestHandler {
|
|
30
|
+
return (req: Request, res, next) => {
|
|
31
|
+
|
|
32
|
+
const session = req.session;
|
|
33
|
+
|
|
34
|
+
// bounce off already authorized session
|
|
35
|
+
if (session.isAuthorized) {
|
|
36
|
+
res.status(ERR_SC.duplicate).json( <ErrorReply> {
|
|
37
|
+
error: "Repeated call: this session has already been authorized."
|
|
38
|
+
});
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
try {
|
|
43
|
+
const c = new Uint8Array(req.body);
|
|
44
|
+
const decryptedKey = session.params.encryptor.open(c);
|
|
45
|
+
const key = session.params.sessionKey;
|
|
46
|
+
if (!compareVectors(decryptedKey, key)) { throw new Error(); }
|
|
47
|
+
session.isAuthorized = true;
|
|
48
|
+
res.status(api.SC.ok).send(
|
|
49
|
+
toBuffer(session.params.serverVerificationBytes));
|
|
50
|
+
} catch (err) {
|
|
51
|
+
session.close();
|
|
52
|
+
res.status(api.SC.authFailed).json( <ErrorReply> {
|
|
53
|
+
error: "Forbidden."
|
|
54
|
+
});
|
|
55
|
+
} finally {
|
|
56
|
+
arrays.wipe(session.params.sessionKey);
|
|
57
|
+
delete (session.params as any).sessionKey;
|
|
58
|
+
delete (session.params as any).serverVerificationBytes;
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
Object.freeze(exports);
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright (C) 2015 - 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
|
+
/**
|
|
19
|
+
* This creates a public key login 'start-login-exchange' route handler
|
|
20
|
+
* for POST method.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
import { RequestHandler } from 'express';
|
|
24
|
+
import { secret_box as sbox, arrays, nonce as nonceMod } from 'ecma-nacl';
|
|
25
|
+
import { base64 } from '../../../lib-common/buffer-utils';
|
|
26
|
+
import { bytes as randomBytes } from '../../../lib-common/random-node';
|
|
27
|
+
import { GenerateSession, Request as SessReq, Session, SessionParams as UserParams } from '../../resources/sessions';
|
|
28
|
+
import { SessionEncryptor, makeSessionEncryptor } from '../../../lib-common/session-encryptor';
|
|
29
|
+
import { start as api, ERR_SC, ErrorReply } from '../../../lib-common/service-api/pub-key-login';
|
|
30
|
+
import { checkAndTransformAddress } from '../../../lib-common/canonical-address';
|
|
31
|
+
|
|
32
|
+
const boxWN = sbox.formatWN;
|
|
33
|
+
const NONCE_LENGTH = sbox.NONCE_LENGTH;
|
|
34
|
+
const KEY_LENGTH = sbox.KEY_LENGTH;
|
|
35
|
+
const POLY_LENGTH = sbox.POLY_LENGTH;
|
|
36
|
+
|
|
37
|
+
export interface SessionParams extends UserParams {
|
|
38
|
+
encryptor: SessionEncryptor;
|
|
39
|
+
sessionKey: Uint8Array;
|
|
40
|
+
serverVerificationBytes: Uint8Array;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export type Request = SessReq<SessionParams>;
|
|
44
|
+
|
|
45
|
+
function addEncryptorToSession(
|
|
46
|
+
session: Session<SessionParams>, sessionKey: Uint8Array, nonce: Uint8Array
|
|
47
|
+
): void {
|
|
48
|
+
const encryptor = makeSessionEncryptor(sessionKey, nonce);
|
|
49
|
+
session.params.encryptor = encryptor;
|
|
50
|
+
session.addCleanUp(() => {
|
|
51
|
+
encryptor.destroy();
|
|
52
|
+
if (session.params.encryptor === encryptor) {
|
|
53
|
+
session.params.encryptor = (undefined as any);
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export interface UserPKeyAndKeyGenParams {
|
|
59
|
+
pkey: Uint8Array;
|
|
60
|
+
params?: any;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* This function checks overall shape of a given user id, possibly
|
|
65
|
+
* transforming it to some canonical form, used by the service.
|
|
66
|
+
* If incoming id is ok, function returns it in a canonical form.
|
|
67
|
+
* Else, if incoming id is not ok, undefined is returned.
|
|
68
|
+
* @params initUserId is a an incoming string, that should be an id
|
|
69
|
+
*/
|
|
70
|
+
export type CheckAndTransformUserId = (initUserId: string) => string|undefined;
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* This returns a promise of user public key and related parameters.
|
|
74
|
+
* If user is not found, undefined is returned.
|
|
75
|
+
* @param userId
|
|
76
|
+
* @param kid is a key id that should be used at login. Undefined value
|
|
77
|
+
* indicates that default key should be used.
|
|
78
|
+
*/
|
|
79
|
+
export type GetUserPKeyAndKeyGenParams = (
|
|
80
|
+
userId: string, kid: string|undefined
|
|
81
|
+
) => Promise<UserPKeyAndKeyGenParams|undefined>;
|
|
82
|
+
|
|
83
|
+
export type ComputeDHSharedKey = (userKey: Uint8Array) => {
|
|
84
|
+
dhsharedKey: Uint8Array; serverPubKey: Uint8Array;
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
export function startPKLogin(
|
|
88
|
+
findUserParamsAndKeyFunc: GetUserPKeyAndKeyGenParams,
|
|
89
|
+
sessionGenFunc: GenerateSession<SessionParams>,
|
|
90
|
+
computeDHSharedKeyFunc: ComputeDHSharedKey
|
|
91
|
+
): RequestHandler {
|
|
92
|
+
if ('function' !== typeof findUserParamsAndKeyFunc) { throw new TypeError(
|
|
93
|
+
"Given argument 'findUserParamsAndKeyFunc' must be function, but is not."); }
|
|
94
|
+
if ('function' !== typeof sessionGenFunc) { throw new TypeError(
|
|
95
|
+
"Given argument 'sessionGenFunc' must be function, but is not."); }
|
|
96
|
+
if ('function' !== typeof computeDHSharedKeyFunc) { throw new TypeError(
|
|
97
|
+
"Given argument 'computeDHSharedKeyFunc' must be function, but is not."); }
|
|
98
|
+
|
|
99
|
+
return async (req: Request, res, next) => {
|
|
100
|
+
|
|
101
|
+
const userId = checkAndTransformAddress((req.body as api.Request).userId);
|
|
102
|
+
const kid = (req.body as api.Request).kid;
|
|
103
|
+
let session = req.session;
|
|
104
|
+
|
|
105
|
+
// missing userId makes a bad request
|
|
106
|
+
if (!userId) {
|
|
107
|
+
res.status(ERR_SC.malformed).json( <ErrorReply> {
|
|
108
|
+
error: "User id is either malformed, or missing."
|
|
109
|
+
});
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
if ((kid !== undefined) && (typeof kid !== 'string')) {
|
|
114
|
+
res.status(ERR_SC.malformed).json( <ErrorReply> {
|
|
115
|
+
error: "Key id is invalid in the request."
|
|
116
|
+
});
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// bounce off existing session
|
|
121
|
+
if (session) {
|
|
122
|
+
res.status(ERR_SC.duplicate).json( <ErrorReply> {
|
|
123
|
+
error: `Repeated call: this session has already been authorized.`
|
|
124
|
+
});
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
try {
|
|
129
|
+
// find user info
|
|
130
|
+
const userParamsAndKey = await findUserParamsAndKeyFunc(userId, kid);
|
|
131
|
+
if (!userParamsAndKey) {
|
|
132
|
+
res.status(api.SC.unknownUser).json( <ErrorReply> {
|
|
133
|
+
error: `User ${userId} ${kid ? `and/or key ${kid} are` : 'is'} unknown.`
|
|
134
|
+
});
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// generate session, if it is not present
|
|
139
|
+
if (!session) {
|
|
140
|
+
session = await sessionGenFunc();
|
|
141
|
+
session.params.userId = userId;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// get random bytes for session key and nonce
|
|
145
|
+
const nonce = await randomBytes(NONCE_LENGTH);
|
|
146
|
+
const sessionKey = await randomBytes(KEY_LENGTH);
|
|
147
|
+
|
|
148
|
+
// compute DH-shared key for encrypting a challenge
|
|
149
|
+
const compRes = computeDHSharedKeyFunc(userParamsAndKey.pkey)
|
|
150
|
+
const dhsharedKey = compRes.dhsharedKey
|
|
151
|
+
const serverPubKey = compRes.serverPubKey
|
|
152
|
+
// make challenge with session key, removing and saving poly part
|
|
153
|
+
// for sending it later as a server verification at the end
|
|
154
|
+
const encryptedSessionKey = boxWN.pack(sessionKey, nonce, dhsharedKey)
|
|
155
|
+
const serverVerificationBytes = encryptedSessionKey.subarray(
|
|
156
|
+
NONCE_LENGTH, NONCE_LENGTH + POLY_LENGTH)
|
|
157
|
+
const challengeWithSessionKey = new Uint8Array(NONCE_LENGTH + KEY_LENGTH);
|
|
158
|
+
challengeWithSessionKey.set(
|
|
159
|
+
encryptedSessionKey.subarray(0, NONCE_LENGTH));
|
|
160
|
+
challengeWithSessionKey.set(
|
|
161
|
+
encryptedSessionKey.subarray(NONCE_LENGTH + POLY_LENGTH),
|
|
162
|
+
NONCE_LENGTH);
|
|
163
|
+
|
|
164
|
+
// wipe the DH-shared key
|
|
165
|
+
arrays.wipe(dhsharedKey);
|
|
166
|
+
|
|
167
|
+
// add to session a corresponding encryptor for login completion, and,
|
|
168
|
+
// may be for further use
|
|
169
|
+
nonceMod.advanceEvenly(nonce);
|
|
170
|
+
addEncryptorToSession(session, sessionKey, nonce);
|
|
171
|
+
session.params.sessionKey = sessionKey;
|
|
172
|
+
session.params.serverVerificationBytes = serverVerificationBytes;
|
|
173
|
+
|
|
174
|
+
// send out reply
|
|
175
|
+
res.status(api.SC.ok).json( <api.Reply> {
|
|
176
|
+
sessionId: session.id,
|
|
177
|
+
sessionKey: base64.pack(challengeWithSessionKey),
|
|
178
|
+
serverPubKey: base64.pack(serverPubKey),
|
|
179
|
+
keyDerivParams: userParamsAndKey.params
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
} catch (err) {
|
|
183
|
+
next(err);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
Object.freeze(exports);
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright (C) 2015 - 2016, 2026 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 { Request } from '../../resources/sessions';
|
|
20
|
+
|
|
21
|
+
export function closeSession(): RequestHandler {
|
|
22
|
+
return (req: Request<any>, res, next) => {
|
|
23
|
+
req.session.close();
|
|
24
|
+
res.status(200).send();
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
Object.freeze(exports);
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright (C) 2015 - 2016, 2026 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 { Request } from './start';
|
|
20
|
+
import { SignedLoad, isLikeSignedMailerIdAssertion, isLikeSignedKeyCert } from '../../../lib-common/jwkeys';
|
|
21
|
+
import { authSession as api, ERR_SC } from '../../../lib-common/service-api/mailer-id/login';
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* This function returns a promise, which resolves to true for
|
|
25
|
+
* authorization passing, and to false for failed authorization.
|
|
26
|
+
* Autherization failure may be due to either, invalid MailerId credentials, or
|
|
27
|
+
* due to other service's restriction(s) on users.
|
|
28
|
+
*/
|
|
29
|
+
export type MidAuthorizer = (
|
|
30
|
+
rpDomain: string, sessionId: string, userId: string,
|
|
31
|
+
mailerIdAssertion: SignedLoad, userCert: SignedLoad, provCert: SignedLoad
|
|
32
|
+
) => Promise<boolean>;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* @param relyingPartyDomain is a domain of service, for which this assertion
|
|
36
|
+
* check is done. Usually, it is this site's domain, which we set explicitly.
|
|
37
|
+
* @param midAuthorizingFunc
|
|
38
|
+
* This creates an authorize-sender route handler.
|
|
39
|
+
*/
|
|
40
|
+
export function midLogin(relyingPartyDomain: string, midAuthorizingFunc: MidAuthorizer): RequestHandler {
|
|
41
|
+
|
|
42
|
+
return async (req: Request, res, next) => {
|
|
43
|
+
|
|
44
|
+
if (req.session.isAuthorized) {
|
|
45
|
+
res.status(ERR_SC.duplicate).send("This protocol request has already been served.");
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const rb: api.Request = req.body;
|
|
50
|
+
const sessionId = req.session.id;
|
|
51
|
+
|
|
52
|
+
if (!isLikeSignedMailerIdAssertion(rb.assertion)
|
|
53
|
+
|| !isLikeSignedKeyCert(rb.userCert)
|
|
54
|
+
|| !isLikeSignedKeyCert(rb.provCert)) {
|
|
55
|
+
res.sendStatus(ERR_SC.malformed);
|
|
56
|
+
req.session.close();
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
try {
|
|
61
|
+
const certsVerified = await midAuthorizingFunc(
|
|
62
|
+
relyingPartyDomain, sessionId, req.session.params.userId, rb.assertion, rb.userCert, rb.provCert
|
|
63
|
+
);
|
|
64
|
+
if (certsVerified) {
|
|
65
|
+
req.session.isAuthorized = true;
|
|
66
|
+
res.status(api.SC.ok).send();
|
|
67
|
+
} else {
|
|
68
|
+
req.session.close();
|
|
69
|
+
res.status(api.SC.authFailed).send("Server is not accepting provided credentials.");
|
|
70
|
+
}
|
|
71
|
+
} catch (err) {
|
|
72
|
+
next(err);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
Object.freeze(exports);
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright (C) 2015 - 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 { RequestHandler, Response } from 'express';
|
|
19
|
+
import { GenerateSession, Request as SessionReq, SessionParams } from '../../resources/sessions';
|
|
20
|
+
import { startSession as api, ERR_SC, ErrorReply } from '../../../lib-common/service-api/mailer-id/login';
|
|
21
|
+
import { checkAndTransformAddress } from '../../../lib-common/canonical-address';
|
|
22
|
+
|
|
23
|
+
export type Request = SessionReq<SessionParams>;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* This function checks overall shape of a given user id, possibly
|
|
27
|
+
* transforming it to some canonical form, used by the service.
|
|
28
|
+
* If incoming id is ok, function returns it in a canonical form.
|
|
29
|
+
* Else, if incoming id is not ok, undefined is returned.
|
|
30
|
+
* @params initUserId is a an incoming string, that should be an id
|
|
31
|
+
*/
|
|
32
|
+
export type CheckAndTransformUserId = (initUserId: string) => string|undefined;
|
|
33
|
+
|
|
34
|
+
export type UserExists = (userId: string) => Promise<boolean>;
|
|
35
|
+
|
|
36
|
+
export type Redirect = (userId: string) => Promise<string>;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* This returns route handler that creates sessions for a given userId, with
|
|
40
|
+
* potential redirect for a named user.
|
|
41
|
+
* @param checkIdFunc
|
|
42
|
+
* @param allowUserFunc
|
|
43
|
+
* @param sessionGenFunc
|
|
44
|
+
* @param redirectFunc (optional)
|
|
45
|
+
*/
|
|
46
|
+
export function startSession(
|
|
47
|
+
userExistsFunc: UserExists, sessionGenFunc: GenerateSession<any>,
|
|
48
|
+
redirectFunc?: Redirect
|
|
49
|
+
): RequestHandler {
|
|
50
|
+
if ('function' !== typeof userExistsFunc) { throw new TypeError(
|
|
51
|
+
"Given argument 'userExistsFunc' must be function, but is not."); }
|
|
52
|
+
if ('function' !== typeof sessionGenFunc) { throw new TypeError(
|
|
53
|
+
"Given argument 'sessionGenFunc' must be function, but is not."); }
|
|
54
|
+
if (('undefined' !== typeof redirectFunc) &&
|
|
55
|
+
('function' !== typeof redirectFunc)) { throw new TypeError(
|
|
56
|
+
"Given argument 'redirectFunc' must either be function, " +
|
|
57
|
+
"or be undefined, but it is neither."); }
|
|
58
|
+
|
|
59
|
+
async function serveRequestHere(
|
|
60
|
+
userId: string, res: Response
|
|
61
|
+
): Promise<void> {
|
|
62
|
+
const userExists = await userExistsFunc(userId);
|
|
63
|
+
if (userExists) {
|
|
64
|
+
const session = await sessionGenFunc();
|
|
65
|
+
(<SessionParams> session.params).userId = userId;
|
|
66
|
+
res.status(api.SC.ok).json( <api.Reply> {
|
|
67
|
+
sessionId: session.id,
|
|
68
|
+
});
|
|
69
|
+
} else {
|
|
70
|
+
res.status(api.SC.unknownUser).json( <ErrorReply> {
|
|
71
|
+
error: `User ${userId} is unknown.`
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return async (req: Request, res, next) => {
|
|
77
|
+
|
|
78
|
+
const session = req.session;
|
|
79
|
+
const userId = checkAndTransformAddress((req.body as api.Request).userId);
|
|
80
|
+
|
|
81
|
+
if (!userId) {
|
|
82
|
+
res.status(ERR_SC.malformed).json( <ErrorReply> {
|
|
83
|
+
error: "User id is either malformed, or missing."
|
|
84
|
+
});
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// already existing session indicates repeated call, which
|
|
89
|
+
// should be bounced off
|
|
90
|
+
if (session) {
|
|
91
|
+
res.status(ERR_SC.duplicate).json( <ErrorReply> {
|
|
92
|
+
error: "This protocol request has already been served."
|
|
93
|
+
});
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
try {
|
|
98
|
+
if (redirectFunc) {
|
|
99
|
+
const redirectTo = await redirectFunc(userId);
|
|
100
|
+
if (redirectTo) {
|
|
101
|
+
res.status(api.SC.redirect).json( <api.RedirectReply> {
|
|
102
|
+
redirect: redirectTo
|
|
103
|
+
});
|
|
104
|
+
} else {
|
|
105
|
+
await serveRequestHere(userId, res);
|
|
106
|
+
}
|
|
107
|
+
} else {
|
|
108
|
+
await serveRequestHere(userId, res);
|
|
109
|
+
}
|
|
110
|
+
} catch (err) {
|
|
111
|
+
next(err);
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
Object.freeze(exports);
|