Simplify OutgoingIdentityKeyError, use it in getKeysForIdentifier
This commit is contained in:
parent
e4b4a0cd1e
commit
fcb96bf92a
6 changed files with 32 additions and 33 deletions
|
@ -1307,7 +1307,7 @@ export async function modifyGroupV2({
|
|||
await conversationJobQueue.add({
|
||||
type: conversationQueueJobEnum.enum.GroupUpdate,
|
||||
conversationId: conversation.id,
|
||||
groupChangeBase64: Bytes.toBase64(groupChangeBuffer),
|
||||
groupChangeBase64,
|
||||
recipients: groupV2Info.members,
|
||||
revision: groupV2Info.revision,
|
||||
});
|
||||
|
|
|
@ -178,12 +178,7 @@ describe('sendToGroup', () => {
|
|||
it('returns true for certain types of error subclasses', async () => {
|
||||
assert.isTrue(
|
||||
_shouldFailSend(
|
||||
new OutgoingIdentityKeyError(
|
||||
'something',
|
||||
new Uint8Array(),
|
||||
200,
|
||||
new Uint8Array()
|
||||
),
|
||||
new OutgoingIdentityKeyError('something'),
|
||||
'testing OutgoingIdentityKeyError'
|
||||
)
|
||||
);
|
||||
|
|
|
@ -73,15 +73,8 @@ export class ReplayableError extends Error {
|
|||
export class OutgoingIdentityKeyError extends ReplayableError {
|
||||
identifier: string;
|
||||
|
||||
identityKey: Uint8Array;
|
||||
|
||||
// Note: Data to resend message is no longer captured
|
||||
constructor(
|
||||
incomingIdentifier: string,
|
||||
_m: Uint8Array,
|
||||
_t: number,
|
||||
identityKey: Uint8Array
|
||||
) {
|
||||
constructor(incomingIdentifier: string) {
|
||||
const identifier = incomingIdentifier.split('.')[0];
|
||||
|
||||
super({
|
||||
|
@ -90,7 +83,6 @@ export class OutgoingIdentityKeyError extends ReplayableError {
|
|||
});
|
||||
|
||||
this.identifier = identifier;
|
||||
this.identityKey = identityKey;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -707,12 +707,7 @@ export default class OutgoingMessage {
|
|||
await this.reloadDevicesAndSend(identifier, true)();
|
||||
} catch (error) {
|
||||
if (error?.message?.includes('untrusted identity for address')) {
|
||||
const newError = new OutgoingIdentityKeyError(
|
||||
identifier,
|
||||
error.originalMessage,
|
||||
error.timestamp,
|
||||
error.identityKey && new Uint8Array(error.identityKey)
|
||||
);
|
||||
const newError = new OutgoingIdentityKeyError(identifier);
|
||||
this.registerError(identifier, 'Untrusted identity', newError);
|
||||
} else {
|
||||
this.registerError(
|
||||
|
|
|
@ -8,13 +8,18 @@ import {
|
|||
PublicKey,
|
||||
} from '@signalapp/signal-client';
|
||||
|
||||
import { UnregisteredUserError, HTTPError } from './Errors';
|
||||
import {
|
||||
UnregisteredUserError,
|
||||
HTTPError,
|
||||
OutgoingIdentityKeyError,
|
||||
} from './Errors';
|
||||
import { Sessions, IdentityKeys } from '../LibSignalStores';
|
||||
import { Address } from '../types/Address';
|
||||
import { QualifiedAddress } from '../types/QualifiedAddress';
|
||||
import { UUID } from '../types/UUID';
|
||||
import type { ServerKeysType, WebAPIType } from './WebAPI';
|
||||
import * as log from '../logging/log';
|
||||
import { isRecord } from '../util/isRecord';
|
||||
|
||||
export async function getKeysForIdentifier(
|
||||
identifier: string,
|
||||
|
@ -54,20 +59,32 @@ async function getServerKeys(
|
|||
server: WebAPIType,
|
||||
accessKey?: string
|
||||
): Promise<{ accessKeyFailed?: boolean; keys: ServerKeysType }> {
|
||||
if (!accessKey) {
|
||||
return {
|
||||
keys: await server.getKeysForIdentifier(identifier),
|
||||
};
|
||||
}
|
||||
|
||||
try {
|
||||
if (!accessKey) {
|
||||
return {
|
||||
keys: await server.getKeysForIdentifier(identifier),
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
keys: await server.getKeysForIdentifierUnauth(identifier, undefined, {
|
||||
accessKey,
|
||||
}),
|
||||
};
|
||||
} catch (error) {
|
||||
if (error.code === 401 || error.code === 403) {
|
||||
} catch (error: unknown) {
|
||||
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 {
|
||||
accessKeyFailed: true,
|
||||
keys: await server.getKeysForIdentifier(identifier),
|
||||
|
|
|
@ -1268,8 +1268,8 @@ async function fetchKeysForIdentifier(
|
|||
});
|
||||
window.Signal.Data.updateConversation(emptyConversation.attributes);
|
||||
}
|
||||
} catch (error) {
|
||||
if (error.name === 'UnregisteredUserError') {
|
||||
} catch (error: unknown) {
|
||||
if (error instanceof UnregisteredUserError) {
|
||||
await markIdentifierUnregistered(identifier);
|
||||
return;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue