import time
def getTokenKey():
- return file('/etc/invirt/secrets/vnc-key').read().strip()
+ return file('/etc/invirt/vnc/token-key').read().strip()
def getPort(name, auth_data):
import get_port
def validateToken(self, token):
self.auth_error = "Invalid token"
try:
- token = base64.urlsafe_b64decode(token)
- token = cPickle.loads(token)
+ (pickled_data, digest) = map(base64.urlsafe_b64decode, token.split("."))
m = hmac.new(getTokenKey(), digestmod=sha)
- m.update(token['data'])
- if (m.digest() == token['digest']):
+ m.update(pickled_data)
+ if (m.digest() == digest):
data = cPickle.loads(token['data'])
expires = data["expires"]
if (time.time() < expires):
self.auth_data = data
else:
self.auth_error = "Token has expired; please try logging in again"
- except (TypeError, cPickle.UnpicklingError):
+ except (TypeError, ValueError, cPickle.UnpicklingError):
self.auth = None
print sys.exc_info()