Пример #1
0
    def decryptFile(self, path, fileObj):
        """Check for encryption and decrypt the fileObj if needed.

        Return a tuple of the file object and True if it was encrypted.
        Return None for the file object if the user cancels.
        Arguments:
            path -- the path name for reference
            fileObj -- the file object to check and decrypt
        """
        if fileObj.read(len(encryptPrefix)) != encryptPrefix:
            fileObj.seek(0)
            return (fileObj, False)
        while True:
            password = self.passwords.get(path, '')
            if not password:
                dialog = miscdialogs.PasswordDialog(
                    False, os.path.basename(path),
                    QtGui.QApplication.activeWindow())
                if dialog.exec_() != QtGui.QDialog.Accepted:
                    fileObj.close()
                    return (None, True)
                password = dialog.password
                if miscdialogs.PasswordDialog.remember:
                    self.passwords[path] = password
            try:
                text = p3.p3_decrypt(fileObj.read(), password.encode())
                fileIO = io.BytesIO(text)
                fileIO.name = path
                return (fileIO, True)
            except p3.CryptError:
                try:
                    del self.passwords[path]
                except KeyError:
                    pass
Пример #2
0
    def decryptFile(self, path, fileObj):
        """Check for encryption and decrypt the fileObj if needed.

        Return a tuple of the file object and True if it was encrypted.
        Return None for the file object if the user cancels.
        Arguments:
            path -- the path name for reference
            fileObj -- the file object to check and decrypt
        """
        if fileObj.read(len(encryptPrefix)) != encryptPrefix:
            fileObj.seek(0)
            return (fileObj, False)
        while True:
            password = self.passwords.get(path, '')
            if not password:
                dialog = miscdialogs.PasswordDialog(False,
                                                    os.path.basename(path),
                                                    QtGui.QApplication.
                                                    activeWindow())
                if dialog.exec_() != QtGui.QDialog.Accepted:
                    fileObj.close()
                    return (None, True)
                password = dialog.password
                if miscdialogs.PasswordDialog.remember:
                    self.passwords[path] = password
            try:
                text = p3.p3_decrypt(fileObj.read(), password.encode())
                fileIO = io.BytesIO(text)
                fileIO.name = path
                return (fileIO, True)
            except p3.CryptError:
                try:
                    del self.passwords[path]
                except KeyError:
                    pass
Пример #3
0
    def protect_value(self, value, mode=0):
        if mode == 0:
            # encrypt
            if crypt != None and self._secretKey != None:
                cipher = crypt.p3_encrypt(value, self._secretKey)
                return base64.b64encode(cipher)
            elif self._hideData is True:
                return base64.b64encode(value)
        else:
            # decrypt
            if crypt != None and self._secretKey != None:
                cipher = base64.b64decode(value)
                return crypt.p3_decrypt(cipher, self._secretKey)
            elif self._hideData is True:
                return base64.b64decode(value)

        return value
Пример #4
0
    def protect_value(self, value, mode=0):
        if mode == 0:
            # encrypt
            if crypt != None and self._secretKey != None :
                cipher = crypt.p3_encrypt(value, self._secretKey)
                return base64.b64encode(cipher)
            elif self._hideData is True:
                return base64.b64encode(value)
        else:
            # decrypt
            if crypt != None and self._secretKey != None :
                cipher = base64.b64decode(value)
                return crypt.p3_decrypt(cipher, self._secretKey)
            elif self._hideData is True:
                return base64.b64decode(value)

        return value
Пример #5
0
 def decryptFile(self, fileObj):
     """Decrypt file if was encrypted"""
     name = fileObj.name
     prefix = fileObj.read(len(encryptPrefix))
     self.encryptFile = prefix == encryptPrefix
     if self.encryptFile:
         password = TreeDoc.passwordDict.get(fileObj.name, '')
         if not password:
             fileObj.close()
             raise PasswordError, 'Missing password'
         try:
             text = p3.p3_decrypt(fileObj.read(), password)
         except p3.CryptError:
             fileObj.close()
             raise PasswordError, 'Incorrect password'
         fileObj.close()
         fileObj = StringIO.StringIO(text)
         fileObj.name = name
     else:
         fileObj.seek(0)
     return fileObj
Пример #6
0
 def decryptFile(self, fileObj):
     """Decrypt file if was encrypted"""
     name = fileObj.name
     prefix = fileObj.read(len(encryptPrefix))
     self.encryptFile = prefix == encryptPrefix
     if self.encryptFile:
         password = TreeDoc.passwordDict.get(fileObj.name, '')
         if not password:
             fileObj.close()
             raise PasswordError, 'Missing password'
         try:
             text = p3.p3_decrypt(fileObj.read(), password)
         except p3.CryptError:
             fileObj.close()
             raise PasswordError, 'Incorrect password'
         fileObj.close()
         fileObj = StringIO.StringIO(text)
         fileObj.name = name
     else:
         fileObj.seek(0)
     return fileObj
Пример #7
0
    def decryptFile(self, fileObj):
        """Check for encryption and decrypt the fileObj if needed.

        Return a tuple of the file object and True if it was encrypted.
        Return None for the file object if the user cancels.
        Arguments:
            fileObj -- the file object to check and decrypt
        """
        if fileObj.read(len(encryptPrefix)) != encryptPrefix:
            fileObj.seek(0)
            return (fileObj, False)
        fileContents = fileObj.read()
        fileName = fileObj.name
        fileObj.close()
        while True:
            pathObj = pathlib.Path(fileName)
            password = self.passwords.get(pathObj, '')
            if not password:
                QApplication.restoreOverrideCursor()
                dialog = miscdialogs.PasswordDialog(
                    False, pathObj.name, QApplication.activeWindow())
                if dialog.exec_() != QDialog.Accepted:
                    return (None, True)
                QApplication.setOverrideCursor(Qt.WaitCursor)
                password = dialog.password
                if miscdialogs.PasswordDialog.remember:
                    self.passwords[pathObj] = password
            try:
                text = p3.p3_decrypt(fileContents, password.encode())
                fileIO = io.BytesIO(text)
                fileIO.name = fileName
                return (fileIO, True)
            except p3.CryptError:
                try:
                    del self.passwords[pathObj]
                except KeyError:
                    pass
Пример #8
0
    def protect_value(self, value, mode=0, section=None):
        if self._secretSections is not None and section is not None:
            for s in self._secretSections:
                if section.startswith(s):
                    break
            else:
                return value

        if mode == 0:
            # encrypt
            if crypt != None and self._secretKey != None:
                cipher = crypt.p3_encrypt(value, self._secretKey)
                return base64.b64encode(cipher)
            elif self._hideData is True:
                return base64.b64encode(value)
        else:
            # decrypt
            if crypt != None and self._secretKey != None:
                cipher = base64.b64decode(value)
                return crypt.p3_decrypt(cipher, self._secretKey)
            elif self._hideData is True:
                return base64.b64decode(value)

        return value
Пример #9
0
    def protect_value(self, value, mode=0, section=None):
        if self._secretSections is not None and section is not None:
            for s in self._secretSections:
                if section.startswith(s):
                    break
            else:
                return value
            
        if mode == 0:
            # encrypt
            if crypt != None and self._secretKey != None :
                cipher = crypt.p3_encrypt(value, self._secretKey)
                return base64.b64encode(cipher)
            elif self._hideData is True:
                return base64.b64encode(value)
        else:
            # decrypt
            if crypt != None and self._secretKey != None :
                cipher = base64.b64decode(value)
                return crypt.p3_decrypt(cipher, self._secretKey)
            elif self._hideData is True:
                return base64.b64decode(value)

        return value
Пример #10
0
def decrypt(code):
    """ decrypts url-safe string to dictinoary """
    return QueryDict(p3_decrypt(b64decode(str(code), B64_ALTCHARS), settings.SECRET_KEY))
Пример #11
0
 def getplaintextpassword(self): return p3.p3_decrypt(self.__passwordhash,self.escrow)
 def getprivileges(self): return self.__privileges