Clean up UUID-handling to prepare for future

This commit is contained in:
Scott Nonnenberg 2020-12-09 14:26:37 -08:00 committed by GitHub
parent 5369950c1d
commit 3f58a9b762
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 55 additions and 31 deletions

View File

@ -65,6 +65,32 @@ function initialize({ events, storage, navigator, logger }) {
// Keeping this entrypoint around so more inialize() calls just kick the timing // Keeping this entrypoint around so more inialize() calls just kick the timing
scheduleNext = scheduleNextRotation; scheduleNext = scheduleNextRotation;
async function saveCert({ certificate, key }) {
const arrayBuffer = window.Signal.Crypto.base64ToArrayBuffer(certificate);
const decodedContainer = textsecure.protobuf.SenderCertificate.decode(
arrayBuffer
);
const decodedCert = textsecure.protobuf.SenderCertificate.Certificate.decode(
decodedContainer.certificate
);
// We don't want to send a protobuf-generated object across IPC, so we make
// our own object.
const toSave = {
expires: decodedCert.expires.toNumber(),
serialized: arrayBuffer,
};
await storage.put(key, toSave);
}
async function removeOldKey() {
const oldCertKey = 'senderCertificateWithUuid';
const oldUuidCert = storage.get(oldCertKey);
if (oldUuidCert) {
await storage.remove(oldCertKey);
}
}
async function run() { async function run() {
logger.info('refreshSenderCertificate: Getting new certificate...'); logger.info('refreshSenderCertificate: Getting new certificate...');
try { try {
@ -76,29 +102,23 @@ function initialize({ events, storage, navigator, logger }) {
password: PASSWORD, password: PASSWORD,
}); });
const { certificate } = await server.getSenderCertificate(); const omitE164 = true;
const arrayBuffer = window.Signal.Crypto.base64ToArrayBuffer(certificate); const [
const decodedContainer = textsecure.protobuf.SenderCertificate.decode( { certificate },
arrayBuffer { certificate: certificateWithNoE164 },
); ] = await Promise.all([
const decodedCert = textsecure.protobuf.SenderCertificate.Certificate.decode( server.getSenderCertificate(),
decodedContainer.certificate server.getSenderCertificate(omitE164),
); ]);
// We don't want to send a protobuf-generated object across IPC, so we make await Promise.all([
// our own object. saveCert({ certificate, key: 'senderCertificate' }),
const toSave = { saveCert({
expires: decodedCert.expires.toNumber(), certificate: certificateWithNoE164,
serialized: arrayBuffer, key: 'senderCertificateNoE164',
}; }),
removeOldKey(),
storage.put('senderCertificate', toSave); ]);
const oldCertKey = 'senderCertificateWithUuid';
const oldUuidCert = storage.get(oldCertKey);
if (oldUuidCert) {
await storage.remove(oldCertKey);
}
scheduledTime = null; scheduledTime = null;
scheduleNextRotation(); scheduleNextRotation();

View File

@ -1810,11 +1810,12 @@ type WhatIsThis = import('./window.d').WhatIsThis;
!c.isEverUnregistered() !c.isEverUnregistered()
) )
) )
.map(c => c.get('e164')); .map(c => c.get('e164'))
.filter(Boolean) as Array<string>;
if (lonelyE164s.length > 0) { if (lonelyE164s.length > 0) {
const lookup = await window.textsecure.messaging.getUuidsForE164s( const lookup = await window.textsecure.messaging.getUuidsForE164s(
lonelyE164s as WhatIsThis lonelyE164s
); );
const e164s = Object.keys(lookup); const e164s = Object.keys(lookup);
e164s.forEach(e164 => { e164s.forEach(e164 => {

View File

@ -2428,7 +2428,6 @@ export class ConversationModel extends window.Backbone.Model<
: ''; : '';
return { return {
author: contact.get('e164'),
authorUuid: contact.get('uuid'), authorUuid: contact.get('uuid'),
bodyRanges: quotedMessage.get('bodyRanges'), bodyRanges: quotedMessage.get('bodyRanges'),
id: quotedMessage.get('sent_at'), id: quotedMessage.get('sent_at'),
@ -2594,7 +2593,6 @@ export class ConversationModel extends window.Backbone.Model<
async sendReactionMessage( async sendReactionMessage(
reaction: { emoji: string; remove: boolean }, reaction: { emoji: string; remove: boolean },
target: { target: {
targetAuthorE164: string;
targetAuthorUuid: string; targetAuthorUuid: string;
targetTimestamp: number; targetTimestamp: number;
} }

View File

@ -628,6 +628,7 @@ async function removeAllSignedPreKeys() {
const ITEM_KEYS: { [key: string]: Array<string> | undefined } = { const ITEM_KEYS: { [key: string]: Array<string> | undefined } = {
identityKey: ['value.pubKey', 'value.privKey'], identityKey: ['value.pubKey', 'value.privKey'],
senderCertificate: ['value.serialized'], senderCertificate: ['value.serialized'],
senderCertificateNoE164: ['value.serialized'],
signaling_key: ['value'], signaling_key: ['value'],
profileKey: ['value'], profileKey: ['value'],
}; };

View File

@ -1083,13 +1083,18 @@ export function initialize({
); );
} }
async function getSenderCertificate() { async function getSenderCertificate(omitE164?: boolean) {
const baseParameters = '?includeUuid=true';
const urlParameters = `${baseParameters}${
omitE164 ? '&includeE164=false' : ''
}`;
return _ajax({ return _ajax({
call: 'deliveryCert', call: 'deliveryCert',
httpType: 'GET', httpType: 'GET',
responseType: 'json', responseType: 'json',
validateResponse: { certificate: 'string' }, validateResponse: { certificate: 'string' },
urlParameters: '?includeUuid=true', urlParameters,
}); });
} }

View File

@ -15173,7 +15173,7 @@
"rule": "jQuery-wrap(", "rule": "jQuery-wrap(",
"path": "ts/textsecure/WebAPI.js", "path": "ts/textsecure/WebAPI.js",
"line": " const byteBuffer = window.dcodeIO.ByteBuffer.wrap(quote, 'binary', window.dcodeIO.ByteBuffer.LITTLE_ENDIAN);", "line": " const byteBuffer = window.dcodeIO.ByteBuffer.wrap(quote, 'binary', window.dcodeIO.ByteBuffer.LITTLE_ENDIAN);",
"lineNumber": 1263, "lineNumber": 1265,
"reasonCategory": "falseMatch", "reasonCategory": "falseMatch",
"updated": "2020-09-08T23:07:22.682Z" "updated": "2020-09-08T23:07:22.682Z"
}, },
@ -15181,7 +15181,7 @@
"rule": "jQuery-wrap(", "rule": "jQuery-wrap(",
"path": "ts/textsecure/WebAPI.ts", "path": "ts/textsecure/WebAPI.ts",
"line": " const byteBuffer = window.dcodeIO.ByteBuffer.wrap(", "line": " const byteBuffer = window.dcodeIO.ByteBuffer.wrap(",
"lineNumber": 2172, "lineNumber": 2177,
"reasonCategory": "falseMatch", "reasonCategory": "falseMatch",
"updated": "2020-09-08T23:07:22.682Z" "updated": "2020-09-08T23:07:22.682Z"
} }

View File

@ -2931,7 +2931,6 @@ Whisper.ConversationView = Whisper.View.extend({
try { try {
await this.model.sendReactionMessage(reaction, { await this.model.sendReactionMessage(reaction, {
targetAuthorE164: messageModel.getSource(),
targetAuthorUuid: messageModel.getSourceUuid(), targetAuthorUuid: messageModel.getSourceUuid(),
targetTimestamp: messageModel.get('sent_at'), targetTimestamp: messageModel.get('sent_at'),
}); });