From 9f62d6577cc116409ebee59c19402109990d1c6b Mon Sep 17 00:00:00 2001 From: audric Date: Tue, 27 Jul 2021 13:19:48 +1000 Subject: [PATCH] remove unused accessKey derived from profileKey --- js/modules/crypto.js | 19 ------------------- ts/models/conversation.ts | 23 ----------------------- 2 files changed, 42 deletions(-) diff --git a/js/modules/crypto.js b/js/modules/crypto.js index e7b543372..445fb49db 100644 --- a/js/modules/crypto.js +++ b/js/modules/crypto.js @@ -9,7 +9,6 @@ module.exports = { concatenateBytes, constantTimeEqual, decryptSymmetric, - deriveAccessKey, encryptAesCtr, encryptSymmetric, getRandomBytes, @@ -27,13 +26,6 @@ function bytesFromString(string) { // High-level Operations -async function deriveAccessKey(profileKey) { - const iv = getZeroes(12); - const plaintext = getZeroes(16); - const accessKey = await _encrypt_aes_gcm(profileKey, iv, plaintext); - return _getFirstBytes(accessKey, 16); -} - const IV_LENGTH = 16; const MAC_LENGTH = 16; const NONCE_LENGTH = 16; @@ -141,17 +133,6 @@ async function encryptAesCtr(key, plaintext, counter) { return ciphertext; } -async function _encrypt_aes_gcm(key, iv, plaintext) { - const algorithm = { - name: 'AES-GCM', - iv, - }; - const extractable = false; - - const cryptoKey = await crypto.subtle.importKey('raw', key, algorithm, extractable, ['encrypt']); - return crypto.subtle.encrypt(algorithm, cryptoKey, plaintext); -} - // Utility function getRandomBytes(n) { diff --git a/ts/models/conversation.ts b/ts/models/conversation.ts index d28515b14..ab3c6f25e 100644 --- a/ts/models/conversation.ts +++ b/ts/models/conversation.ts @@ -92,7 +92,6 @@ export interface ConversationAttributes { profile?: any; profileAvatar?: any; profileKey?: string; - accessKey?: any; triggerNotificationsFor: ConversationNotificationSettingType; isTrustedForAttachmentDownload: boolean; isPinned: boolean; @@ -130,7 +129,6 @@ export interface ConversationAttributesOptionals { profile?: any; profileAvatar?: any; profileKey?: string; - accessKey?: any; triggerNotificationsFor?: ConversationNotificationSettingType; isTrustedForAttachmentDownload?: boolean; isPinned: boolean; @@ -1201,34 +1199,13 @@ export class ConversationModel extends Backbone.Model { if (this.get('profileKey') !== profileKey) { this.set({ profileKey, - accessKey: null, }); - await this.deriveAccessKeyIfNeeded(); await this.commit(); } } - public async deriveAccessKeyIfNeeded() { - const profileKey = this.get('profileKey'); - if (!profileKey) { - return; - } - if (this.get('accessKey')) { - return; - } - - try { - const profileKeyBuffer = fromBase64ToArrayBuffer(profileKey); - const accessKeyBuffer = await window.Signal.Crypto.deriveAccessKey(profileKeyBuffer); - const accessKey = fromArrayBufferToBase64(accessKeyBuffer); - this.set({ accessKey }); - } catch (e) { - window?.log?.warn(`Failed to derive access key for ${this.id}`); - } - } - public async upgradeMessages(messages: any) { // tslint:disable-next-line: one-variable-per-declaration for (let max = messages.length, i = 0; i < max; i += 1) {