Fetch PNI group credentials

This commit is contained in:
Fedor Indutny 2022-07-08 13:46:25 -07:00 committed by GitHub
parent b9ba732724
commit a450e13a99
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
61 changed files with 1911 additions and 875 deletions

View file

@ -5,7 +5,7 @@ import PQueue from 'p-queue';
import { omit } from 'lodash';
import EventTarget from './EventTarget';
import type { WebAPIType, GroupCredentialType } from './WebAPI';
import type { WebAPIType } from './WebAPI';
import { HTTPError } from './Errors';
import type { KeyPairType } from './Types.d';
import ProvisioningCipher from './ProvisioningCipher';
@ -755,14 +755,6 @@ export default class AccountManager extends EventTarget {
});
}
async getGroupCredentials(
startDay: number,
endDay: number,
uuidKind: UUIDKind
): Promise<Array<GroupCredentialType>> {
return this.server.getGroupCredentials(startDay, endDay, uuidKind);
}
// Takes the same object returned by generateKeys
async confirmKeys(
keys: GeneratedKeysType,

View file

@ -759,7 +759,9 @@ export default class MessageReceiver
// Proto.Envelope fields
type: decoded.type,
source: decoded.source || item.source,
sourceUuid: decoded.sourceUuid || item.sourceUuid,
sourceUuid: decoded.sourceUuid
? UUID.cast(decoded.sourceUuid)
: item.sourceUuid,
sourceDevice: decoded.sourceDevice || item.sourceDevice,
destinationUuid: new UUID(
decoded.destinationUuid || item.destinationUuid || ourUuid.toString()

View file

@ -3,7 +3,7 @@
import type { SignalService as Proto } from '../protobuf';
import type { IncomingWebSocketRequest } from './WebsocketResources';
import type { UUID } from '../types/UUID';
import type { UUID, UUIDStringType } from '../types/UUID';
import type { TextAttachmentType } from '../types/Attachment';
import { GiftBadgeStates } from '../components/conversation/Message';
import { MIMEType } from '../types/MIME';
@ -84,7 +84,7 @@ export type ProcessedEnvelope = Readonly<{
// Mostly from Proto.Envelope except for null/undefined
type: Proto.Envelope.Type;
source?: string;
sourceUuid?: string;
sourceUuid?: UUIDStringType;
sourceDevice?: number;
destinationUuid: UUID;
timestamp: number;

View file

@ -490,7 +490,7 @@ const URL_CALLS = {
directoryAuthV2: 'v2/directory/auth',
discovery: 'v1/discovery',
getGroupAvatarUpload: 'v1/groups/avatar/form',
getGroupCredentials: 'v1/certificate/group',
getGroupCredentials: 'v1/certificate/auth/group',
getIceServers: 'v1/accounts/turn',
getStickerPackUpload: 'v1/sticker/pack/form',
groupLog: 'v1/groups/logs',
@ -718,6 +718,9 @@ export type ProfileType = Readonly<{
unrestrictedUnidentifiedAccess?: string;
uuid?: string;
credential?: string;
// Only present when `credentialType` is `pni`
pniCredential?: string;
capabilities?: CapabilitiesType;
paymentAddress?: string;
badges?: unknown;
@ -769,7 +772,7 @@ export type GetUuidsForE164sV2OptionsType = Readonly<{
type GetProfileCommonOptionsType = Readonly<
{
userLanguages: ReadonlyArray<string>;
credentialType?: 'pni' | 'profileKey';
credentialType?: 'pni' | 'expiringProfileKey';
} & (
| {
profileKeyVersion?: undefined;
@ -792,6 +795,11 @@ export type GetProfileUnauthOptionsType = GetProfileCommonOptionsType &
accessKey: string;
}>;
export type GetGroupCredentialsOptionsType = Readonly<{
startDayInMs: number;
endDayInMs: number;
}>;
export type WebAPIType = {
startRegistration(): unknown;
finishRegistration(baton: unknown): void;
@ -819,9 +827,7 @@ export type WebAPIType = {
) => Promise<Proto.GroupJoinInfo>;
getGroupAvatar: (key: string) => Promise<Uint8Array>;
getGroupCredentials: (
startDay: number,
endDay: number,
uuidKind: UUIDKind
options: GetGroupCredentialsOptionsType
) => Promise<Array<GroupCredentialType>>;
getGroupExternalCredential: (
options: GroupCredentialsType
@ -1580,7 +1586,7 @@ export function initialize({
{
profileKeyVersion,
profileKeyCredentialRequest,
credentialType = 'profileKey',
credentialType = 'expiringProfileKey',
}: GetProfileCommonOptionsType
) {
let profileUrl = `/${identifier}`;
@ -2509,14 +2515,17 @@ export function initialize({
credentials: Array<GroupCredentialType>;
};
async function getGroupCredentials(
startDay: number,
endDay: number,
uuidKind: UUIDKind
): Promise<Array<GroupCredentialType>> {
async function getGroupCredentials({
startDayInMs,
endDayInMs,
}: GetGroupCredentialsOptionsType): Promise<Array<GroupCredentialType>> {
const startDayInSeconds = startDayInMs / durations.SECOND;
const endDayInSeconds = endDayInMs / durations.SECOND;
const response = (await _ajax({
call: 'getGroupCredentials',
urlParameters: `/${startDay}/${endDay}?${uuidKindToQuery(uuidKind)}`,
urlParameters:
`?redemptionStartSeconds=${startDayInSeconds}&` +
`redemptionEndSeconds=${endDayInSeconds}`,
httpType: 'GET',
responseType: 'json',
})) as CredentialResponseType;

View file

@ -5,6 +5,7 @@
import type { PublicKey } from '@signalapp/libsignal-client';
import type { SignalService as Proto } from '../protobuf';
import type { UUIDStringType } from '../types/UUID';
import type {
ProcessedEnvelope,
ProcessedDataMessage,
@ -129,7 +130,7 @@ export type DeliveryEventData = Readonly<{
timestamp: number;
envelopeTimestamp: number;
source?: string;
sourceUuid?: string;
sourceUuid?: UUIDStringType;
sourceDevice?: number;
}>;
@ -166,7 +167,7 @@ export class DecryptionErrorEvent extends ConfirmableEvent {
export type RetryRequestEventData = Readonly<{
groupId?: string;
ratchetKey?: PublicKey;
requesterUuid: string;
requesterUuid: UUIDStringType;
requesterDevice: number;
senderDevice: number;
sentAt: number;
@ -204,7 +205,7 @@ export class SentEvent extends ConfirmableEvent {
export type ProfileKeyUpdateData = Readonly<{
source?: string;
sourceUuid?: string;
sourceUuid?: UUIDStringType;
profileKey: string;
}>;
@ -219,7 +220,7 @@ export class ProfileKeyUpdateEvent extends ConfirmableEvent {
export type MessageEventData = Readonly<{
source?: string;
sourceUuid?: string;
sourceUuid?: UUIDStringType;
sourceDevice?: number;
timestamp: number;
serverGuid?: string;
@ -243,7 +244,7 @@ export type ReadOrViewEventData = Readonly<{
timestamp: number;
envelopeTimestamp: number;
source?: string;
sourceUuid?: string;
sourceUuid?: UUIDStringType;
sourceDevice?: number;
}>;
@ -276,14 +277,14 @@ export class ConfigurationEvent extends ConfirmableEvent {
export type ViewOnceOpenSyncOptions = {
source?: string;
sourceUuid?: string;
sourceUuid?: UUIDStringType;
timestamp?: number;
};
export class ViewOnceOpenSyncEvent extends ConfirmableEvent {
public readonly source?: string;
public readonly sourceUuid?: string;
public readonly sourceUuid?: UUIDStringType;
public readonly timestamp?: number;