Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(346)

Side by Side Diff: remoting/tools/register_host.py

Issue 2958001: Added RSA key generator for register_host.py (Closed)
Patch Set: - Created 10 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« remoting/host/keygen_main.cc ('K') | « remoting/tools/keygen.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # 2 #
3 # Copyright (c) 2010 The Chromium Authors. All rights reserved. 3 # Copyright (c) 2010 The Chromium Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be 4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file. 5 # found in the LICENSE file.
6 # 6 #
7 # register_host.py registers new hosts in chromoting directory. It 7 # register_host.py registers new hosts in chromoting directory. It
8 # asks for username/password and then writes these settings to config file. 8 # asks for username/password and then writes these settings to config file.
9 9
10 import getpass 10 import getpass
11 import os 11 import os
12 import urllib 12 import urllib
13 import urllib2 13 import urllib2
14 import uuid 14 import uuid
15 import socket 15 import socket
16 import sys 16 import sys
17 17
18 import gaia_auth 18 import gaia_auth
19 import keygen
19 20
20 server = 'www-googleapis-test.sandbox.google.com' 21 server = 'www-googleapis-test.sandbox.google.com'
21 url = 'http://' + server + '/chromoting/v1/@me/hosts' 22 url = 'http://' + server + '/chromoting/v1/@me/hosts'
22 23
23 settings_filepath = os.path.join(os.path.expanduser('~'), 24 settings_filepath = os.path.join(os.path.expanduser('~'),
24 '.ChromotingConfig.json') 25 '.ChromotingConfig.json')
25 26
26 print "Email:", 27 print "Email:",
27 email = raw_input() 28 email = raw_input()
28 password = getpass.getpass("Password: ") 29 password = getpass.getpass("Password: ")
29 30
30 xapi_auth = gaia_auth.GaiaAuthenticator('xapi') 31 xapi_auth = gaia_auth.GaiaAuthenticator('xapi')
31 xapi_token = xapi_auth.authenticate(email, password) 32 xapi_token = xapi_auth.authenticate(email, password)
32 33
33 host_id = str(uuid.uuid1()) 34 host_id = str(uuid.uuid1())
34 print "HostId:", host_id 35 print "HostId:", host_id
35 host_name = socket.gethostname() 36 host_name = socket.gethostname()
36 print "HostName:", host_name 37 print "HostName:", host_name
37 # TODO(sergeyu): Implement keypair generation.
38 public_key = '123123'
39 jingle_id = ''
40 38
41 #f = urllib.urlopen(url, params); 39 print "Generating RSA key pair...",
42 #print params 40 (private_key, public_key) = keygen.generateRSAKeyPair()
41 print "Done"
42
43 params = ('{"data":{' + \ 43 params = ('{"data":{' + \
44 '"host_id": "%(host_id)s",' + \ 44 '"host_id": "%(host_id)s",' + \
45 '"host_name": "%(host_name)s",' + \ 45 '"host_name": "%(host_name)s",' + \
46 '"public_key": "%(public_key)s",' + \ 46 '"public_key": "%(public_key)s"}}') % \
47 '"jingle_id": "%(jingle_id)s"}}') % \
48 {'host_id': host_id, 'host_name': host_name, 47 {'host_id': host_id, 'host_name': host_name,
49 'public_key': public_key, 'jingle_id': jingle_id} 48 'public_key': public_key}
50 headers = {"Authorization": "GoogleLogin auth=" + xapi_token, 49 headers = {"Authorization": "GoogleLogin auth=" + xapi_token,
51 "Content-Type": "application/json" } 50 "Content-Type": "application/json" }
52 request = urllib2.Request(url, params, headers) 51 request = urllib2.Request(url, params, headers)
53 52
54 opener = urllib2.OpenerDirector() 53 opener = urllib2.OpenerDirector()
55 opener.add_handler(urllib2.HTTPDefaultErrorHandler()) 54 opener.add_handler(urllib2.HTTPDefaultErrorHandler())
56 55
57 print 56 print
58 print "Registering host with directory service..." 57 print "Registering host with directory service..."
59 try: 58 try:
(...skipping 11 matching lines...) Expand all
71 auth_token = authenticator.authenticate(email, password) 70 auth_token = authenticator.authenticate(email, password)
72 71
73 # Write settings file. 72 # Write settings file.
74 os.umask(0066) # Set permission mask for created file. 73 os.umask(0066) # Set permission mask for created file.
75 settings_file = open(settings_filepath, 'w') 74 settings_file = open(settings_filepath, 'w')
76 settings_file.write('{\n'); 75 settings_file.write('{\n');
77 settings_file.write(' "xmpp_login" : "' + email + '",\n') 76 settings_file.write(' "xmpp_login" : "' + email + '",\n')
78 settings_file.write(' "xmpp_auth_token" : "' + auth_token + '",\n') 77 settings_file.write(' "xmpp_auth_token" : "' + auth_token + '",\n')
79 settings_file.write(' "host_id" : "' + host_id + '",\n') 78 settings_file.write(' "host_id" : "' + host_id + '",\n')
80 settings_file.write(' "host_name" : "' + host_name + '",\n') 79 settings_file.write(' "host_name" : "' + host_name + '",\n')
81 settings_file.write(' "public_key" : "' + public_key + '"\n') 80 settings_file.write(' "private_key" : "' + private_key + '",\n')
82 settings_file.write('}\n') 81 settings_file.write('}\n')
83 settings_file.close() 82 settings_file.close()
84 83
85 print 'Configuration saved in', settings_filepath 84 print 'Configuration saved in', settings_filepath
OLDNEW
« remoting/host/keygen_main.cc ('K') | « remoting/tools/keygen.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698