Simplify OutgoingIdentityKeyError, use it in getKeysForIdentifier

Co-authored-by: Scott Nonnenberg <scott@signal.org>
This commit is contained in:
automated-signal 2022-02-25 18:44:05 -08:00 committed by GitHub
parent 9854223f1f
commit d45a52bc22
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 32 additions and 33 deletions

View File

@ -1307,7 +1307,7 @@ export async function modifyGroupV2({
await conversationJobQueue.add({ await conversationJobQueue.add({
type: conversationQueueJobEnum.enum.GroupUpdate, type: conversationQueueJobEnum.enum.GroupUpdate,
conversationId: conversation.id, conversationId: conversation.id,
groupChangeBase64: Bytes.toBase64(groupChangeBuffer), groupChangeBase64,
recipients: groupV2Info.members, recipients: groupV2Info.members,
revision: groupV2Info.revision, revision: groupV2Info.revision,
}); });

View File

@ -178,12 +178,7 @@ describe('sendToGroup', () => {
it('returns true for certain types of error subclasses', async () => { it('returns true for certain types of error subclasses', async () => {
assert.isTrue( assert.isTrue(
_shouldFailSend( _shouldFailSend(
new OutgoingIdentityKeyError( new OutgoingIdentityKeyError('something'),
'something',
new Uint8Array(),
200,
new Uint8Array()
),
'testing OutgoingIdentityKeyError' 'testing OutgoingIdentityKeyError'
) )
); );

View File

@ -73,15 +73,8 @@ export class ReplayableError extends Error {
export class OutgoingIdentityKeyError extends ReplayableError { export class OutgoingIdentityKeyError extends ReplayableError {
identifier: string; identifier: string;
identityKey: Uint8Array;
// Note: Data to resend message is no longer captured // Note: Data to resend message is no longer captured
constructor( constructor(incomingIdentifier: string) {
incomingIdentifier: string,
_m: Uint8Array,
_t: number,
identityKey: Uint8Array
) {
const identifier = incomingIdentifier.split('.')[0]; const identifier = incomingIdentifier.split('.')[0];
super({ super({
@ -90,7 +83,6 @@ export class OutgoingIdentityKeyError extends ReplayableError {
}); });
this.identifier = identifier; this.identifier = identifier;
this.identityKey = identityKey;
} }
} }

View File

@ -707,12 +707,7 @@ export default class OutgoingMessage {
await this.reloadDevicesAndSend(identifier, true)(); await this.reloadDevicesAndSend(identifier, true)();
} catch (error) { } catch (error) {
if (error?.message?.includes('untrusted identity for address')) { if (error?.message?.includes('untrusted identity for address')) {
const newError = new OutgoingIdentityKeyError( const newError = new OutgoingIdentityKeyError(identifier);
identifier,
error.originalMessage,
error.timestamp,
error.identityKey && new Uint8Array(error.identityKey)
);
this.registerError(identifier, 'Untrusted identity', newError); this.registerError(identifier, 'Untrusted identity', newError);
} else { } else {
this.registerError( this.registerError(

View File

@ -8,13 +8,18 @@ import {
PublicKey, PublicKey,
} from '@signalapp/signal-client'; } from '@signalapp/signal-client';
import { UnregisteredUserError, HTTPError } from './Errors'; import {
UnregisteredUserError,
HTTPError,
OutgoingIdentityKeyError,
} from './Errors';
import { Sessions, IdentityKeys } from '../LibSignalStores'; import { Sessions, IdentityKeys } from '../LibSignalStores';
import { Address } from '../types/Address'; import { Address } from '../types/Address';
import { QualifiedAddress } from '../types/QualifiedAddress'; import { QualifiedAddress } from '../types/QualifiedAddress';
import { UUID } from '../types/UUID'; import { UUID } from '../types/UUID';
import type { ServerKeysType, WebAPIType } from './WebAPI'; import type { ServerKeysType, WebAPIType } from './WebAPI';
import * as log from '../logging/log'; import * as log from '../logging/log';
import { isRecord } from '../util/isRecord';
export async function getKeysForIdentifier( export async function getKeysForIdentifier(
identifier: string, identifier: string,
@ -54,20 +59,32 @@ async function getServerKeys(
server: WebAPIType, server: WebAPIType,
accessKey?: string accessKey?: string
): Promise<{ accessKeyFailed?: boolean; keys: ServerKeysType }> { ): Promise<{ accessKeyFailed?: boolean; keys: ServerKeysType }> {
if (!accessKey) {
return {
keys: await server.getKeysForIdentifier(identifier),
};
}
try { try {
if (!accessKey) {
return {
keys: await server.getKeysForIdentifier(identifier),
};
}
return { return {
keys: await server.getKeysForIdentifierUnauth(identifier, undefined, { keys: await server.getKeysForIdentifierUnauth(identifier, undefined, {
accessKey, accessKey,
}), }),
}; };
} catch (error) { } catch (error: unknown) {
if (error.code === 401 || error.code === 403) { if (
error instanceof Error &&
error.message.includes('untrusted identity')
) {
throw new OutgoingIdentityKeyError(identifier);
}
if (
accessKey &&
isRecord(error) &&
typeof error.code === 'number' &&
(error.code === 401 || error.code === 403)
) {
return { return {
accessKeyFailed: true, accessKeyFailed: true,
keys: await server.getKeysForIdentifier(identifier), keys: await server.getKeysForIdentifier(identifier),

View File

@ -1246,8 +1246,8 @@ async function fetchKeysForIdentifier(
}); });
window.Signal.Data.updateConversation(emptyConversation.attributes); window.Signal.Data.updateConversation(emptyConversation.attributes);
} }
} catch (error) { } catch (error: unknown) {
if (error.name === 'UnregisteredUserError') { if (error instanceof UnregisteredUserError) {
await markIdentifierUnregistered(identifier); await markIdentifierUnregistered(identifier);
return; return;
} }