Beispiel #1
0
 def decrypt_flat_config(flat_config):
     """
     Same as decrypt_config but for a flat configuration
     """
     keys = [
         config_arr_as_array[2]
         for config_arr_as_array in ENCRYPTED_CONFIG_ARRAYS
     ]
     for key in keys:
         if isinstance(flat_config[key],
                       collections.Sequence) and not isinstance(
                           flat_config[key], string_types):
             # Check if we are decrypting ssh key pair
             if flat_config[key] and isinstance(
                     flat_config[key][0],
                     dict) and 'public_key' in flat_config[key][0]:
                 flat_config[key] = [
                     ConfigService.decrypt_ssh_key_pair(item)
                     for item in flat_config[key]
                 ]
             else:
                 flat_config[key] = [
                     encryptor.dec(item) for item in flat_config[key]
                 ]
         else:
             flat_config[key] = encryptor.dec(flat_config[key])
     return flat_config
Beispiel #2
0
 def decrypt_ssh_key_pair(pair, encrypt=False):
     if encrypt:
         pair['public_key'] = encryptor.enc(pair['public_key'])
         pair['private_key'] = encryptor.enc(pair['private_key'])
     else:
         pair['public_key'] = encryptor.dec(pair['public_key'])
         pair['private_key'] = encryptor.dec(pair['private_key'])
     return pair
Beispiel #3
0
 def decrypt_flat_config(flat_config):
     """
     Same as decrypt_config but for a flat configuration
     """
     keys = [config_arr_as_array[2] for config_arr_as_array in ENCRYPTED_CONFIG_ARRAYS]
     for key in keys:
         if isinstance(flat_config[key], collections.Sequence) and not isinstance(flat_config[key], basestring):
             flat_config[key] = [encryptor.dec(item) for item in flat_config[key]]
         else:
             flat_config[key] = encryptor.dec(flat_config[key])
     return flat_config
Beispiel #4
0
    def _encrypt_or_decrypt_config(config, is_decrypt=False):
        for config_arr_as_array in ENCRYPTED_CONFIG_ARRAYS:
            config_arr = config
            for config_key_part in config_arr_as_array:
                config_arr = config_arr[config_key_part]

            for i in range(len(config_arr)):
                config_arr[i] = encryptor.dec(config_arr[i]) if is_decrypt else encryptor.enc(config_arr[i])
Beispiel #5
0
    def _encrypt_or_decrypt_config(config, is_decrypt=False):
        for config_arr_as_array in ENCRYPTED_CONFIG_ARRAYS:
            config_arr = config
            for config_key_part in config_arr_as_array:
                config_arr = config_arr[config_key_part]

            for i in range(len(config_arr)):
                config_arr[i] = encryptor.dec(config_arr[i]) if is_decrypt else encryptor.enc(config_arr[i])
Beispiel #6
0
 def decrypt_flat_config(flat_config):
     """
     Same as decrypt_config but for a flat configuration
     """
     keys = [
         config_arr_as_array[2]
         for config_arr_as_array in ENCRYPTED_CONFIG_ARRAYS
     ]
     for key in keys:
         if isinstance(flat_config[key],
                       collections.Sequence) and not isinstance(
                           flat_config[key], basestring):
             flat_config[key] = [
                 encryptor.dec(item) for item in flat_config[key]
             ]
         else:
             flat_config[key] = encryptor.dec(flat_config[key])
     return flat_config
Beispiel #7
0
    def _encrypt_or_decrypt_config(config, is_decrypt=False):
        for config_arr_as_array in ENCRYPTED_CONFIG_ARRAYS:
            config_arr = config
            for config_key_part in config_arr_as_array:
                config_arr = config_arr[config_key_part]

            for i in range(len(config_arr)):
                # Check if array of shh key pairs and then decrypt
                if isinstance(config_arr[i], dict) and 'public_key' in config_arr[i]:
                    config_arr[i] = ConfigService.decrypt_ssh_key_pair(config_arr[i]) if is_decrypt else \
                                    ConfigService.decrypt_ssh_key_pair(config_arr[i], True)
                else:
                    config_arr[i] = encryptor.dec(config_arr[i]) if is_decrypt else encryptor.enc(config_arr[i])
Beispiel #8
0
 def get_config_value(config_key_as_arr, is_initial_config=False, should_decrypt=True):
     """
     Get a specific config value.
     :param config_key_as_arr: The config key as an array. e.g. ['basic', 'credentials', 'exploit_password_list'].
     :param is_initial_config: If True, returns the value of the initial config instead of the current config.
     :param should_decrypt: If True, the value of the config key will be decrypted
                            (if it's in the list of encrypted config values).
     :return: The value of the requested config key.
     """
     config_key = functools.reduce(lambda x, y: x + '.' + y, config_key_as_arr)
     config = mongo.db.config.find_one({'name': 'initial' if is_initial_config else 'newconfig'}, {config_key: 1})
     for config_key_part in config_key_as_arr:
         config = config[config_key_part]
     if should_decrypt and (config_key_as_arr in ENCRYPTED_CONFIG_ARRAYS):
         config = [encryptor.dec(x) for x in config]
     return config
Beispiel #9
0
 def get_config_value(config_key_as_arr, is_initial_config=False, should_decrypt=True):
     """
     Get a specific config value.
     :param config_key_as_arr: The config key as an array. e.g. ['basic', 'credentials', 'exploit_password_list'].
     :param is_initial_config: If True, returns the value of the initial config instead of the current config.
     :param should_decrypt: If True, the value of the config key will be decrypted
                            (if it's in the list of encrypted config values).
     :return: The value of the requested config key.
     """
     config_key = functools.reduce(lambda x, y: x + '.' + y, config_key_as_arr)
     config = mongo.db.config.find_one({'name': 'initial' if is_initial_config else 'newconfig'}, {config_key: 1})
     for config_key_part in config_key_as_arr:
         config = config[config_key_part]
     if should_decrypt and (config_key_as_arr in ENCRYPTED_CONFIG_ARRAYS):
         config = [encryptor.dec(x) for x in config]
     return config