spec-3nweb-server 1.3.6 → 1.4.1
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/build/3nstorage/3nstorage-app.js +4 -4
- package/build/3nstorage/owner.js +21 -21
- package/build/3nstorage/resources/store.js +25 -24
- package/build/3nstorage/resources/users.js +2 -2
- package/build/3nstorage/routes/owner/archive-obj-version.d.ts +2 -2
- package/build/3nstorage/routes/owner/archive-obj-version.js +3 -2
- package/build/3nstorage/routes/owner/cancel-trans.js +1 -1
- package/build/3nstorage/routes/owner/delete-obj.js +1 -1
- package/build/3nstorage/routes/owner/get-archived-obj-ver.js +2 -2
- package/build/3nstorage/routes/owner/get-current-obj.js +2 -2
- package/build/3nstorage/routes/owner/list-obj-archive.js +3 -2
- package/build/3nstorage/routes/owner/param-getter.js +3 -2
- package/build/3nstorage/routes/owner/param-setter.js +3 -2
- package/build/3nstorage/routes/owner/put-current-obj.js +12 -10
- package/build/3nstorage/routes/owner/session-params.js +4 -3
- package/build/admin/admin-app.js +7 -5
- package/build/admin/resources/users.d.ts +10 -4
- package/build/admin/resources/users.js +90 -37
- package/build/admin/routes/add.js +3 -3
- package/build/admin/routes/get-available-domains.d.ts +3 -0
- package/build/admin/routes/get-available-domains.js +38 -0
- package/build/admin/signup-tokens.js +11 -11
- package/build/asmail/asmail-app.js +7 -7
- package/build/asmail/config.js +9 -8
- package/build/asmail/delivery.js +10 -9
- package/build/asmail/resources/delivery-sessions.js +4 -3
- package/build/asmail/resources/inbox.d.ts +1 -1
- package/build/asmail/resources/inbox.js +22 -22
- package/build/asmail/resources/recipients.d.ts +2 -1
- package/build/asmail/resources/recipients.js +4 -4
- package/build/asmail/resources/sessions.js +2 -1
- package/build/asmail/retrieval.js +13 -8
- package/build/asmail/routes/config/param-getter.js +3 -2
- package/build/asmail/routes/config/param-setter.js +3 -2
- package/build/asmail/routes/delivery/finalize-delivery.js +3 -2
- package/build/asmail/routes/delivery/pre-flight.js +5 -4
- package/build/asmail/routes/delivery/provide-recipient-pubkey.js +3 -2
- package/build/asmail/routes/delivery/put-metadata.js +3 -2
- package/build/asmail/routes/delivery/put-obj.js +4 -4
- package/build/asmail/routes/delivery/restart-session.js +4 -3
- package/build/asmail/routes/delivery/sender-authorization.d.ts +1 -3
- package/build/asmail/routes/delivery/sender-authorization.js +3 -2
- package/build/asmail/routes/delivery/start-session.js +5 -4
- package/build/asmail/routes/retrieval/get-message-meta.js +3 -2
- package/build/asmail/routes/retrieval/get-message-obj.js +4 -3
- package/build/asmail/routes/retrieval/list-messages.js +3 -2
- package/build/asmail/routes/retrieval/remove-message.js +3 -2
- package/build/lib-common/admin-api/signup.d.ts +9 -0
- package/build/lib-common/admin-api/signup.js +11 -2
- package/build/lib-common/async-fs-node.js +13 -13
- package/build/lib-common/byte-streaming/common.js +9 -9
- package/build/lib-common/canonical-address.js +1 -1
- package/build/lib-common/ipc/generic-ipc.js +12 -12
- package/build/lib-common/ipc/ws-ipc.js +2 -2
- package/build/lib-common/mid-sigs-NaCl-Ed.js +14 -14
- package/build/lib-common/objs-on-disk/file-layout.js +10 -10
- package/build/lib-common/objs-on-disk/obj-file.js +11 -11
- package/build/lib-common/objs-on-disk/utils.js +3 -3
- package/build/lib-common/processes.js +1 -1
- package/build/lib-common/random-node.js +7 -7
- package/build/lib-common/service-api/3nstorage/owner.d.ts +5 -4
- package/build/lib-common/service-api/3nstorage/owner.js +11 -10
- package/build/lib-common/service-api/asmail/delivery.js +2 -2
- package/build/lib-common/service-api/asmail/retrieval.js +1 -1
- package/build/lib-server/conf-util.js +2 -1
- package/build/lib-server/middleware/body-parsers.js +16 -16
- package/build/lib-server/middleware/error-handler.js +1 -1
- package/build/lib-server/resources/mailerid-authorizer.js +3 -3
- package/build/lib-server/resources/mem-backed-sessions-factory.js +3 -3
- package/build/lib-server/resources/server-data-folders.js +23 -23
- package/build/lib-server/resources/sessions.js +5 -5
- package/build/lib-server/resources/user-files.js +8 -8
- package/build/lib-server/routes/pub-key-login/complete-exchange.js +4 -3
- package/build/lib-server/routes/pub-key-login/start-exchange.js +7 -6
- package/build/lib-server/routes/sessions/mid-auth.js +6 -5
- package/build/lib-server/routes/sessions/start.js +4 -3
- package/build/lib-server/web-sockets/app.js +6 -5
- package/build/lib-server/web-sockets/server-events.js +5 -4
- package/build/mailerId/mailerId-app.js +7 -7
- package/build/mailerId/resources/certifier.d.ts +4 -6
- package/build/mailerId/resources/certifier.js +8 -7
- package/build/mailerId/resources/compute-login-dhshared-key.js +2 -1
- package/build/mailerId/resources/sessions.js +2 -1
- package/build/mailerId/resources/users.js +4 -4
- package/build/mailerId/routes/certify.js +1 -1
- package/build/main.js +10 -10
- package/build/mock/dns.js +1 -1
- package/build/mock/mock-as-child-proc.js +10 -10
- package/build/mock/node-child-ipc.js +2 -2
- package/build/mock/run-in-proc.js +7 -7
- package/build/run-config.js +10 -10
- package/build/run.js +4 -4
- package/build/services.js +5 -5
- package/package.json +9 -6
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/*
|
|
3
|
-
Copyright (C) 2015 - 2016, 2020 3NSoft Inc.
|
|
3
|
+
Copyright (C) 2015 - 2016, 2020 - 2021 3NSoft Inc.
|
|
4
4
|
|
|
5
5
|
This program is free software: you can redistribute it and/or modify it under
|
|
6
6
|
the terms of the GNU General Public License as published by the Free Software
|
|
@@ -84,26 +84,26 @@ async function writeJson(path, json) {
|
|
|
84
84
|
return fs.writeFile(path, JSON.stringify(json), { encoding: 'utf8', flag: 'w', mode: '660' });
|
|
85
85
|
}
|
|
86
86
|
function writeJsonSync(path, json) {
|
|
87
|
-
fs_1.writeFileSync(path, JSON.stringify(json), { encoding: 'utf8', flag: 'w', mode: '660' });
|
|
87
|
+
(0, fs_1.writeFileSync)(path, JSON.stringify(json), { encoding: 'utf8', flag: 'w', mode: '660' });
|
|
88
88
|
}
|
|
89
89
|
function setGeneralDefaults(defaults) {
|
|
90
90
|
const infoFolder = defaults.info.path;
|
|
91
|
-
writeJsonSync(path_1.join(infoFolder, 'quota'), 100 * 1024 * 1024 * 1024);
|
|
91
|
+
writeJsonSync((0, path_1.join)(infoFolder, 'quota'), 100 * 1024 * 1024 * 1024);
|
|
92
92
|
}
|
|
93
93
|
function setStoreDefaults(store) {
|
|
94
94
|
const sp = store.params.path;
|
|
95
|
-
writeJsonSync(path_1.join(sp, 'key-deriv'), null);
|
|
95
|
+
writeJsonSync((0, path_1.join)(sp, 'key-deriv'), null);
|
|
96
96
|
}
|
|
97
97
|
function setMailDefaults(mail) {
|
|
98
|
-
writeJsonSync(path_1.join(mail.params.path, 'pubkey'), null);
|
|
98
|
+
writeJsonSync((0, path_1.join)(mail.params.path, 'pubkey'), null);
|
|
99
99
|
const anonFolder = mail.params.anonymous.path;
|
|
100
100
|
const anonPolicy = {
|
|
101
101
|
accept: true,
|
|
102
102
|
acceptWithInvitesOnly: false,
|
|
103
103
|
defaultMsgSize: 1024 * 1024
|
|
104
104
|
};
|
|
105
|
-
writeJsonSync(path_1.join(anonFolder, 'policy'), anonPolicy);
|
|
106
|
-
writeJsonSync(path_1.join(anonFolder, 'invites'), {});
|
|
105
|
+
writeJsonSync((0, path_1.join)(anonFolder, 'policy'), anonPolicy);
|
|
106
|
+
writeJsonSync((0, path_1.join)(anonFolder, 'invites'), {});
|
|
107
107
|
const authFolder = mail.params.authenticated.path;
|
|
108
108
|
const authPolicy = {
|
|
109
109
|
acceptWithInvitesOnly: false,
|
|
@@ -111,10 +111,10 @@ function setMailDefaults(mail) {
|
|
|
111
111
|
applyBlackList: true,
|
|
112
112
|
defaultMsgSize: 1024 * 1024
|
|
113
113
|
};
|
|
114
|
-
writeJsonSync(path_1.join(authFolder, 'policy'), authPolicy);
|
|
115
|
-
writeJsonSync(path_1.join(authFolder, 'whitelist'), {});
|
|
116
|
-
writeJsonSync(path_1.join(authFolder, 'blacklist'), {});
|
|
117
|
-
writeJsonSync(path_1.join(authFolder, 'invites'), {});
|
|
114
|
+
writeJsonSync((0, path_1.join)(authFolder, 'policy'), authPolicy);
|
|
115
|
+
writeJsonSync((0, path_1.join)(authFolder, 'whitelist'), {});
|
|
116
|
+
writeJsonSync((0, path_1.join)(authFolder, 'blacklist'), {});
|
|
117
|
+
writeJsonSync((0, path_1.join)(authFolder, 'invites'), {});
|
|
118
118
|
}
|
|
119
119
|
class Users {
|
|
120
120
|
constructor(rootFolder, noTokenFile) {
|
|
@@ -122,25 +122,25 @@ class Users {
|
|
|
122
122
|
if (!fs.existsFolderSync(rootFolder)) {
|
|
123
123
|
throw new Error(`Given root folder does not exist: ${rootFolder}`);
|
|
124
124
|
}
|
|
125
|
-
const folders = server_data_folders_1.treeInRootFolder(rootFolder);
|
|
126
|
-
server_data_folders_1.createFolderTreeSync(folders);
|
|
125
|
+
const folders = (0, server_data_folders_1.treeInRootFolder)(rootFolder);
|
|
126
|
+
(0, server_data_folders_1.createFolderTreeSync)(folders);
|
|
127
127
|
this.users = folders.users.path;
|
|
128
128
|
this.defaults = folders.defaults.path;
|
|
129
129
|
this.tokens = folders.tokens.path;
|
|
130
130
|
this.populateDefaultsIfEmpty();
|
|
131
131
|
}
|
|
132
132
|
populateDefaultsIfEmpty() {
|
|
133
|
-
if (fs_1.readdirSync(this.defaults).length > 0) {
|
|
133
|
+
if ((0, fs_1.readdirSync)(this.defaults).length > 0) {
|
|
134
134
|
return;
|
|
135
135
|
}
|
|
136
|
-
const defaults = server_data_folders_1.treeInDefaultsFolder(this.defaults);
|
|
137
|
-
server_data_folders_1.createFolderTreeSync(defaults);
|
|
136
|
+
const defaults = (0, server_data_folders_1.treeInDefaultsFolder)(this.defaults);
|
|
137
|
+
(0, server_data_folders_1.createFolderTreeSync)(defaults);
|
|
138
138
|
setGeneralDefaults(defaults);
|
|
139
139
|
setMailDefaults(defaults.mail);
|
|
140
140
|
setStoreDefaults(defaults.store);
|
|
141
141
|
}
|
|
142
142
|
userFolderPath(userId) {
|
|
143
|
-
return path_1.join(this.users, server_data_folders_1.addressToFName(userId));
|
|
143
|
+
return (0, path_1.join)(this.users, (0, server_data_folders_1.addressToFName)(userId));
|
|
144
144
|
}
|
|
145
145
|
async add(userId, midParams, storeKeyDerivParams, signupToken) {
|
|
146
146
|
if (!validateUserMidParams(midParams)) {
|
|
@@ -161,16 +161,16 @@ class Users {
|
|
|
161
161
|
});
|
|
162
162
|
try {
|
|
163
163
|
// make folder tree
|
|
164
|
-
const tree = server_data_folders_1.treeInUserFolder(userFolder);
|
|
165
|
-
await server_data_folders_1.createFolderTree(tree);
|
|
164
|
+
const tree = (0, server_data_folders_1.treeInUserFolder)(userFolder);
|
|
165
|
+
await (0, server_data_folders_1.createFolderTree)(tree);
|
|
166
166
|
// record user id
|
|
167
|
-
await fs.writeFile(path_1.join(tree.info.path, 'userid'), userId, { encoding: 'utf8', flag: 'w', mode: '440' });
|
|
167
|
+
await fs.writeFile((0, path_1.join)(tree.info.path, 'userid'), userId, { encoding: 'utf8', flag: 'w', mode: '440' });
|
|
168
168
|
// copy defaults
|
|
169
169
|
await fs.copyTree(this.defaults, userFolder);
|
|
170
170
|
// record mid parameters
|
|
171
|
-
await writeJson(path_1.join(tree.info.path, 'mid-params'), midParams);
|
|
171
|
+
await writeJson((0, path_1.join)(tree.info.path, 'mid-params'), midParams);
|
|
172
172
|
// record storage params
|
|
173
|
-
await writeJson(path_1.join(tree.store.params.path, 'key-deriv'), storeKeyDerivParams);
|
|
173
|
+
await writeJson((0, path_1.join)(tree.store.params.path, 'key-deriv'), storeKeyDerivParams);
|
|
174
174
|
if (rmToken) {
|
|
175
175
|
await rmToken();
|
|
176
176
|
}
|
|
@@ -182,21 +182,21 @@ class Users {
|
|
|
182
182
|
}
|
|
183
183
|
async checkIfCreationAllowed(userId, signupToken) {
|
|
184
184
|
if (signupToken) {
|
|
185
|
-
const t = signup_tokens_1.parseToken(signupToken);
|
|
185
|
+
const t = (0, signup_tokens_1.parseToken)(signupToken);
|
|
186
186
|
if (!t) {
|
|
187
187
|
throw exports.SC.CREATION_UNAUTHORIZED;
|
|
188
188
|
}
|
|
189
|
-
const ctxFilePath = path_1.join(this.tokens, t.tokenFile);
|
|
189
|
+
const ctxFilePath = (0, path_1.join)(this.tokens, t.tokenFile);
|
|
190
190
|
const str = await fs.readFile(ctxFilePath, { encoding: 'utf8' })
|
|
191
191
|
.catch((exc) => {
|
|
192
192
|
throw (exc.notFound ? exports.SC.CREATION_UNAUTHORIZED : exc);
|
|
193
193
|
});
|
|
194
194
|
try {
|
|
195
195
|
const ctx = JSON.parse(str);
|
|
196
|
-
if (ctx.token && !signup_tokens_1.areTokensSame(t.tokenBytes, ctx.token)) {
|
|
196
|
+
if (ctx.token && !(0, signup_tokens_1.areTokensSame)(t.tokenBytes, ctx.token)) {
|
|
197
197
|
throw exports.SC.CREATION_UNAUTHORIZED;
|
|
198
198
|
}
|
|
199
|
-
if (signup_tokens_1.canCreateUser(userId, ctx)) {
|
|
199
|
+
if ((0, signup_tokens_1.canCreateUser)(userId, ctx)) {
|
|
200
200
|
if (ctx.type === 'single-user') {
|
|
201
201
|
return () => fs.unlink(ctxFilePath).catch(noop);
|
|
202
202
|
}
|
|
@@ -206,32 +206,84 @@ class Users {
|
|
|
206
206
|
}
|
|
207
207
|
}
|
|
208
208
|
catch (err) {
|
|
209
|
-
throw error_1.errWithCause(err, `Error occured in using file ${ctxFilePath} as a signup context.`);
|
|
209
|
+
throw (0, error_1.errWithCause)(err, `Error occured in using file ${ctxFilePath} as a signup context.`);
|
|
210
210
|
}
|
|
211
211
|
}
|
|
212
212
|
else if (this.noTokenFile) {
|
|
213
213
|
try {
|
|
214
214
|
const str = await fs.readFile(this.noTokenFile, { encoding: 'utf8' });
|
|
215
215
|
const ctx = JSON.parse(str);
|
|
216
|
-
if (signup_tokens_1.canCreateUser(userId, ctx)) {
|
|
216
|
+
if ((0, signup_tokens_1.canCreateUser)(userId, ctx)) {
|
|
217
217
|
return;
|
|
218
218
|
}
|
|
219
219
|
}
|
|
220
220
|
catch (exc) {
|
|
221
221
|
if (!exc.notFound) {
|
|
222
|
-
throw error_1.errWithCause(exc, `Error occured in using file ${this.noTokenFile} as a no-token signup context.`);
|
|
222
|
+
throw (0, error_1.errWithCause)(exc, `Error occured in using file ${this.noTokenFile} as a no-token signup context.`);
|
|
223
223
|
}
|
|
224
224
|
}
|
|
225
225
|
}
|
|
226
226
|
throw exports.SC.CREATION_UNAUTHORIZED;
|
|
227
227
|
}
|
|
228
|
+
async getAvailableDomains(signupToken) {
|
|
229
|
+
if (signupToken) {
|
|
230
|
+
const t = (0, signup_tokens_1.parseToken)(signupToken);
|
|
231
|
+
if (!t) {
|
|
232
|
+
return [];
|
|
233
|
+
}
|
|
234
|
+
const ctxFilePath = (0, path_1.join)(this.tokens, t.tokenFile);
|
|
235
|
+
const str = await fs.readFile(ctxFilePath, { encoding: 'utf8' })
|
|
236
|
+
.catch((exc) => {
|
|
237
|
+
if (exc.notFound) {
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
else {
|
|
241
|
+
throw exc;
|
|
242
|
+
}
|
|
243
|
+
});
|
|
244
|
+
if (!str) {
|
|
245
|
+
return [];
|
|
246
|
+
}
|
|
247
|
+
try {
|
|
248
|
+
const ctx = JSON.parse(str);
|
|
249
|
+
if ((ctx.type === 'single-user')
|
|
250
|
+
|| (ctx.token && !(0, signup_tokens_1.areTokensSame)(t.tokenBytes, ctx.token))) {
|
|
251
|
+
return [];
|
|
252
|
+
}
|
|
253
|
+
else {
|
|
254
|
+
return ctx.domains;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
catch (err) {
|
|
258
|
+
throw (0, error_1.errWithCause)(err, `Error occured in using file ${ctxFilePath} as a signup context.`);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
else if (this.noTokenFile) {
|
|
262
|
+
try {
|
|
263
|
+
const str = await fs.readFile(this.noTokenFile, { encoding: 'utf8' });
|
|
264
|
+
const ctx = JSON.parse(str);
|
|
265
|
+
return ctx.domains;
|
|
266
|
+
}
|
|
267
|
+
catch (exc) {
|
|
268
|
+
if (exc.notFound) {
|
|
269
|
+
return [];
|
|
270
|
+
}
|
|
271
|
+
else {
|
|
272
|
+
throw (0, error_1.errWithCause)(exc, `Error occured in using file ${this.noTokenFile} as a no-token signup context.`);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
else {
|
|
277
|
+
return [];
|
|
278
|
+
}
|
|
279
|
+
}
|
|
228
280
|
async getAvailableAddresses(name, signupToken) {
|
|
229
281
|
if (signupToken) {
|
|
230
|
-
const t = signup_tokens_1.parseToken(signupToken);
|
|
282
|
+
const t = (0, signup_tokens_1.parseToken)(signupToken);
|
|
231
283
|
if (!t) {
|
|
232
284
|
return [];
|
|
233
285
|
}
|
|
234
|
-
const ctxFilePath = path_1.join(this.tokens, t.tokenFile);
|
|
286
|
+
const ctxFilePath = (0, path_1.join)(this.tokens, t.tokenFile);
|
|
235
287
|
const str = await fs.readFile(ctxFilePath, { encoding: 'utf8' })
|
|
236
288
|
.catch((exc) => {
|
|
237
289
|
if (exc.notFound) {
|
|
@@ -246,13 +298,13 @@ class Users {
|
|
|
246
298
|
}
|
|
247
299
|
try {
|
|
248
300
|
const ctx = JSON.parse(str);
|
|
249
|
-
if (ctx.token && !signup_tokens_1.areTokensSame(t.tokenBytes, ctx.token)) {
|
|
301
|
+
if (ctx.token && !(0, signup_tokens_1.areTokensSame)(t.tokenBytes, ctx.token)) {
|
|
250
302
|
return [];
|
|
251
303
|
}
|
|
252
304
|
return this.availableAddressInCtx(name, ctx);
|
|
253
305
|
}
|
|
254
306
|
catch (err) {
|
|
255
|
-
throw error_1.errWithCause(err, `Error occured in using file ${ctxFilePath} as a signup context.`);
|
|
307
|
+
throw (0, error_1.errWithCause)(err, `Error occured in using file ${ctxFilePath} as a signup context.`);
|
|
256
308
|
}
|
|
257
309
|
}
|
|
258
310
|
else if (this.noTokenFile) {
|
|
@@ -266,7 +318,7 @@ class Users {
|
|
|
266
318
|
return [];
|
|
267
319
|
}
|
|
268
320
|
else {
|
|
269
|
-
throw error_1.errWithCause(exc, `Error occured in using file ${this.noTokenFile} as a no-token signup context.`);
|
|
321
|
+
throw (0, error_1.errWithCause)(exc, `Error occured in using file ${this.noTokenFile} as a no-token signup context.`);
|
|
270
322
|
}
|
|
271
323
|
}
|
|
272
324
|
}
|
|
@@ -275,7 +327,7 @@ class Users {
|
|
|
275
327
|
}
|
|
276
328
|
}
|
|
277
329
|
async availableAddressInCtx(name, ctx) {
|
|
278
|
-
const allIds = signup_tokens_1.addressesForName(name, ctx);
|
|
330
|
+
const allIds = (0, signup_tokens_1.addressesForName)(name, ctx);
|
|
279
331
|
if (!allIds) {
|
|
280
332
|
return [];
|
|
281
333
|
}
|
|
@@ -305,8 +357,9 @@ class Users {
|
|
|
305
357
|
}
|
|
306
358
|
wrap() {
|
|
307
359
|
const wrap = {
|
|
308
|
-
|
|
309
|
-
|
|
360
|
+
getAvailableDomains: (0, binding_1.bind)(this, this.getAvailableDomains),
|
|
361
|
+
getAvailableAddresses: (0, binding_1.bind)(this, this.getAvailableAddresses),
|
|
362
|
+
add: (0, binding_1.bind)(this, this.add),
|
|
310
363
|
};
|
|
311
364
|
Object.freeze(wrap);
|
|
312
365
|
return wrap;
|
|
@@ -24,15 +24,15 @@ function addUser(addUserFunc) {
|
|
|
24
24
|
return async function (req, res, next) {
|
|
25
25
|
const { mailerId, storage, userId, signupToken } = req.body;
|
|
26
26
|
if (('string' !== typeof userId)
|
|
27
|
-
|| !canonical_address_1.checkAndTransformAddress(userId)) {
|
|
27
|
+
|| !(0, canonical_address_1.checkAndTransformAddress)(userId)) {
|
|
28
28
|
res.status(signup_1.ERR_SC.malformed).send('Given user id is malformed.');
|
|
29
29
|
return;
|
|
30
30
|
}
|
|
31
|
-
if (!users_1.validateUserMidParams(mailerId)) {
|
|
31
|
+
if (!(0, users_1.validateUserMidParams)(mailerId)) {
|
|
32
32
|
res.status(signup_1.ERR_SC.malformed).send('MailerId parameters are malformed.');
|
|
33
33
|
return;
|
|
34
34
|
}
|
|
35
|
-
if (!users_1.validateUserStorageParams(storage)) {
|
|
35
|
+
if (!(0, users_1.validateUserStorageParams)(storage)) {
|
|
36
36
|
res.status(signup_1.ERR_SC.malformed).send('Storage parameters are malformed.');
|
|
37
37
|
return;
|
|
38
38
|
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
Copyright (C) 2021 3NSoft Inc.
|
|
4
|
+
|
|
5
|
+
This program is free software: you can redistribute it and/or modify it under
|
|
6
|
+
the terms of the GNU General Public License as published by the Free Software
|
|
7
|
+
Foundation, either version 3 of the License, or (at your option) any later
|
|
8
|
+
version.
|
|
9
|
+
|
|
10
|
+
This program is distributed in the hope that it will be useful, but
|
|
11
|
+
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
13
|
+
See the GNU General Public License for more details.
|
|
14
|
+
|
|
15
|
+
You should have received a copy of the GNU General Public License along with
|
|
16
|
+
this program. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
+
*/
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
exports.availableDomains = void 0;
|
|
20
|
+
const signup_1 = require("../../lib-common/admin-api/signup");
|
|
21
|
+
function availableDomains(availableDomainsFunc) {
|
|
22
|
+
return async function (req, res, next) {
|
|
23
|
+
const { signupToken } = req.body;
|
|
24
|
+
if ((signupToken !== undefined) && (typeof signupToken !== 'string')) {
|
|
25
|
+
res.status(signup_1.ERR_SC.malformed).send('signupToken is invalid.');
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
try {
|
|
29
|
+
const addresses = await availableDomainsFunc(signupToken);
|
|
30
|
+
res.status(signup_1.availableDomains.SC.ok).json(addresses);
|
|
31
|
+
}
|
|
32
|
+
catch (err) {
|
|
33
|
+
next(err);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
exports.availableDomains = availableDomains;
|
|
38
|
+
Object.freeze(exports);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/*
|
|
3
|
-
Copyright (C) 2020 3NSoft Inc.
|
|
3
|
+
Copyright (C) 2020 - 2021 3NSoft Inc.
|
|
4
4
|
|
|
5
5
|
This program is free software: you can redistribute it and/or modify it under
|
|
6
6
|
the terms of the GNU General Public License as published by the Free Software
|
|
@@ -31,12 +31,12 @@ function canCreateUser(userId, ctx) {
|
|
|
31
31
|
return false;
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
|
-
const cAddr = canonical_address_1.toCanonicalAddress(userId);
|
|
34
|
+
const cAddr = (0, canonical_address_1.toCanonicalAddress)(userId);
|
|
35
35
|
if (ctx.type === 'single-user') {
|
|
36
36
|
return (cAddr === ctx.userId);
|
|
37
37
|
}
|
|
38
38
|
else if (ctx.type === 'multi-domain') {
|
|
39
|
-
return !!ctx.domains.find(d => cAddr.endsWith(d));
|
|
39
|
+
return !!ctx.domains.find(d => cAddr.endsWith(`@${d}`));
|
|
40
40
|
}
|
|
41
41
|
else {
|
|
42
42
|
return false;
|
|
@@ -52,11 +52,11 @@ function addressesForName(name, ctx) {
|
|
|
52
52
|
}
|
|
53
53
|
if (ctx.type === 'single-user') {
|
|
54
54
|
const userId = `${name}${ctx.userId.substring(ctx.userId.indexOf('@'))}`;
|
|
55
|
-
return ((canonical_address_1.toCanonicalAddress(userId) === ctx.userId) ?
|
|
55
|
+
return (((0, canonical_address_1.toCanonicalAddress)(userId) === ctx.userId) ?
|
|
56
56
|
[userId] : []);
|
|
57
57
|
}
|
|
58
58
|
else if (ctx.type === 'multi-domain') {
|
|
59
|
-
return ctx.domains.map(d => `${name}
|
|
59
|
+
return ctx.domains.map(d => `${name}@${d}`);
|
|
60
60
|
}
|
|
61
61
|
else {
|
|
62
62
|
throw Error(`Unknown signup context type ${ctx.type}`);
|
|
@@ -67,7 +67,7 @@ function makeSingleUserSignupCtx(token, userId, validitySecs) {
|
|
|
67
67
|
const ctx = {
|
|
68
68
|
token,
|
|
69
69
|
type: 'single-user',
|
|
70
|
-
userId: canonical_address_1.toCanonicalAddress(userId)
|
|
70
|
+
userId: (0, canonical_address_1.toCanonicalAddress)(userId)
|
|
71
71
|
};
|
|
72
72
|
if (validitySecs) {
|
|
73
73
|
ctx.validTill = Math.floor(Date.now() / 1000) + validitySecs;
|
|
@@ -76,11 +76,11 @@ function makeSingleUserSignupCtx(token, userId, validitySecs) {
|
|
|
76
76
|
}
|
|
77
77
|
exports.makeSingleUserSignupCtx = makeSingleUserSignupCtx;
|
|
78
78
|
function makeMultiDomainSignupCtx(signupDomains, token, validitySecs) {
|
|
79
|
-
assert_1.assert(Array.isArray(signupDomains));
|
|
79
|
+
(0, assert_1.assert)(Array.isArray(signupDomains));
|
|
80
80
|
const ctx = {
|
|
81
81
|
token,
|
|
82
82
|
type: 'multi-domain',
|
|
83
|
-
domains: signupDomains.map(canonical_address_1.toCanonicalAddress)
|
|
83
|
+
domains: signupDomains.map(d => (0, canonical_address_1.toCanonicalAddress)(d).substring(1))
|
|
84
84
|
};
|
|
85
85
|
if (validitySecs) {
|
|
86
86
|
ctx.validTill = Math.floor(Date.now() / 1000) + validitySecs;
|
|
@@ -91,7 +91,7 @@ exports.makeMultiDomainSignupCtx = makeMultiDomainSignupCtx;
|
|
|
91
91
|
const TOKEN_BYTES_LEN = 30;
|
|
92
92
|
const TOKEN_FILE_NAME_LEN = 10;
|
|
93
93
|
async function generateToken() {
|
|
94
|
-
const tokenBytes = await random_node_1.bytes(TOKEN_BYTES_LEN);
|
|
94
|
+
const tokenBytes = await (0, random_node_1.bytes)(TOKEN_BYTES_LEN);
|
|
95
95
|
const token = buffer_utils_1.base64urlSafe.pack(tokenBytes);
|
|
96
96
|
return token;
|
|
97
97
|
}
|
|
@@ -111,13 +111,13 @@ function tokenFileName(token) {
|
|
|
111
111
|
return token.substring(0, TOKEN_FILE_NAME_LEN);
|
|
112
112
|
}
|
|
113
113
|
function tokenPath(rootFolder, token) {
|
|
114
|
-
return path_1.join(server_data_folders_1.tokensInRootFolder(rootFolder), tokenFileName(token));
|
|
114
|
+
return (0, path_1.join)((0, server_data_folders_1.tokensInRootFolder)(rootFolder), tokenFileName(token));
|
|
115
115
|
}
|
|
116
116
|
exports.tokenPath = tokenPath;
|
|
117
117
|
function areTokensSame(t1, t2) {
|
|
118
118
|
try {
|
|
119
119
|
const t2Bytes = buffer_utils_1.base64urlSafe.open(t2);
|
|
120
|
-
return ecma_nacl_1.compareVectors(t1, t2Bytes);
|
|
120
|
+
return (0, ecma_nacl_1.compareVectors)(t1, t2Bytes);
|
|
121
121
|
}
|
|
122
122
|
catch (err) {
|
|
123
123
|
return false;
|
|
@@ -49,14 +49,14 @@ function setupStaticEntryRoute(app) {
|
|
|
49
49
|
function makeApp(rootFolder, domain, midAuthorizer) {
|
|
50
50
|
const app = new app_1.AppWithWSs();
|
|
51
51
|
const mailDeliverySessions = delivery_sessions_1.DeliverySessions.make(5 * 60);
|
|
52
|
-
const recipientsSessions = sessions_1.makeSessionFactory(10 * 60);
|
|
53
|
-
const userSettingSessions = sessions_1.makeSessionFactory(10 * 60);
|
|
54
|
-
const recipients = recipients_1.makeFactory(rootFolder);
|
|
52
|
+
const recipientsSessions = (0, sessions_1.makeSessionFactory)(10 * 60);
|
|
53
|
+
const userSettingSessions = (0, sessions_1.makeSessionFactory)(10 * 60);
|
|
54
|
+
const recipients = (0, recipients_1.makeFactory)(rootFolder);
|
|
55
55
|
setupStaticEntryRoute(app.http);
|
|
56
|
-
app.http.use(PATHS.delivery, delivery_1.makeApp(domain, mailDeliverySessions, recipients, midAuthorizer));
|
|
57
|
-
app.use(PATHS.retrieval, retrieval_1.makeApp(domain, recipientsSessions, recipients, midAuthorizer));
|
|
58
|
-
app.http.use(PATHS.config, config_1.makeApp(domain, userSettingSessions, recipients, midAuthorizer));
|
|
59
|
-
app.http.use(error_handler_1.makeErrHandler((err, req) => {
|
|
56
|
+
app.http.use(PATHS.delivery, (0, delivery_1.makeApp)(domain, mailDeliverySessions, recipients, midAuthorizer));
|
|
57
|
+
app.use(PATHS.retrieval, (0, retrieval_1.makeApp)(domain, recipientsSessions, recipients, midAuthorizer));
|
|
58
|
+
app.http.use(PATHS.config, (0, config_1.makeApp)(domain, userSettingSessions, recipients, midAuthorizer));
|
|
59
|
+
app.http.use((0, error_handler_1.makeErrHandler)((err, req) => {
|
|
60
60
|
if (typeof err.status !== 'number') {
|
|
61
61
|
console.error(`\n --- Error occured in asmail, when handling ${req.method} request to ${req.originalUrl}`);
|
|
62
62
|
console.error(err);
|
package/build/asmail/config.js
CHANGED
|
@@ -13,7 +13,8 @@
|
|
|
13
13
|
See the GNU General Public License for more details.
|
|
14
14
|
|
|
15
15
|
You should have received a copy of the GNU General Public License along with
|
|
16
|
-
this program. If not, see <http://www.gnu.org/licenses/>.
|
|
16
|
+
this program. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
+
*/
|
|
17
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
19
|
exports.makeApp = void 0;
|
|
19
20
|
/**
|
|
@@ -33,17 +34,17 @@ const api = require("../lib-common/service-api/asmail/config");
|
|
|
33
34
|
function makeApp(domain, sessions, recipients, midAuthorizer) {
|
|
34
35
|
const app = express();
|
|
35
36
|
app.disable('etag');
|
|
36
|
-
app.post('/' + api.midLogin.START_URL_END, sessions.checkSession(), body_parsers_1.json('1kb'), start_1.startSession(recipients.exists, sessions.generate));
|
|
37
|
-
app.post('/' + api.midLogin.AUTH_URL_END, sessions.ensureOpenedSession(), body_parsers_1.json('4kb'), mid_auth_1.midLogin(domain, midAuthorizer));
|
|
37
|
+
app.post('/' + api.midLogin.START_URL_END, sessions.checkSession(), (0, body_parsers_1.json)('1kb'), (0, start_1.startSession)(recipients.exists, sessions.generate));
|
|
38
|
+
app.post('/' + api.midLogin.AUTH_URL_END, sessions.ensureOpenedSession(), (0, body_parsers_1.json)('4kb'), (0, mid_auth_1.midLogin)(domain, midAuthorizer));
|
|
38
39
|
// *** Require authorized session for everything below ***
|
|
39
40
|
app.use(sessions.ensureAuthorizedSession());
|
|
40
|
-
app.post('/' + api.closeSession.URL_END, body_parsers_1.emptyBody(), close_1.closeSession());
|
|
41
|
+
app.post('/' + api.closeSession.URL_END, (0, body_parsers_1.emptyBody)(), (0, close_1.closeSession)());
|
|
41
42
|
app.route('/' + api.p.initPubKey.URL_END)
|
|
42
|
-
.get(param_getter_1.getParam(recipients.getPubKey))
|
|
43
|
-
.put(body_parsers_1.json('4kb', true), param_setter_1.setParam(recipients.setPubKey));
|
|
43
|
+
.get((0, param_getter_1.getParam)(recipients.getPubKey))
|
|
44
|
+
.put((0, body_parsers_1.json)('4kb', true), (0, param_setter_1.setParam)(recipients.setPubKey));
|
|
44
45
|
app.route('/' + api.p.anonSenderInvites.URL_END)
|
|
45
|
-
.get(param_getter_1.getParam(recipients.getAnonSenderInvites))
|
|
46
|
-
.put(body_parsers_1.json('4kb', true), param_setter_1.setParam(recipients.setAnonSenderInvites));
|
|
46
|
+
.get((0, param_getter_1.getParam)(recipients.getAnonSenderInvites))
|
|
47
|
+
.put((0, body_parsers_1.json)('4kb', true), (0, param_setter_1.setParam)(recipients.setAnonSenderInvites));
|
|
47
48
|
return app;
|
|
48
49
|
}
|
|
49
50
|
exports.makeApp = makeApp;
|
package/build/asmail/delivery.js
CHANGED
|
@@ -13,7 +13,8 @@
|
|
|
13
13
|
See the GNU General Public License for more details.
|
|
14
14
|
|
|
15
15
|
You should have received a copy of the GNU General Public License along with
|
|
16
|
-
this program. If not, see <http://www.gnu.org/licenses/>.
|
|
16
|
+
this program. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
+
*/
|
|
17
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
19
|
exports.makeApp = void 0;
|
|
19
20
|
/**
|
|
@@ -37,16 +38,16 @@ const MAX_CHUNK_SIZE = '0.5mb';
|
|
|
37
38
|
function makeApp(domain, sessions, recipients, midAuthorizer) {
|
|
38
39
|
const app = express();
|
|
39
40
|
app.disable('etag');
|
|
40
|
-
app.post('/' + api.sessionStart.URL_END, sessions.checkSession(), body_parsers_1.json('1kb'), start_session_1.startSession(recipients.allowedMaxMsgSize, sessions.generate));
|
|
41
|
-
app.post('/' + api.preFlight.URL_END, sessions.checkSession(), body_parsers_1.json('1kb'), pre_flight_1.preFlight(recipients.allowedMaxMsgSize));
|
|
42
|
-
app.post('/' + api.sessionRestart.URL_END, sessions.checkSession(), body_parsers_1.json('1kb'), restart_session_1.restartSession(sessions.generate, sessions.getSessionForMsg, recipients.incompleteMsgDeliveryParams, MAX_CHUNK_SIZE));
|
|
43
|
-
app.post('/' + api.authSender.URL_END, sessions.ensureOpenedSession(), body_parsers_1.json('4kb'), sender_authorization_1.authorize(domain, midAuthorizer));
|
|
41
|
+
app.post('/' + api.sessionStart.URL_END, sessions.checkSession(), (0, body_parsers_1.json)('1kb'), (0, start_session_1.startSession)(recipients.allowedMaxMsgSize, sessions.generate));
|
|
42
|
+
app.post('/' + api.preFlight.URL_END, sessions.checkSession(), (0, body_parsers_1.json)('1kb'), (0, pre_flight_1.preFlight)(recipients.allowedMaxMsgSize));
|
|
43
|
+
app.post('/' + api.sessionRestart.URL_END, sessions.checkSession(), (0, body_parsers_1.json)('1kb'), (0, restart_session_1.restartSession)(sessions.generate, sessions.getSessionForMsg, recipients.incompleteMsgDeliveryParams, MAX_CHUNK_SIZE));
|
|
44
|
+
app.post('/' + api.authSender.URL_END, sessions.ensureOpenedSession(), (0, body_parsers_1.json)('4kb'), (0, sender_authorization_1.authorize)(domain, midAuthorizer));
|
|
44
45
|
// *** Require authorized session for everything below ***
|
|
45
46
|
app.use(sessions.ensureAuthorizedSession());
|
|
46
|
-
app.get('/' + api.initPubKey.URL_END, provide_recipient_pubkey_1.getRecipientPubKey(recipients.getPubKey));
|
|
47
|
-
app.put('/' + api.msgMeta.URL_END, body_parsers_1.json('16kb'), put_metadata_1.saveMetadata(recipients.setMsgStorage, MAX_CHUNK_SIZE));
|
|
48
|
-
app.put('/' + api.msgObj.EXPRESS_URL_END, put_obj_1.saveMsgObj(recipients.saveObj, MAX_CHUNK_SIZE));
|
|
49
|
-
app.post('/' + api.completion.URL_END, body_parsers_1.emptyBody(), finalize_delivery_1.finalizeDelivery(recipients.finalizeDelivery));
|
|
47
|
+
app.get('/' + api.initPubKey.URL_END, (0, provide_recipient_pubkey_1.getRecipientPubKey)(recipients.getPubKey));
|
|
48
|
+
app.put('/' + api.msgMeta.URL_END, (0, body_parsers_1.json)('16kb'), (0, put_metadata_1.saveMetadata)(recipients.setMsgStorage, MAX_CHUNK_SIZE));
|
|
49
|
+
app.put('/' + api.msgObj.EXPRESS_URL_END, (0, put_obj_1.saveMsgObj)(recipients.saveObj, MAX_CHUNK_SIZE));
|
|
50
|
+
app.post('/' + api.completion.URL_END, (0, body_parsers_1.emptyBody)(), (0, finalize_delivery_1.finalizeDelivery)(recipients.finalizeDelivery));
|
|
50
51
|
return app;
|
|
51
52
|
}
|
|
52
53
|
exports.makeApp = makeApp;
|
|
@@ -13,7 +13,8 @@
|
|
|
13
13
|
See the GNU General Public License for more details.
|
|
14
14
|
|
|
15
15
|
You should have received a copy of the GNU General Public License along with
|
|
16
|
-
this program. If not, see <http://www.gnu.org/licenses/>.
|
|
16
|
+
this program. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
+
*/
|
|
17
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
19
|
exports.DeliverySessions = void 0;
|
|
19
20
|
/**
|
|
@@ -82,8 +83,8 @@ class DeliverySessions extends mem_backed_sessions_factory_1.InMemorySessions {
|
|
|
82
83
|
*/
|
|
83
84
|
static make(timeout) {
|
|
84
85
|
const factory = new DeliverySessions(timeout);
|
|
85
|
-
const wrap = sessions_1.wrapFactory(factory);
|
|
86
|
-
wrap.getSessionForMsg = binding_1.bind(factory, factory.getSessionForMsg);
|
|
86
|
+
const wrap = (0, sessions_1.wrapFactory)(factory);
|
|
87
|
+
wrap.getSessionForMsg = (0, binding_1.bind)(factory, factory.getSessionForMsg);
|
|
87
88
|
return Object.freeze(wrap);
|
|
88
89
|
}
|
|
89
90
|
}
|
|
@@ -53,7 +53,7 @@ export declare class Inbox extends UserFiles {
|
|
|
53
53
|
* @param completeMsg flag, true for complete messages, and false for
|
|
54
54
|
* incomplete (in-delivery) messages.
|
|
55
55
|
*/
|
|
56
|
-
getMsgMeta(msgId: string, completeMsg:
|
|
56
|
+
getMsgMeta(msgId: string, completeMsg: boolean): Promise<MsgMeta>;
|
|
57
57
|
startSavingObj(msgId: string, objId: string, bytes: Readable, bytesLen: number, opts: deliveryApi.PutObjFirstQueryOpts): Promise<void>;
|
|
58
58
|
continueSavingObj(msgId: string, objId: string, bytes: Readable, bytesLen: number, opts: deliveryApi.PutObjSecondQueryOpts): Promise<void>;
|
|
59
59
|
/**
|