self.socks.transport.loseConnection()
def dataReceived(self,data):
+ #self.socks.log(self,"R"+data)
self.socks.write(data)
def write(self,data):
- #self.socks.log(self,data)
+ #self.socks.log(self,'W'+data)
self.transport.write(data)
def validateToken(self, token):
global TOKEN_KEY
+ self.auth_error = "Invalid token"
try:
token = base64.urlsafe_b64decode(token)
token = cPickle.loads(token)
m = hmac.new(TOKEN_KEY, digestmod=sha)
m.update(token['data'])
- self.auth_error = "Invalid token"
if (m.digest() == token['digest']):
data = cPickle.loads(token['data'])
expires = data["expires"]
self.auth_data = data
else:
self.auth_error = "Token has expired; please try logging in again"
- except:
- self.auth = None
+ except (TypeError, cPickle.UnpicklingError):
+ self.auth = None
print sys.exc_info()
def dataReceived(self,data):
try:
(header, data) = line.split(": ", 1)
headers[header] = data
- except:
+ except ValueError:
pass
if command == "AUTHTOKEN":
vmname = args[0]
if ("Auth-token" in headers):
token = headers["Auth-token"]
- try:
- self.validateToken(token)
- finally:
- if self.auth is not None:
- port = getPort(vmname, self.auth_data)
- if port is not None: # FIXME
- if port is not 0:
- d = self.connectClass(self.server, port, VNCAuthOutgoing, self)
- d.addErrback(lambda result, self=self: self.makeReply(404, result.getErrorMessage()))
- else:
- self.makeReply(404, "Unable to find VNC for VM "+vmname)
+ self.validateToken(token)
+ if self.auth is not None:
+ port = getPort(vmname, self.auth_data)
+ if port is not None: # FIXME
+ if port != 0:
+ d = self.connectClass(self.server, port, VNCAuthOutgoing, self)
+ d.addErrback(lambda result, self=self: self.makeReply(404, result.getErrorMessage()))
else:
- self.makeReply(401, "Unauthorized to connect to VM "+vmname)
+ self.makeReply(404, "Unable to find VNC for VM "+vmname)
else:
- if self.auth_error:
- self.makeReply(401, self.auth_error)
- else:
- self.makeReply(401, "Invalid token")
+ self.makeReply(401, "Unauthorized to connect to VM "+vmname)
+ else:
+ if self.auth_error:
+ self.makeReply(401, self.auth_error)
+ else:
+ self.makeReply(401, "Invalid token")
else:
self.makeReply(401, "Login first")
else: