]> git.ipfire.org Git - oddments/fireinfo.git/commitdiff
Add some new "secret_id" and make it readable from file.
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 10 Dec 2010 23:22:22 +0000 (00:22 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 10 Dec 2010 23:22:22 +0000 (00:22 +0100)
fireinfo/system.py

index c0ade716a7e11f72430c43cd1fb8d64ebe17554b..a4fff57e765e96f96ef88a003f308c4e2897ad8b 100644 (file)
@@ -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):
                """