open-wa / wa-decrypt-nodejs Goto Github PK
View Code? Open in Web Editor NEWA lightweight implementation of the wa-automate-nodejs media decryption code for NodeJS
A lightweight implementation of the wa-automate-nodejs media decryption code for NodeJS
Describe the bug
Audio OGG decryption is losing some bytes. In every test, there is between 4 to 12 bytes trimmed off / lost. Resulting OGG from wa-decrypt is always a multiple of 16. (This is likely issue of block-mode decrypt, skipping any trailing bytes below block size (16/32 ?) .I Believe this may be the cause of the issue of losing a second from OGG sending.
Steps to Reproduce
Uploaded files for testing below:
create() code
This is the code you use to create the client. e.g
...
Expected behavior
Full OGG decrypted, without loss of bytes
DEBUG INFO
This is the info printed to the console when you start your app. It should look like this
Debug Info {
Current Release / Default settings
}
Screenshots
If applicable, add screenshots to help explain your problem. Use headless: false
to get screenshots
Host (please complete the following information):
Additional context
using php for testing (requires openssl extension / use phpfiddle.org):
$salt = base64_decode('e+nLIMCM2QRQX/Z/kT9iYkc6vQoSIHT+ZMOffiG2PlM=');
$iv = base64_decode('jOVmsDgmWsQ/gSQK/YMWcg==');
$data = substr($encoded_data, 0, -10);
$decrypted = (openssl_decrypt($data, 'aes-256-cbc', $salt, 0, $iv));
$resultOk = hash('sha256',$decrypted) == '783a377639dfc065319958aaf0f1fc9336ffc180ebcaeeca0386f2bdd58533f6';
echo $resultOk ? "ok":"failed";
message.clientUrl change to message.deprecatedMms3Url
if (!message.clientUrl ) throw new Error('message is missing critical data needed to download the file.');
to
if (!message.deprecatedMms3Url) throw new Error('message is missing critical data needed to download the file.');
id='true_41********[email protected]_3EB0201B6B3EA660A0B8';
decryptMedia = require('@open-wa/wa-decrypt').decryptMedia;
client.getMessageById(id).then(message => decryptMedia(message).then(console.log));
Promise { <pending> }
> (node:37462) UnhandledPromiseRejectionWarning: Error: Request failed with status code 404
at createError (/private/tmp/kk/node_modules/@open-wa/wa-decrypt/node_modules/axios/lib/core/createError.js:16:15)
at settle (/private/tmp/kk/node_modules/@open-wa/wa-decrypt/node_modules/axios/lib/core/settle.js:17:12)
at IncomingMessage.handleStreamEnd (/private/tmp/kk/node_modules/@open-wa/wa-decrypt/node_modules/axios/lib/adapters/http.js:236:11)
at IncomingMessage.emit (events.js:327:22)
at IncomingMessage.EventEmitter.emit (domain.js:506:15)
at endReadableNT (_stream_readable.js:1220:12)
at processTicksAndRejections (internal/process/task_queues.js:84:21)
(node:37462) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 34)
However, it works if I use this other message id:
id='true_4********[email protected]_3EB0BDAAE8FDF920D479';
Both ids are correct, with message.mimetype = "image/jpeg"
, and both images are available on the android phone.
What can be the problem?
add types | Message | boolean
then check/log issues with the message payload
request-promise-native is on the way out.
wa-decrypt-nodejs/src/decrypt.ts
Line 23 in d88b16c
I believe WA has changed something on their backend, it might be some proxy/caching artefact. Apparently it has become mandatory to include
'origin': 'https://web.whatsapp.com/',
'referer': 'https://web.whatsapp.com/'
as headers as well, otherwise the promise could be rejected with status 400 - Bad Request. Without this change the test won't pass as well (same kind of error). With the change the test saves the balls image. Afterwards it stops mattering if the headers are there or not - the request is accepted just fine.
Hi everyone!
the trouble is when access for second time to the app.
this example is with simple message (like the example webpage)
if i remove session folder and ask me to qr code scan works...
but when the session exist and no qr code needed there is the trouble :
so first time works, en second time no works.
thanks!
I am a beginner in nodejs and I am not able to decrypt image ....
could you please show me a basic example?
because when I run the example available I have the following error
root@167:/var/www/adm/services# node ../../admin/teste.js
/var/www/admin/teste.js:1
import { decryptMedia } from '@open-wa/wa-decrypt';
^
this and the script I'm using...
import { decryptMedia } from '@open-wa/wa-decrypt';
const mime = require('mime-types');
const fs = require('fs');
${message.t}.${mime.extension(message.mimetype)}
;data:${message.mimetype};base64,${mediaData.toString( 'base64' )}
;I would just like to save the received images ...
please help me
Hi,
I'm checking the source code of this project. I can see that one of the dependencies is "fs" which is listed in npm as a security problem https://www.npmjs.com/package/fs.
Why not using node fs?
I've been using the library for over 1 year and in the meantime only 1 time we've had a problem with audio files having a few seconds cut off,
however this was fixed with a fix and so far we have never had any problems with any type of media, except excel files in .xlsx format, which when going through the decrypt function it becomes corrupted.
What I could analyze and I don't know if this is the reason for the problem is that, between the original file and the file that returns from the decrypt (this comparing the base64) there is a difference at the end of the file, everything is identical except the last 15 to 25 characters.
I will attach 2 links here:
This is the original file uploaded directly:
original_file
This is the same however after going through the decrypt.
after_decrypt
I will also attach the 2 base64 files from the same files I used to analyze.
example image
txt original Base64
txt afterdecrypt base64
Once again I reinforce that I already use the same lib for all the rest of the files and none of them generates this type of error.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.