diff options
author | sergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-17 23:43:00 +0000 |
---|---|---|
committer | sergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-17 23:43:00 +0000 |
commit | 7620735be42ebc236d2da42d64f22dc5dedd01f9 (patch) | |
tree | baf0e6311b84830cd76df764e73e9aacfeb65e3e /remoting/tools | |
parent | f90ab58c11abf783c850c632f9b0467f968e4045 (diff) | |
download | chromium_src-7620735be42ebc236d2da42d64f22dc5dedd01f9.zip chromium_src-7620735be42ebc236d2da42d64f22dc5dedd01f9.tar.gz chromium_src-7620735be42ebc236d2da42d64f22dc5dedd01f9.tar.bz2 |
JSON based host config storage implemented. Python script for host registration.
BUG=None
TEST=None
Review URL: http://codereview.chromium.org/2804007
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@50166 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting/tools')
-rw-r--r-- | remoting/tools/gaia_auth.py | 29 | ||||
-rwxr-xr-x | remoting/tools/gettoken.py | 48 | ||||
-rwxr-xr-x | remoting/tools/register_host.py | 83 |
3 files changed, 130 insertions, 30 deletions
diff --git a/remoting/tools/gaia_auth.py b/remoting/tools/gaia_auth.py new file mode 100644 index 0000000..da364e0 --- /dev/null +++ b/remoting/tools/gaia_auth.py @@ -0,0 +1,29 @@ +# Copyright (c) 2010 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +import getpass +import os +import urllib + +default_gaia_url = "https://www.google.com:443/accounts/ClientLogin" + +class GaiaAuthenticator: + def __init__(self, service, url = default_gaia_url): + self._service = service + self._url = url + + ## Logins to gaia and returns auth token. + def authenticate(self, email, passwd): + params = urllib.urlencode({'Email': email, 'Passwd': passwd, + 'source': 'chromoting', + 'service': self._service, + 'PersistentCookie': 'true', + 'accountType': 'GOOGLE'}) + f = urllib.urlopen(self._url, params); + result = f.read() + for line in result.splitlines(): + if line.startswith('Auth='): + auth_string = line[5:] + return auth_string + raise Exception("Gaia didn't return auth token: " + result) diff --git a/remoting/tools/gettoken.py b/remoting/tools/gettoken.py index 31db75b..3a61927 100755 --- a/remoting/tools/gettoken.py +++ b/remoting/tools/gettoken.py @@ -11,7 +11,8 @@ import getpass import os import urllib -url = "https://www.google.com:443/accounts/ClientLogin" +import gaia_auth + auth_filename = '.chromotingAuthToken' print "Email:", @@ -19,32 +20,19 @@ email = raw_input() passwd = getpass.getpass("Password: ") -params = urllib.urlencode({'Email': email, 'Passwd': passwd, - 'source': 'chromoting', 'service': 'chromiumsync', - 'PersistentCookie': 'true', 'accountType': 'GOOGLE'}) -f = urllib.urlopen(url, params); - -auth_found = False -for line in f: - if line.startswith('Auth='): - auth_string = line[5:] - - # Set permission mask for created file. - os.umask(0066) - auth_file = open(auth_filename, 'w') - auth_file.write(email) - auth_file.write('\n') - auth_file.write(auth_string) - auth_file.close() - - print - print 'Auth token:' - print - print auth_string - print '...saved in', auth_filename - auth_found = True - -if not auth_found: - print 'ERROR - Unable to find Auth token in output:' - for line in f: - print line, +authenticator = gaia_auth.GaiaAuthenticator('chromiumsync'); +auth_token = authenticator.authenticate(email, passwd) + +# Set permission mask for created file. +os.umask(0066) +auth_file = open(auth_filename, 'w') +auth_file.write(email) +auth_file.write('\n') +auth_file.write(auth_token) +auth_file.close() + +print +print 'Auth token:' +print +print auth_token +print '...saved in', auth_filename diff --git a/remoting/tools/register_host.py b/remoting/tools/register_host.py new file mode 100755 index 0000000..bb9f473 --- /dev/null +++ b/remoting/tools/register_host.py @@ -0,0 +1,83 @@ +#!/usr/bin/env python +# +# Copyright (c) 2010 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. +# +# register_host.py registers new hosts in chromoting directory. It +# asks for username/password and then writes these settings to config file. + +import getpass +import os +import urllib +import urllib2 +import uuid +import sys + +import gaia_auth + +server = 'www-googleapis-test.sandbox.google.com' +url = 'http://' + server + '/chromoting/v1/@me/hosts' + +settings_filename = 'ChromotingConfig.json' + +print "Email:", +email = raw_input() +password = getpass.getpass("Password: ") + +xapi_auth = gaia_auth.GaiaAuthenticator('xapi') +xapi_token = xapi_auth.authenticate(email, password) + +host_id = str(uuid.uuid1()) +print "HostId:", host_id +host_name = os.uname()[1] +print "HostName:", host_name +# TODO(sergeyu): Implement keypair generaion. +public_key = '123123' +jingle_id = '' + +#f = urllib.urlopen(url, params); +#print params +params = ('{"data":{' + \ + '"host_id": "%(host_id)s",' + \ + '"host_name": "%(host_name)s",' + \ + '"public_key": "%(public_key)s",' + \ + '"jingle_id": "%(jingle_id)s"}}') % \ + {'host_id': host_id, 'host_name': host_name, + 'public_key': public_key, 'jingle_id': jingle_id} +headers = {"Authorization": "GoogleLogin auth=" + xapi_token, + "Content-Type": "application/json" } +request = urllib2.Request(url, params, headers) + +opener = urllib2.OpenerDirector() +opener.add_handler(urllib2.HTTPDefaultErrorHandler()) + +print +print "Registering host with directory service..." +try: + res = urllib2.urlopen(request) + data = res.read() +except urllib2.HTTPError, err: + print >> sys.stderr, "Directory returned error:", err + print >> sys.stderr, err.fp.read() + sys.exit(1) + +print "Done" + +# Get token that the host will use to athenticate in talk network. +authenticator = gaia_auth.GaiaAuthenticator('chromiumsync'); +auth_token = authenticator.authenticate(email, password) + +# Write settings file. +os.umask(0066) # Set permission mask for created file. +settings_file = open(settings_filename, 'w') +settings_file.write('{\n'); +settings_file.write(' "xmpp_login" : "' + email + '",\n') +settings_file.write(' "xmpp_auth_token" : "' + auth_token + '",\n') +settings_file.write(' "host_id" : "' + host_id + '",\n') +settings_file.write(' "host_name" : "' + host_name + '",\n') +settings_file.write(' "public_key" : "' + public_key + '"\n') +settings_file.write('}\n') +settings_file.close() + +print 'Configuration saved in', settings_filename |