def decrypt_config(self): "Decrypt entries as necessary with decryptLoop from Cipher" if 1 == 1: #try: cipher = Cipher(self.password) cipher.decrypt_dict(self.data) else: #except: errmsg = "Error decrypting configuration" raise MachineConfigurationException(self.machine_name, errmsg)
def _validate_password(self, password): "Very shallow password validation" lazy_dog = "the_quick_brown_fox_jumped_over_the_lazy_dog\n" test_decrypt_file = os.path.join(self.server_home, 'admin', 'encryption_validation.yml') if not os.path.isfile(test_decrypt_file): msg = "%s doesn't exist, creating..." % test_decrypt_file self.server_log.warning( msg ) cipher = Cipher(password) enc_lazy = cipher.encrypt_string(lazy_dog) enc_dict = { "enc_test" : enc_lazy } open( test_decrypt_file, 'w' ).write(yaml.dump( enc_dict )) try: cipher_dict = yaml.load(open(test_decrypt_file, 'r').read()) except IOError: return FAIL, "Encryption not set up properly. %s not readable" try: cipher = Cipher(password) clear_dict = cipher.decrypt_dict(cipher_dict) except DecryptionException: return FAIL, ["Invalid configuration key."] if clear_dict.get("test") == lazy_dog: return OK, ['Configuration key set.'] return FAIL, ["Invalid configuration key."]