remove unused accessKey derived from profileKey

pull/1794/head
audric 4 years ago
parent 1ae7a71afc
commit 9f62d6577c

@ -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) {

@ -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<ConversationAttributes> {
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) {

Loading…
Cancel
Save