Remote files are now encrypted. To get image content, use message.getMediaContent() from master in my fork.
Sorry.don't understand well. I use your master. Which layer will I have to
modify?
Sorry for the noob question ;)
Thorsten Fröhlich
Am 03.04.2016 18:22 schrieb "jlguardi" [email protected]:
Remote files are now encrypted. To get image content, use
message.getMediaContent() from master in my fork.—
You are receiving this because you authored the thread.
Reply to this email directly or view it on GitHub
https://github.com/tgalal/yowsup/issues/1449#issuecomment-205006717
Just to explain something regarding the [email protected]. this is a xmpp
muc not the irc channel. Would highly appreciate to meet u there. Do u use
xmpp?
Thorsten Fröhlich
Am 03.04.2016 18:22 schrieb "jlguardi" [email protected]:
Remote files are now encrypted. To get image content, use
message.getMediaContent() from master in my fork.—
You are receiving this because you authored the thread.
Reply to this email directly or view it on GitHub
https://github.com/tgalal/yowsup/issues/1449#issuecomment-205006717
You can edit your top layer.py and implement:
def onMessage(self,message):
if message.getType() == "media" and message.getMediaType() in ("image", "audio", "video"):
with open("file","wb") as f:
f.write(message.getMediaContent())
You can see more or less this code in cli/layer.py
asyncore.loop(timeout=1.0, count=10, use_poll=True)
File "/usr/lib/python2.7/asyncore.py", line 220, in loop
poll_fun(timeout, map)
File "/usr/lib/python2.7/asyncore.py", line 201, in poll2
readwrite(obj, flags)
File "/usr/lib/python2.7/asyncore.py", line 123, in readwrite
obj.handle_error()
File "/usr/lib/python2.7/asyncore.py", line 108, in readwrite
obj.handle_read_event()
File "/usr/lib/python2.7/asyncore.py", line 449, in handle_read_event
self.handle_read()
File "/usr/local/lib/python2.7/dist-packages/yowsup2-2.4.102-py2.7.egg/yowsup/layers/network/layer.py", line 88, in handle_read
self.receive(data)
File "/usr/local/lib/python2.7/dist-packages/yowsup2-2.4.102-py2.7.egg/yowsup/layers/network/layer.py", line 96, in receive
self.toUpper(data)
File "/usr/local/lib/python2.7/dist-packages/yowsup2-2.4.102-py2.7.egg/yowsup/layers/init.py", line 75, in toUpper
self.upper.receive(data)
File "/usr/local/lib/python2.7/dist-packages/yowsup2-2.4.102-py2.7.egg/yowsup/layers/stanzaregulator/layer.py", line 29, in receive
self.processReceived()
File "/usr/local/lib/python2.7/dist-packages/yowsup2-2.4.102-py2.7.egg/yowsup/layers/stanzaregulator/layer.py", line 49, in processReceived
self.toUpper(oneMessageData)
File "/usr/local/lib/python2.7/dist-packages/yowsup2-2.4.102-py2.7.egg/yowsup/layers/__init.py", line 75, in toUpper
self.upper.receive(data)
File "/usr/local/lib/python2.7/dist-packages/yowsup2-2.4.102-py2.7.egg/yowsup/layers/auth/layer_crypt.py", line 65, in receive
self.toUpper(payload)
File "/usr/local/lib/python2.7/dist-packages/yowsup2-2.4.102-py2.7.egg/yowsup/layers/__init.py", line 75, in toUpper
self.upper.receive(data)
File "/usr/local/lib/python2.7/dist-packages/yowsup2-2.4.102-py2.7.egg/yowsup/layers/coder/layer.py", line 35, in receive
self.toUpper(node)
File "/usr/local/lib/python2.7/dist-packages/yowsup2-2.4.102-py2.7.egg/yowsup/layers/__init.py", line 75, in toUpper
self.upper.receive(data)
File "/usr/local/lib/python2.7/dist-packages/yowsup2-2.4.102-py2.7.egg/yowsup/layers/axolotl/layer.py", line 124, in receive
self.onMessage(protocolTreeNode)
File "/usr/local/lib/python2.7/dist-packages/yowsup2-2.4.102-py2.7.egg/yowsup/layers/axolotl/layer.py", line 146, in onMessage
self.handleEncMessage(protocolTreeNode)
File "/usr/local/lib/python2.7/dist-packages/yowsup2-2.4.102-py2.7.egg/yowsup/layers/axolotl/layer.py", line 231, in handleEncMessage
self.handleWhisperMessage(node)
File "/usr/local/lib/python2.7/dist-packages/yowsup2-2.4.102-py2.7.egg/yowsup/layers/axolotl/layer.py", line 288, in handleWhisperMessage
self.toUpper(node)
File "/usr/local/lib/python2.7/dist-packages/yowsup2-2.4.102-py2.7.egg/yowsup/layers/__init.py", line 75, in toUpper
self.upper.receive(data)
File "/usr/local/lib/python2.7/dist-packages/yowsup2-2.4.102-py2.7.egg/yowsup/layers/__init.py", line 188, in receive
s.receive(data)
File "/usr/local/lib/python2.7/dist-packages/yowsup2-2.4.102-py2.7.egg/yowsup/layers/init.py", line 124, in receive
recv(node)
File "/usr/local/lib/python2.7/dist-packages/yowsup2-2.4.102-py2.7.egg/yowsup/layers/protocol_media/layer.py", line 40, in recvMessageStanza
if mediaNode.getAttributeValue("type") == "image":
AttributeError: 'NoneType' object has no attribute 'getAttributeValue'
Is this linke to this issue?
I really don't kniw what I have to do @jlguardi . i insert the code:
def onMessage(self,message):
if message.getType() == "media" and message.getMediaType() in ("image", "audio", "video"):
with open("file","wb") as f:
f.write(message.getMediaContent())
in layer: /usr/local/lib/python2.7/dist-packages/yowsup2-2.4.102-py2.7.egg/yowsup/layers/protocol_media/layer.py
but of course it fails :(
@thundergreen Do not edit layers if you aren't sure about what are you doing. Just edit your top level layer. For instance cli/layer.py or sendclient/layer.py.
Hi all, i have problms to get images decrypted:
2016-04-03 22:46:02,358 DEBUG Session: Received image message Message:
ID: C789AABA4320AD3E6409953BDBF230
From: [email protected]
Type: media
Timestamp: 1459716350
Media Type: image
Has Preview: True
MimeType: image/jpeg
File Hash: paLUD3JxGsMoVs8CAOMFifx4PjcTRt2hthwYdfKR69o=
URL: https://mmi256.whatsapp.net/d/RY3QdQrug3QM0RYcuk6S6FcBgP0/Api2OnFuHmIlbyWEzqS8fDwUncZhMIDYMRJbeAcQQIfr.enc
IP: None
File Size: 167475
File name: unknown
File is encrypted
Encoding: unknown
Width: 0
Height: 0
2016-04-03 22:46:00,823 DEBUG yowsup.layers.axolotl.layer:
SOme ideas how to fix this?
@jlguardi I don't really understand what u mean with the top level layers :(
might u help me?
how can i fix this @jlguardi ? where do i have to outz in what? will you fix this anyway in your brnach? then i would wait for the commit.
LG
Thunder
+1
i'm still getting that error with the current revision.
Message:
ID: D2...DF
From: [email protected]
Type: media
Timestamp: 1490475019
Media Type: image
Has Preview: True
MimeType: image/jpeg
File Hash: 4f241...0dfc2a
URL: https://mmi304.whatsapp.net/d/...RS8KLuBq_HXm.enc
IP: 0
File Size: 118298
File name: enc
Encoding: raw
Width: 899
Height: 1599
i'm using this code in transwhat and it looks like media.isEncrypted() returns False although the media is clearly encrypted.
Is there anything I could do to fix this?
You might use some parts of https://github.com/jlguardi/yowsup
getExtension-method of common/tools.py
in folder layers/protocol_media/protocolentities/
message_media_downloadable.py
message_media_downloadable_image.py
I think this might help.
EDIT:
Or just see #1713
Thank you. But I can't see how that would make media.isEncrypted() return True as it should.
I think 1aa1c55 of this PR implements your requested methods...
worked fine for me! Thanks!!!
not clear abt mediaKey and cryptKeys ... can somebody help me understand it .. where i can find those data
Could somebody please clearly wrap up what needs to be do to get the image instead of a link to _file.enc_? Thank you in advance for your efforts.
@pabloruan0710 which solution did you use for decrypted .enc file to media ??
I did not use any solution so far. I am trying to find one, but so far I have not found anything that would be working from me / or I did not implement them right. I tried to replace files from different forks mentioned in various issues and now I am back to stock transwhat 0.2.2 + latest yowsup2.
@o--- is it work to upload send media and receive media on transwat 0.2.2 ?
Hello Guys, I received every type files in my code using getMediaContent(), implement this three function in layers/protocol_media/protocolentities/message_media_downloadable.py:
Use this import and CRIPTKEYS in final of image:

After, add functions:
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)
Now, in layer use getMediaContent() for save image.
filename = "%s/%s%s"%(caminho_servidor, message.getId(), message.getExtension())
filenameurl = "%s/%s.jpg"%(caminho_servidor, message.getId())
with open(filename, 'wb') as f:
f.write(message.getMediaContent())
try:
im = Image.open(filename)
im.save(filenameurl)
except Exception as e:
print("Erro ao gerar imagem %s"%e)
In message_media_downloadable_image.py:
def setImageProps(self, encoding, width, height, caption):
self.encoding = encoding
self.width = int(width)
self.height = int(height)
self.caption = caption
self.cryptKeys = '576861747341707020496d616765204b657973'
In message_media_downloadable_document.py:
def setDocumentProps(self, title, pages):
self.pages = int(pages)
self.title = title
self.cryptKeys = '576861747341707020446f63756d656e74204b657973'
In message_media_downloadable_audio.py:
def setAudioProps(self, abitrate = None, acodec = None, asampfreq = None,
duration = None, encoding = None, origin = None, seconds = None):
self.abitrate = abitrate
self.acodec = acodec
self.asampfreq = asampfreq
self.duration = duration
self.encoding = encoding
self.origin = origin
self.seconds = seconds
self.cryptKeys = '576861747341707020417564696f204b657973'
Try @albaizzz and comment with you feedback.
** Sorry, my english is bad :D
Thanks pabloruan0710.
My imports look a bit different in message_media_downloadable.py and when I changed them, I was getting No module name khdfv3.
I am also not sure how do you want me to implement in layer and in which layer?
/yowsup/layers/protocol_media/layer.py
`from yowsup.layers import YowLayer, YowLayerEvent, YowProtocolLayer
from .protocolentities import ImageDownloadableMediaMessageProtocolEntity
from .protocolentities import AudioDownloadableMediaMessageProtocolEntity
from .protocolentities import VideoDownloadableMediaMessageProtocolEntity
from .protocolentities import LocationMediaMessageProtocolEntity
from .protocolentities import VCardMediaMessageProtocolEntity
from .protocolentities import RequestUploadIqProtocolEntity, ResultRequestUploadIqProtocolEntity
from yowsup.layers.protocol_iq.protocolentities import IqProtocolEntity, ErrorIqProtocolEntity
class YowMediaProtocolLayer(YowProtocolLayer):
# EVENT_REQUEST_UPLOAD = "org.openwhatsapp.org.yowsup.event.protocol_media.request_upload"
def __init__(self):
handleMap = {
"message": (self.recvMessageStanza, self.sendMessageEntity),
"iq": (self.recvIq, self.sendIq)
}
super(YowMediaProtocolLayer, self).__init__(handleMap)
def __str__(self):
return "Media Layer"
# def onEvent(self, yowLayerEvent):
# if yowLayerEvent.getArg(self.__class__.EVENT_REQUEST_UPLOAD):
# fpath = yowLayerEvent.getArg("file")
# _type = yowLayerEvent.getArg("type")
# assert fpath and _type, "Must specify 'file' and 'type' in EVENT_REQUEST_UPLOAD args"
# entity = RequestUploadIqProtocolEntity(_type, filePath=fpath)
# self._sendIq(entity, self.onRequestUploadSuccess, self.onRequestUploadError)
def sendMessageEntity(self, entity):
if entity.getType() == "media":
self.entityToLower(entity)
def recvMessageStanza(self, node):
if node.getAttributeValue("type") == "media":
mediaNode = node.getChild("media")
if mediaNode.getAttributeValue("type") == "image":
entity = ImageDownloadableMediaMessageProtocolEntity.fromProtocolTreeNode(node)
self.toUpper(entity)
elif mediaNode.getAttributeValue("type") == "audio":
entity = AudioDownloadableMediaMessageProtocolEntity.fromProtocolTreeNode(node)
self.toUpper(entity)
elif mediaNode.getAttributeValue("type") == "video":
entity = VideoDownloadableMediaMessageProtocolEntity.fromProtocolTreeNode(node)
self.toUpper(entity)
elif mediaNode.getAttributeValue("type") == "location":
entity = LocationMediaMessageProtocolEntity.fromProtocolTreeNode(node)
self.toUpper(entity)
elif mediaNode.getAttributeValue("type") == "vcard":
entity = VCardMediaMessageProtocolEntity.fromProtocolTreeNode(node)
self.toUpper(entity)
def sendIq(self, entity):
"""
:type entity: IqProtocolEntity
"""
if entity.getType() == IqProtocolEntity.TYPE_SET and entity.getXmlns() == "w:m":
#media upload!
self._sendIq(entity, self.onRequestUploadSuccess, self.onRequestUploadError)
def recvIq(self, node):
"""
:type node: ProtocolTreeNode
"""
def onRequestUploadSuccess(self, resultNode, requestUploadEntity):
self.toUpper(ResultRequestUploadIqProtocolEntity.fromProtocolTreeNode(resultNode))
def onRequestUploadError(self, errorNode, requestUploadEntity):
self.toUpper(ErrorIqProtocolEntity.fromProtocolTreeNode(errorNode))
`
What version python_axolotl your use? 0.1.35 ? @o---
I seem to be on 0.1.39.
I am using yowsup2.5.7 and current transwhat version from git.
The module issue mentioned above was a typo error.
Please,
where I can find the refkey value?
Thanks
@pabloruan0710 Thanks for your post.
Could you specify where to add the code to the message_media_downloadable.py file and to the layer? And how exactly to get the keys?
Thanks in advance
Is anyone knows how to get the refkey from axolotl.db?
Thank you
Hi, is there any update?
which fork is the best to support mediafiles, currently I’m using @AragurDEV’s
do you know this post:
https://github.com/AragurDEV/yowsup/issues/10
Most helpful comment
You can edit your top layer.py and implement:
You can see more or less this code in cli/layer.py