signal,messages-send,libsignal: properly parse and ignore hosted devices
This commit is contained in:
@@ -332,6 +332,10 @@ const jidToSignalProtocolAddress = (jid: string): libsignal.ProtocolAddress => {
|
|||||||
const signalUser = domainType !== WAJIDDomains.WHATSAPP ? `${user}_${domainType}` : user
|
const signalUser = domainType !== WAJIDDomains.WHATSAPP ? `${user}_${domainType}` : user
|
||||||
const finalDevice = device || 0
|
const finalDevice = device || 0
|
||||||
|
|
||||||
|
if (device == 99 && decoded.server !== 'hosted' && decoded.server !== 'hosted.lid') {
|
||||||
|
throw new Error('Unexpected non-hosted device JID with device 99. This ID seems invalid. ID:' + jid)
|
||||||
|
}
|
||||||
|
|
||||||
return new libsignal.ProtocolAddress(signalUser, finalDevice)
|
return new libsignal.ProtocolAddress(signalUser, finalDevice)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -279,7 +279,7 @@ export const makeMessagesSocket = (config: SocketConfig) => {
|
|||||||
|
|
||||||
const requestedLidUsers = new Set<string>()
|
const requestedLidUsers = new Set<string>()
|
||||||
for (const jid of toFetch) {
|
for (const jid of toFetch) {
|
||||||
if (jid.includes('@lid')) {
|
if (jid.includes('@lid') || jid.includes('@hosted.lid')) {
|
||||||
const user = jidDecode(jid)?.user
|
const user = jidDecode(jid)?.user
|
||||||
if (user) requestedLidUsers.add(user)
|
if (user) requestedLidUsers.add(user)
|
||||||
}
|
}
|
||||||
@@ -301,7 +301,12 @@ export const makeMessagesSocket = (config: SocketConfig) => {
|
|||||||
await signalRepository.lidMapping.storeLIDPNMappings(lidResults.map(a => ({ lid: a.lid as string, pn: a.id })))
|
await signalRepository.lidMapping.storeLIDPNMappings(lidResults.map(a => ({ lid: a.lid as string, pn: a.id })))
|
||||||
}
|
}
|
||||||
|
|
||||||
const extracted = extractDeviceJids(result?.list, authState.creds.me!.id, ignoreZeroDevices)
|
const extracted = extractDeviceJids(
|
||||||
|
result?.list,
|
||||||
|
authState.creds.me!.id,
|
||||||
|
authState.creds.me!.lid!,
|
||||||
|
ignoreZeroDevices
|
||||||
|
)
|
||||||
const deviceMap: { [_: string]: FullJid[] } = {}
|
const deviceMap: { [_: string]: FullJid[] } = {}
|
||||||
|
|
||||||
for (const item of extracted) {
|
for (const item of extracted) {
|
||||||
@@ -316,8 +321,8 @@ export const makeMessagesSocket = (config: SocketConfig) => {
|
|||||||
// Process all devices for this user
|
// Process all devices for this user
|
||||||
for (const item of userDevices) {
|
for (const item of userDevices) {
|
||||||
const finalJid = isLidUser
|
const finalJid = isLidUser
|
||||||
? jidEncode(user, item.server === 'hosted' ? 'hosted.lid' : 'lid', item.device)
|
? jidEncode(user, item.server, item.device, item.domainType)
|
||||||
: jidEncode(item.user, item.server === 'hosted' ? 'hosted' : 's.whatsapp.net', item.device)
|
: jidEncode(item.user, item.server, item.device, item.domainType)
|
||||||
|
|
||||||
deviceResults.push({
|
deviceResults.push({
|
||||||
...item,
|
...item,
|
||||||
@@ -699,7 +704,12 @@ export const makeMessagesSocket = (config: SocketConfig) => {
|
|||||||
for (const device of devices) {
|
for (const device of devices) {
|
||||||
const deviceJid = device.jid
|
const deviceJid = device.jid
|
||||||
const hasKey = !!senderKeyMap[deviceJid]
|
const hasKey = !!senderKeyMap[deviceJid]
|
||||||
if ((!hasKey || !!participant) && !isJidHostedLidUser(deviceJid) && !isJidHostedPnUser(deviceJid)) {
|
if (
|
||||||
|
(!hasKey || !!participant) &&
|
||||||
|
!isJidHostedLidUser(deviceJid) &&
|
||||||
|
!isJidHostedPnUser(deviceJid) &&
|
||||||
|
device.device !== 99
|
||||||
|
) {
|
||||||
//todo: revamp all this logic
|
//todo: revamp all this logic
|
||||||
// the goal is to follow with what I said above for each group, and instead of a true false map of ids, we can set an array full of those the app has already sent pkmsgs
|
// the goal is to follow with what I said above for each group, and instead of a true false map of ids, we can set an array full of those the app has already sent pkmsgs
|
||||||
senderKeyRecipients.push(deviceJid)
|
senderKeyRecipients.push(deviceJid)
|
||||||
|
|||||||
+11
-6
@@ -17,7 +17,8 @@ import {
|
|||||||
getBinaryNodeChildren,
|
getBinaryNodeChildren,
|
||||||
getBinaryNodeChildUInt,
|
getBinaryNodeChildUInt,
|
||||||
jidDecode,
|
jidDecode,
|
||||||
S_WHATSAPP_NET
|
S_WHATSAPP_NET,
|
||||||
|
WAJIDDomains
|
||||||
} from '../WABinary'
|
} from '../WABinary'
|
||||||
import type { DeviceListData, ParsedDeviceInfo, USyncQueryResultList } from '../WAUSync'
|
import type { DeviceListData, ParsedDeviceInfo, USyncQueryResultList } from '../WAUSync'
|
||||||
import { Curve, generateSignalPubKey } from './crypto'
|
import { Curve, generateSignalPubKey } from './crypto'
|
||||||
@@ -131,24 +132,28 @@ export const parseAndInjectE2ESessions = async (node: BinaryNode, repository: Si
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const extractDeviceJids = (result: USyncQueryResultList[], myJid: string, excludeZeroDevices: boolean) => {
|
export const extractDeviceJids = (
|
||||||
|
result: USyncQueryResultList[],
|
||||||
|
myJid: string,
|
||||||
|
myLid: string,
|
||||||
|
excludeZeroDevices: boolean
|
||||||
|
) => {
|
||||||
const { user: myUser, device: myDevice } = jidDecode(myJid)!
|
const { user: myUser, device: myDevice } = jidDecode(myJid)!
|
||||||
|
|
||||||
const extracted: FullJid[] = []
|
const extracted: FullJid[] = []
|
||||||
|
|
||||||
for (const userResult of result) {
|
for (const userResult of result) {
|
||||||
// TODO: ADD SUPPORT FOR HOSTED JIDS
|
|
||||||
const { devices, id } = userResult as { devices: ParsedDeviceInfo; id: string }
|
const { devices, id } = userResult as { devices: ParsedDeviceInfo; id: string }
|
||||||
const { user } = jidDecode(id)!
|
const { user, domainType, server } = jidDecode(id)!
|
||||||
const deviceList = devices?.deviceList as DeviceListData[]
|
const deviceList = devices?.deviceList as DeviceListData[]
|
||||||
if (Array.isArray(deviceList)) {
|
if (Array.isArray(deviceList)) {
|
||||||
for (const { id: device, keyIndex, isHosted } of deviceList) {
|
for (const { id: device, keyIndex, isHosted } of deviceList) {
|
||||||
if (
|
if (
|
||||||
(!excludeZeroDevices || device !== 0) && // if zero devices are not-excluded, or device is non zero
|
(!excludeZeroDevices || device !== 0) && // if zero devices are not-excluded, or device is non zero
|
||||||
(myUser !== user || myDevice !== device) && // either different user or if me user, not this device
|
((myUser !== user && myLid !== user) || myDevice !== device) && // either different user or if me user, not this device
|
||||||
(device === 0 || !!keyIndex) // ensure that "key-index" is specified for "non-zero" devices, produces a bad req otherwise
|
(device === 0 || !!keyIndex) // ensure that "key-index" is specified for "non-zero" devices, produces a bad req otherwise
|
||||||
) {
|
) {
|
||||||
extracted.push({ user, device, server: isHosted ? 'hosted' : 's.whatsapp.net' })
|
extracted.push({ user, device, domainType, server })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user