Handle Safety Number changes while sending a story

This commit is contained in:
Josh Perez 2022-08-19 14:05:31 -04:00 committed by GitHub
parent d036803df9
commit 0fb45f045d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 392 additions and 44 deletions

View file

@ -17,7 +17,7 @@ import {
} from '@signalapp/libsignal-client';
import * as Bytes from './Bytes';
import { constantTimeEqual } from './Crypto';
import { constantTimeEqual, sha256 } from './Crypto';
import { assert, strictAssert } from './util/assert';
import { isNotNil } from './util/isNotNil';
import { Zone } from './util/Zone';
@ -1565,6 +1565,23 @@ export class SignalProtocolStore extends EventsMixin {
return undefined;
}
async getFingerprint(uuid: UUID): Promise<string | undefined> {
if (uuid === null || uuid === undefined) {
throw new Error('loadIdentityKey: uuid was undefined/null');
}
const pubKey = await this.loadIdentityKey(uuid);
if (!pubKey) {
return;
}
const hash = sha256(pubKey);
const fingerprint = hash.slice(0, 4);
return Bytes.toBase64(fingerprint);
}
private async _saveIdentityKey(data: IdentityKeyType): Promise<void> {
if (!this.identityKeys) {
throw new Error('_saveIdentityKey: this.identityKeys not yet cached!');
@ -1831,7 +1848,7 @@ export class SignalProtocolStore extends EventsMixin {
return false;
}
isUntrusted(uuid: UUID): boolean {
isUntrusted(uuid: UUID, timestampThreshold = TIMESTAMP_THRESHOLD): boolean {
if (uuid === null || uuid === undefined) {
throw new Error('isUntrusted: uuid was undefined/null');
}
@ -1842,7 +1859,7 @@ export class SignalProtocolStore extends EventsMixin {
}
if (
isMoreRecentThan(identityRecord.timestamp, TIMESTAMP_THRESHOLD) &&
isMoreRecentThan(identityRecord.timestamp, timestampThreshold) &&
!identityRecord.nonblockingApproval &&
!identityRecord.firstUse
) {