Move storage outside
This commit is contained in:
parent
73f2fe4fd0
commit
ac1e4ad9a2
|
@ -25,6 +25,7 @@ const everyoneMentionPattern = new RegExp(`(?:\\s+|^)@everyone(?:\\s+|$)`);
|
||||||
|
|
||||||
const START_DATE = new Date();
|
const START_DATE = new Date();
|
||||||
const TEMP_KEY = 'temporarymasterkey';
|
const TEMP_KEY = 'temporarymasterkey';
|
||||||
|
const ECDH_STORAGE = {};
|
||||||
let seed;
|
let seed;
|
||||||
|
|
||||||
export default new class E2EE extends BuiltinModule {
|
export default new class E2EE extends BuiltinModule {
|
||||||
|
@ -92,30 +93,26 @@ export default new class E2EE extends BuiltinModule {
|
||||||
Settings.getSetting('security', 'e2eedb', 'e2ekvps').addItem({ value: { key: channelId, value: key } });
|
Settings.getSetting('security', 'e2eedb', 'e2ekvps').addItem({ value: { key: channelId, value: key } });
|
||||||
}
|
}
|
||||||
|
|
||||||
get ecdhStorage() {
|
|
||||||
return this._ecdhStorage || (this._ecdhStorage = {});
|
|
||||||
}
|
|
||||||
|
|
||||||
createKeyExchange(dmChannelID) {
|
createKeyExchange(dmChannelID) {
|
||||||
if (this.ecdhStorage.hasOwnProperty(dmChannelID)) return null;
|
if (ECDH_STORAGE.hasOwnProperty(dmChannelID)) return null;
|
||||||
this.ecdhStorage[dmChannelID] = Security.createECDH();
|
ECDH_STORAGE[dmChannelID] = Security.createECDH();
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
if (this.ecdhStorage.hasOwnProperty(dmChannelID)) {
|
if (ECDH_STORAGE.hasOwnProperty(dmChannelID)) {
|
||||||
delete this.ecdhStorage[dmChannelID];
|
delete ECDH_STORAGE[dmChannelID];
|
||||||
Toasts.error('Key exchange expired!');
|
Toasts.error('Key exchange expired!');
|
||||||
}
|
}
|
||||||
}, 30000);
|
}, 30000);
|
||||||
return Security.generateECDHKeys(this.ecdhStorage[dmChannelID]);
|
return Security.generateECDHKeys(ECDH_STORAGE[dmChannelID]);
|
||||||
}
|
}
|
||||||
|
|
||||||
publicKeyFor(dmChannelID) {
|
publicKeyFor(dmChannelID) {
|
||||||
return Security.getECDHPublicKey(this.ecdhStorage[dmChannelID]);
|
return Security.getECDHPublicKey(ECDH_STORAGE[dmChannelID]);
|
||||||
}
|
}
|
||||||
|
|
||||||
computeSecret(dmChannelID, otherKey) {
|
computeSecret(dmChannelID, otherKey) {
|
||||||
try {
|
try {
|
||||||
const secret = Security.computeECDHSecret(this.ecdhStorage[dmChannelID], otherKey);
|
const secret = Security.computeECDHSecret(ECDH_STORAGE[dmChannelID], otherKey);
|
||||||
delete this.ecdhStorage[dmChannelID];
|
delete ECDH_STORAGE[dmChannelID];
|
||||||
return Security.hash('sha384', secret, 'hex');
|
return Security.hash('sha384', secret, 'hex');
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
throw e;
|
throw e;
|
||||||
|
@ -138,7 +135,7 @@ export default new class E2EE extends BuiltinModule {
|
||||||
try {
|
try {
|
||||||
await Modals.confirm('Key Exhcange', 'Public key received. Accept?').promise;
|
await Modals.confirm('Key Exhcange', 'Public key received. Accept?').promise;
|
||||||
// We already sent our key
|
// We already sent our key
|
||||||
if (!this.ecdhStorage.hasOwnProperty(channelId)) {
|
if (!ECDH_STORAGE.hasOwnProperty(channelId)) {
|
||||||
const publicKeyMessage = `\`\`\`\n-----BEGIN PUBLIC KEY-----\n${this.createKeyExchange(channelId)}\n-----END PUBLIC KEY-----\n\`\`\``;
|
const publicKeyMessage = `\`\`\`\n-----BEGIN PUBLIC KEY-----\n${this.createKeyExchange(channelId)}\n-----END PUBLIC KEY-----\n\`\`\``;
|
||||||
if (this.encryptNewMessages) this.encryptNewMessages = false;
|
if (this.encryptNewMessages) this.encryptNewMessages = false;
|
||||||
WebpackModules.getModuleByName('DraftActions').saveDraft(channelId, publicKeyMessage);
|
WebpackModules.getModuleByName('DraftActions').saveDraft(channelId, publicKeyMessage);
|
||||||
|
|
Loading…
Reference in New Issue