mirror of
https://github.com/oxen-io/session-desktop.git
synced 2023-12-14 02:12:57 +01:00
remove keypair request manager
This commit is contained in:
parent
89a0868fc3
commit
0b410404a3
|
@ -55,7 +55,6 @@ window.lokiFeatureFlags = {
|
|||
useOnionRequests: true,
|
||||
useFileOnionRequests: true,
|
||||
useFileOnionRequestsV2: true, // more compact encoding of files in response
|
||||
useRequestEncryptionKeyPair: false,
|
||||
padOutgoingAttachments: true,
|
||||
};
|
||||
|
||||
|
@ -394,7 +393,6 @@ if (config.environment.includes('test-integration')) {
|
|||
window.lokiFeatureFlags = {
|
||||
useOnionRequests: false,
|
||||
useFileOnionRequests: false,
|
||||
useRequestEncryptionKeyPair: false,
|
||||
};
|
||||
/* eslint-disable global-require, import/no-extraneous-dependencies */
|
||||
window.sinon = require('sinon');
|
||||
|
|
|
@ -484,14 +484,11 @@ async function performIfValid(
|
|||
} else if (groupUpdate.type === Type.MEMBER_LEFT) {
|
||||
await handleClosedGroupMemberLeft(envelope, convo);
|
||||
} else if (groupUpdate.type === Type.ENCRYPTION_KEY_PAIR_REQUEST) {
|
||||
if (window.lokiFeatureFlags.useRequestEncryptionKeyPair) {
|
||||
await handleClosedGroupEncryptionKeyPairRequest(envelope, groupUpdate, convo);
|
||||
} else {
|
||||
window?.log?.warn(
|
||||
'Received ENCRYPTION_KEY_PAIR_REQUEST message but it is not enabled for now.'
|
||||
);
|
||||
await removeFromCache(envelope);
|
||||
}
|
||||
window?.log?.warn(
|
||||
'Received ENCRYPTION_KEY_PAIR_REQUEST message but it is not enabled for now.'
|
||||
);
|
||||
await removeFromCache(envelope);
|
||||
|
||||
// if you add a case here, remember to add it where performIfValid is called too.
|
||||
}
|
||||
|
||||
|
@ -832,26 +829,6 @@ async function sendLatestKeyPairToUsers(
|
|||
);
|
||||
}
|
||||
|
||||
async function handleClosedGroupEncryptionKeyPairRequest(
|
||||
envelope: EnvelopePlus,
|
||||
groupUpdate: SignalService.DataMessage.ClosedGroupControlMessage,
|
||||
groupConvo: ConversationModel
|
||||
) {
|
||||
if (!window.lokiFeatureFlags.useRequestEncryptionKeyPair) {
|
||||
throw new Error('useRequestEncryptionKeyPair is disabled');
|
||||
}
|
||||
const sender = envelope.senderIdentity;
|
||||
const groupPublicKey = envelope.source;
|
||||
// Guard against self-sends
|
||||
if (UserUtils.isUsFromCache(sender)) {
|
||||
window?.log?.info('Dropping self send message of type ENCRYPTION_KEYPAIR_REQUEST');
|
||||
await removeFromCache(envelope);
|
||||
return;
|
||||
}
|
||||
await sendLatestKeyPairToUsers(groupConvo, groupPublicKey, [sender]);
|
||||
return removeFromCache(envelope);
|
||||
}
|
||||
|
||||
export async function createClosedGroup(groupName: string, members: Array<string>) {
|
||||
const setOfMembers = new Set(members);
|
||||
|
||||
|
|
|
@ -13,8 +13,6 @@ import { concatUInt8Array, getSodium } from '../session/crypto';
|
|||
import { getConversationController } from '../session/conversations';
|
||||
import { getAllEncryptionKeyPairsForGroup } from '../../ts/data/data';
|
||||
import { ECKeyPair } from './keypairs';
|
||||
import { KeyPairRequestManager } from './keyPairRequestManager';
|
||||
import { requestEncryptionKeyPair } from '../session/group';
|
||||
import { handleConfigurationMessage } from './configMessage';
|
||||
import { ConversationTypeEnum } from '../models/conversation';
|
||||
import { removeMessagePadding } from '../session/crypto/BufferPadding';
|
||||
|
@ -107,14 +105,6 @@ async function decryptForClosedGroup(envelope: EnvelopePlus, ciphertext: ArrayBu
|
|||
window?.log?.warn('decryptWithSessionProtocol for medium group message throw:', e);
|
||||
const groupPubKey = PubKey.cast(envelope.source);
|
||||
|
||||
// To enable back if we decide to enable encryption key pair request work again
|
||||
if (window.lokiFeatureFlags.useRequestEncryptionKeyPair) {
|
||||
const keypairRequestManager = KeyPairRequestManager.getInstance();
|
||||
if (keypairRequestManager.canTriggerRequestWith(groupPubKey)) {
|
||||
keypairRequestManager.markRequestSendFor(groupPubKey, Date.now());
|
||||
await requestEncryptionKeyPair(groupPubKey);
|
||||
}
|
||||
}
|
||||
// IMPORTANT do not remove the message from the cache just yet.
|
||||
// We will try to decrypt it once we get the encryption keypair.
|
||||
// for that to work, we need to throw an error just like here.
|
||||
|
|
|
@ -1,47 +0,0 @@
|
|||
import { DURATION } from '../session/constants';
|
||||
import { PubKey } from '../session/types';
|
||||
|
||||
/**
|
||||
* Singleton handling the logic behing requesting EncryptionKeypair for a closed group we need.
|
||||
*
|
||||
* Nothing is read/written to the db, it's all on memory for now.
|
||||
*/
|
||||
export class KeyPairRequestManager {
|
||||
public static DELAY_BETWEEN_TWO_REQUEST_MS = DURATION.SECONDS * 30;
|
||||
private static instance: KeyPairRequestManager | null;
|
||||
private readonly requestTimestamps: Map<string, number>;
|
||||
|
||||
private constructor() {
|
||||
this.requestTimestamps = new Map();
|
||||
}
|
||||
|
||||
public static getInstance() {
|
||||
if (KeyPairRequestManager.instance) {
|
||||
return KeyPairRequestManager.instance;
|
||||
}
|
||||
KeyPairRequestManager.instance = new KeyPairRequestManager();
|
||||
return KeyPairRequestManager.instance;
|
||||
}
|
||||
|
||||
public reset() {
|
||||
this.requestTimestamps.clear();
|
||||
}
|
||||
|
||||
public markRequestSendFor(pubkey: PubKey, timestamp: number) {
|
||||
this.requestTimestamps.set(pubkey.key, timestamp);
|
||||
}
|
||||
|
||||
public get(pubkey: PubKey) {
|
||||
return this.requestTimestamps.get(pubkey.key);
|
||||
}
|
||||
|
||||
public canTriggerRequestWith(pubkey: PubKey) {
|
||||
const record = this.requestTimestamps.get(pubkey.key);
|
||||
if (!record) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const now = Date.now();
|
||||
return now - record >= KeyPairRequestManager.DELAY_BETWEEN_TWO_REQUEST_MS;
|
||||
}
|
||||
}
|
|
@ -539,31 +539,3 @@ export async function buildEncryptionKeyPairWrappers(
|
|||
);
|
||||
return wrappers;
|
||||
}
|
||||
|
||||
export async function requestEncryptionKeyPair(groupPublicKey: string | PubKey) {
|
||||
if (!window.lokiFeatureFlags.useRequestEncryptionKeyPair) {
|
||||
throw new Error('useRequestEncryptionKeyPair is disabled');
|
||||
}
|
||||
|
||||
const groupConvo = getConversationController().get(PubKey.cast(groupPublicKey).key);
|
||||
|
||||
if (!groupConvo) {
|
||||
window?.log?.warn(
|
||||
'requestEncryptionKeyPair: Trying to request encryption key pair from unknown group'
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
const ourNumber = UserUtils.getOurPubKeyFromCache();
|
||||
if (!groupConvo.get('members').includes(ourNumber.key)) {
|
||||
window?.log?.info('requestEncryptionKeyPair: We are not a member of this group.');
|
||||
return;
|
||||
}
|
||||
|
||||
const ecRequestMessage = new ClosedGroupEncryptionPairRequestMessage({
|
||||
groupId: groupPublicKey,
|
||||
timestamp: Date.now(),
|
||||
});
|
||||
|
||||
await getMessageQueue().sendToGroup(ecRequestMessage);
|
||||
}
|
||||
|
|
|
@ -1,81 +0,0 @@
|
|||
// tslint:disable: no-implicit-dependencies
|
||||
|
||||
import chai from 'chai';
|
||||
|
||||
import _ from 'lodash';
|
||||
import { describe } from 'mocha';
|
||||
import { KeyPairRequestManager } from '../../../../receiver/keyPairRequestManager';
|
||||
import { TestUtils } from '../../../test-utils';
|
||||
|
||||
import chaiAsPromised from 'chai-as-promised';
|
||||
chai.use(chaiAsPromised as any);
|
||||
|
||||
chai.should();
|
||||
const { expect } = chai;
|
||||
|
||||
// tslint:disable-next-line: max-func-body-length
|
||||
describe('KeyPairRequestManager', () => {
|
||||
let inst: KeyPairRequestManager;
|
||||
beforeEach(() => {
|
||||
KeyPairRequestManager.getInstance().reset();
|
||||
inst = KeyPairRequestManager.getInstance();
|
||||
});
|
||||
|
||||
it('getInstance() should return an instance', () => {
|
||||
expect(inst).to.exist;
|
||||
});
|
||||
|
||||
describe('markRequestSendFor', () => {
|
||||
it('should be able to set a timestamp for a pubkey', () => {
|
||||
const groupPubkey = TestUtils.generateFakePubKey();
|
||||
const now = Date.now();
|
||||
inst.markRequestSendFor(groupPubkey, now);
|
||||
expect(inst.get(groupPubkey)).to.be.equal(now);
|
||||
});
|
||||
|
||||
it('should be able to override a timestamp for a pubkey', () => {
|
||||
const groupPubkey = TestUtils.generateFakePubKey();
|
||||
const timestamp1 = Date.now();
|
||||
inst.markRequestSendFor(groupPubkey, timestamp1);
|
||||
expect(inst.get(groupPubkey)).to.be.equal(timestamp1);
|
||||
const timestamp2 = Date.now() + 1000;
|
||||
inst.markRequestSendFor(groupPubkey, timestamp2);
|
||||
expect(inst.get(groupPubkey)).to.be.equal(timestamp2);
|
||||
});
|
||||
});
|
||||
|
||||
describe('canTriggerRequestWith', () => {
|
||||
it('should return true if there is no timestamp set for this pubkey', () => {
|
||||
const groupPubkey = TestUtils.generateFakePubKey();
|
||||
const can = inst.canTriggerRequestWith(groupPubkey);
|
||||
expect(can).to.be.equal(
|
||||
true,
|
||||
'should return true if we there is no timestamp set for this pubkey'
|
||||
);
|
||||
});
|
||||
|
||||
it('should return false if there is a timestamp set for this pubkey and it is less than DELAY_BETWEEN_TWO_REQUEST_MS', () => {
|
||||
const groupPubkey = TestUtils.generateFakePubKey();
|
||||
const timestamp1 = Date.now();
|
||||
|
||||
inst.markRequestSendFor(groupPubkey, timestamp1);
|
||||
const can = inst.canTriggerRequestWith(groupPubkey);
|
||||
expect(can).to.be.equal(
|
||||
false,
|
||||
'return false if there is a timestamp set for this pubkey and it is less than DELAY_BETWEEN_TWO_REQUEST_MS'
|
||||
);
|
||||
});
|
||||
|
||||
it('should return true if there is a timestamp set for this pubkey and it is more than DELAY_BETWEEN_TWO_REQUEST_MS', () => {
|
||||
const groupPubkey = TestUtils.generateFakePubKey();
|
||||
const timestamp1 = Date.now() - KeyPairRequestManager.DELAY_BETWEEN_TWO_REQUEST_MS;
|
||||
|
||||
inst.markRequestSendFor(groupPubkey, timestamp1);
|
||||
const can = inst.canTriggerRequestWith(groupPubkey);
|
||||
expect(can).to.be.equal(
|
||||
true,
|
||||
'true if there is a timestamp set for this pubkey and it is more than DELAY_BETWEEN_TWO_REQUEST_MS'
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
1
ts/window.d.ts
vendored
1
ts/window.d.ts
vendored
|
@ -48,7 +48,6 @@ declare global {
|
|||
useOnionRequests: boolean;
|
||||
useFileOnionRequests: boolean;
|
||||
useFileOnionRequestsV2: boolean;
|
||||
useRequestEncryptionKeyPair: boolean;
|
||||
padOutgoingAttachments: boolean;
|
||||
};
|
||||
lokiSnodeAPI: LokiSnodeAPI;
|
||||
|
|
Loading…
Reference in a new issue