core-3nweb-client-lib 0.41.7 → 0.41.8

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.
@@ -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.ratchetUpSendingPair(pair);
249
+ if (!ck) {
250
+ ck = this.addCorrespondent(correspondent);
250
251
  }
251
- else {
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
- if (msgMeta.recipientKid) {
303
- if (!pair.isSenderIntroKey) {
304
- throw new Error(`Introductory message is not referencing used intro key in the next crypto`);
305
- }
306
- if (msgMeta.recipientKid !== pair.senderKid) {
307
- throw new Error(`Introductory message is referencing wrong key in the next crypto`);
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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "core-3nweb-client-lib",
3
- "version": "0.41.7",
3
+ "version": "0.41.8",
4
4
  "description": "3NWeb client core library, embeddable into different environments",
5
5
  "main": "build/lib-index.js",
6
6
  "types": "build/lib-index.d.ts",