- Timestamp:
- Oct 7, 2007, 6:16:07 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/vnc/vnc_server/vncexternalauth.py
r118 r125 8 8 9 9 # python imports 10 import sys 10 11 import struct 11 12 import string … … 22 23 TOKEN_KEY = "0M6W0U1IXexThi5idy8mnkqPKEq1LtEnlK/pZSn0cDrN" 23 24 24 def getPort(name, auth): 25 port = get_port.findPort(name) 26 if port is None: 27 return 0 28 return int(port.split(':')[1]) 29 25 def getPort(name, auth_data): 26 if (auth_data["machine"] == name): 27 port = get_port.findPort(name) 28 if port is None: 29 return 0 30 return int(port.split(':')[1]) 31 else: 32 return None 33 30 34 class VNCAuthOutgoing(protocol.Protocol): 31 35 … … 62 66 def validateToken(self, token): 63 67 global TOKEN_KEY 64 if token == "quentin": 65 self.auth = "quentin@ATHENA.MIT.EDU" 66 return #FIXME 67 token = base64.urlsafe_b64decode(token) 68 token = cPickle.loads(token) 69 m = hmac.new(TOKEN_KEY, digestmod=sha) 70 m.update(token['data']) 71 if (m.digest() == token['digest']): 72 data = cPickle.loads(token['data']) 73 expires = data["expires"] 74 if (time.time() < expires): 75 self.auth = data["user"] 68 try: 69 token = base64.urlsafe_b64decode(token) 70 token = cPickle.loads(token) 71 m = hmac.new(TOKEN_KEY, digestmod=sha) 72 m.update(token['data']) 73 self.auth_error = "Invalid token" 74 if (m.digest() == token['digest']): 75 data = cPickle.loads(token['data']) 76 expires = data["expires"] 77 if (time.time() < expires): 78 self.auth = data["user"] 79 self.auth_error = None 80 self.auth_machine = data["machine"] 81 self.auth_data = data 82 else: 83 self.auth_error = "Token has expired; please try logging in again" 84 except: 85 self.auth = None 86 print sys.exc_info() 76 87 77 88 def dataReceived(self,data): … … 108 119 finally: 109 120 if self.auth is not None: 110 port = getPort(vmname, self.auth )121 port = getPort(vmname, self.auth_data) 111 122 if port is not None: # FIXME 112 d = self.connectClass(self.server, port, VNCAuthOutgoing, self) 113 d.addErrback(lambda result, self=self: self.makeReply(404, result.getErrorMessage())) 123 if port is not 0: 124 d = self.connectClass(self.server, port, VNCAuthOutgoing, self) 125 d.addErrback(lambda result, self=self: self.makeReply(404, result.getErrorMessage())) 126 else: 127 self.makeReply(404, "Unable to find VNC for VM "+vmname) 114 128 else: 115 129 self.makeReply(401, "Unauthorized to connect to VM "+vmname) 116 130 else: 117 self.makeReply(401, "Invalid token") 131 if self.auth_error: 132 self.makeReply(401, self.auth_error) 133 else: 134 self.makeReply(401, "Invalid token") 118 135 else: 119 136 self.makeReply(401, "Login first")
Note: See TracChangeset
for help on using the changeset viewer.