Exemple #1
0
    def _verify_file_hash(self):
        if not os.path.exists(self.filename):
            log.debug('File does not exist')
            return False

        file_hash = self._get_file_hash_from_manifest()
        try:
            with open(self.filename, 'rb') as f:
                data = f.read()
        except Exception as err:
            log.debug(err, exc_info=True)
            return False

        if file_hash == get_hash(data):
            return True
        else:
            return False
Exemple #2
0
    def _check_hash(self):
        # Checks hash of downloaded file
        if self.hexdigest is None:
            # No hash provided to check.
            # So just return any data recieved
            log.debug("No hash to verify")
            return None
        if self.file_binary_data is None:
            # Exit quickly if we got nohting to compare
            # Also I'm sure we'll get an exception trying to
            # pass None to get hash :)
            log.debug("Cannot verify file hash - No Data")
            return False
        log.debug("Checking file hash")
        log.debug("Update hash: {}".format(self.hexdigest))

        file_hash = get_hash(self.file_binary_data)
        if file_hash == self.hexdigest:
            log.debug("File hash verified")
            return True
        log.debug("Cannot verify file hash")
        return False
Exemple #3
0
    def _check_hash(self):
        # Checks hash of downloaded file
        if self.hexdigest is None:
            # No hash provided to check.
            # So just return any data recieved
            log.debug('No hash to verify')
            return None
        if self.file_binary_data is None:
            # Exit quickly if we got nohting to compare
            # Also I'm sure we'll get an exception trying to
            # pass None to get hash :)
            log.debug('Cannot verify file hash - No Data')
            return False
        log.debug('Checking file hash')
        log.debug('Update hash: %s', self.hexdigest)

        file_hash = get_hash(self.file_binary_data)
        if file_hash == self.hexdigest:
            log.debug('File hash verified')
            return True
        log.debug('Cannot verify file hash')
        return False
Exemple #4
0
    def _is_downloaded(self, name):
        latest = get_highest_version(name, self.platform, self.easy_data)

        filename = get_filename(name, latest, self.platform, self.easy_data)

        hash_key = '{}*{}*{}*{}*{}'.format(self.updates_key, name, latest,
                                           self.platform, 'file_hash')
        _hash = self.easy_data.get(hash_key)
        # Comparing file hashes to ensure security
        with jms_utils.paths.ChDir(self.update_folder):
            if not os.path.exists(filename):
                return False
            try:
                with open(filename, 'rb') as f:
                    data = f.read()
            except Exception as err:
                log.debug(err, exc_info=True)
                return False
            if _hash == get_hash(data):
                return True
            else:
                return False
Exemple #5
0
    def _is_downloaded(self, name):
        latest = get_highest_version(name, self.platform, self.easy_data)

        filename = get_filename(name, latest, self.platform, self.easy_data)

        hash_key = '{}*{}*{}*{}*{}'.format(self.updates_key, name,
                                           latest, self.platform,
                                           'file_hash')
        _hash = self.easy_data.get(hash_key)
        # Comparing file hashes to ensure security
        with jms_utils.paths.ChDir(self.update_folder):
            if not os.path.exists(filename):
                return False
            try:
                with open(filename, 'rb') as f:
                    data = f.read()
            except Exception as err:
                log.debug(err, exc_info=True)
                return False
            if _hash == get_hash(data):
                return True
            else:
                return False
Exemple #6
0
 def test_get_hash(self):
     digest = ('380fd2bf3d78bb411e4c1801ce3ce7804bf5a22d79'
               '405d950e5d5c8f3169fca0')
     assert digest == get_hash('Get this hash please')
Exemple #7
0
 def test_get_hash(self):
     digest = ('380fd2bf3d78bb411e4c1801ce3ce7804bf5a22d79'
               '405d950e5d5c8f3169fca0')
     assert digest == get_hash('Get this hash please')