diff --git a/src/Defaults/index.ts b/src/Defaults/index.ts index 1f0926a..e557e54 100644 --- a/src/Defaults/index.ts +++ b/src/Defaults/index.ts @@ -13,18 +13,18 @@ export const PHONE_CONNECTION_CB = 'CB:Pong' export const WA_DEFAULT_EPHEMERAL = 7 * 24 * 60 * 60 export const NOISE_MODE = 'Noise_XX_25519_AESGCM_SHA256\0\0\0\0' -export const DICT_VERSION = Buffer.from([2]) +export const DICT_VERSION = 2 export const KEY_BUNDLE_TYPE = Buffer.from([5]) -export const NOISE_WA_HEADER = Buffer.concat( - [ - Buffer.from('WA', 'ascii'), - KEY_BUNDLE_TYPE, - DICT_VERSION - ] +export const NOISE_WA_HEADER = Buffer.from( + [ 87, 65, 6, DICT_VERSION ] ) // last is "DICT_VERSION" /** from: https://stackoverflow.com/questions/3809401/what-is-a-good-regular-expression-to-match-a-url */ export const URL_REGEX = /[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_+.~#?&//=]*)?/gi +export const WA_CERT_DETAILS = { + SERIAL: 0, +} + const BASE_CONNECTION_CONFIG: CommonSocketConfig = { version: version as any, browser: Browsers.baileys('Chrome'), diff --git a/src/Utils/noise-handler.ts b/src/Utils/noise-handler.ts index 079b2aa..7eb92ba 100644 --- a/src/Utils/noise-handler.ts +++ b/src/Utils/noise-handler.ts @@ -2,7 +2,7 @@ import { Boom } from '@hapi/boom' import { createCipheriv, createDecipheriv } from 'crypto' import { Logger } from 'pino' import { proto } from '../../WAProto' -import { NOISE_MODE, NOISE_WA_HEADER } from '../Defaults' +import { NOISE_MODE, NOISE_WA_HEADER, WA_CERT_DETAILS } from '../Defaults' import { KeyPair } from '../Types' import { BinaryNode, decodeBinaryNode } from '../WABinary' import { Curve, hkdf, sha256 } from './crypto' @@ -117,11 +117,11 @@ export const makeNoiseHandler = ( mixIntoKey(Curve.sharedKey(privateKey, decStaticContent)) const certDecoded = decrypt(serverHello!.payload!) - const { details: certDetails } = proto.NoiseCertificate.decode(certDecoded) + const { intermediate: certIntermediate } = proto.CertChain.decode(certDecoded) - const { key: certKey } = proto.NoiseCertificateDetails.decode(certDetails) + const { issuerSerial } = proto.Details.decode(certIntermediate!.details!) - if(Buffer.compare(decStaticContent, certKey) !== 0) { + if(issuerSerial !== WA_CERT_DETAILS.SERIAL) { throw new Boom('certification match failed', { statusCode: 400 }) }