2022-08-19 18:05:31 +00:00
|
|
|
// Copyright 2022 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
import * as log from '../logging/log';
|
|
|
|
import { isNotNil } from './isNotNil';
|
|
|
|
import { updateIdentityKey } from '../services/profiles';
|
2023-08-10 16:43:33 +00:00
|
|
|
import type { ServiceIdString } from '../types/ServiceId';
|
2022-08-19 18:05:31 +00:00
|
|
|
|
|
|
|
export async function verifyStoryListMembers(
|
2023-08-10 16:43:33 +00:00
|
|
|
serviceIds: Array<ServiceIdString>
|
|
|
|
): Promise<{
|
|
|
|
untrustedServiceIds: Set<ServiceIdString>;
|
|
|
|
verifiedServiceIds: Set<ServiceIdString>;
|
|
|
|
}> {
|
2022-08-19 18:05:31 +00:00
|
|
|
const { server } = window.textsecure;
|
|
|
|
if (!server) {
|
|
|
|
throw new Error('verifyStoryListMembers: server not available');
|
|
|
|
}
|
|
|
|
|
2023-08-10 16:43:33 +00:00
|
|
|
const verifiedServiceIds = new Set<ServiceIdString>();
|
|
|
|
const untrustedServiceIds = new Set<ServiceIdString>();
|
2022-08-19 18:05:31 +00:00
|
|
|
|
|
|
|
const elements = await Promise.all(
|
2023-08-10 16:43:33 +00:00
|
|
|
serviceIds.map(async serviceId => {
|
2022-08-19 18:05:31 +00:00
|
|
|
const fingerprint =
|
2023-08-10 16:43:33 +00:00
|
|
|
await window.textsecure.storage.protocol.getFingerprint(serviceId);
|
2022-08-19 18:05:31 +00:00
|
|
|
|
|
|
|
if (!fingerprint) {
|
2023-08-10 16:43:33 +00:00
|
|
|
log.warn(
|
|
|
|
'verifyStoryListMembers: no fingerprint found for serviceId=',
|
|
|
|
serviceId
|
|
|
|
);
|
|
|
|
untrustedServiceIds.add(serviceId);
|
2022-08-19 18:05:31 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-08-10 16:43:33 +00:00
|
|
|
verifiedServiceIds.add(serviceId);
|
|
|
|
return { uuid: serviceId, fingerprint };
|
2022-08-19 18:05:31 +00:00
|
|
|
})
|
|
|
|
);
|
|
|
|
|
2023-08-10 16:43:33 +00:00
|
|
|
const { elements: unverifiedServiceId } = await server.postBatchIdentityCheck(
|
2022-08-19 18:05:31 +00:00
|
|
|
elements.filter(isNotNil)
|
|
|
|
);
|
|
|
|
|
|
|
|
await Promise.all(
|
2023-08-10 16:43:33 +00:00
|
|
|
unverifiedServiceId.map(async ({ uuid: serviceId, identityKey }) => {
|
|
|
|
untrustedServiceIds.add(serviceId);
|
|
|
|
verifiedServiceIds.delete(serviceId);
|
2022-08-19 18:05:31 +00:00
|
|
|
|
|
|
|
if (identityKey) {
|
2023-08-10 16:43:33 +00:00
|
|
|
await updateIdentityKey(identityKey, serviceId);
|
2022-08-19 18:05:31 +00:00
|
|
|
} else {
|
2023-08-10 16:43:33 +00:00
|
|
|
await window.ConversationController.get(serviceId)?.getProfiles();
|
2022-08-19 18:05:31 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
);
|
|
|
|
|
2023-08-10 16:43:33 +00:00
|
|
|
return { untrustedServiceIds, verifiedServiceIds };
|
2022-08-19 18:05:31 +00:00
|
|
|
}
|