示例#1
0
def login_cmd(args):
  """login command"""
  if len(args) != 0:
    return usage()

  import getpass
  import gaia_auth

  print "Email:",
  email = raw_input()
  passwd = getpass.getpass("Password: ")

  authenticator = gaia_auth.GaiaAuthenticator('chromoting');
  auth_token = authenticator.authenticate(email, passwd)

  # Set permission mask for created file.
  os.umask(0066)
  auth_file = open(auth_filepath, 'w')
  auth_file.write(email)
  auth_file.write('\n')
  auth_file.write(auth_token)
  auth_file.close()

  print 'Auth token: ', auth_token
  print '...saved in', auth_filepath
示例#2
0
def main():
    basepath = os.path.expanduser('~')
    chromoting_auth_filepath = os.path.join(basepath, '.chromotingAuthToken')
    chromoting_dir_auth_filepath = os.path.join(
        basepath, '.chromotingDirectoryAuthToken')

    print "Email:",
    email = raw_input()

    passwd = getpass.getpass("Password: ")

    chromoting_authenticator = gaia_auth.GaiaAuthenticator('chromiumsync')
    chromoting_auth_token = chromoting_authenticator.authenticate(
        email, passwd)

    chromoting_dir_authenticator = gaia_auth.GaiaAuthenticator('chromoting')
    chromoting_dir_auth_token = chromoting_dir_authenticator.authenticate(
        email, passwd)

    # Set permission mask for created files.
    os.umask(0066)

    chromoting_auth_file = open(chromoting_auth_filepath, 'w')
    chromoting_auth_file.write(email)
    chromoting_auth_file.write('\n')
    chromoting_auth_file.write(chromoting_auth_token)
    chromoting_auth_file.close()

    print
    print 'Chromoting (sync) Auth Token:'
    print
    print chromoting_auth_token
    print '...saved in', chromoting_auth_filepath

    chromoting_dir_auth_file = open(chromoting_dir_auth_filepath, 'w')
    chromoting_dir_auth_file.write(email)
    chromoting_dir_auth_file.write('\n')
    chromoting_dir_auth_file.write(chromoting_dir_auth_token)
    chromoting_dir_auth_file.close()

    print
    print 'Chromoting Directory Auth Token:'
    print
    print chromoting_dir_auth_token
    print '...saved in', chromoting_dir_auth_filepath
    return 0
示例#3
0
    def generate_tokens(self):
        """Prompt for username/password and use them to generate new authentication
    tokens.

    Raises:
      Exception: Failed to get new authentication tokens.
    """
        print "Email:",
        self.login = raw_input()
        password = getpass.getpass("Password: ")

        chromoting_auth = gaia_auth.GaiaAuthenticator('chromoting')
        self.chromoting_auth_token = chromoting_auth.authenticate(
            self.login, password)

        xmpp_authenticator = gaia_auth.GaiaAuthenticator('chromiumsync')
        self.xmpp_auth_token = xmpp_authenticator.authenticate(
            self.login, password)
示例#4
0
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
示例#5
0
import os
import urllib

import gaia_auth

chromoting_auth_filepath = os.path.join(os.path.expanduser('~'),
                                        '.chromotingAuthToken')
chromoting_dir_auth_filepath = os.path.join(os.path.expanduser('~'),
                                            '.chromotingDirectoryAuthToken')

print "Email:",
email = raw_input()

passwd = getpass.getpass("Password: ")

chromoting_authenticator = gaia_auth.GaiaAuthenticator('chromiumsync');
chromoting_auth_token = chromoting_authenticator.authenticate(email, passwd)

chromoting_dir_authenticator = gaia_auth.GaiaAuthenticator('chromoting');
chromoting_dir_auth_token = \
    chromoting_dir_authenticator.authenticate(email, passwd)

# Set permission mask for created files.
os.umask(0066)

chromoting_auth_file = open(chromoting_auth_filepath, 'w')
chromoting_auth_file.write(email)
chromoting_auth_file.write('\n')
chromoting_auth_file.write(chromoting_auth_token)
chromoting_auth_file.close()
示例#6
0
  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

  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_filepath, 'w')
  config = {
      "xmpp_login" : email,
      "xmpp_auth_token" : auth_token,
      "host_id" : host_id,
      "host_name" : host_name,
      "host_secret_hash": host_secret_hash,
      "private_key" : private_key,
      }

  settings_file.write(json.dumps(config, indent=2))