Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test to verify WAMPCRA salt authentication #2122

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions crossbar/router/test/test_authorize.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from crossbar.router.auth import cryptosign, wampcra, ticket, tls, anonymous

from autobahn.wamp import types
from autobahn.wamp import auth as autobahn_auth

from mock import Mock

Expand Down Expand Up @@ -144,6 +145,68 @@ def fake_call(method, *args, **kw):
self.assertTrue("challenge" in val.extra)
self.assertEqual(auth._authextra, {"what": "authenticator-supplied authextra"})

@defer.inlineCallbacks
def test_authextra_wampcra_with_salt(self):
"""
We pass along the authextra to a dynamic authenticator
"""
session = Mock()
session._transport.transport_details = types.TransportDetails()

secret = "deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef"
authextra = { "foo": "bar", "salt": "malok", "iterations": 1000, "keylen": 32}

def fake_call(method, *args, **kw):
realm, authid, details = args
self.assertEqual("foo.auth_a_doodle", method)
self.assertEqual("realm", realm)
self.assertEqual(details["authmethod"], "wampcra")
self.assertEqual(details["authextra"], authextra)
return defer.succeed({
"secret": secret,
"role": "some_role",
"salt": "malok",
"iterations": 1000,
"keylen": 32,
"extra": {
"what": "authenticator-supplied authextra",
}
})

session.call = Mock(side_effect=fake_call)
realm = Mock()
realm._realm.session = session
session._pending_session_id = 'pending session id'
session._router_factory = {
"realm": realm,
}
config = {
"type": "dynamic",
"authenticator": "foo.auth_a_doodle",
"authenticator-realm": "realm",
"authenticator-role": "myauth_role"
}
details = Mock()
details.authid = 'alice'
details.authextra = authextra

pending_session_id = 1
transport_details = types.TransportDetails()
realm_container = MockRealmContainer("realm", ["some_role", "myauth_role"], session)

auth = wampcra.PendingAuthWampCra(pending_session_id, transport_details, realm_container, config)
val = yield auth.hello("realm", details)

self.assertTrue(isinstance(val, types.Challenge))
self.assertEqual("wampcra", val.method)
self.assertTrue("challenge" in val.extra)
self.assertEqual(auth._authextra, {"what": "authenticator-supplied authextra"})

config = {"authid": "alice", "secret": secret}
# generate a signature from client & match it with the existing
expected_signature = autobahn_auth.AuthWampCra(**config).on_challenge("res", val)
self.assertEqual(auth._signature, expected_signature)

@defer.inlineCallbacks
def test_authextra_tls(self):
"""
Expand Down
Loading