-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
256 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
__version__ = "2.3.185" | ||
__version__ = "2.4" | ||
__author__ = "Tarek Galal" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,6 +48,7 @@ def __init__(self): | |
self.username = None | ||
self.sendReceipts = True | ||
self.disconnectAction = self.__class__.DISCONNECT_ACTION_PROMPT | ||
self.credentials = None | ||
|
||
#add aliases to make it user to use commands. for example you can then do: | ||
# /message send foobar "HI" | ||
|
@@ -77,6 +78,9 @@ def normalizeJid(self, number): | |
|
||
return "%[email protected]" % number | ||
|
||
def setCredentials(self, username, password): | ||
self.getLayerInterface(YowAuthenticationProtocolLayer).setCredentials(username, password) | ||
|
||
def onEvent(self, layerEvent): | ||
if layerEvent.getName() == self.__class__.EVENT_START: | ||
self.startInput() | ||
|
@@ -406,23 +410,20 @@ def contacts_sync(self, contacts): | |
@clicmd("Disconnect") | ||
def disconnect(self): | ||
if self.assertConnected(): | ||
|
||
self.broadcastEvent(YowLayerEvent(YowNetworkLayer.EVENT_STATE_DISCONNECT)) | ||
|
||
@clicmd("Quick login") | ||
def L(self): | ||
return self.login(*self.getProp(YowAuthenticationProtocolLayer.PROP_CREDENTIALS)) | ||
|
||
@clicmd("Login to WhatsApp", 0) | ||
def login(self, username, b64password): | ||
|
||
if self.connected: | ||
return self.output("Already connected, disconnect first") | ||
self.getLayerInterface(YowNetworkLayer).connect() | ||
return True | ||
|
||
self.getStack().setProp(YowAuthenticationProtocolLayer.PROP_CREDENTIALS, (username, b64password)) | ||
connectEvent = YowLayerEvent(YowNetworkLayer.EVENT_STATE_CONNECT) | ||
self.broadcastEvent(connectEvent) | ||
return True #prompt will wait until notified | ||
|
||
@clicmd("Login to WhatsApp", 0) | ||
def login(self, username, b64password): | ||
self.setCredentials(username, b64password) | ||
return self.L() | ||
|
||
######## receive ######### | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,12 @@ | ||
from yowsup.layers import YowLayer, YowLayerEvent, YowProtocolLayer | ||
from yowsup.layers import YowLayerEvent, YowProtocolLayer | ||
from .keystream import KeyStream | ||
from yowsup.common.tools import TimeTools | ||
from .layer_crypt import YowCryptLayer | ||
from yowsup.layers.network import YowNetworkLayer | ||
from .autherror import AuthError | ||
from .protocolentities import * | ||
from yowsup.common.tools import StorageTools | ||
from .layer_interface_authentication import YowAuthenticationProtocolLayerInterface | ||
import base64 | ||
class YowAuthenticationProtocolLayer(YowProtocolLayer): | ||
EVENT_LOGIN = "org.openwhatsapp.yowsup.event.auth.login" | ||
|
@@ -22,29 +23,38 @@ def __init__(self): | |
"stream:error": (self.handleStreamError, None), | ||
} | ||
super(YowAuthenticationProtocolLayer, self).__init__(handleMap) | ||
self.credentials = None | ||
self.interface = YowAuthenticationProtocolLayerInterface(self) | ||
self.credentials = None #left for backwards-compat | ||
self._credentials = None #new style set | ||
|
||
def __str__(self): | ||
return "Authentication Layer" | ||
|
||
def __getCredentials(self): | ||
u, pb64 = self.getProp(YowAuthenticationProtocolLayer.PROP_CREDENTIALS) | ||
def __getCredentials(self, credentials = None): | ||
u, pb64 = credentials or self.getProp(YowAuthenticationProtocolLayer.PROP_CREDENTIALS) | ||
if type(pb64) is str: | ||
pb64 = pb64.encode() | ||
password = base64.b64decode(pb64) | ||
return (u, bytearray(password)) | ||
|
||
def setCredentials(self, credentials): | ||
self.setProp(YowAuthenticationProtocolLayer.PROP_CREDENTIALS, credentials) #keep for now | ||
self._credentials = self.__getCredentials(credentials) | ||
|
||
def getUsername(self, full = False): | ||
if self._credentials: | ||
return self._credentials[0] if not full else ("%[email protected]" % self._credentials[0]) | ||
else: | ||
prop = self.getProp(YowAuthenticationProtocolLayer.PROP_CREDENTIALS) | ||
return prop[0] if prop else None | ||
|
||
def onEvent(self, event): | ||
if event.getName() == YowNetworkLayer.EVENT_STATE_CONNECTED: | ||
self.login() | ||
elif event.getName() == YowNetworkLayer.EVENT_STATE_CONNECT: | ||
self.credentials = self.__getCredentials() | ||
if not self.credentials: | ||
raise AuthError("Auth stopped connection signal as no credentials have been set") | ||
|
||
## general methods | ||
def login(self): | ||
|
||
self.credentials = self._credentials or self.__getCredentials() | ||
self._sendFeatures() | ||
self._sendAuth() | ||
|
||
|
@@ -102,7 +112,7 @@ def _sendResponse(self,nonce): | |
responseEntity = ResponseProtocolEntity(authBlob) | ||
|
||
#to prevent enr whole response | ||
self.broadcastEvent(YowLayerEvent(YowCryptLayer.EVENT_KEYS_READY, keys = (inputKey, None))) | ||
self.broadcastEvent(YowLayerEvent(YowCryptLayer.EVENT_KEYS_READY, keys = (inputKey, None))) | ||
self.entityToLower(responseEntity) | ||
self.broadcastEvent(YowLayerEvent(YowCryptLayer.EVENT_KEYS_READY, keys = (inputKey, outputKey))) | ||
#YowCryptLayer.setProp("outputKey", outputKey) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from yowsup.layers import YowLayerInterface | ||
|
||
class YowAuthenticationProtocolLayerInterface(YowLayerInterface): | ||
def setCredentials(self, phone, password): | ||
self._layer.setCredentials(phone, password) | ||
|
||
def getUsername(self, full = False): | ||
return self._layer.getUsername(full) |
Oops, something went wrong.