commit f759f0fde748cfb88e0451dd19715794a5ca1e53
Author: Radek Novacek <rnovacek(a)redhat.com>
Date: Fri Nov 7 14:12:22 2014 +0100
password: fix decoding user password from crypted form
Encrypted passwords in the config file (returned by virt-who-password)
are always converted to hex because they contain unprintable bytes.
Converting from hex was missing.
config.py | 3 ++-
tests/test_config.py | 24 ++++++++++++++++++++++++
2 files changed, 26 insertions(+), 1 deletions(-)
---
diff --git a/config.py b/config.py
index 0df1159..a7f6ae3 100644
--- a/config.py
+++ b/config.py
@@ -22,6 +22,7 @@ import os
import logging
from ConfigParser import SafeConfigParser, NoOptionError, Error,
MissingSectionHeaderError
from password import Password
+from binascii import unhexlify
VIRTWHO_CONF_DIR = "/etc/virt-who.d/"
@@ -83,7 +84,7 @@ class Config(object):
if password is None:
try:
crypted = parser.get(name, "encrypted_password")
- password = Password.decrypt(crypted)
+ password = Password.decrypt(unhexlify(crypted))
except NoOptionError:
password = None
diff --git a/tests/test_config.py b/tests/test_config.py
index 08eb4f2..776e07b 100644
--- a/tests/test_config.py
+++ b/tests/test_config.py
@@ -24,6 +24,8 @@ import shutil
from config import ConfigManager, InvalidOption
from tempfile import mkdtemp
from base import TestBase, unittest
+from binascii import hexlify
+from mock import patch
class TestReadingConfigs(TestBase):
@@ -94,6 +96,28 @@ env=staging
manager = ConfigManager(self.config_dir)
self.assertEqual(len(manager.configs), 0)
+ @patch('password.Password._read_key_iv')
+ def testCryptedPassword(self, password):
+ from password import Password
+ password.return_value = (hexlify(Password._generate_key()),
hexlify(Password._generate_key()))
+ passwd = "TestSecretPassword!"
+ crypted = hexlify(Password.encrypt(passwd))
+
+ filename = os.path.join(self.config_dir, "test.conf")
+ with open(filename, "w") as f:
+ f.write("""
+[test]
+type=esx
+server=1.2.3.4
+username=admin
+encrypted_password=%s
+owner=root
+env=staging
+""" % crypted)
+ manager = ConfigManager(self.config_dir)
+ self.assertEqual(len(manager.configs), 1)
+ self.assertEqual(manager.configs[0].password, passwd)
+
def testNoOptionsConfig(self):
with open(os.path.join(self.config_dir, "test.conf"), "w") as
f:
f.write("""
Show replies by date