From: Michael Tremer Date: Fri, 10 Dec 2010 23:22:22 +0000 (+0100) Subject: Add some new "secret_id" and make it readable from file. X-Git-Tag: v0.7~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=73014efe6d2d2f5b93f054cc359b81fcb4f64149;p=oddments%2Ffireinfo.git Add some new "secret_id" and make it readable from file. --- diff --git a/fireinfo/system.py b/fireinfo/system.py index c0ade71..a4fff57 100644 --- a/fireinfo/system.py +++ b/fireinfo/system.py @@ -14,6 +14,7 @@ import hypervisor PROFILE_VERSION = 0 SYS_CLASS_DMI = "/sys/class/dmi/id" +SECRET_ID_FILE = "/etc/fireinfo-id" class Singleton(type): def __init__(cls, name, bases, dict): @@ -117,9 +118,6 @@ class System(object): "public_id" : self.public_id, "private_id" : self.private_id, - # XXX just for testing: - "secret_id" : self._unique_id, - # Actual profile data "profile" : p, } @@ -135,7 +133,7 @@ class System(object): This returns a globally (hopefully) ID to identify the host later (by request) in the database. """ - public_id = self._unique_id + public_id = self.secret_id if not public_id: return "0" * 40 @@ -150,7 +148,7 @@ class System(object): No one could ever guess this without access to the host. """ private_id = "" - for i in reversed(self._unique_id): + for i in reversed(self.secret_id): private_id += i if not private_id: @@ -158,6 +156,17 @@ class System(object): return hashlib.sha1(private_id).hexdigest() + @property + def secret_id(self): + """ + Read a "secret" ID from a file if available + or calculate it from the hardware. + """ + if os.path.exists(SECRET_ID_FILE): + return read_from_file(SECRET_ID_FILE) + + return hashlib.sha1(self._unique_id).hexdigest() + @property def _unique_id(self): """