Skip to content
Permalink
Browse files

[feat] ensure client_static_keypair is set

yowsup-cli will now check first if config has client_static_keypair
before starting demos

noise layer will also do the check and disconnect if  specified
config does not have client_static_keypair
  • Loading branch information...
tgalal committed Jun 3, 2019
1 parent 500f576 commit f14a03fb780410ab949bc76855b2039e65866b7d
Showing with 62 additions and 43 deletions.
  1. +10 −0 yowsup-cli
  2. +52 −43 yowsup/layers/noise/layer.py
@@ -616,7 +616,13 @@ class DemosArgParser(YowArgParser):
return False
return True

def _ensure_config_props(self):
if self._profile.config.client_static_keypair is None:
print("Specified config does not have client_static_keypair, aborting")
sys.exit(1)

def startCmdline(self):
self._ensure_config_props()
logger.debug("starting cmd")
from yowsup.demos import cli
self.printInfoText()
@@ -626,6 +632,7 @@ class DemosArgParser(YowArgParser):
stack.start()

def startEcho(self):
self._ensure_config_props()
from yowsup.demos import echoclient
try:
self.printInfoText()
@@ -638,6 +645,7 @@ class DemosArgParser(YowArgParser):
sys.exit(0)

def startSendClient(self):
self._ensure_config_props()
from yowsup.demos import sendclient
try:
self.printInfoText()
@@ -650,6 +658,7 @@ class DemosArgParser(YowArgParser):
sys.exit(0)

def startSyncContacts(self):
self._ensure_config_props()
from yowsup.demos import contacts
try:
self.printInfoText()
@@ -662,6 +671,7 @@ class DemosArgParser(YowArgParser):
sys.exit(0)

def startMediaSink(self, storage_dir):
self._ensure_config_props()
from yowsup.demos import mediasink
self.printInfoText()
stack = mediasink.MediaSinkStack(self._profile, storage_dir)
@@ -63,54 +63,63 @@ def on_auth(self, event):
local_static = config.client_static_keypair
username = int(self._profile.username)

if type(local_static) is bytes:
local_static = KeyPair.from_bytes(local_static)
assert type(local_static) is KeyPair, type(local_static)
passive = event.getArg('passive')
if local_static is None:
logger.error("client_static_keypair is not defined in specified config, disconnecting")
self.broadcastEvent(
YowLayerEvent(
YowNetworkLayer.EVENT_STATE_DISCONNECT,
reason="client_static_keypair is not defined in specified config"
)
)
else:
if type(local_static) is bytes:
local_static = KeyPair.from_bytes(local_static)
assert type(local_static) is KeyPair, type(local_static)
passive = event.getArg('passive')

self.setProp(YowNoiseSegmentsLayer.PROP_ENABLED, False)

self.setProp(YowNoiseSegmentsLayer.PROP_ENABLED, False)
if config.edge_routing_info:
self.toLower(self.EDGE_HEADER)
self.setProp(YowNoiseSegmentsLayer.PROP_ENABLED, True)
self.toLower(config.edge_routing_info)
self.setProp(YowNoiseSegmentsLayer.PROP_ENABLED, False)

if config.edge_routing_info:
self.toLower(self.EDGE_HEADER)
self.toLower(self.HEADER)
self.setProp(YowNoiseSegmentsLayer.PROP_ENABLED, True)
self.toLower(config.edge_routing_info)
self.setProp(YowNoiseSegmentsLayer.PROP_ENABLED, False)

self.toLower(self.HEADER)
self.setProp(YowNoiseSegmentsLayer.PROP_ENABLED, True)

remote_static = config.server_static_public

self._rs = remote_static
yowsupenv = YowsupEnv.getCurrent()
client_config = ClientConfig(
username=username,
passive=passive,
useragent=UserAgentConfig(
platform=0,
app_version=yowsupenv.getVersion(),
mcc=config.mcc or "000",
mnc=config.mnc or "000",
os_version=yowsupenv.getOSVersion(),
manufacturer=yowsupenv.getManufacturer(),
device=yowsupenv.getDeviceName(),
os_build_number=yowsupenv.getOSVersion(),
phone_id=config.fdid or "",
locale_lang="en",
locale_country="US"
),
pushname=config.pushname or self.DEFAULT_PUSHNAME,
short_connect=True
)
if not self._in_handshake():
logger.debug("Performing handshake [username= %d, passive=%s]" % (username, passive) )
self._handshake_worker = WANoiseProtocolHandshakeWorker(
self._wa_noiseprotocol, self._stream, client_config, local_static, remote_static,
self.on_handshake_finished
remote_static = config.server_static_public

self._rs = remote_static
yowsupenv = YowsupEnv.getCurrent()
client_config = ClientConfig(
username=username,
passive=passive,
useragent=UserAgentConfig(
platform=0,
app_version=yowsupenv.getVersion(),
mcc=config.mcc or "000",
mnc=config.mnc or "000",
os_version=yowsupenv.getOSVersion(),
manufacturer=yowsupenv.getManufacturer(),
device=yowsupenv.getDeviceName(),
os_build_number=yowsupenv.getOSVersion(),
phone_id=config.fdid or "",
locale_lang="en",
locale_country="US"
),
pushname=config.pushname or self.DEFAULT_PUSHNAME,
short_connect=True
)
logger.debug("Starting handshake worker")
self._stream.set_events_callback(self._handle_stream_event)
self._handshake_worker.start()
if not self._in_handshake():
logger.debug("Performing handshake [username= %d, passive=%s]" % (username, passive) )
self._handshake_worker = WANoiseProtocolHandshakeWorker(
self._wa_noiseprotocol, self._stream, client_config, local_static, remote_static,
self.on_handshake_finished
)
logger.debug("Starting handshake worker")
self._stream.set_events_callback(self._handle_stream_event)
self._handshake_worker.start()

def on_handshake_finished(self, e=None):
# type: (Exception) -> None

0 comments on commit f14a03f

Please sign in to comment.
You can’t perform that action at this time.