Last change
on this file since 1605 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
|
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 |
---|
| 11 | |
---|
| 12 | def 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 | |
---|
| 25 | def 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 | |
---|
| 33 | if __name__ == '__main__': |
---|
| 34 | main() |
---|
Note: See
TracBrowser
for help on using the repository browser.