MessageReceiver: Extract cipherTextBytes/Type from non-sealed messages
This commit is contained in:
parent
ec3a3bd7b2
commit
0bb0e6e9fc
1 changed files with 27 additions and 6 deletions
|
@ -14,6 +14,7 @@ import type {
|
||||||
UnidentifiedSenderMessageContent,
|
UnidentifiedSenderMessageContent,
|
||||||
} from '@signalapp/signal-client';
|
} from '@signalapp/signal-client';
|
||||||
import {
|
import {
|
||||||
|
CiphertextMessageType,
|
||||||
DecryptionErrorMessage,
|
DecryptionErrorMessage,
|
||||||
groupDecrypt,
|
groupDecrypt,
|
||||||
PlaintextContent,
|
PlaintextContent,
|
||||||
|
@ -116,7 +117,8 @@ type UnsealedEnvelope = Readonly<
|
||||||
unidentifiedDeliveryReceived?: boolean;
|
unidentifiedDeliveryReceived?: boolean;
|
||||||
contentHint?: number;
|
contentHint?: number;
|
||||||
groupId?: string;
|
groupId?: string;
|
||||||
usmc?: UnidentifiedSenderMessageContent;
|
cipherTextBytes?: Uint8Array;
|
||||||
|
cipherTextType?: number;
|
||||||
certificate?: SenderCertificate;
|
certificate?: SenderCertificate;
|
||||||
unsealedContent?: UnidentifiedSenderMessageContent;
|
unsealedContent?: UnidentifiedSenderMessageContent;
|
||||||
}
|
}
|
||||||
|
@ -1128,7 +1130,11 @@ export default class MessageReceiver
|
||||||
}
|
}
|
||||||
|
|
||||||
if (envelope.type !== Proto.Envelope.Type.UNIDENTIFIED_SENDER) {
|
if (envelope.type !== Proto.Envelope.Type.UNIDENTIFIED_SENDER) {
|
||||||
return envelope;
|
return {
|
||||||
|
...envelope,
|
||||||
|
cipherTextBytes: envelope.content,
|
||||||
|
cipherTextType: envelopeTypeToCiphertextType(envelope.type),
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (uuidKind === UUIDKind.PNI) {
|
if (uuidKind === UUIDKind.PNI) {
|
||||||
|
@ -1160,6 +1166,9 @@ export default class MessageReceiver
|
||||||
const newEnvelope: UnsealedEnvelope = {
|
const newEnvelope: UnsealedEnvelope = {
|
||||||
...envelope,
|
...envelope,
|
||||||
|
|
||||||
|
cipherTextBytes: messageContent.contents(),
|
||||||
|
cipherTextType: messageContent.msgType(),
|
||||||
|
|
||||||
// Overwrite Envelope fields
|
// Overwrite Envelope fields
|
||||||
source: dropNull(certificate.senderE164()),
|
source: dropNull(certificate.senderE164()),
|
||||||
sourceUuid: normalizeUuid(
|
sourceUuid: normalizeUuid(
|
||||||
|
@ -1172,7 +1181,6 @@ export default class MessageReceiver
|
||||||
unidentifiedDeliveryReceived: !(originalSource || originalSourceUuid),
|
unidentifiedDeliveryReceived: !(originalSource || originalSourceUuid),
|
||||||
contentHint: messageContent.contentHint(),
|
contentHint: messageContent.contentHint(),
|
||||||
groupId: messageContent.groupId()?.toString('base64'),
|
groupId: messageContent.groupId()?.toString('base64'),
|
||||||
usmc: messageContent,
|
|
||||||
certificate,
|
certificate,
|
||||||
unsealedContent: messageContent,
|
unsealedContent: messageContent,
|
||||||
};
|
};
|
||||||
|
@ -1660,11 +1668,11 @@ export default class MessageReceiver
|
||||||
}
|
}
|
||||||
|
|
||||||
if (uuid && deviceId) {
|
if (uuid && deviceId) {
|
||||||
const { usmc } = envelope;
|
const { cipherTextBytes, cipherTextType } = envelope;
|
||||||
const event = new DecryptionErrorEvent(
|
const event = new DecryptionErrorEvent(
|
||||||
{
|
{
|
||||||
cipherTextBytes: usmc ? usmc.contents() : undefined,
|
cipherTextBytes,
|
||||||
cipherTextType: usmc ? usmc.msgType() : undefined,
|
cipherTextType,
|
||||||
contentHint: envelope.contentHint,
|
contentHint: envelope.contentHint,
|
||||||
groupId: envelope.groupId,
|
groupId: envelope.groupId,
|
||||||
receivedAtCounter: envelope.receivedAtCounter,
|
receivedAtCounter: envelope.receivedAtCounter,
|
||||||
|
@ -2782,3 +2790,16 @@ export default class MessageReceiver
|
||||||
return processDataMessage(decrypted, envelope.timestamp);
|
return processDataMessage(decrypted, envelope.timestamp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function envelopeTypeToCiphertextType(type: number | undefined): number {
|
||||||
|
if (type === Proto.Envelope.Type.CIPHERTEXT) {
|
||||||
|
return CiphertextMessageType.Whisper;
|
||||||
|
}
|
||||||
|
if (type === Proto.Envelope.Type.PLAINTEXT_CONTENT) {
|
||||||
|
return CiphertextMessageType.Plaintext;
|
||||||
|
}
|
||||||
|
if (type === Proto.Envelope.Type.PREKEY_BUNDLE) {
|
||||||
|
return CiphertextMessageType.PreKey;
|
||||||
|
}
|
||||||
|
throw new Error(`envelopeTypeToCiphertextType: Unknown type ${type}`);
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue