Always refetch profile key credential if expired

This commit is contained in:
Fedor Indutny 2022-07-18 13:05:41 -07:00 committed by GitHub
parent 2f252b8e26
commit a4cf2e0948
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 61 additions and 37 deletions

View file

@ -60,6 +60,7 @@ import type {
GroupCredentialsType,
GroupLogResponseType,
} from './textsecure/WebAPI';
import { HTTPError } from './textsecure/Errors';
import type MessageSender from './textsecure/SendMessage';
import { CURRENT_SCHEMA_VERSION as MAX_MESSAGE_SCHEMA } from './types/Message2';
import type { ConversationModel } from './models/conversations';
@ -1491,13 +1492,6 @@ export async function modifyGroupV2({
log.info(`modifyGroupV2/${logId}: Fetching profiles for ${logIds}`);
}
for (const member of membersMissingCredentials) {
member.set({
profileKeyCredential: null,
profileKeyCredentialExpiration: null,
});
}
// eslint-disable-next-line no-await-in-loop
await Promise.all(
membersMissingCredentials.map(member => member.getProfiles())
@ -1735,19 +1729,25 @@ export async function fetchMembershipProof({
// Creating a group
export async function createGroupV2({
name,
avatar,
expireTimer,
conversationIds,
avatars,
}: Readonly<{
name: string;
avatar: undefined | Uint8Array;
expireTimer: undefined | number;
conversationIds: Array<string>;
avatars?: Array<AvatarDataType>;
}>): Promise<ConversationModel> {
export async function createGroupV2(
options: Readonly<{
name: string;
avatar: undefined | Uint8Array;
expireTimer: undefined | number;
conversationIds: Array<string>;
avatars?: Array<AvatarDataType>;
refreshedCredentials?: boolean;
}>
): Promise<ConversationModel> {
const {
name,
avatar,
expireTimer,
conversationIds,
avatars,
refreshedCredentials = false,
} = options;
// Ensure we have the credentials we need before attempting GroupsV2 operations
await maybeFetchNewCredentials();
@ -1770,10 +1770,6 @@ export async function createGroupV2({
window.ConversationController.getOurConversationOrThrow();
if (ourConversation.hasProfileKeyCredentialExpired()) {
log.info(`createGroupV2/${logId}: fetching our own credentials`);
ourConversation.set({
profileKeyCredential: null,
profileKeyCredentialExpiration: null,
});
await ourConversation.getProfiles();
}
@ -1869,12 +1865,45 @@ export async function createGroupV2({
...protoAndConversationAttributes,
});
await makeRequestWithTemporalRetry({
logId: `createGroupV2/${logId}`,
publicParams,
secretParams,
request: (sender, options) => sender.createGroup(groupProto, options),
});
try {
await makeRequestWithTemporalRetry({
logId: `createGroupV2/${logId}`,
publicParams,
secretParams,
request: (sender, requestOptions) =>
sender.createGroup(groupProto, requestOptions),
});
} catch (error) {
if (!(error instanceof HTTPError)) {
throw error;
}
if (error.code !== 400 || refreshedCredentials) {
throw error;
}
const logIds = conversationIds.map(conversationId => {
const contact = window.ConversationController.get(conversationId);
if (!contact) {
return;
}
contact.set({
profileKeyCredential: null,
profileKeyCredentialExpiration: null,
});
return contact.idForLogging();
});
log.warn(
`createGroupV2/${logId}: Profile key credentials were not ` +
`up-to-date. Updating profiles for ${logIds} and retrying`
);
return createGroupV2({
...options,
refreshedCredentials: true,
});
}
let avatarAttribute: ConversationAttributesType['avatar'];
if (uploadedAvatar) {