source: trunk/packages/invirt-vnc-server/invirt-vnc-authtoken @ 2521

Last change on this file since 2521 was 1965, checked in by quentin, 16 years ago

Include the VNC host and port in the VNC authentication token

  • Property svn:executable set to *
File size: 1.0 KB
Line 
1#!/usr/bin/python
2
3import os
4import sys
5import hmac
6import cPickle
7import sha
8import time
9import base64
10from invirt.vnc import getTokenKey
11from invirt.config import structs as config
12
13def getAuthToken(username, machine, lifetime=5*60):
14    data = {}
15    data['user'] = username
16    data['machine'] = machine
17    data['expires'] = time.time() + lifetime
18    data['connect_host'] = config.web.hostname
19    try:
20        data['connect_port'] = 10003 + [h.hostname for h in
21                                        config.hosts].index(os.uname()[1])
22    except:
23        data['connect_port'] = 5900
24    pickled_data = cPickle.dumps(data)
25    m = hmac.new(getTokenKey(), digestmod=sha)
26    m.update(pickled_data)
27    token = {'data': pickled_data, 'digest': m.digest()}
28    token = cPickle.dumps(token)
29    token = base64.urlsafe_b64encode(token)
30    return token
31
32def main():
33    try:
34        username = os.environ['REMOTE_USER']
35    except KeyError:
36        username = None
37    machine = sys.argv[1]
38    print getAuthToken(username, machine)
39
40if __name__ == '__main__':
41    main()
Note: See TracBrowser for help on using the repository browser.