0
4

1 回答 1

0

这是使用带有 NodeJS 的苹果商务聊天 API 解决解密问题的更新。主要问题是在发送到 Apple 进行解码之前将解密的数据转换为缓冲区。

const decryptKeyFromInteractiveRef = "03f30ff3d3d03dc3".toUpperCase()

async function main(decryptKeyFromInteractiveRef) {

const url = await preDownloadUrl();

const data = await downloadPayload(url);

const decipheredData = await decipherInteractiveRef(data);

const decodedData = await appleDecode(decipheredData);
console.log("Finally your data", decodedData);

async function appleDecode(decipheredData) {

    var config = {
        method: 'post',
        url: 'https://mspgw.push.apple.com/v1/decodePayload',
        headers: {
            "Authorization": Authorization,
            "bid": "com.apple.messages.MSMessageExtensionBalloonPlugin:0000000000:com.apple.icloud.apps.messages.business.extension",
            "source-id": BIZ_ID,
            "accept": "*/*",
            "accept-encoding": "gzip, deflate",
            'Content-Type': 'application/octet-stream'
        },
        data: decipheredData
    };

    const { data } = await axios(config);
    const path = Path.resolve(__dirname, 'images', 'data.json')
    fs.writeFileSync(path, JSON.stringify(data))
}


async function decipherInteractiveRef() {

    const iv = Buffer.alloc(16); // buffer alloc fills with zeros
    const key = Buffer.from(decryptKey.slice(2), 'hex',);
    const decipher = crypto.createDecipheriv("aes-256-ctr", key, iv);
    decipher.setAutoPadding(false); // No Padding
    let decrypted = decipher.update(data); // if input is a buffer dont choose a encoding

    return decrypted;
}


async function preDownloadUrl() {
    //Using the fields in the received interactiveDataRef key, 
    // retrieve the URL to the payload by calling the /preDownload endpoint.

    //interactiveDataRef key
    const signatureHex = "81101cc048b6b588c895f01c12715421f9d0a25329".toUpperCase()
    const signature = Buffer.from(signatureHex, 'hex').toString('base64')

    var configInteractiveRef = {
        method: 'get',
        url: 'https://mspgw.push.apple.com/v1/preDownload',
        headers: {
            'Authorization': Authorization,
            'source-id': BIZ_ID,
            'MMCS-Url': 'https://p56-content.icloud.com/MZ02db38070edccb2ce8c972efdcdd25437439745cad6f15473bb7880d436377702752e134be8bd3b4d695567a5d574142.C01USN00',
            'MMCS-Signature': signature,
            'MMCS-Owner': 'MZ02db38070edccb2ce8c972efdcdd25437439745cad6f15473bb7880d436377702752e134be8bd3b4d695567a5d574142.C01USN00'
        }
    };

    const response = await axios(configInteractiveRef)
    return response.data["download-url"];
}

// download big payload from apple
async function downloadPayload(url) {
    const { data } = await axios.get(url, { responseType: 'arraybuffer' });
    return data
}}
于 2021-12-13T13:09:10.510 回答