Skip to content

Commit ead1923

Browse files
committed
Merge branch 'release/2.4'
2 parents 77330b8 + 5a2f794 commit ead1923

File tree

17 files changed

+256
-109
lines changed

17 files changed

+256
-109
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22

33
<a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=Z9KKEUVYEY6BN" target="_blank"><img src="https://www.paypalobjects.com/en_US/i/btn/btn_donate_LG.gif" /></a>
44

5-
## Updates (August 01, 2015)
5+
## Updates (September 07, 2015)
6+
Yowsup v2.4 is out, See [release notes](https://github.com/tgalal/yowsup/releases/tag/v2.4)
7+
8+
### Updates (August 01, 2015)
69
Yowsup v2.3.185 is out, contains fixes in axolotl integration. See [release notes](https://github.com/tgalal/yowsup/releases/tag/v2.3.185)
710

811
### Updates (July 27, 2015)

yowsup-cli

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env python
2-
__version__ = "2.0.12"
2+
__version__ = "2.0.13"
33
__author__ = "Tarek Galal"
44

55
import sys, argparse, yowsup, logging
@@ -205,8 +205,7 @@ class DemosArgParser(YowArgParser):
205205
credentialsOpts.add_argument("-c", "--config", action="store",
206206
help = "Path to config file containing authentication info. For more info about config format use --help-config")
207207

208-
configGroup.add_argument("-m", "--moxie", action="store_true", help="Enable experimental support for the"
209-
" new WhatsApp encryption")
208+
configGroup.add_argument("-M", "--unmoxie", action="store_true", help="Disable E2E Encryption")
210209

211210
cmdopts = self.add_argument_group("Command line interface demo")
212211
cmdopts.add_argument('-y', '--yowsup', action = "store_true", help = "Start the Yowsup command line client")
@@ -224,9 +223,6 @@ class DemosArgParser(YowArgParser):
224223
def process(self):
225224
super(DemosArgParser, self).process()
226225

227-
if self.args["moxie"]:
228-
logger.warning("--moxie/-m is deprecated and will be removed soon as e2e encryption is now almost mandatory.")
229-
230226
if self.args["yowsup"]:
231227
self.startCmdline()
232228
elif self.args["echo"]:
@@ -255,7 +251,7 @@ class DemosArgParser(YowArgParser):
255251
if not credentials:
256252
print("Error: You must specify a configuration method")
257253
sys.exit(1)
258-
stack = cli.YowsupCliStack(credentials, self.args["moxie"])
254+
stack = cli.YowsupCliStack(credentials, not self.args["unmoxie"])
259255
stack.start()
260256

261257
def startEcho(self):
@@ -265,7 +261,7 @@ class DemosArgParser(YowArgParser):
265261
print("Error: You must specify a configuration method")
266262
sys.exit(1)
267263
try:
268-
stack = echoclient.YowsupEchoStack(credentials, self.args["moxie"])
264+
stack = echoclient.YowsupEchoStack(credentials, not self.args["unmoxie"])
269265
stack.start()
270266
except KeyboardInterrupt:
271267
print("\nYowsdown")
@@ -280,7 +276,7 @@ class DemosArgParser(YowArgParser):
280276

281277
try:
282278
stack = sendclient.YowsupSendStack(credentials, [([self.args["send"][0], self.args["send"][1]])],
283-
self.args["moxie"])
279+
not self.args["unmoxie"])
284280
stack.start()
285281
except KeyboardInterrupt:
286282
print("\nYowsdown")
@@ -293,7 +289,7 @@ class DemosArgParser(YowArgParser):
293289
print("Error: You must specify a configuration method")
294290
sys.exit(1)
295291
try:
296-
stack = contacts.YowsupSyncStack(credentials,self.args["sync"].split(','),self.args["moxie"])
292+
stack = contacts.YowsupSyncStack(credentials,self.args["sync"].split(','), not self.args["unmoxie"])
297293
stack.start()
298294
except KeyboardInterrupt:
299295
print("\nYowsdown")
@@ -326,4 +322,3 @@ if __name__ == "__main__":
326322
parser = modeDict[mode]()
327323
if not parser.process():
328324
parser.print_help()
329-

yowsup/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
__version__ = "2.3.185"
1+
__version__ = "2.4"
22
__author__ = "Tarek Galal"

yowsup/demos/cli/layer.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ def __init__(self):
4848
self.username = None
4949
self.sendReceipts = True
5050
self.disconnectAction = self.__class__.DISCONNECT_ACTION_PROMPT
51+
self.credentials = None
5152

5253
#add aliases to make it user to use commands. for example you can then do:
5354
# /message send foobar "HI"
@@ -77,6 +78,9 @@ def normalizeJid(self, number):
7778

7879
return "%s@s.whatsapp.net" % number
7980

81+
def setCredentials(self, username, password):
82+
self.getLayerInterface(YowAuthenticationProtocolLayer).setCredentials(username, password)
83+
8084
def onEvent(self, layerEvent):
8185
if layerEvent.getName() == self.__class__.EVENT_START:
8286
self.startInput()
@@ -406,23 +410,20 @@ def contacts_sync(self, contacts):
406410
@clicmd("Disconnect")
407411
def disconnect(self):
408412
if self.assertConnected():
413+
409414
self.broadcastEvent(YowLayerEvent(YowNetworkLayer.EVENT_STATE_DISCONNECT))
410415

411416
@clicmd("Quick login")
412417
def L(self):
413-
return self.login(*self.getProp(YowAuthenticationProtocolLayer.PROP_CREDENTIALS))
414-
415-
@clicmd("Login to WhatsApp", 0)
416-
def login(self, username, b64password):
417-
418418
if self.connected:
419419
return self.output("Already connected, disconnect first")
420+
self.getLayerInterface(YowNetworkLayer).connect()
421+
return True
420422

421-
self.getStack().setProp(YowAuthenticationProtocolLayer.PROP_CREDENTIALS, (username, b64password))
422-
connectEvent = YowLayerEvent(YowNetworkLayer.EVENT_STATE_CONNECT)
423-
self.broadcastEvent(connectEvent)
424-
return True #prompt will wait until notified
425-
423+
@clicmd("Login to WhatsApp", 0)
424+
def login(self, username, b64password):
425+
self.setCredentials(username, b64password)
426+
return self.L()
426427

427428
######## receive #########
428429

yowsup/demos/cli/stack.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
from yowsup.stacks import YowStack, YowStackBuilder
1+
from yowsup.stacks import YowStackBuilder
22
from .layer import YowsupCliLayer
33
from yowsup.layers.auth import AuthError
44
from yowsup.layers import YowLayerEvent
5-
from yowsup import env
6-
from yowsup.env import S40YowsupEnv
5+
from yowsup.layers.auth import YowAuthenticationProtocolLayer
76
import sys
87

98
class YowsupCliStack(object):
@@ -15,6 +14,7 @@ def __init__(self, credentials, encryptionEnabled = True):
1514
.push(YowsupCliLayer)\
1615
.build()
1716

17+
# self.stack.setCredentials(credentials)
1818
self.stack.setCredentials(credentials)
1919

2020
def start(self):
@@ -27,4 +27,4 @@ def start(self):
2727
print("Auth Error, reason %s" % e)
2828
except KeyboardInterrupt:
2929
print("\nYowsdown")
30-
sys.exit(0)
30+
sys.exit(0)

yowsup/env/env_s40.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
import base64
33
import hashlib
44
class S40YowsupEnv(YowsupEnv):
5-
_VERSION = "2.12.89"
5+
_VERSION = "2.12.96"
66
_OS_NAME= "S40"
77
_OS_VERSION = "14.26"
88
_DEVICE_NAME = "Nokia302"
9-
_TOKEN_STRING = "PdA2DJyKoUrwLw1Bg6EIhzh502dF9noR9uFCllGk1435688727801{phone}"
9+
_TOKEN_STRING = "PdA2DJyKoUrwLw1Bg6EIhzh502dF9noR9uFCllGk1439921717185{phone}"
1010
_AXOLOTL = True
1111

1212
def getVersion(self):
@@ -34,4 +34,3 @@ def getUserAgent(self):
3434
OS_VERSION = self.getOSVersion(),
3535
DEVICE_NAME = self.getDeviceName()
3636
)
37-

yowsup/layers/__init__.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ class YowLayer(object):
3333

3434
def __init__(self):
3535
self.setLayers(None, None)
36+
self.interface = None
37+
38+
def getLayerInterface(self, YowLayerClass = None):
39+
return self.interface if YowLayerClass is None else self.__stack.getLayerInterface(YowLayerClass)
3640

3741
def setStack(self, stack):
3842
self.__stack = stack
@@ -149,6 +153,11 @@ def __init__(self, sublayers = None):
149153
s.emitEvent = self.subEmitEvent
150154

151155

156+
def getLayerInterface(self, YowLayerClass):
157+
for s in self.sublayers:
158+
if s.__class__ == YowLayerClass:
159+
return s
160+
152161
def setStack(self, stack):
153162
super(YowParallelLayer, self).setStack(stack)
154163
for s in self.sublayers:
@@ -182,6 +191,10 @@ def onEvent(self, yowLayerEvent):
182191
def __str__(self):
183192
return " - ".join([l.__str__() for l in self.sublayers])
184193

194+
class YowLayerInterface(object):
195+
def __init__(self, layer):
196+
self._layer = layer
197+
185198

186199
class YowLayerTest(unittest.TestCase):
187200
def __init__(self, *args):

yowsup/layers/auth/layer_authentication.py

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
from yowsup.layers import YowLayer, YowLayerEvent, YowProtocolLayer
1+
from yowsup.layers import YowLayerEvent, YowProtocolLayer
22
from .keystream import KeyStream
33
from yowsup.common.tools import TimeTools
44
from .layer_crypt import YowCryptLayer
55
from yowsup.layers.network import YowNetworkLayer
66
from .autherror import AuthError
77
from .protocolentities import *
88
from yowsup.common.tools import StorageTools
9+
from .layer_interface_authentication import YowAuthenticationProtocolLayerInterface
910
import base64
1011
class YowAuthenticationProtocolLayer(YowProtocolLayer):
1112
EVENT_LOGIN = "org.openwhatsapp.yowsup.event.auth.login"
@@ -22,29 +23,38 @@ def __init__(self):
2223
"stream:error": (self.handleStreamError, None),
2324
}
2425
super(YowAuthenticationProtocolLayer, self).__init__(handleMap)
25-
self.credentials = None
26+
self.interface = YowAuthenticationProtocolLayerInterface(self)
27+
self.credentials = None #left for backwards-compat
28+
self._credentials = None #new style set
2629

2730
def __str__(self):
2831
return "Authentication Layer"
2932

30-
def __getCredentials(self):
31-
u, pb64 = self.getProp(YowAuthenticationProtocolLayer.PROP_CREDENTIALS)
33+
def __getCredentials(self, credentials = None):
34+
u, pb64 = credentials or self.getProp(YowAuthenticationProtocolLayer.PROP_CREDENTIALS)
3235
if type(pb64) is str:
3336
pb64 = pb64.encode()
3437
password = base64.b64decode(pb64)
3538
return (u, bytearray(password))
3639

40+
def setCredentials(self, credentials):
41+
self.setProp(YowAuthenticationProtocolLayer.PROP_CREDENTIALS, credentials) #keep for now
42+
self._credentials = self.__getCredentials(credentials)
43+
44+
def getUsername(self, full = False):
45+
if self._credentials:
46+
return self._credentials[0] if not full else ("%s@s.whatsapp.net" % self._credentials[0])
47+
else:
48+
prop = self.getProp(YowAuthenticationProtocolLayer.PROP_CREDENTIALS)
49+
return prop[0] if prop else None
50+
3751
def onEvent(self, event):
3852
if event.getName() == YowNetworkLayer.EVENT_STATE_CONNECTED:
3953
self.login()
40-
elif event.getName() == YowNetworkLayer.EVENT_STATE_CONNECT:
41-
self.credentials = self.__getCredentials()
42-
if not self.credentials:
43-
raise AuthError("Auth stopped connection signal as no credentials have been set")
4454

4555
## general methods
4656
def login(self):
47-
57+
self.credentials = self._credentials or self.__getCredentials()
4858
self._sendFeatures()
4959
self._sendAuth()
5060

@@ -102,7 +112,7 @@ def _sendResponse(self,nonce):
102112
responseEntity = ResponseProtocolEntity(authBlob)
103113

104114
#to prevent enr whole response
105-
self.broadcastEvent(YowLayerEvent(YowCryptLayer.EVENT_KEYS_READY, keys = (inputKey, None)))
115+
self.broadcastEvent(YowLayerEvent(YowCryptLayer.EVENT_KEYS_READY, keys = (inputKey, None)))
106116
self.entityToLower(responseEntity)
107117
self.broadcastEvent(YowLayerEvent(YowCryptLayer.EVENT_KEYS_READY, keys = (inputKey, outputKey)))
108118
#YowCryptLayer.setProp("outputKey", outputKey)

yowsup/layers/auth/layer_crypt.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def __init__(self):
1313
self.keys = (None,None)
1414

1515
def onEvent(self, yowLayerEvent):
16-
if yowLayerEvent.getName() == YowNetworkLayer.EVENT_STATE_CONNECT:
16+
if yowLayerEvent.getName() == YowNetworkLayer.EVENT_STATE_CONNECTED:
1717
self.keys = (None,None)
1818
elif yowLayerEvent.getName() == YowCryptLayer.EVENT_KEYS_READY:
1919
self.keys = yowLayerEvent.getArg("keys")
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from yowsup.layers import YowLayerInterface
2+
3+
class YowAuthenticationProtocolLayerInterface(YowLayerInterface):
4+
def setCredentials(self, phone, password):
5+
self._layer.setCredentials(phone, password)
6+
7+
def getUsername(self, full = False):
8+
return self._layer.getUsername(full)

0 commit comments

Comments
 (0)