Exemple #1
0
    def __on_find_clicked (self, _data):
        self._apply_button.set_sensitive (False)
        self._find_button.set_sensitive (False)
        self._filename = self._totem.get_current_mrl ()
        (movie_hash, movie_size) = hash_file (self._filename)

        self._get_results (movie_hash, movie_size)
    def __on_find_clicked(self, _):
        self._apply_button.set_sensitive(False)
        self._find_button.set_sensitive(False)
        self._filename = self._totem.get_current_mrl()  # pylint: disable=no-member
        (movie_hash, movie_size) = hash_file(self._filename)

        self._get_results(movie_hash, movie_size)
    def __on_find_clicked (self, _):
        self._apply_button.set_sensitive (False)
        self._find_button.set_sensitive (False)
        self._filename = self._totem.get_current_mrl ()
        (movie_hash, movie_size) = hash_file (self._filename)

        self._get_results (movie_hash, movie_size)
Exemple #4
0
def create_signature(file):
    hashed = hash.hash_file(file).encode()
    (pubkey, privkey) = rsa.newkeys(528)
    signature = rsa.sign(hashed, privkey, 'SHA-1')
    verification = rsa.verify(hashed, signature, privkey)

    return signature, pubkey
def verify_signature(file,signature,public_key):
    hashed = hash.hash_file(file).encode()
    sign = file_open(signature)
    print(sign)
    pubkey = rsa.PublicKey.load_pkcs1(file_open(public_key))
    print(pubkey)
    verification = rsa.verify(hashed,sign,pubkey)
Exemple #6
0
    def recurse(subdir):
        # To ensure that a line-by-line comparison of the manifests
        # is possible, we require that filenames don't contain newlines.
        # Otherwise, you can name a file so that the part after the \n
        # would be interpreted as another line in the manifest.
        if '\n' in subdir: raise Exception("Newline in filename '%s'" %
                                           subdir)
        assert subdir.startswith('/')

        full = os.path.join(root, subdir[1:])
        
        if not os.path.isdir(full): 
            raise Exception('Not a directory: "%s"' % full)

        if subdir != '/':
            yield "D %s" % subdir

        items = os.listdir(full)
        items.sort()
        dirs = []
        for item in items:
            path = os.path.join(root, subdir[1:], item)
            info = os.lstat(path)
            m = info.st_mode

            if stat.S_ISREG(m):
                d = hash_file(path, alg).hexdigest()
                if m & 0o111:
                    yield "X %s %s %s" % (d, info.st_size, item)
                else:
                    yield "F %s %s %s" % (d, info.st_size, item)
            elif stat.S_ISLNK(m):
                target = os.readlink(path)
                d = alg(target).hexdigest()
                # Note: Can't use utime on symlinks, so skip mtime
                # Note: eCryptfs may report length as zero, so count ourselves instead
                yield "S %s %s %s" % (d, len(target), item)
            elif stat.S_ISDIR(m):
                dirs.append(item)
            else:
                raise Exception("Unknown object '%s' (not a file, directory or symlink)" %
                        path)

        if not subdir.endswith('/'):
            subdir += '/'
        for x in dirs:
            # Note: "subdir" is always Unix style. Don't use os.path.join here.
            for y in recurse(subdir + x): yield y
        return
Exemple #7
0
def parse(config, dir='repos', *args, **kwargs):
    dbh = dbhandler.Handler(db=config.db)
    dbh.reset()
    finder = file.Finder(config, dir)
    git_manager = git.GitManager(config, dir)
    tags = git_manager.parse_tags(*args, **kwargs)
    for repo in config.repos:
        logging.info('parsing repo {}'.format(repo.name))
        for tag in tags[repo.name]:
            logging.info('parsing tag {}'.format(tag))
            git_manager.checkout(repo.git, tag)
            for match in finder.find(repo):
                id = models.Identifier(cms=repo.name,
                                       tag=tag,
                                       hash=hash.hash_file(match.path),
                                       name=match.name,
                                       url=match.url,
                                       path=match.path)
                dbh.lazy_save(id)
    dbh.flush_lazy()
Exemple #8
0
    def backup_file(self, path: str) -> None:
        """Backup the file 'path' to the repository.

        Write the hashed contents to 'objects' if it isn't already there.
        Write a line in the backup file to describe the backed up file.
        """
        if self.verbose:
            print('backup', path)
        self.files_total += 1
        s = os.stat(path)
        # self.bytes_read += os.stat(path).st_size
        self.bytes_read += s.st_size
        h = hash_file(path)
        # mtime = os.path.getmtime(path) # XXX get this from os.stat ?
        mtime = s.st_mtime
        if self.repo.store_file(path, h):
            print(f'new\t{h}\t{mtime}\t{path}', file=self.bkf)
            self.files_stored += 1
            s = os.stat(path)
        else:
            print(f'old\t{h}\t{mtime}\t{path}', file=self.bkf)
            self.files_not_stored += 1