yowsup icon indicating copy to clipboard operation
yowsup copied to clipboard

Media download stoped working

Open eduardosan opened this issue 8 years ago • 3 comments

Hi,

Just merged your branch on tgalal's new release (v2.5.0) and everything seems to be working fine. However, I can't decrypt media files anymore. The content returns as data, even inserting the methods from your code. Take a look at tgalal's MediaDownloadable:

https://github.com/tgalal/yowsup/blob/master/yowsup/layers/protocol_media/protocolentities/message_media_downloadable.py

I just added the method to decrypt media content, like this:

    def decrypt(self, encimg, refkey):
        derivative = HKDFv3().deriveSecrets(refkey, binascii.unhexlify(self.cryptKeys), 112)
        parts = ByteUtil.split(derivative, 16, 32)
        iv = parts[0]
        cipherKey = parts[1]
        e_img = encimg[:-10]
        AES.key_size=128
        cr_obj = AES.new(key=cipherKey,mode=AES.MODE_CBC,IV=iv)
        return cr_obj.decrypt(e_img)

    def isEncrypted(self):
        return self.cryptKeys and self.mediaKey

    def getMediaContent(self):
        data = urlopen(self.url).read()
        if self.isEncrypted():
            data = self.decrypt(data, self.mediaKey)
        return bytearray(data)

I try to write decrypted output like this:

with open(path, "wb") as f:
                f.write(entity.getMediaContent())

When I try to open a media downloaded file and write its contents as JPEG, it seems like the file is wrongly decrypted:

file /media/images/2016/4/2/3EB04D9120B3C89FDC44.jpeg
projects/whatsapp/media/images/2016/4/2/3EB04D9120B3C89FDC44.jpeg: data

Linux can't recognize it as JPEG image.

Am I missing something in encryption? It also seems like your method is different from Chat-API:

https://github.com/mgp25/Chat-API/blob/master/src/handlers/MessageHandler.php#L443

Chat API uses a pkcs5_unpad on decrypted content. However, even if I try to do the same, the image can't still be read.

Can you provide me some directions about how to decrypt the image? Funny thing is that it seems to be still working in your branch, even knowing that your code looks compatible with tgalal's

eduardosan avatar May 24 '16 21:05 eduardosan

encountered the same problem. Any solutions regarding this issue?

oip976 avatar Jul 09 '16 02:07 oip976

You have to add

"mediakey": imageMessage.media_key

in the ProtocolTreeNode of handleImageMessage in layers/axolotl/layer_receive.py

dazzzl avatar Jul 25 '16 16:07 dazzzl

thanks dazzl but There's another problem in derivative = HKDFv3().deriveSecrets (...............) I am not able to get self.cryptKeys

charanjit-singh avatar Dec 17 '17 10:12 charanjit-singh