Esempio n. 1
0
    def create(self, password):
        """Encrypt a folder"""
        
        if len(password) == 0:
            raise exc.NullPassword()

        if os.path.exists( os.path.join(self.device, KEYFILE) ):
            print self.device
            raise exc.AlreadyExists()


        if not os.path.exists(self.mountpoint):
            os.makedirs(self.mountpoint)

        os.makedirs(self.device)

        param = "%(mode)s\n%(pass)s\n" % {"mode": MODE, "pass": password}
        p1 = subprocess.Popen([ECHO, "-e", param], stdout=subprocess.PIPE)
        p2 = subprocess.Popen([ENCFS, "-S", self.device,\
            self.mountpoint], stdin=p1.stdout, stdout=subprocess.PIPE)
        p2.communicate(param)[0]
        if p2.returncode is not 0:
            raise exc.BadPassword()

        self.umount()

        return (not bool(p2.returncode))
Esempio n. 2
0
    def make_backup(self, password, target):
        ok, stdout, stderr = self.call_command( "backup", params=(self.device,),
                                 input = self._MAKE_BACKUP_PARAMS % locals())

        if "Incorrect password" in stdout:
            raise exc.BadPassword("Incorrect password")
        return ok
Esempio n. 3
0
    def mount(self, password):

        ok, stdout, stderr = self.call_command("mount",
                                               params=(password, self.device,
                                                       self.mountpoint))
        if stdout.startswith("Incorrect password"):
            raise exc.BadPassword("Incorrect password")
        return ok
Esempio n. 4
0
 def restore_backup(self, password, backup):
     ok, stdout, stderr = self.call_command(
         "restore",
         params=(self.device, ),
         input=self._RESTORE_BACKUP_PARAMS % locals())
     if "Incorrect password" in stderr:
         raise exc.BadPassword("Incorrect password")
     return ok
Esempio n. 5
0
    def change_password(self, old, new):
        """Change password"""
        param = "%(old)s\n%(new)s\n" % {"old": old, "new" : new}
        p1 = subprocess.Popen([ECHO, "-e", param],\
            stdout=subprocess.PIPE)
        p2 = subprocess.Popen([ENCFSCTL, "autopasswd", self.device],\
            stdin=p1.stdout, stdout=subprocess.PIPE)
        p2.communicate()[0]
        
        if p2.returncode is not 0:
            raise exc.BadPassword()

        return (not bool(p2.returncode))
Esempio n. 6
0
    def mount(self, password, idle=None):
        """Mount an encrypted folder"""

        if self.is_mounted():
            return

        p1 = subprocess.Popen([ECHO, password],\
            stdout=subprocess.PIPE)
        if idle == None:
            p2 = subprocess.Popen([ENCFS, "-S", self.device,\
                self.mountpoint, "--", "-o", "nonempty"],\
                    stdin=p1.stdout, stdout=subprocess.PIPE)
        else:
            p2 = subprocess.Popen([ENCFS, "-S", self.device, "-i",\
                str(idle), self.mountpoint, "--", "-o", "nonempty"],\
                    stdin=p1.stdout, stdout=subprocess.PIPE)
        p3 = p2.communicate(password + "\n")[0]
        if p2.returncode is not 0:
            raise exc.BadPassword()

        return (not bool(p2.returncode))