You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
from twisted.internet.defer import inlineCallbacks
from autobahn.twisted.wamp import ApplicationSession
class BackendSession(ApplicationSession):
@inlineCallbacks
def onJoin(self, details):
print("Backend session joined: {}".format(details))
def add2(x, y):
print("add2() called with {} and {}".format(x, y))
return x + y
try:
yield self.register(add2, 'com.example.add2')
print("procedure add2() registered")
except Exception as e:
print("could not register procedure: {}".format(e))
The client.py file to call the procedure:
import sys
from twisted.internet import reactor
from twisted.internet.defer import inlineCallbacks
import txaio
txaio.use_twisted()
from autobahn.wamp.serializer import JsonSerializer
from autobahn.twisted.wamp import ApplicationSession
from autobahn.twisted.util import sleep
from autobahn.wamp import auth
USER_SECRET = "new-secret"
if len(sys.argv) > 1:
USER = sys.argv[1]
else:
raise RuntimeError('missing authid')
class ClientSession(ApplicationSession):
def onConnect(self):
print("Client session connected. Starting WAMP-CRA authentication on realm '{}' as user '{}' ..".format(
self.config.realm, USER))
self.join(self.config.realm, ["wampcra"], USER)
def onChallenge(self, challenge):
if challenge.method == "wampcra":
print("WAMP-CRA challenge received: {}".format(challenge))
if 'salt' in challenge.extra:
# salted secret
key = auth.derive_key(USER_SECRET,
challenge.extra['salt'],
challenge.extra['iterations'],
challenge.extra['keylen'])
else:
# plain, unsalted secret
key = USER_SECRET
signature = auth.compute_wcs(key, challenge.extra['challenge'])
return signature
else:
raise Exception("Invalid authmethod {}".format(challenge.method))
@inlineCallbacks
def onJoin(self, details):
print("Client session joined: {}".format(details))
yield sleep(1)
try:
res = yield self.call('com.example.add2', 2, 3)
print("call result: {}".format(res))
except Exception as e:
print("call error: {}".format(e))
self.leave()
def onLeave(self, details):
print("Client session left: {}".format(details))
self.config.extra['exit_details'] = details
self.disconnect()
def onDisconnect(self):
print("Client session disconnected.")
reactor.stop()
if __name__ == '__main__':
from autobahn.twisted.wamp import ApplicationRunner
extra = {
'exit_details': None,
}
serializers = [JsonSerializer(batched=False)]
runner = ApplicationRunner(url='ws://localhost:8080/ws', realm='realm1', extra=extra, serializers=serializers)
runner.run(ClientSession)
print(extra['exit_details'])
if not extra['exit_details'] or extra['exit_details'].reason != 'wamp.close.normal':
sys.exit(1)
else:
sys.exit(0)
WAMPCRA authentication with salting doesn't work.
To reproduce the issue, here's my setup:
A simple
config.json
file that registers a procedure:The
backend.py
file to register the procedure:The
client.py
file to call the procedure:Logs of
client.py
file:crossbar router logs:
I have written a failing CICD test #2122 to support the claim.
To fix this, we need to derive key from salt if given.
There's a PR #2121 to fix this issue.
Here are the router logs of the PR #2121:
client.py
file logs:The text was updated successfully, but these errors were encountered: