Last change
on this file since 2523 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
|
Rev | Line | |
---|
[1389] | 1 | #!/usr/bin/python |
---|
| 2 | |
---|
| 3 | import os |
---|
| 4 | import sys |
---|
| 5 | import hmac |
---|
| 6 | import cPickle |
---|
| 7 | import sha |
---|
| 8 | import time |
---|
| 9 | import base64 |
---|
| 10 | from invirt.vnc import getTokenKey |
---|
[1965] | 11 | from invirt.config import structs as config |
---|
[1389] | 12 | |
---|
| 13 | def getAuthToken(username, machine, lifetime=5*60): |
---|
| 14 | data = {} |
---|
| 15 | data['user'] = username |
---|
| 16 | data['machine'] = machine |
---|
| 17 | data['expires'] = time.time() + lifetime |
---|
[1965] | 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 |
---|
[1389] | 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 | |
---|
| 32 | def 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 | |
---|
| 40 | if __name__ == '__main__': |
---|
| 41 | main() |
---|
Note: See
TracBrowser
for help on using the repository browser.