From 33081d903dc187a1f8fc7b4765f4e1f092e1d9ec Mon Sep 17 00:00:00 2001 From: Iustin Pop <iustin@google.com> Date: Sun, 28 Sep 2008 14:44:52 +0000 Subject: [PATCH] Move the pseudo-secret generation to utils.py The bootstrap code needs a pseudo-secret and this is currently generated inside the InitGanetiServerSetup function. Since more users will need this, move it to utils.py Reviewed-by: ultrotter --- lib/bootstrap.py | 2 +- lib/utils.py | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/bootstrap.py b/lib/bootstrap.py index 160c1a59a..118c7b137 100644 --- a/lib/bootstrap.py +++ b/lib/bootstrap.py @@ -81,7 +81,7 @@ def _InitGanetiServerSetup(ss): """ # Create pseudo random password - randpass = sha.new(os.urandom(64)).hexdigest() + randpass = utils.GenerateSecret() # and write it into sstore ss.SetKey(ss.SS_NODED_PASS, randpass) diff --git a/lib/utils.py b/lib/utils.py index ebe974262..d73ee36a0 100644 --- a/lib/utils.py +++ b/lib/utils.py @@ -864,6 +864,16 @@ def NewUUID(): f.close() +def GenerateSecret(): + """Generates a random secret. + + This will generate a pseudo-random secret, and return its sha digest + (so that it can be used where an ASCII string is needed). + + """ + return sha.new(os.urandom(64)).hexdigest() + + def ReadFile(file_name, size=None): """Reads a file. -- GitLab