Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/yowsup/layers/axolotl/layer_send.py b/yowsup/layers/axolotl/layer_send.py
- index bbeacd8..2615d5e 100644
- --- a/yowsup/layers/axolotl/layer_send.py
- +++ b/yowsup/layers/axolotl/layer_send.py
- @@ -9,6 +9,8 @@ from axolotl.axolotladdress import AxolotlAddress
- from axolotl.protocol.whispermessage import WhisperMessage
- from axolotl.groups.senderkeyname import SenderKeyName
- from axolotl.groups.groupsessionbuilder import GroupSessionBuilder
- +from yowsup.structs import ProtocolTreeNode
- +from yowsup.layers.protocol_iq.protocolentities import IqProtocolEntity
- import logging
- from random import randint
- @@ -44,19 +46,20 @@ class AxolotlSendLayer(AxolotlBaseLayer):
- def send(self, node):
- - if node.tag == "message" and node["to"] not in self.skipEncJids and not node.getChild("enc") and (not node.getChild("media") or node.getChild("media")["mediakey"]):
- - self.processPlaintextNodeAndSend(node)
- - # elif node.tag == "iq" and node["xmlns"] == "w:m":
- - # mediaNode = node.getChild("media")
- - # if mediaNode and mediaNode["type"] == "image":
- - # iqNode = IqProtocolEntity.fromProtocolTreeNode(node).toProtocolTreeNode()
- - # iqNode.addChild(ProtocolTreeNode(
- - # "encr_media", {
- - # "type": mediaNode["type"],
- - # "hash": mediaNode["hash"]
- - # }
- - # ))
- - # self.toLower(iqNode)
- + #if node.tag == "message" and node["to"] not in self.skipEncJids and not node.getChild("enc") and (not node.getChild("media") or node.getChild("media")["mediakey"]):
- + if node.tag == "message" and node["to"] not in self.skipEncJids and not node.getChild("enc"):
- + self.processPlaintextNodeAndSend(node)
- + elif node.tag == "iq" and node["xmlns"] == "w:m":
- + mediaNode = node.getChild("encr_media")
- + if mediaNode:
- + iqNode = IqProtocolEntity.fromProtocolTreeNode(node).toProtocolTreeNode()
- + iqNode.addChild(ProtocolTreeNode(
- + "encr_media", {
- + "type": mediaNode["type"],
- + "hash": mediaNode["hash"]
- + }
- + ))
- + self.toLower(iqNode)
- else:
- self.toLower(node)
- diff --git a/yowsup/layers/protocol_media/mediauploader.py b/yowsup/layers/protocol_media/mediauploader.py
- index da9b3d1..6750b31 100644
- --- a/yowsup/layers/protocol_media/mediauploader.py
- +++ b/yowsup/layers/protocol_media/mediauploader.py
- @@ -5,6 +5,22 @@ from time import sleep
- import threading
- import logging
- from yowsup.common.tools import MimeTools
- +from axolotl.kdf.hkdfv3 import HKDFv3
- +import binascii
- +from axolotl.util.byteutil import ByteUtil
- +import Crypto.Cipher.AES as AES
- +from axolotl.ecc.curve import Curve
- +from axolotl.sessionbuilder import SessionBuilder
- +from axolotl.state.sessionstate import SessionState
- +from axolotl.protocol.whispermessage import WhisperMessage
- +from axolotl.protocol.prekeywhispermessage import PreKeyWhisperMessage
- +from axolotl.nosessionexception import NoSessionException
- +from axolotl.invalidmessageexception import InvalidMessageException
- +from axolotl.duplicatemessagexception import DuplicateMessageException
- +import hashlib
- +import base64
- +import hmac
- +from yowsup.common.tools import WATools
- logger = logging.getLogger(__name__)
- @@ -29,6 +45,20 @@ class MediaUploader(WARequest, threading.Thread):
- self.sock = socket.socket()
- + def pad(self, s):
- + return s + ((16-len(s) % 16) * '{')
- +
- + def encryptImg(self, img, refkey):
- + #refkey = binascii.hexlify(os.urandom(112))
- + img = self.pad(img)
- + derivative = HKDFv3().deriveSecrets(binascii.unhexlify(refkey), binascii.unhexlify("576861747341707020496d616765204b657973"), 112)
- + parts = ByteUtil.split(derivative, 16, 32)
- + iv = parts[0]
- + cipherKey = parts[1]
- + cipher = AES.new(key=cipherKey, mode=AES.MODE_CBC, IV=iv)
- + imgEnc=cipher.encrypt(img)
- + return imgEnc[:-6]
- +
- def start(self):
- if self.async:
- threading.Thread.__init__(self)
- @@ -46,9 +76,25 @@ class MediaUploader(WARequest, threading.Thread):
- try:
- + #filename = os.path.basename(sourcePath)
- + #filetype = MimeTools.getMIME(filename)
- + #filesize = os.path.getsize(sourcePath)
- filename = os.path.basename(sourcePath)
- filetype = MimeTools.getMIME(filename)
- - filesize = os.path.getsize(sourcePath)
- + f = open(sourcePath, 'rb')
- + stream = f.read()
- + f.close()
- + refkey = binascii.hexlify(os.urandom(112))
- + stream=self.encryptImg(stream,refkey)
- + fenc = open(filename + ".enc", 'wb')
- + fenc.write(stream)
- + fenc.seek(0, 2)
- + filesize=fenc.tell()
- + fenc.close()
- +
- + sha1 = hashlib.sha256()
- + sha1.update(stream)
- + b64Hash = base64.b64encode(sha1.digest())
- self.sock.connect((self.url, self.port))
- ssl_sock = ssl.wrap_socket(self.sock)
- @@ -60,23 +106,34 @@ class MediaUploader(WARequest, threading.Thread):
- boundary = "zzXXzzYYzzXXzzQQ"#"-------" + m.hexdigest() #"zzXXzzYYzzXXzzQQ"
- contentLength = 0
- + digTo = hmac.new("".encode("utf-8"), self.jid.replace("@s.whatsapp.net","@c.us").encode("utf-8"), hashlib.sha256).digest()[:20]
- + refTo = base64.b64encode(digTo).decode()
- + digFrom = hmac.new("".encode("utf-8"), self.accountJid.replace("@s.whatsapp.net","@c.us").encode("utf-8"), hashlib.sha256).digest()[:20]
- + refFrom = base64.b64encode(digFrom).decode()
- hBAOS = "--" + boundary + "\r\n"
- - hBAOS += "Content-Disposition: form-data; name=\"to\"\r\n\r\n"
- - hBAOS += self.jid + "\r\n"
- + #hBAOS += "Content-Disposition: form-data; name=\"to\"\r\n\r\n"
- + #hBAOS += self.jid + "\r\n"
- + #hBAOS += "--" + boundary + "\r\n"
- + #hBAOS += "Content-Disposition: form-data; name=\"from\"\r\n\r\n"
- + #hBAOS += self.accountJid.replace("@whatsapp.net","") + "\r\n"
- + #hBAOS += "--" + boundary + "\r\n"
- + hBAOS += "Content-Disposition: form-data; name=\"hash\"\r\n\r\n"
- + hBAOS += WATools.getFileHashForUpload(filename + ".enc") + "\r\n"
- hBAOS += "--" + boundary + "\r\n"
- - hBAOS += "Content-Disposition: form-data; name=\"from\"\r\n\r\n"
- - hBAOS += self.accountJid.replace("@whatsapp.net","") + "\r\n"
- + hBAOS += "Content-Disposition: form-data; name=\"refs\"\r\n\r\n"
- + hBAOS += refFrom + "\r\n"
- + hBAOS += refTo + "\r\n"
- hBAOS += "--" + boundary + "\r\n"
- hBAOS += "Content-Disposition: form-data; name=\"file\"; filename=\"" + crypto + "\"\r\n"
- - hBAOS += "Content-Type: " + filetype + "\r\n\r\n"
- + hBAOS += "Content-Type: application/octet-stream\r\n\r\n"
- fBAOS = "\r\n--" + boundary + "--\r\n"
- contentLength += len(hBAOS)
- contentLength += len(fBAOS)
- contentLength += filesize
- -
- +
- POST = "POST %s\r\n" % uploadUrl
- POST += "Content-Type: multipart/form-data; boundary=" + boundary + "\r\n"
- POST += "Host: %s\r\n" % self.url
- @@ -88,12 +145,12 @@ class MediaUploader(WARequest, threading.Thread):
- totalsent = 0
- buf = 1024
- - f = open(sourcePath, 'rb')
- - stream = f.read()
- - f.close()
- + #f = open(sourcePath, 'rb')
- + #stream = f.read()
- + #stream = self.encryptImg(stream1)
- + #f.close()
- status = 0
- lastEmit = 0
- -
- while totalsent < int(filesize):
- ssl_sock.write(stream[:buf])
- status = totalsent * 100 / filesize
- @@ -125,6 +182,9 @@ class MediaUploader(WARequest, threading.Thread):
- result = None
- for l in lines:
- + logger.warning("################################")
- + logger.warning(l)
- + logger.warning("################################")
- if l.startswith("{"):
- result = self.parser.parse(l, self.pvars)
- break
- diff --git a/yowsup/layers/protocol_media/protocolentities/iq_requestupload.py b/yowsup/layers/protocol_media/protocolentities/iq_requestupload.py
- index bdd1e69..7a2a1a8 100644
- --- a/yowsup/layers/protocol_media/protocolentities/iq_requestupload.py
- +++ b/yowsup/layers/protocol_media/protocolentities/iq_requestupload.py
- @@ -62,7 +62,7 @@ class RequestUploadIqProtocolEntity(IqProtocolEntity):
- }
- if self.origHash:
- attribs["orighash"] = self.origHash
- - mediaNode = ProtocolTreeNode("media", attribs)
- + mediaNode = ProtocolTreeNode("encr_media", attribs)
- node.addChild(mediaNode)
- return node
- @@ -71,7 +71,7 @@ class RequestUploadIqProtocolEntity(IqProtocolEntity):
- assert node.getAttributeValue("type") == "set", "Expected set as iq type in request upload, got %s" % node.getAttributeValue("type")
- entity = IqProtocolEntity.fromProtocolTreeNode(node)
- entity.__class__ = RequestUploadIqProtocolEntity
- - mediaNode = node.getChild("media")
- + mediaNode = node.getChild("encr_media")
- entity.setRequestArguments(
- mediaNode.getAttributeValue("type"),
- mediaNode.getAttributeValue("hash"),
- diff --git a/yowsup/layers/protocol_media/protocolentities/iq_requestupload_result.py b/yowsup/layers/protocol_media/protocolentities/iq_requestupload_result.py
- index 45e7eb8..982249f 100644
- --- a/yowsup/layers/protocol_media/protocolentities/iq_requestupload_result.py
- +++ b/yowsup/layers/protocol_media/protocolentities/iq_requestupload_result.py
- @@ -35,7 +35,7 @@ class ResultRequestUploadIqProtocolEntity(ResultIqProtocolEntity):
- node = super(ResultRequestUploadIqProtocolEntity, self).toProtocolTreeNode()
- if not self.isDuplicate():
- - mediaNode = ProtocolTreeNode("media", {"url": self.url})
- + mediaNode = ProtocolTreeNode("encr_media", {"url": self.url})
- if self.ip:
- mediaNode["ip"] = self.ip
- @@ -52,8 +52,11 @@ class ResultRequestUploadIqProtocolEntity(ResultIqProtocolEntity):
- entity= ResultIqProtocolEntity.fromProtocolTreeNode(node)
- entity.__class__ = ResultRequestUploadIqProtocolEntity
- mediaNode = node.getChild("media")
- + encrMediaNode = node.getChild("encr_media")
- if mediaNode:
- entity.setUploadProps(mediaNode["url"], mediaNode["ip"], mediaNode["resume"])
- + elif encrMediaNode:
- + entity.setUploadProps(encrMediaNode["url"], encrMediaNode["ip"], encrMediaNode["resume"])
- else:
- duplicateNode = node.getChild("duplicate")
- if duplicateNode:
Advertisement
Add Comment
Please, Sign In to add comment