Commit 18a804f8 authored by Scott Wittenburg's avatar Scott Wittenburg Committed by Code Review

Merge topic 'pvweb-update-autobahn-for-longpoll' into master

81a6eb04 Update autobahn client/server as well as vtkweb connect for longpoll.
parents d5876d34 81a6eb04
......@@ -16,5 +16,5 @@
##
###############################################################################
__version__ = "0.8.13"
__version__ = "0.8.14"
version = __version__ # backward compat.
......@@ -119,7 +119,7 @@ def pbkdf2_bin(data, salt, iterations = 1000, keylen = 32, hashfunc = None):
def derive_key(secret, salt, iterations = 1000, keylen = 32):
def derive_key(secret, salt, iterations = None, keylen = None):
"""
Computes a derived cryptographic key from a password according to PBKDF2.
......@@ -136,7 +136,7 @@ def derive_key(secret, salt, iterations = 1000, keylen = 32):
:returns: str -- The derived key in Base64 encoding.
"""
key = pbkdf2_bin(secret, salt, iterations, keylen)
key = pbkdf2_bin(secret, salt, iterations or 1000, keylen or 32)
return binascii.b2a_base64(key).strip()
......@@ -171,4 +171,4 @@ def compute_wcs(key, challenge):
:returns: str -- The authentication signature.
"""
sig = hmac.new(key, challenge, hashlib.sha256).digest()
return binascii.b2a_base64(sig).strip()
return binascii.b2a_base64(sig).strip().decode('ascii')
......@@ -551,7 +551,7 @@ class Challenge(Message):
raise ProtocolError("invalid message length {0} for CHALLENGE".format(len(wmsg)))
method = wmsg[1]
if type(method) != str:
if type(method) != six.text_type:
raise ProtocolError("invalid type {0} for 'method' in CHALLENGE".format(type(method)))
extra = check_or_raise_extra(wmsg[2], "'extra' in CHALLENGE")
......
......@@ -356,7 +356,7 @@ class ApplicationSession(BaseSession):
self.join(self.config.realm)
def join(self, realm):
def join(self, realm, authmethods = None, authid = None):
"""
Implements :func:`autobahn.wamp.interfaces.ISession.join`
"""
......@@ -375,7 +375,7 @@ class ApplicationSession(BaseSession):
role.RoleCalleeFeatures()
]
msg = message.Hello(realm, roles)
msg = message.Hello(realm, roles, authmethods, authid)
self._realm = realm
self._transport.send(msg)
......@@ -396,13 +396,36 @@ class ApplicationSession(BaseSession):
"""
if self._session_id is None:
## the first message MUST be WELCOME
## the first message must be WELCOME, ABORT or CHALLENGE ..
##
if isinstance(msg, message.Welcome):
self._session_id = msg.session
details = SessionDetails(self._realm, self._session_id, msg.authid, msg.authrole, msg.authmethod)
self._as_future(self.onJoin, details)
#self.onJoin(details)
elif isinstance(msg, message.Abort):
## fire callback and close the transport
self.onLeave(types.CloseDetails(msg.reason, msg.message))
elif isinstance(msg, message.Challenge):
challenge = types.Challenge(msg.method, msg.extra)
d = self._as_future(self.onChallenge, challenge)
def success(signature):
reply = message.Authenticate(signature)
self._transport.send(reply)
def error(err):
reply = message.Abort(u"wamp.error.cannot_authenticate", u"{0}".format(err.value))
self._transport.send(reply)
## fire callback and close the transport
self.onLeave(types.CloseDetails(reply.reason, reply.message))
self._add_future_callbacks(d, success, error)
else:
raise ProtocolError("Received {} message, and session is not yet established".format(msg.__class__))
......@@ -737,6 +760,13 @@ class ApplicationSession(BaseSession):
self.onDisconnect()
def onChallenge(self, challenge):
"""
Implements :func:`autobahn.wamp.interfaces.ISession.onChallenge`
"""
raise Exception("received authentication challenge, but onChallenge not implemented")
def onJoin(self, details):
"""
Implements :func:`autobahn.wamp.interfaces.ISession.onJoin`
......@@ -1281,6 +1311,16 @@ class RouterSession(BaseSession):
self._add_future_callbacks(d, success, failed)
elif isinstance(msg, message.Abort):
## fire callback and close the transport
self.onLeave(types.CloseDetails(msg.reason, msg.message))
self._session_id = None
self._pending_session_id = None
#self._transport.close()
else:
raise ProtocolError("Received {} message, and session is not yet established".format(msg.__class__))
......
......@@ -2236,7 +2236,7 @@ class CallHandler(Handler):
self.proto.onAfterSendCallError(rmsg, call)
if killsession:
self.proto.sendClose(3000, "killing WAMP session upon request by application exception")
self.proto.sendClose(3000, u"killing WAMP session upon request by application exception")
else:
raise Exception("fatal: internal error in CallHandler._sendCallError")
......
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -16,6 +16,29 @@
// Connections field used to store a map of the active sessions
var connections = {}, module = {};
/*
* Create a transport object appropriate to the protocol specified
* in the given url.
*/
function getTransportObject(url) {
var idx = url.indexOf(':'),
protocol = url.substring(0, idx);
if (protocol === 'ws' || protocol === 'wss') {
return {
'type': 'websocket',
'url': url,
};
} else if (protocol === 'http' || protocol === 'https') {
return {
'type': 'longpoll',
'url': url,
request_timeout: 300000
};
} else {
throw "Unknown protocol (" + protocol + ") for url (" + url + "). Unable to create transport object.";
}
}
/**
* @class vtkWeb.Session
* vtkWeb Session object on which RPC method calls can be made.
......@@ -94,14 +117,29 @@
* );
*/
function connect(connectionInfo, readyCallback, closeCallback) {
var wsuri = connectionInfo.sessionURL, onReady = readyCallback, onClose = closeCallback;
var uri = connectionInfo.sessionURL,
onReady = readyCallback,
onClose = closeCallback,
uriList = [].concat(uri),
transports = [];
if(!connectionInfo.hasOwnProperty("secret")) {
connectionInfo.secret = "vtkweb-secret"; // Default value
}
for (var i = 0; i < uriList.length; i+=1) {
var url = uriList[i],
transport = null;
try {
transport = getTransportObject(url);
transports.push(transport);
} catch (transportCreateError) {
console.error(transportCreateError);
}
}
connectionInfo.connection = new autobahn.Connection({
url: wsuri,
transports: transports,
realm: "vtkweb",
authmethods: ["wampcra"],
authid: "vtkweb",
......
......@@ -203,7 +203,14 @@ def start_webserver(options, protocol=vtk_wamp.ServerProtocol, disableLogging=Fa
# Handle possibly complex lp endpoint
if not options.nolp:
lpResource = WampLongPollResource(session_factory)
lpResource = WampLongPollResource(session_factory,
timeout=options.timeout,
debug=options.debug)
#killAfter = 30000,
#queueLimitBytes = 1024 * 1024,
#queueLimitMessages = 1000,
#debug=True,
#reactor=reactor)
handle_complex_resource_path(options.lp, root, lpResource)
if options.uploadPath != None :
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment