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

Unified Diff: remoting/tools/me2me_virtual_host.py

Issue 9270031: Enable V2 authentication for Me2Me host. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: - Created 8 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « remoting/protocol/me2me_host_authenticator_factory.cc ('k') | remoting/tools/register_host.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: remoting/tools/me2me_virtual_host.py
diff --git a/remoting/tools/me2me_virtual_host.py b/remoting/tools/me2me_virtual_host.py
index 5a742c25da26397a5800d298e900c5a862478431..0ffbee1cadcf0a06e2693794147f9f20c7075e3b 100755
--- a/remoting/tools/me2me_virtual_host.py
+++ b/remoting/tools/me2me_virtual_host.py
@@ -10,8 +10,10 @@
# process, running under an ordinary (non-root) user account.
import atexit
+import base64
import getpass
import hashlib
+import hmac
import json
import logging
import optparse
@@ -115,13 +117,13 @@ class Host:
Callers should instantiate a Host object (passing in a filename where the
config will be kept), then should call either of the methods:
- * create_config(auth): Create a new Host configuration and register it with
- the Directory Service (the "auth" parameter is used to authenticate with the
- Service).
+ * register(auth): Create a new Host configuration and register it
+ with the Directory Service (the "auth" parameter is used to
+ authenticate with the Service).
* load_config(): Load a config from disk, with details of an existing Host
registration.
- After calling create_config() (or making any config changes) the method
+ After calling register() (or making any config changes) the method
save_config() should be called to save the details to disk.
"""
@@ -130,11 +132,13 @@ class Host:
def __init__(self, config_file):
self.config_file = config_file
-
- def create_config(self, auth):
self.host_id = str(uuid.uuid1())
- logging.info("HostId: " + self.host_id)
self.host_name = socket.gethostname()
+ self.host_secret_hash = None
+ self.private_key = None
+
+ def register(self, auth):
+ logging.info("HostId: " + self.host_id)
logging.info("HostName: " + self.host_name)
logging.info("Generating RSA key pair...")
@@ -168,16 +172,31 @@ class Host:
sys.exit(1)
logging.info("Done")
+ def ask_pin(self):
+ 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 == "":
+ self.host_secret_hash = None
+ else:
+ self.host_secret_hash = "hmac:" + base64.b64encode(
+ hmac.new(str(self.host_id), pin, hashlib.sha256).digest())
+
def load_config(self):
try:
settings_file = open(self.config_file, 'r')
data = json.load(settings_file)
settings_file.close()
- self.host_id = data["host_id"]
- self.host_name = data["host_name"]
- self.private_key = data["private_key"]
except:
+ logging.info("Failed to load: " + self.config_file)
return False
+ self.host_id = data["host_id"]
+ self.host_name = data["host_name"]
+ self.host_secret_hash = data.get("host_secret_hash")
+ self.private_key = data["private_key"]
return True
def save_config(self):
@@ -186,6 +205,9 @@ class Host:
"host_name": self.host_name,
"private_key": self.private_key,
}
+ if self.host_secret_hash:
+ data["host_secret_hash"] = self.host_secret_hash,
+
old_umask = os.umask(0066)
settings_file = open(self.config_file, 'w')
settings_file.write(json.dumps(data, indent=2))
@@ -503,7 +525,8 @@ def main():
host = Host(os.path.join(CONFIG_DIR, "host#%s.json" % host_hash))
if not host.load_config():
- host.create_config(auth)
+ host.ask_pin()
+ host.register(auth)
host.save_config()
global g_pidfile
« no previous file with comments | « remoting/protocol/me2me_host_authenticator_factory.cc ('k') | remoting/tools/register_host.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698