def register(self, auth): logging.info("HostId: " + self.host_id) logging.info("HostName: " + self.host_name) logging.info("Generating RSA key pair...") (self.private_key, public_key) = keygen.generateRSAKeyPair() logging.info("Done") json_data = { "data": { "hostId": self.host_id, "hostName": self.host_name, "publicKey": public_key, } } params = json.dumps(json_data) headers = { "Authorization": "GoogleLogin auth=" + auth.chromoting_auth_token, "Content-Type": "application/json", } request = urllib2.Request(self.url, params, headers) opener = urllib2.OpenerDirector() opener.add_handler(urllib2.HTTPDefaultErrorHandler()) logging.info("Registering host with directory service...") try: res = urllib2.urlopen(request) data = res.read() except urllib2.HTTPError, err: logging.error("Directory returned error: " + str(err)) logging.error(err.read()) sys.exit(1)
def main(): server = 'www.googleapis.com' url = 'https://' + server + '/chromoting/v1/@me/hosts' settings_filepath = os.path.join(os.path.expanduser('~'), '.ChromotingConfig.json') print "Email:", email = raw_input() password = getpass.getpass("Password: "******"HostId:", host_id host_name = socket.gethostname() print "HostName:", host_name print "Generating RSA key pair...", (private_key, public_key) = keygen.generateRSAKeyPair() print "Done" while 1: pin = getpass.getpass("Host PIN: ") if len(pin) < 4: print "PIN must be at least 4 characters long." continue pin2 = getpass.getpass("Confirm host PIN: ") if pin2 != pin: print "PINs didn't match. Please try again." continue break host_secret_hash = "hmac:" + base64.b64encode( hmac.new(str(host_id), pin, hashlib.sha256).digest()) params = { "data": { "hostId": host_id, "hostName": host_name, "publicKey": public_key, } } headers = {"Authorization": "GoogleLogin auth=" + auth_token, "Content-Type": "application/json" } request = urllib2.Request(url, json.dumps(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() return 1
def main(): server = 'www.googleapis.com' url = 'https://' + server + '/chromoting/v1/@me/hosts' settings_filepath = os.path.join(os.path.expanduser('~'), '.ChromotingConfig.json') print "Email:", email = raw_input() password = getpass.getpass("Password: "******"HostId:", host_id host_name = socket.gethostname() print "HostName:", host_name print "Generating RSA key pair...", (private_key, public_key) = keygen.generateRSAKeyPair() print "Done" while 1: pin = getpass.getpass("Host PIN (can be empty): ") if len(pin) > 0 and len(pin) < 4: print "PIN must be at least 4 characters long." continue break if pin == "": host_secret_hash = None else: host_secret_hash = "hmac:" + base64.b64encode( hmac.new(str(host_id), pin, hashlib.sha256).digest()) params = { "data": { "hostId": host_id, "hostName": host_name, "publicKey": public_key, } } headers = {"Authorization": "GoogleLogin auth=" + auth_token, "Content-Type": "application/json" } request = urllib2.Request(url, json.dumps(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() return 1
def register(self, auth): """Generates a private key for the stored |host_id|, and registers it with the Directory service. Args: auth: Authentication object with credentials for authenticating with the Directory service. Raises: urllib2.HTTPError: An error occurred talking to the Directory server (for example, if the |auth| credentials were rejected). """ logging.info("HostId: " + self.host_id) logging.info("HostName: " + self.host_name) logging.info("Generating RSA key pair...") (self.private_key, public_key) = keygen.generateRSAKeyPair() logging.info("Done") json_data = { "data": { "hostId": self.host_id, "hostName": self.host_name, "publicKey": public_key, } } params = json.dumps(json_data) headers = { "Authorization": "GoogleLogin auth=" + auth.chromoting_auth_token, "Content-Type": "application/json", } request = urllib2.Request(self.url, params, headers) opener = urllib2.OpenerDirector() opener.add_handler(urllib2.HTTPDefaultErrorHandler()) logging.info("Registering host with directory service...") res = urllib2.urlopen(request) data = res.read() logging.info("Done")
'.ChromotingConfig.json') print "Email:", email = raw_input() password = getpass.getpass("Password: "******"HostId:", host_id host_name = socket.gethostname() print "HostName:", host_name print "Generating RSA key pair...", (private_key, public_key) = keygen.generateRSAKeyPair() print "Done" params = ('{"data":{' + \ '"hostId": "%(hostId)s",' + \ '"hostName": "%(hostName)s",' + \ '"publicKey": "%(publicKey)s"}}') % \ {'hostId': host_id, 'hostName': host_name, 'publicKey': public_key} headers = { "Authorization": "GoogleLogin auth=" + auth_token, "Content-Type": "application/json" } request = urllib2.Request(url, params, headers) opener = urllib2.OpenerDirector()
'.ChromotingConfig.json') print "Email:", email = raw_input() password = getpass.getpass("Password: "******"HostId:", host_id host_name = socket.gethostname() print "HostName:", host_name print "Generating RSA key pair...", (private_key, public_key) = keygen.generateRSAKeyPair() print "Done" params = ('{"data":{' + \ '"hostId": "%(hostId)s",' + \ '"hostName": "%(hostName)s",' + \ '"publicKey": "%(publicKey)s"}}') % \ {'hostId': host_id, 'hostName': host_name, 'publicKey': public_key} headers = {"Authorization": "GoogleLogin auth=" + auth_token, "Content-Type": "application/json" } request = urllib2.Request(url, params, headers) opener = urllib2.OpenerDirector() opener.add_handler(urllib2.HTTPDefaultErrorHandler())