Merge branch 'master' into invalid-qr-patch

This commit is contained in:
Adhiraj Singh
2022-04-13 19:04:32 +05:30
4 changed files with 18 additions and 11 deletions

View File

@@ -6,6 +6,7 @@ const logger = MAIN_LOGGER.child({ })
logger.level = 'trace'
const useStore = !process.argv.includes('--no-store')
const doReplies = !process.argv.includes('--no-reply')
// the store maintains the data of the WA connection in memory
// can be written out to a file & read from it
@@ -59,7 +60,7 @@ const startSock = async() => {
console.log(JSON.stringify(m, undefined, 2))
const msg = m.messages[0]
if(!msg.key.fromMe && m.type === 'notify') {
if(!msg.key.fromMe && m.type === 'notify' && doReplies) {
console.log('replying to', m.messages[0].key.remoteJid)
await sock!.sendReadReceipt(msg.key.remoteJid, msg.key.participant, [msg.key.id])
await sendMessageWTyping({ text: 'Hello there!' }, msg.key.remoteJid)

View File

@@ -546,7 +546,6 @@ export const makeChatsSocket = (config: SocketConfig) => {
to: S_WHATSAPP_NET,
xmlns: 'abt',
type: 'get',
id: generateMessageTag(),
},
content: [
{ tag: 'props', attrs: { protocol: '1' } }
@@ -573,7 +572,6 @@ export const makeChatsSocket = (config: SocketConfig) => {
to: S_WHATSAPP_NET,
xmlns: 'w',
type: 'get',
id: generateMessageTag(),
},
content: [
{ tag: 'props', attrs: { } }

View File

@@ -17,7 +17,7 @@ export const makeNoiseHandler = ({ public: publicKey, private: privateKey }: Key
const authenticate = (data: Uint8Array) => {
if(!isFinished) {
hash = sha256(Buffer.from(Binary.build(hash, data).readByteArray()))
hash = sha256(Buffer.concat([hash, data]))
}
}
@@ -83,7 +83,7 @@ export const makeNoiseHandler = ({ public: publicKey, private: privateKey }: Key
isFinished = true
}
const data = Binary.build(NOISE_MODE).readBuffer()
const data = Buffer.from(NOISE_MODE)
let hash = Buffer.from(data.byteLength === 32 ? data : sha256(Buffer.from(data)))
let salt = hash
let encKey = hash

View File

@@ -3,7 +3,7 @@ import { createHash } from 'crypto'
import { proto } from '../../WAProto'
import { KEY_BUNDLE_TYPE } from '../Defaults'
import type { AuthenticationCreds, SignalCreds, SocketConfig } from '../Types'
import { Binary, BinaryNode, getBinaryNodeChild, jidDecode, S_WHATSAPP_NET } from '../WABinary'
import { BinaryNode, getBinaryNodeChild, jidDecode, S_WHATSAPP_NET } from '../WABinary'
import { Curve, hmacSign } from './crypto'
import { encodeBigEndian } from './generics'
import { createSignalIdentity } from './signal'
@@ -124,18 +124,26 @@ export const configureSuccessfulPairing = (
const account = proto.ADVSignedDeviceIdentity.decode(details)
const { accountSignatureKey, accountSignature } = account
const accountMsg = Binary.build(new Uint8Array([6, 0]), account.details, signedIdentityKey.public).readByteArray()
const accountMsg = Buffer.concat([
Buffer.from([6, 0]),
account.details,
signedIdentityKey.public
])
if(!Curve.verify(accountSignatureKey, accountMsg, accountSignature)) {
throw new Boom('Failed to verify account signature')
}
const deviceMsg = Buffer.concat([
new Uint8Array([6, 1]),
account.details,
signedIdentityKey.public,
account.accountSignatureKey
])
account.deviceSignature = Curve.sign(signedIdentityKey.private, deviceMsg)
const identity = createSignalIdentity(jid, accountSignatureKey)
const deviceIdentity = proto.ADVDeviceIdentity.decode(account.details)
const keyIndex = deviceIdentity.keyIndex
const deviceMsg = Binary.build(new Uint8Array([6, 1]), account.details, signedIdentityKey.public, account.accountSignatureKey).readByteArray()
account.deviceSignature = Curve.sign(signedIdentityKey.private, deviceMsg)
delete account.accountSignatureKey
const accountEnc = proto.ADVSignedDeviceIdentity.encode(account).finish()