Пример #1
0
    def ShowVolumeInfoClicked(self):
        encfsgui_helper.print_debug("Start %s" % inspect.stack()[0][3])
        volumename = encfsgui_globals.g_CurrentlySelected
        if volumename != "":
            if volumename in encfsgui_globals.g_Volumes:
                EncVolumeObj =  encfsgui_globals.g_Volumes[volumename]
                infotext = ""
                if EncVolumeObj.enctype == "encfs":
                    if os.path.exists(encfsgui_globals.g_Settings["encfspath"]):
                        cmd = "%sctl info '%s'" % (encfsgui_globals.g_Settings["encfspath"], EncVolumeObj.enc_path)
                        cmdoutput = encfsgui_helper.execOSCmd(cmd)
                        infotext = "EncFS volume info for '%s'\n" % volumename
                        infotext += "Encrypted folder '%s'\n\n" % EncVolumeObj.enc_path
                        for l in cmdoutput:
                            infotext = infotext + l + "\n"

                if EncVolumeObj.enctype == "gocryptfs":
                    if os.path.exists(encfsgui_globals.g_Settings["gocryptfspath"]):
                        cmd = "%s -info '%s'" % (encfsgui_globals.g_Settings["gocryptfspath"], EncVolumeObj.enc_path)
                        cmdoutput = encfsgui_helper.execOSCmd(cmd)
                        infotext = "GoCryptFS volume info for '%s'\n" % volumename
                        infotext += "Encrypted folder '%s'\n\n" % EncVolumeObj.enc_path
                        for l in cmdoutput:
                            infotext = infotext + l + "\n"
                if not infotext == "":
                    msgBox = QtWidgets.QMessageBox()
                    msgBox.setIcon(QtWidgets.QMessageBox.Information)
                    msgBox.setWindowTitle("Encrypted Volume info (%s)" % EncVolumeObj.enctype)
                    msgBox.setText(infotext)
                    msgBox.setStandardButtons(QtWidgets.QMessageBox.Ok)
                    msgBox.show()
                    msgBox.exec_()
        return
Пример #2
0
 def SavePasswordInKeyChain(self, volumename, password):
     encfsgui_helper.print_debug("Start %s" % inspect.stack()[0][3])
     cmd = "sh -c \"security add-generic-password -U -a 'EncFSGUI_%s' -s 'EncFSGUI_%s' -w '%s' login.keychain\"" % (
         volumename, volumename, str(password))
     encfsgui_helper.print_debug(cmd)
     setpwoutput = encfsgui_helper.execOSCmd(cmd)
     return
Пример #3
0
    def UnmountVolume(self, volumename, forced=False):
        encfsgui_helper.print_debug("Start %s" % inspect.stack()[0][3])
        # do we need to ask for confirmation?
        askforconfirmation = True
        dounmount = False
        if "noconfirmationunmount" in encfsgui_globals.g_Settings:
            if encfsgui_globals.g_Settings["noconfirmationunmount"].lower() == "true":
                askforconfirmation = False

        if volumename in encfsgui_globals.g_Volumes:
            EncVolumeObj = encfsgui_globals.g_Volumes[volumename]
            if EncVolumeObj.ismounted:
                dounmount = True
                if askforconfirmation and not forced:
                    msgBox = QtWidgets.QMessageBox()
                    msgBox.setIcon(QMessageBox.Question)
                    msgBox.setWindowTitle("Are you sure?")
                    msgBox.setText("Unmount volume '%s' \n '%s'?\n\n(Make sure all files on this volume are closed first!)" % (volumename, EncVolumeObj.mount_path))
                    msgBox.setStandardButtons(QtWidgets.QMessageBox.Yes)
                    msgBox.addButton(QtWidgets.QMessageBox.No)
                    msgBox.show()
                    if (msgBox.exec_() == QtWidgets.QMessageBox.No):
                        dounmount = False

            if dounmount:
                cmd = "'%s' '%s'" % (encfsgui_globals.g_Settings["umountpath"], EncVolumeObj.mount_path)
                if EncVolumeObj.sudo == "1":
                    cmd = "sudo '%s' '%s'" % (encfsgui_globals.g_Settings["umountpath"], EncVolumeObj.mount_path)
                encfsgui_helper.execOSCmd(cmd)
                # did unmount work?
                self.RefreshVolumes()
                EncVolumeObj = encfsgui_globals.g_Volumes[volumename]
                if EncVolumeObj.ismounted:
                    QtWidgets.QMessageBox.critical(None,"Error unmounting volume","Unable to unmount volume '%s'\nMake sure all files are closed and try again." % volumename)

        # update context menu's
        self.PopulateVolumeMenu()

        return
Пример #4
0
    def MountVolume(self, volumename, password):
        encfsgui_helper.print_debug("Start %s" % inspect.stack()[0][3])
        if volumename in encfsgui_globals.g_Volumes:
            EncVolumeObj = encfsgui_globals.g_Volumes[volumename]
            extra_osxfuse_opts = ""
            if (password != ""):
                #mountcmd = "%s '%s' '%s' %s" % (encfsgui_globals.g_Settings["encfspath"], EncVolumeObj.enc_path, EncVolumeObj.mount_path, EncVolumeObj.encfsmountoptions)
                if (EncVolumeObj.allowother):
                    extra_osxfuse_opts += "-o allow_other "
                if (EncVolumeObj.mountaslocal):
                    extra_osxfuse_opts += "-o local "
                # first, create mount point if necessary
                createfoldercmd = "mkdir -p '%s'" % EncVolumeObj.mount_path
                encfsgui_helper.execOSCmd(createfoldercmd)

                encfsbin = encfsgui_globals.g_Settings["encfspath"]
                encvol = EncVolumeObj.enc_path
                mountvol = EncVolumeObj.mount_path
                encfsmountoptions = ""
                if not EncVolumeObj.encfsmountoptions == "":
                    encfsmountoptions = "'%s'" % EncVolumeObj.encfsmountoptions

                # do the actual mount
                mountcmd = "sh -c \"echo '%s' | %s -v -S %s %s -o volname='%s' '%s' '%s' \"" % (str(password), encfsbin, extra_osxfuse_opts, encfsmountoptions, volumename, encvol, mountvol)

                encfsgui_helper.execOSCmd(mountcmd)
                self.RefreshVolumes()
                EncVolumeObj = encfsgui_globals.g_Volumes[volumename]
                if not EncVolumeObj.ismounted:
                    QtWidgets.QMessageBox.critical(None,"Error mounting volume","Unable to mount volume '%s'\n" % volumename)
            else:
                encfsgui_helper.print_debug("Did not attempt to mount, empty password given")

            # update context menu's
            self.PopulateVolumeMenu()
        return
Пример #5
0
    def getVolumes(self):
        curframe = inspect.currentframe()
        calframe = inspect.getouterframes(curframe, 2)
        encfsgui_helper.print_debug("%s() Called from: %s()" %
                                    (inspect.stack()[0][3], calframe[1][3]))
        encfsgui_globals.g_Volumes.clear()

        volumeconfig = configparser.ConfigParser()
        volumeconfig.read(encfsgui_globals.volumesfile)

        # prepare to get mount states
        mountcmd = encfsgui_globals.g_Settings["mountpath"]
        mountlist = encfsgui_helper.execOSCmd(mountcmd)

        for volumename in volumeconfig.sections():
            EncVolume = CEncryptedVolume()

            EncVolume.errormessage = ""

            if "enc_path" in volumeconfig[volumename]:
                EncVolume.enc_path = volumeconfig[volumename]["enc_path"]
            if "mount_path" in volumeconfig[volumename]:
                EncVolume.mount_path = volumeconfig[volumename]["mount_path"]
            if "automount" in volumeconfig[volumename]:
                EncVolume.automount = volumeconfig[volumename]["automount"]
            if "preventautounmount" in volumeconfig[volumename]:
                EncVolume.preventautounmount = volumeconfig[volumename][
                    "preventautounmount"]
            if "allowother" in volumeconfig[volumename]:
                EncVolume.allowother = volumeconfig[volumename]["allowother"]
            if "mountaslocal" in volumeconfig[volumename]:
                EncVolume.mountaslocal = volumeconfig[volumename][
                    "mountaslocal"]
            if "encfsmountoptions" in volumeconfig[volumename]:
                EncVolume.encfsmountoptions = volumeconfig[volumename][
                    "encfsmountoptions"]
            if "passwordsaved" in volumeconfig[volumename]:
                EncVolume.passwordsaved = volumeconfig[volumename][
                    "passwordsaved"]
            if "type" in volumeconfig[volumename]:
                EncVolume.enctype = volumeconfig[volumename]["type"]
            if "enctype" in volumeconfig[volumename]:
                EncVolume.enctype = volumeconfig[volumename]["enctype"]
            else:
                EncVolume.enctype = "encfs"
            if "sudo" in volumeconfig[volumename]:
                EncVolume.sudo = volumeconfig[volumename]["sudo"]

            # do we need to decrypt ?
            # if encryption is enabled, decrypt strings in memory using master password
            if encfsgui_globals.g_Settings["encrypt"] == "true":
                # do we have the master key?
                if (encfsgui_globals.masterkey == ""):
                    # ask for masterkey
                    encfsgui_helper.getMasterKey()
                    print_debug("Obtained masterkey, length %d" %
                                len(encfsgui_globals.masterkey))
                if (encfsgui_globals.masterkey != ""):
                    try:
                        EncVolume.enc_path = encfsgui_helper.decrypt(
                            EncVolume.enc_path).decode()
                        EncVolume.mount_path = encfsgui_helper.decrypt(
                            EncVolume.mount_path).decode()
                        encfsgui_globals.timeswrong = 0
                    except Exception:
                        msg = traceback.format_exc()
                        print(msg)
                        encfsgui_helper.print_debug(msg)
                        QtWidgets.QMessageBox.critical(
                            None, "Error",
                            "Error decrypting information.\n\nTry again later."
                        )
                        encfsgui_globals.masterkey = ""
                        encfsgui_globals.timeswrong += 1
                        if encfsgui_globals.timeswrong > 3:
                            sys.exit(1)

            encfsgui_helper.print_debug("Check if path '%s' exists" %
                                        EncVolume.enc_path)
            EncVolume.enc_path_exists = os.path.exists(EncVolume.enc_path)
            encfsgui_helper.print_debug(">> %s" %
                                        str(EncVolume.enc_path_exists))
            if not EncVolume.enc_path_exists:
                EncVolume.errormessage += "- Encrypted folder '%s' does not seem to exist\n" % EncVolume.enc_path
            EncVolume.ismounted = False
            encfsgui_helper.print_debug(
                "Check if %s volume '%s' is mounted at '%s'" %
                (EncVolume.enctype, volumename, EncVolume.mount_path))
            if not os.path.exists(EncVolume.mount_path):
                encfsgui_helper.print_debug(
                    "Warning! '%s' does not seem to exist!" %
                    (EncVolume.mount_path))
                EncVolume.errormessage += "- Mount path '%s' does not seem to exist\n" % EncVolume.mount_path
            if EncVolume.mount_path != "":
                # the extra space is important !
                path_to_check = "%s " % EncVolume.mount_path
                for item in mountlist:
                    thismountline = str(item).strip()
                    foundinitem = False
                    if path_to_check in thismountline:
                        foundinitem = True
                    encfsgui_helper.print_debug(
                        "Mount check: Does '%s' contain '%s'? %s" %
                        (thismountline, path_to_check, str(foundinitem)))
                    if EncVolume.enctype == "encfs":
                        if path_to_check in thismountline:
                            encfsgui_helper.print_debug(
                                "EncFS volume is mounted, mount path '%s' found in '%s'"
                                % (path_to_check, thismountline))
                            EncVolume.ismounted = True
                            break
                    elif EncVolume.enctype == "gocryptfs":
                        if path_to_check in thismountline:
                            encfsgui_helper.print_debug(
                                "GoCryptFS volume is mounted, mount path '%s' found in '%s'"
                                % (path_to_check, thismountline))
                            EncVolume.ismounted = True
                            break
                if not EncVolume.ismounted:
                    encfsgui_helper.print_debug("Volume is not mounted")
                else:
                    EncVolume.errormessage = ""
            encfsgui_globals.g_Volumes[volumename] = EncVolume

        self.clearMasterKeyIfNeeded()
        return
Пример #6
0
    def CreateNewEncryptedVolume(self):
        encfsgui_helper.print_debug("Start %s" % inspect.stack()[0][3])
        msgBox = QtWidgets.QMessageBox()
        msgBox.setIcon(QMessageBox.Question)
        msgBox.setWindowTitle("Are you sure?")
        msgBox.setText(
            "Are you sure you would like to create a new encfs volume '%s' at '%s' ?"
            % (self.txt_volumename.text(), self.txt_encfsfolder.text()))
        msgBox.setStandardButtons(QtWidgets.QMessageBox.No)
        msgBox.addButton(QtWidgets.QMessageBox.Yes)
        msgBox.show()

        cipheralgos = {}
        cipheralgos["AES"] = 1
        cipheralgos["Blowfish"] = 2
        cipheralgos["Camilla"] = 3

        encfsversion = encfsgui_helper.getEncFSVersion()
        selectedalgo = 1
        if not encfsversion.startswith("1.9."):
            # number selection
            selectedalgo = str(cipheralgos[self.ciphercombo.currentText()])
        else:
            # selectedalgo = "%s" % self.ciphercombo.currentText()
            selectedalgo = str(cipheralgos[self.ciphercombo.currentText()])

        fileencodings = {}
        encodingindex = 1
        selectedfileencoding = ""
        for encodingtype in encfsgui_globals.g_Encodings:
            fileencodings[encodingtype] = encodingindex
            encodingindex += 1
        encfsgui_helper.print_debug("File encodings: %s" % fileencodings)
        if not encfsversion.startswith("1.9."):
            # number selection
            selectedfileencoding = str(
                fileencodings[self.filenameencodingcombo.currentText()])
        else:
            selectedfileencoding = str(
                fileencodings[self.filenameencodingcombo.currentText()])
            #selectedfileencoding = "%s" % self.filenameencodingcombo.currentText()
        encfsgui_helper.print_debug("Encoding selected: %s" %
                                    selectedfileencoding)
        encfolderfound = False

        if (msgBox.exec_() == QtWidgets.QMessageBox.Yes):
            # create expect script
            scriptcontents = encfsgui_helper.getExpectScriptContents(False)
            # replace variables in the script
            scriptcontents = scriptcontents.replace(
                "$ENCFSBIN", encfsgui_globals.g_Settings["encfspath"])
            scriptcontents = scriptcontents.replace(
                "$ENCPATH", self.txt_encfsfolder.text())
            scriptcontents = scriptcontents.replace(
                "$MOUNTPATH", self.txt_mountfolder.text())
            scriptcontents = scriptcontents.replace("$CIPHERALGO",
                                                    selectedalgo)
            scriptcontents = scriptcontents.replace(
                "$CIPHERKEYSIZE", self.keysizecombo.currentText())
            scriptcontents = scriptcontents.replace(
                "$BLOCKSIZE", self.blocksizecombo.currentText())
            scriptcontents = scriptcontents.replace("$ENCODINGALGO",
                                                    selectedfileencoding)

            if (self.chk_chainediv.isChecked()):
                scriptcontents = scriptcontents.replace("$IVCHAINING", "")
            else:
                scriptcontents = scriptcontents.replace("$IVCHAINING", "n")

            if (self.chk_perfileuniqueiv.isChecked()):
                scriptcontents = scriptcontents.replace("$PERFILEIV", "")
            else:
                scriptcontents = scriptcontents.replace("$PERFILEIV", "n")

            if (self.chk_externaliv.isChecked()):
                scriptcontents = scriptcontents.replace(
                    "$FILETOIVHEADERCHAINING", "y")
            else:
                scriptcontents = scriptcontents.replace(
                    "$FILETOIVHEADERCHAINING", "")  # n is default here

            if (self.chk_perblockhmac.isChecked()):
                scriptcontents = scriptcontents.replace(
                    "$BLOCKAUTHCODEHEADERS", "y")
            else:
                scriptcontents = scriptcontents.replace(
                    "$BLOCKAUTHCODEHEADERS", "")  # n is default here

            scriptcontents = scriptcontents.replace("sleep x", "expect eof")

            expectfilename = "expect.encfsgui"
            # write script to file
            scriptfile = open(expectfilename, 'w')
            scriptfile.write(scriptcontents)
            scriptfile.close()
            # run script file
            cmdarray = [
                "expect", expectfilename,
                self.txt_password.text(), ">/dev/null"
            ]
            encfsgui_helper.execOScmdAsync(cmdarray)
            self.setEnabled(False)
            time.sleep(3)
            encfolderfound = False
            secondswaited = 1
            while not encfolderfound:
                if (os.path.exists(self.txt_encfsfolder.text() +
                                   "/.encfs6.xml")):
                    encfolderfound = True
                else:
                    time.sleep(1)
                    secondswaited += 1
                if (secondswaited > 20):
                    break
            self.setEnabled(True)

            # unmount new volume
            cmd = "%s '%s'" % (encfsgui_globals.g_Settings["umountpath"],
                               self.txt_mountfolder.text())
            encfsgui_helper.execOSCmd(cmd)

            if encfolderfound:
                QtWidgets.QMessageBox.information(
                    None, "EncFS volume created successfully",
                    "EncFS volume was created successfully")
            else:
                QtWidgets.QMessageBox.information(
                    None, "Error creating volume",
                    "Error while creating EncFS volume")

            #delete script file again
            os.remove(expectfilename)

        return encfolderfound
Пример #7
0
    def CreateNewEncryptedVolume(self):
        encfsgui_helper.print_debug("Start %s" % inspect.stack()[0][3])
        msgBox = QtWidgets.QMessageBox()
        msgBox.setIcon(QMessageBox.Question)
        msgBox.setWindowTitle("Are you sure?")
        msgboxtext = ""
        if self.radio_volumetype_encfs.isChecked():
            msgboxtext = "Are you sure you would like to create a new encfs volume '%s' at '%s' ?" % (self.txt_volumename.text(), self.txt_encfsfolder.text())
        if self.radio_volumetype_gocryptfs.isChecked():
            msgboxtext = "Are you sure you would like to create a new gocryptfs volume '%s' at '%s' ?" % (self.txt_volumename.text(), self.txt_encfsfolder.text())

        msgBox.setText(msgboxtext)
        msgBox.setStandardButtons(QtWidgets.QMessageBox.No)
        msgBox.addButton(QtWidgets.QMessageBox.Yes)
        msgBox.show()

        encfolderfound = False

        if (msgBox.exec_() == QtWidgets.QMessageBox.Yes):

            # encfs

            if self.radio_volumetype_encfs.isChecked():            

                cipheralgos = {}
                cipheralgos["AES"] = 1
                cipheralgos["Blowfish"] = 2
                cipheralgos["Camilla"] = 3

                encfsversion = encfsgui_helper.getEncFSVersion() 
                selectedalgo = 1
                if not encfsversion.startswith("1.9."):
                    # number selection
                    selectedalgo = str(cipheralgos[self.ciphercombo.currentText()])
                else:
                    # selectedalgo = "%s" % self.ciphercombo.currentText()
                    selectedalgo = str(cipheralgos[self.ciphercombo.currentText()])
                
                fileencodings = {}
                encodingindex = 1
                selectedfileencoding = ""
                for encodingtype in encfsgui_globals.g_Encodings:
                    fileencodings[encodingtype] = encodingindex
                    encodingindex += 1
                encfsgui_helper.print_debug("File encodings: %s" % fileencodings)
                if not encfsversion.startswith("1.9."):
                    # number selection
                    selectedfileencoding = str(fileencodings[self.filenameencodingcombo.currentText()])
                else:
                    selectedfileencoding = str(fileencodings[self.filenameencodingcombo.currentText()])
                    #selectedfileencoding = "%s" % self.filenameencodingcombo.currentText()
                encfsgui_helper.print_debug("Encoding selected: %s" % selectedfileencoding)

                # create expect script
                scriptcontents = encfsgui_helper.getExpectScriptContents("encfs", False)
                # replace variables in the script
                scriptcontents = scriptcontents.replace("$ENCFSBIN", encfsgui_globals.g_Settings["encfspath"])
                scriptcontents = scriptcontents.replace("$ENCPATH", self.txt_encfsfolder.text())
                scriptcontents = scriptcontents.replace("$MOUNTPATH", self.txt_mountfolder.text())
                scriptcontents = scriptcontents.replace("$CIPHERALGO", selectedalgo)
                scriptcontents = scriptcontents.replace("$CIPHERKEYSIZE", self.keysizecombo.currentText())
                scriptcontents = scriptcontents.replace("$BLOCKSIZE", self.blocksizecombo.currentText())
                scriptcontents = scriptcontents.replace("$ENCODINGALGO", selectedfileencoding)

                if (self.chk_chainediv.isChecked()):
                    scriptcontents = scriptcontents.replace("$IVCHAINING","")
                else:
                    scriptcontents = scriptcontents.replace("$IVCHAINING","n")

                if (self.chk_perfileuniqueiv.isChecked()):
                    scriptcontents = scriptcontents.replace("$PERFILEIV","")
                else:
                    scriptcontents = scriptcontents.replace("$PERFILEIV","n")

                if (self.chk_externaliv.isChecked()):
                    scriptcontents = scriptcontents.replace("$FILETOIVHEADERCHAINING","y")
                else:
                    scriptcontents = scriptcontents.replace("$FILETOIVHEADERCHAINING","")   # n is default here
                
                if (self.chk_perblockhmac.isChecked()):
                    scriptcontents = scriptcontents.replace("$BLOCKAUTHCODEHEADERS","y")
                else:
                    scriptcontents = scriptcontents.replace("$BLOCKAUTHCODEHEADERS","")  # n is default here

                scriptcontents = scriptcontents.replace("sleep x","expect eof")

                expectfilename = "expect.encfsgui"
                # write script to file
                scriptfile = open(expectfilename, 'w')
                scriptfile.write(scriptcontents)
                scriptfile.close()
                # run script file
                cmdarray = ["expect",expectfilename, self.txt_password.text(), ">/dev/null"]
                encfsgui_helper.execOScmdAsync(cmdarray)
                self.setEnabled(False)
                time.sleep(3)
                encfolderfound = False
                secondswaited = 1
                while not encfolderfound:
                    if (os.path.exists( self.txt_encfsfolder.text() + "/.encfs6.xml" )):
                        encfolderfound = True
                    else:
                        time.sleep(1)
                        secondswaited += 1
                    if (secondswaited > 10):
                        break
                self.setEnabled(True)

                # unmount new volume
                cmd = "%s '%s'" % (encfsgui_globals.g_Settings["umountpath"], self.txt_mountfolder.text())
                encfsgui_helper.execOSCmd(cmd)
                
                if encfolderfound:
                    QtWidgets.QMessageBox.information(None,"EncFS volume created successfully","EncFS volume was created successfully")
                    #delete script file again
                    os.remove(expectfilename)  
                else:
                    QtWidgets.QMessageBox.information(None,"Error creating volume","Error while creating EncFS volume")
                    # keep the expect file for debugging purposes in case debug mode is active
                    if not encfsgui_globals.debugmode:
                        os.remove(expectfilename)
            
            # gocryptfs

            if self.radio_volumetype_gocryptfs.isChecked():            

                # create expect script

                extra_opts = ""
                if self.chk_gocryptfs_plaintext.isChecked():
                    extra_opts += "-plaintextnames "
                if self.chk_gocryptfs_aessiv.isChecked():
                    extra_opts += "-aessiv "


                scriptcontents = encfsgui_helper.getExpectScriptContents("gocryptfs", False)
                # replace variables in the script
                scriptcontents = scriptcontents.replace("$GOCRYPTFSBIN", encfsgui_globals.g_Settings["gocryptfspath"])
                scriptcontents = scriptcontents.replace("$ENCPATH", self.txt_encfsfolder.text())
                scriptcontents = scriptcontents.replace("$MOUNTPATH", self.txt_mountfolder.text())
                scriptcontents = scriptcontents.replace("$EXTRAOPTS", extra_opts)

                scriptcontents = scriptcontents.replace("sleep x","expect eof")

                expectfilename = "expect.encfsgui"
                # write script to file
                scriptfile = open(expectfilename, 'w')
                scriptfile.write(scriptcontents)
                scriptfile.close()
                # run script file
                cmdarray = ["expect",expectfilename, self.txt_password.text(), ">/dev/null"]
                #QtWidgets.QMessageBox.information(None,"expect script ready","expect script ready")
                
                #encfsgui_helper.execOScmdAsync(cmdarray)
                gocryptfslines, retval = encfsgui_helper.execOSCmdRetVal(cmdarray)
                
                self.setEnabled(False)
                time.sleep(3)
                encfolderfound = False
                secondswaited = 1
                while not encfolderfound:
                    if (os.path.exists( self.txt_encfsfolder.text() + "/gocryptfs.diriv" ) or os.path.exists( self.txt_encfsfolder.text() + "/gocryptfs.conf" )):
                        encfolderfound = True
                    else:
                        time.sleep(1)
                        secondswaited += 1
                    if (secondswaited > 10):
                        break
                self.setEnabled(True)
                
                if encfolderfound:
                    QtWidgets.QMessageBox.information(None,"GoCryptFS volume created successfully","GoCryptFS volume was created successfully")
                    masterkeyinfo = ""
                    takenote = False
                    for line in gocryptfslines:
                        if "Your master key" in line:
                            takenote = True
                        if takenote:
                            if "-" in line:
                                masterkeyinfo += "%s\n" % str(line.replace(" ","").replace("[2m","").replace("[0m","").replace("\x1b",""))
                    QtWidgets.QMessageBox.information(None,"Your master key","WARNING! This is the only time when you get to see your master key!\n\nYour master key is:\n\n%s\n\nPrint it to a piece of paper and store it in a safe location.\n" % masterkeyinfo)                          
                    #delete script file again
                    os.remove(expectfilename)  
                else:
                    QtWidgets.QMessageBox.information(None,"Error creating volume","Error while creating GoCryptFS volume")
                    # keep the expect file for debugging purposes in case debug mode is active
                    if not encfsgui_globals.debugmode:
                        os.remove(expectfilename)
                        
        return encfolderfound
Пример #8
0
    def getVolumes(self):
        curframe = inspect.currentframe()
        calframe = inspect.getouterframes(curframe, 2)
        encfsgui_helper.print_debug("%s() Called from: %s()" %
                                    (inspect.stack()[0][3], calframe[1][3]))
        encfsgui_globals.g_Volumes.clear()

        volumeconfig = configparser.ConfigParser()
        volumeconfig.read(encfsgui_globals.volumesfile)

        # prepare to get mount states
        mountcmd = encfsgui_globals.g_Settings["mountpath"]
        mountlist = encfsgui_helper.execOSCmd(mountcmd)

        for volumename in volumeconfig.sections():
            EncVolume = CEncryptedVolume()

            if "enc_path" in volumeconfig[volumename]:
                EncVolume.enc_path = volumeconfig[volumename]["enc_path"]
            if "mount_path" in volumeconfig[volumename]:
                EncVolume.mount_path = volumeconfig[volumename]["mount_path"]
            if "automount" in volumeconfig[volumename]:
                EncVolume.automount = volumeconfig[volumename]["automount"]
            if "preventautounmount" in volumeconfig[volumename]:
                EncVolume.preventautounmount = volumeconfig[volumename][
                    "preventautounmount"]
            if "allowother" in volumeconfig[volumename]:
                EncVolume.allowother = volumeconfig[volumename]["allowother"]
            if "mountaslocal" in volumeconfig[volumename]:
                EncVolume.mountaslocal = volumeconfig[volumename][
                    "mountaslocal"]
            if "encfsmountoptions" in volumeconfig[volumename]:
                EncVolume.encfsmountoptions = volumeconfig[volumename][
                    "encfsmountoptions"]
            if "passwordsaved" in volumeconfig[volumename]:
                EncVolume.passwordsaved = volumeconfig[volumename][
                    "passwordsaved"]

            # do we need to decrypt ?
            # if encryption is enabled, decrypt strings in memory using master password
            if encfsgui_globals.g_Settings["encrypt"] == "true":
                # do we have the master key?
                if (encfsgui_globals.masterkey == ""):
                    # ask for masterkey
                    encfsgui_helper.getMasterKey()
                    print_debug("Obtained masterkey, length %d" %
                                len(encfsgui_globals.masterkey))
                if (encfsgui_globals.masterkey != ""):
                    try:
                        EncVolume.enc_path = encfsgui_helper.decrypt(
                            EncVolume.enc_path).decode()
                        EncVolume.mount_path = encfsgui_helper.decrypt(
                            EncVolume.mount_path).decode()
                        encfsgui_globals.timeswrong = 0
                    except Exception:
                        msg = traceback.format_exc()
                        print(msg)
                        encfsgui_helper.print_debug(msg)
                        QtWidgets.QMessageBox.critical(
                            None, "Error",
                            "Error decrypting information.\n\nTry again later."
                        )
                        encfsgui_globals.masterkey = ""
                        encfsgui_globals.timeswrong += 1
                        if encfsgui_globals.timeswrong > 3:
                            sys.exit(1)

            EncVolume.ismounted = False
            encfsgui_helper.print_debug("Check if volume '%s' is mounted" %
                                        volumename)
            if EncVolume.mount_path != "":
                # the extra space is important !
                path_to_check = "%s " % EncVolume.mount_path
                for item in mountlist:
                    if "encfs" in str(item) and path_to_check in str(item):
                        encfsgui_helper.print_debug(
                            "Volume is mounted, mount path '%s' found in '%s'"
                            % (path_to_check, str(item).strip()))
                        EncVolume.ismounted = True
                        break
                if not EncVolume.ismounted:
                    encfsgui_helper.print_debug("Volume is not mounted")
            encfsgui_globals.g_Volumes[volumename] = EncVolume

        self.clearMasterKeyIfNeeded()
        return
Пример #9
0
    def MountVolume(self, volumename, password):
        encfsgui_helper.print_debug("Start %s" % inspect.stack()[0][3])
        if volumename in encfsgui_globals.g_Volumes:
            EncVolumeObj = encfsgui_globals.g_Volumes[volumename]
            if (password != ""):
                if not encfsgui_helper.ifExists(EncVolumeObj.enctype):
                    QtWidgets.QMessageBox.critical(None,"Error mounting volume","Unable to mount volume '%s', '%s' binary not found\n" % ( volumename, EncVolumeObj.enctype))
                else:
                    usesudo = ""
                    if EncVolumeObj.sudo == "1":
                        usesudo = "sudo"

                    # if volume is encfs:
                    if EncVolumeObj.enctype == "encfs":
                        extra_osxfuse_opts = ""
                        #mountcmd = "%s '%s' '%s' %s" % (encfsgui_globals.g_Settings["encfspath"], EncVolumeObj.enc_path, EncVolumeObj.mount_path, EncVolumeObj.encfsmountoptions)
                        if (str(EncVolumeObj.allowother) == "1"):
                            extra_osxfuse_opts += "-o allow_other "
                        if (str(EncVolumeObj.mountaslocal) == "1"):
                            extra_osxfuse_opts += "-o local "
                        # first, create mount point if necessary
                        createfoldercmd = "mkdir -p '%s'" % EncVolumeObj.mount_path
                        encfsgui_helper.execOSCmd(createfoldercmd)

                        encfsbin = encfsgui_globals.g_Settings["encfspath"]
                        encvol = EncVolumeObj.enc_path
                        mountvol = EncVolumeObj.mount_path
                        encfsmountoptions = ""
                        if not EncVolumeObj.encfsmountoptions == "":
                            encfsmountoptions = "'%s'" % EncVolumeObj.encfsmountoptions

                        # do the actual mount
                        mountcmd = "sh -c \"echo '%s' | %s '%s' -v -S %s %s -o volname='%s' '%s' '%s' \"" % (str(password), usesudo, encfsbin, extra_osxfuse_opts, encfsmountoptions, volumename, encvol, mountvol)

                        encfsgui_helper.execOSCmd(mountcmd)

                    # if volume is gocryptfs:
                    if EncVolumeObj.enctype == "gocryptfs":
                        extra_osxfuse_opts = ""
                        extra_gocryptfs_opts = ""
                        if (str(EncVolumeObj.allowother) == "1"):
                            extra_gocryptfs_opts += "-allow_other "
                        if (str(EncVolumeObj.mountaslocal) == "1"):
                            extra_osxfuse_opts += "-ko local "
                        # first, create mount point if necessary
                        createfoldercmd = "mkdir -p '%s'" % EncVolumeObj.mount_path
                        encfsgui_helper.execOSCmd(createfoldercmd)

                        gocryptfsbin = encfsgui_globals.g_Settings["gocryptfspath"]
                        encvol = EncVolumeObj.enc_path
                        mountvol = EncVolumeObj.mount_path
                        if not EncVolumeObj.encfsmountoptions == "":
                            extra_gocryptfs_opts += "'%s'" % EncVolumeObj.encfsmountoptions

                        # do the actual mount
                        #mountcmd = "sh -c \"echo '%s' | %s -v -S %s %s -o volname='%s' '%s' '%s' \"" % (str(password), gocryptfsbin, extra_osxfuse_opts, gocryptfsmountoptions, volumename, encvol, mountvol)
                        mountcmd = "sh -c \"echo '%s' | %s '%s' -ko volname='%s' -ko fsname='%s' %s %s '%s' '%s'\"" % (str(password), usesudo, gocryptfsbin, volumename, volumename, extra_osxfuse_opts, extra_gocryptfs_opts, encvol, mountvol)

                        encfsgui_helper.execOSCmd(mountcmd)

                    self.RefreshVolumes()
                    EncVolumeObj = encfsgui_globals.g_Volumes[volumename]
                    if not EncVolumeObj.ismounted:
                        QtWidgets.QMessageBox.critical(None,"Error mounting volume","Unable to mount volume '%s'\n\n%s" % ( volumename, EncVolumeObj.errormessage ))
            else:
                encfsgui_helper.print_debug("Did not attempt to mount, empty password given")

            # update context menu's
            self.PopulateVolumeMenu()
        return