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

Last change on this file since 1545 was 1389, checked in by broder, 16 years ago

Add a script for generating VNC auth tokens, to be exposed over remctl

  • Property svn:executable set to *
File size: 792 bytes
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
11
12def getAuthToken(username, machine, lifetime=5*60):
13    data = {}
14    data['user'] = username
15    data['machine'] = machine
16    data['expires'] = time.time() + lifetime
17    pickled_data = cPickle.dumps(data)
18    m = hmac.new(getTokenKey(), digestmod=sha)
19    m.update(pickled_data)
20    token = {'data': pickled_data, 'digest': m.digest()}
21    token = cPickle.dumps(token)
22    token = base64.urlsafe_b64encode(token)
23    return token
24
25def main():
26    try:
27        username = os.environ['REMOTE_USER']
28    except KeyError:
29        username = None
30    machine = sys.argv[1]
31    print getAuthToken(username, machine)
32
33if __name__ == '__main__':
34    main()
Note: See TracBrowser for help on using the repository browser.