core-3nweb-client-lib 0.41.7 → 0.41.10
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/api-defs/keys.d.ts +1 -1
- package/build/api-defs/mailerid.d.ts +1 -1
- package/build/core/index.js +1 -1
- package/build/core/keyring/index.d.ts +3 -1
- package/build/core/keyring/index.js +33 -15
- package/build/lib-client/cryptor/worker-js.js +0 -10
- package/build/lib-client/mailer-id/provisioner.js +15 -7
- package/build/lib-client/service-locator.d.ts +7 -15
- package/build/lib-client/service-locator.js +6 -6
- package/build/lib-common/buffer-utils.d.ts +1 -1
- package/build/lib-common/objs-on-disk/v1-obj-file-format.d.ts +1 -1
- package/build/lib-common/service-api/3nstorage/root-route.d.ts +5 -0
- package/build/lib-common/service-api/3nstorage/root-route.js +18 -0
- package/build/lib-common/service-api/asmail/root-route.d.ts +5 -0
- package/build/lib-common/service-api/asmail/root-route.js +18 -0
- package/build/lib-common/service-api/mailer-id/root-route.d.ts +7 -0
- package/build/lib-common/service-api/mailer-id/root-route.js +18 -0
- package/build/protos/asmail.proto.js +387 -129
- package/build/protos/bytes.proto.js +54 -18
- package/build/protos/common.proto.js +27 -9
- package/build/protos/cryptor.proto.js +21 -7
- package/build/protos/file.proto.js +144 -48
- package/build/protos/fs.proto.js +321 -107
- package/build/protos/ipc.proto.js +33 -11
- package/build/protos/json-ipc.proto.js +39 -13
- package/build/protos/storage.proto.js +39 -13
- package/package.json +2 -2
package/build/api-defs/keys.d.ts
CHANGED
package/build/core/index.js
CHANGED
|
@@ -42,7 +42,7 @@ class Core {
|
|
|
42
42
|
this.isInitialized = false;
|
|
43
43
|
this.cryptor = makeCryptor(this.logger.logError, this.logger.logWarning);
|
|
44
44
|
this.storages = new storage_1.Storages(this.cryptor.cryptor.sbox, this.appDirs.storagePathFor);
|
|
45
|
-
this.keyrings = new keyring_1.Keyrings(this.cryptor.cryptor.sbox);
|
|
45
|
+
this.keyrings = new keyring_1.Keyrings(this.cryptor.cryptor.sbox, this.logger);
|
|
46
46
|
this.asmail = new asmail_1.ASMail(this.cryptor.cryptor.sbox, this.makeNet, this.appDirs.inboxPathFor, this.logger);
|
|
47
47
|
Object.seal(this);
|
|
48
48
|
}
|
|
@@ -5,6 +5,7 @@ import { ResourcesForSending } from '../asmail/delivery/common';
|
|
|
5
5
|
import { ResourcesForReceiving } from '../asmail/inbox';
|
|
6
6
|
import { GetSigner } from '../id-manager';
|
|
7
7
|
import { ParamOnServer } from '../../lib-client/asmail/service-config';
|
|
8
|
+
import { Logger } from '../../lib-client/logging/log-to-file';
|
|
8
9
|
export { KEY_USE, MsgKeyRole } from './common';
|
|
9
10
|
export interface MsgKeyInfo {
|
|
10
11
|
correspondent: string;
|
|
@@ -37,6 +38,7 @@ export interface KeyPairsStorage {
|
|
|
37
38
|
}
|
|
38
39
|
export declare class Keyrings {
|
|
39
40
|
private readonly cryptor;
|
|
41
|
+
private readonly logger;
|
|
40
42
|
/**
|
|
41
43
|
* This is a map from correspondents' canonical addresses to key objects.
|
|
42
44
|
*/
|
|
@@ -45,7 +47,7 @@ export declare class Keyrings {
|
|
|
45
47
|
private readonly workLabel;
|
|
46
48
|
private storage;
|
|
47
49
|
private publishedKeys;
|
|
48
|
-
constructor(cryptor: AsyncSBoxCryptor);
|
|
50
|
+
constructor(cryptor: AsyncSBoxCryptor, logger: Logger);
|
|
49
51
|
private readonly asKeyPairsStorage;
|
|
50
52
|
private addCorrespondent;
|
|
51
53
|
init(fs: WritableFS, getSigner: GetSigner, pkeyOnServer: ParamOnServer<'init-pub-key'>): Promise<void>;
|
|
@@ -34,8 +34,9 @@ Object.defineProperty(exports, "KEY_USE", { enumerable: true, get: function () {
|
|
|
34
34
|
const FILE_FOR_INTRO_KEY_ON_SERVER = 'introductory-keys/published-on-server.json';
|
|
35
35
|
// XXX Keyring is just a storage and crypto functionality around keys
|
|
36
36
|
class Keyrings {
|
|
37
|
-
constructor(cryptor) {
|
|
37
|
+
constructor(cryptor, logger) {
|
|
38
38
|
this.cryptor = cryptor;
|
|
39
|
+
this.logger = logger;
|
|
39
40
|
/**
|
|
40
41
|
* This is a map from correspondents' canonical addresses to key objects.
|
|
41
42
|
*/
|
|
@@ -245,20 +246,32 @@ class Keyrings {
|
|
|
245
246
|
}
|
|
246
247
|
absorbSuggestedNextKeyPair(correspondent, pair) {
|
|
247
248
|
let ck = this.corrKeys.get(correspondent);
|
|
248
|
-
if (ck) {
|
|
249
|
-
ck.
|
|
249
|
+
if (!ck) {
|
|
250
|
+
ck = this.addCorrespondent(correspondent);
|
|
250
251
|
}
|
|
251
|
-
|
|
252
|
-
if (!pair.isSenderIntroKey) {
|
|
253
|
-
throw new Error(`Expected addition of correspondent to be done, when new `);
|
|
254
|
-
}
|
|
252
|
+
if (pair.isSenderIntroKey) {
|
|
255
253
|
const usedIntro = this.publishedKeys.find(pair.senderKid);
|
|
256
254
|
if (!usedIntro) {
|
|
257
255
|
throw new Error(`Recently used published intro key is not found`);
|
|
258
256
|
}
|
|
259
|
-
ck = this.addCorrespondent(correspondent);
|
|
260
257
|
ck.ratchetUpSendingPair(pair, usedIntro.pair);
|
|
261
258
|
}
|
|
259
|
+
else {
|
|
260
|
+
ck.ratchetUpSendingPair(pair);
|
|
261
|
+
}
|
|
262
|
+
// if (ck) {
|
|
263
|
+
// ck.ratchetUpSendingPair(pair);
|
|
264
|
+
// } else {
|
|
265
|
+
// if (!pair.isSenderIntroKey) {
|
|
266
|
+
// throw new Error(`Expected addition of correspondent to be done, when new `);
|
|
267
|
+
// }
|
|
268
|
+
// const usedIntro = this.publishedKeys.find(pair.senderKid);
|
|
269
|
+
// if (!usedIntro) {
|
|
270
|
+
// throw new Error(`Recently used published intro key is not found`);
|
|
271
|
+
// }
|
|
272
|
+
// ck = this.addCorrespondent(correspondent);
|
|
273
|
+
// ck.ratchetUpSendingPair(pair, usedIntro.pair);
|
|
274
|
+
// }
|
|
262
275
|
this.saveChanges();
|
|
263
276
|
}
|
|
264
277
|
async decrypt(msgMeta, getMainObjHeader, getOpenedMsg, checkMidKeyCerts) {
|
|
@@ -299,15 +312,20 @@ class Keyrings {
|
|
|
299
312
|
// absorb next crypto
|
|
300
313
|
const pair = openedMsg.nextCrypto;
|
|
301
314
|
if (pair) {
|
|
302
|
-
|
|
303
|
-
if (
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
315
|
+
try {
|
|
316
|
+
if (msgMeta.recipientKid) {
|
|
317
|
+
if (!pair.isSenderIntroKey) {
|
|
318
|
+
throw new Error(`Introductory message is not referencing used intro key in the next crypto`);
|
|
319
|
+
}
|
|
320
|
+
if (msgMeta.recipientKid !== pair.senderKid) {
|
|
321
|
+
throw new Error(`Introductory message is referencing wrong key in the next crypto`);
|
|
322
|
+
}
|
|
308
323
|
}
|
|
324
|
+
this.absorbSuggestedNextKeyPair(decrInfo.correspondent, pair);
|
|
325
|
+
}
|
|
326
|
+
catch (err) {
|
|
327
|
+
this.logger.logError(err, `Fail to absorb next suggested key for messaging`);
|
|
309
328
|
}
|
|
310
|
-
this.absorbSuggestedNextKeyPair(decrInfo.correspondent, pair);
|
|
311
329
|
}
|
|
312
330
|
return { decrInfo, openedMsg };
|
|
313
331
|
}
|
|
@@ -19,16 +19,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
19
19
|
const worker_threads_1 = require("worker_threads");
|
|
20
20
|
const ecma_nacl_1 = require("ecma-nacl");
|
|
21
21
|
const error_1 = require("../../lib-common/exceptions/error");
|
|
22
|
-
function transfer(...arrs) {
|
|
23
|
-
const transferLst = [];
|
|
24
|
-
for (const arr of arrs) {
|
|
25
|
-
const buffer = arr.buffer;
|
|
26
|
-
if (!transferLst.includes(buffer)) {
|
|
27
|
-
transferLst.push(buffer);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
return transferLst;
|
|
31
|
-
}
|
|
32
22
|
if (!worker_threads_1.parentPort) {
|
|
33
23
|
throw new Error(`Missing expected parentPort. Is this called within WebWorker process?`);
|
|
34
24
|
}
|
|
@@ -58,10 +58,10 @@ class MailerIdProvisioner extends user_with_pkl_session_1.ServiceUser {
|
|
|
58
58
|
Object.seal(this);
|
|
59
59
|
}
|
|
60
60
|
async setUrlAndDomain() {
|
|
61
|
-
const
|
|
61
|
+
const { currentCert, provisioning } = await (0, service_locator_1.mailerIdInfoAt)(this.net, this.entryURI);
|
|
62
62
|
this.midDomain = (0, url_1.parse)(this.serviceURI).hostname;
|
|
63
|
-
this.serviceURI =
|
|
64
|
-
this.rootCert =
|
|
63
|
+
this.serviceURI = provisioning;
|
|
64
|
+
this.rootCert = currentCert;
|
|
65
65
|
}
|
|
66
66
|
/**
|
|
67
67
|
* @param pkey is a public key, that needs to be certified.
|
|
@@ -73,10 +73,7 @@ class MailerIdProvisioner extends user_with_pkl_session_1.ServiceUser {
|
|
|
73
73
|
*/
|
|
74
74
|
async getCertificates(pkey, duration) {
|
|
75
75
|
(0, assert_1.assert)(!!this.encryptor);
|
|
76
|
-
const plainReqData = {
|
|
77
|
-
pkey: pkey,
|
|
78
|
-
duration: duration
|
|
79
|
-
};
|
|
76
|
+
const plainReqData = { pkey, duration };
|
|
80
77
|
const rep = await this.net.doBinaryRequest({
|
|
81
78
|
url: this.serviceURI + api.certify.URL_END,
|
|
82
79
|
method: api.certify.method,
|
|
@@ -95,6 +92,17 @@ class MailerIdProvisioner extends user_with_pkl_session_1.ServiceUser {
|
|
|
95
92
|
if (!certs.userCert || !certs.provCert) {
|
|
96
93
|
throw (0, request_utils_1.makeException)(rep, 'Malformed reply: Certificates are missing.');
|
|
97
94
|
}
|
|
95
|
+
if (certs.provCert.kid !== this.rootCert.kid) {
|
|
96
|
+
const { currentCert, previousCerts } = await (0, service_locator_1.mailerIdInfoAt)(this.net, this.entryURI);
|
|
97
|
+
const rootCert = ((currentCert.kid === certs.provCert.kid) ?
|
|
98
|
+
currentCert : previousCerts.find(cert => (cert.kid === certs.provCert.kid)));
|
|
99
|
+
if (rootCert) {
|
|
100
|
+
this.rootCert = rootCert;
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
throw (0, request_utils_1.makeException)(rep, 'Malformed reply: referenced root MailerId certificate id is unknown.');
|
|
104
|
+
}
|
|
105
|
+
}
|
|
98
106
|
const pkeyAndId = (0, relying_party_1.verifyChainAndGetUserKey)({ user: certs.userCert, prov: certs.provCert, root: this.rootCert }, this.midDomain, (0, jwkeys_1.getKeyCert)(certs.userCert).issuedAt + 1);
|
|
99
107
|
if (pkeyAndId.address !== (0, canonical_address_1.toCanonicalAddress)(this.userId)) {
|
|
100
108
|
throw (0, request_utils_1.makeException)(rep, 'Malformed reply: Certificate is for a wrong address.');
|
|
@@ -1,39 +1,31 @@
|
|
|
1
1
|
import { NetClient } from './request-utils';
|
|
2
2
|
import { promises as dnsPromises } from 'dns';
|
|
3
|
+
import { StorageRootRoute } from '../lib-common/service-api/3nstorage/root-route';
|
|
4
|
+
import { ASMailRootRoute } from '../lib-common/service-api/asmail/root-route';
|
|
3
5
|
type SignedLoad = web3n.keys.SignedLoad;
|
|
4
|
-
export interface ASMailRoutes {
|
|
5
|
-
delivery?: string;
|
|
6
|
-
retrieval?: string;
|
|
7
|
-
config?: string;
|
|
8
|
-
}
|
|
9
6
|
/**
|
|
10
|
-
* This returns a promise, resolvable to
|
|
7
|
+
* This returns a promise, resolvable to ASMailRootRoute object.
|
|
11
8
|
* @param client
|
|
12
9
|
* @param url
|
|
13
10
|
*/
|
|
14
|
-
export declare function asmailInfoAt(client: NetClient, url: string): Promise<
|
|
11
|
+
export declare function asmailInfoAt(client: NetClient, url: string): Promise<ASMailRootRoute>;
|
|
15
12
|
export interface MailerIdServiceInfo {
|
|
16
13
|
provisioning: string;
|
|
17
14
|
currentCert: SignedLoad;
|
|
18
15
|
previousCerts: SignedLoad[];
|
|
19
16
|
}
|
|
20
17
|
/**
|
|
21
|
-
* This returns a promise, resolvable to
|
|
18
|
+
* This returns a promise, resolvable to MailerIdRootRoute object.
|
|
22
19
|
* @param client
|
|
23
20
|
* @param url
|
|
24
21
|
*/
|
|
25
22
|
export declare function mailerIdInfoAt(client: NetClient, url: string): Promise<MailerIdServiceInfo>;
|
|
26
|
-
export interface StorageRoutes {
|
|
27
|
-
owner?: string;
|
|
28
|
-
shared?: string;
|
|
29
|
-
config?: string;
|
|
30
|
-
}
|
|
31
23
|
/**
|
|
32
|
-
* This returns a promise, resolvable to
|
|
24
|
+
* This returns a promise, resolvable to StorageRootRoute object.
|
|
33
25
|
* @param client
|
|
34
26
|
* @param url
|
|
35
27
|
*/
|
|
36
|
-
export declare function storageInfoAt(client: NetClient, url: string): Promise<
|
|
28
|
+
export declare function storageInfoAt(client: NetClient, url: string): Promise<StorageRootRoute>;
|
|
37
29
|
export type ServiceTypeDNSLabel = 'mailerid' | 'asmail' | '3nstorage';
|
|
38
30
|
export type ServiceLocatorMaker = (serviceLabel: ServiceTypeDNSLabel) => ServiceLocator;
|
|
39
31
|
export type ServiceLocator = (address: string) => Promise<string>;
|
|
@@ -59,7 +59,7 @@ function transformPathToCompleteUri(url, path, rep) {
|
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
61
|
/**
|
|
62
|
-
* This returns a promise, resolvable to
|
|
62
|
+
* This returns a promise, resolvable to ASMailRootRoute object.
|
|
63
63
|
* @param client
|
|
64
64
|
* @param url
|
|
65
65
|
*/
|
|
@@ -80,7 +80,7 @@ async function asmailInfoAt(client, url) {
|
|
|
80
80
|
return transform;
|
|
81
81
|
}
|
|
82
82
|
/**
|
|
83
|
-
* This returns a promise, resolvable to
|
|
83
|
+
* This returns a promise, resolvable to MailerIdRootRoute object.
|
|
84
84
|
* @param client
|
|
85
85
|
* @param url
|
|
86
86
|
*/
|
|
@@ -94,10 +94,10 @@ async function mailerIdInfoAt(client, url) {
|
|
|
94
94
|
else {
|
|
95
95
|
throw (0, request_utils_1.makeException)(rep, 'Malformed reply');
|
|
96
96
|
}
|
|
97
|
-
if ((
|
|
98
|
-
(0, jwkeys_1.isLikeSignedKeyCert)(json["current-cert"])) {
|
|
97
|
+
if ((0, jwkeys_1.isLikeSignedKeyCert)(json["current-cert"])) {
|
|
99
98
|
transform.currentCert = json["current-cert"];
|
|
100
|
-
transform.previousCerts = json["previous-certs"]
|
|
99
|
+
transform.previousCerts = (Array.isArray(json["previous-certs"]) ?
|
|
100
|
+
json["previous-certs"].filter(jwkeys_1.isLikeSignedKeyCert) : []);
|
|
101
101
|
}
|
|
102
102
|
else {
|
|
103
103
|
throw (0, request_utils_1.makeException)(rep, 'Malformed reply');
|
|
@@ -106,7 +106,7 @@ async function mailerIdInfoAt(client, url) {
|
|
|
106
106
|
return transform;
|
|
107
107
|
}
|
|
108
108
|
/**
|
|
109
|
-
* This returns a promise, resolvable to
|
|
109
|
+
* This returns a promise, resolvable to StorageRootRoute object.
|
|
110
110
|
* @param client
|
|
111
111
|
* @param url
|
|
112
112
|
*/
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
Copyright (C) 2025 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 });
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
Copyright (C) 2025 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 });
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
Copyright (C) 2025 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 });
|