mobile: deprecation.

This commit is contained in:
Rajeh Taher
2024-10-14 03:39:46 +03:00
parent 647f8d767f
commit 61a0ff3178
18 changed files with 47 additions and 533 deletions

View File

@@ -1,7 +1,6 @@
import { randomBytes } from 'crypto'
import NodeCache from 'node-cache'
import type { Logger } from 'pino'
import { v4 as uuidv4 } from 'uuid'
import { DEFAULT_CACHE_TTLS } from '../Defaults'
import type { AuthenticationCreds, CacheStore, SignalDataSet, SignalDataTypeMap, SignalKeyStore, SignalKeyStoreWithTransaction, TransactionCapabilityOptions } from '../Types'
import { Curve, signedKeyPair } from './crypto'
@@ -208,13 +207,6 @@ export const initAuthCreds = (): AuthenticationCreds => {
accountSettings: {
unarchiveChats: false
},
// mobile creds
deviceId: Buffer.from(uuidv4().replace(/-/g, ''), 'hex').toString('base64url'),
phoneId: uuidv4(),
identityId: randomBytes(20),
registered: false,
backupToken: randomBytes(20),
registration: {} as never,
pairingCode: undefined,
lastPropHash: undefined,
routingInfo: undefined,

View File

@@ -16,13 +16,11 @@ const generateIV = (counter: number) => {
export const makeNoiseHandler = ({
keyPair: { private: privateKey, public: publicKey },
NOISE_HEADER,
mobile,
logger,
routingInfo
}: {
keyPair: KeyPair
NOISE_HEADER: Uint8Array
mobile: boolean
logger: Logger
routingInfo?: Buffer | undefined
}) => {
@@ -113,16 +111,12 @@ export const makeNoiseHandler = ({
const certDecoded = decrypt(serverHello!.payload!)
if(mobile) {
proto.CertChain.NoiseCertificate.decode(certDecoded)
} else {
const { intermediate: certIntermediate } = proto.CertChain.decode(certDecoded)
const { intermediate: certIntermediate } = proto.CertChain.decode(certDecoded)
const { issuerSerial } = proto.CertChain.NoiseCertificate.Details.decode(certIntermediate!.details!)
const { issuerSerial } = proto.CertChain.NoiseCertificate.Details.decode(certIntermediate!.details!)
if(issuerSerial !== WA_CERT_DETAILS.SERIAL) {
throw new Boom('certification match failed', { statusCode: 400 })
}
if(issuerSerial !== WA_CERT_DETAILS.SERIAL) {
throw new Boom('certification match failed', { statusCode: 400 })
}
const keyEnc = encrypt(noiseKey.public)
@@ -183,11 +177,11 @@ export const makeNoiseHandler = ({
inBytes = inBytes.slice(size + 3)
if(isFinished) {
const result = decrypt(frame as Uint8Array)
const result = decrypt(frame)
frame = await decodeBinaryNode(result)
}
logger.trace({ msg: (frame as any)?.attrs?.id }, 'recv frame')
logger.trace({ msg: (frame as BinaryNode)?.attrs?.id }, 'recv frame')
onFrame(frame)
size = getBytesSize()

View File

@@ -9,30 +9,20 @@ import { encodeBigEndian } from './generics'
import { createSignalIdentity } from './signal'
const getUserAgent = (config: SocketConfig): proto.ClientPayload.IUserAgent => {
const osVersion = config.mobile ? '15.3.1' : '0.1'
const version = config.mobile ? [2, 24, 6] : config.version
const device = config.mobile ? 'iPhone_7' : 'Desktop'
const manufacturer = config.mobile ? 'Apple' : ''
const platform = config.mobile ? proto.ClientPayload.UserAgent.Platform.IOS : proto.ClientPayload.UserAgent.Platform.WEB
const phoneId = config.mobile ? { phoneId: config.auth.creds.phoneId } : {}
return {
appVersion: {
primary: version[0],
secondary: version[1],
tertiary: version[2],
primary: config.version[0],
secondary: config.version[1],
tertiary: config.version[2],
},
platform,
platform: proto.ClientPayload.UserAgent.Platform.WEB,
releaseChannel: proto.ClientPayload.UserAgent.ReleaseChannel.RELEASE,
mcc: config.auth.creds.registration?.phoneNumberMobileCountryCode || '000',
mnc: config.auth.creds.registration?.phoneNumberMobileNetworkCode || '000',
osVersion: osVersion,
manufacturer,
device,
osBuildNumber: osVersion,
osVersion: '0.1',
device: 'Desktop',
osBuildNumber: '0.1',
localeLanguageIso6391: 'en',
localeCountryIso31661Alpha2: 'US',
...phoneId
localeCountryIso31661Alpha2: 'US'
}
}
@@ -58,34 +48,11 @@ const getClientPayload = (config: SocketConfig) => {
userAgent: getUserAgent(config),
}
if(!config.mobile) {
payload.webInfo = getWebInfo(config)
}
payload.webInfo = getWebInfo(config)
return payload
}
export const generateMobileNode = (config: SocketConfig): proto.IClientPayload => {
if(!config.auth.creds) {
throw new Boom('No registration data found', { data: config })
}
const payload: proto.IClientPayload = {
...getClientPayload(config),
sessionId: Math.floor(Math.random() * 999999999 + 1),
shortConnect: true,
connectAttemptCount: 0,
device: 0,
dnsSource: {
appCached: false,
dnsMethod: proto.ClientPayload.DNSSource.DNSResolutionMethod.SYSTEM,
},
passive: false, // XMPP heartbeat setting (false: server actively pings) (true: client actively pings)
pushName: 'test',
username: Number(`${config.auth.creds.registration.phoneNumberCountryCode}${config.auth.creds.registration.phoneNumberNationalNumber}`),
}
return proto.ClientPayload.fromObject(payload)
}
export const generateLoginNode = (userJid: string, config: SocketConfig): proto.IClientPayload => {
const { user, device } = jidDecode(userJid)!