def _scp_all_client_data(self, raw_data):
     """If the remote machine has a configuration key, we will
     encrypt its configuration data and secure-copy it to him rather
     than stream the data to bc.py's stdin"""
     enc_key = self.data['config_key']
     yaml_data_str = yaml.dump(raw_data)
     cipher = Cipher(enc_key)
     enc_data = cipher.encrypt_string(yaml_data_str)
     dest_path = os.path.join(self.spkg_dir, self.machine_name, "client.yml.enc")
     temp_file = tempfile.mkstemp()[1]
     open(temp_file, 'w').write(enc_data)
     self.scp(temp_file, dest_path, False)
     #self.server_log.debug("Cleaning local temporary file %s" % temp_file)
     #os.system("rm -f %s" % temp_file)
     self._stream_data("config_key: '%s'\n" % enc_key)
Beispiel #2
0
    def test_encrypted_ci(self):
        self.reset_packages()
        cipher = Cipher(CONFIG_PASSWORD)
        cipher_text = cipher.encrypt_string("/tmp/foogazi")
        package_config = {"test": {"value":"nowisthetimeforalldooment",
                                   "enc_directory": cipher_text},
                          "packages": ["TestPackageType4"],  
                         }
        self.make_localhost_config(additional_config=package_config)

        self.reset_packages()

        url = '/json/machine/reconcile/localhost'
        status, output, cmd_output = self.run_job(url, data={}, timeout=60)
        assert status == OK, output
Beispiel #3
0
 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."]