Example #1
0
def GetPassFromFile(index, encryptionKey):
    AESEncryptionKey = Encryptor.BindKey(Encryptor.GetKey(), encryptionKey)
    if (not DoesProgramFileExist(passFile)):
        return None
    with open((GetFileLocation() + passFile), "r") as f:
        dataSet = f.readline()
    #Decrypt file
    data = Encryptor.DecryptFile(dataSet, AESEncryptionKey)

    sepData = SplitString(data[index], sep2)

    foundPass = Encryptor.AESDecrypt(sepData[2], AESEncryptionKey)
    splitData = foundPass.split(userpassSep)

    toReturn = []
    if (splitData[1].lower() != "null"):
        toReturn.append("USER: "******"PASS: "******"null"):
        toReturn.append("Additional: " + splitData[2])
    #Add group to return
    if (sepData[0].lower() != "null"):
        toReturn.append("")
        toReturn.append("In group: " + sepData[0])
    return toReturn
Example #2
0
def ReadSecurityFile(AESKey):
    if (not DoesProgramFileExist(securityFile)):
        return None  #This should never happen (only with tampering)
    try:
        with open((GetFileLocation() + securityFile), "r") as f:
            lines = f.readlines()
        return Encryptor.AESDecrypt(lines[2], AESKey)
    except:
        return None
Example #3
0
def GetPasswordTitles(encryptionKey, byGroup="NULL"):
    AESEncryptionKey = Encryptor.BindKey(Encryptor.GetKey(), encryptionKey)
    if (not DoesProgramFileExist(passFile)):
        return None
    with open((GetFileLocation() + passFile), "r") as f:
        encDataSet = f.readline()
    titles = []
    dataSet = Encryptor.DecryptFile(encDataSet, AESEncryptionKey)
    for data in dataSet:
        if (data != "" and data[0] != "#"):
            splitData = SplitString(data, sep2)
            title = splitData[1]
            if (byGroup != "NULL"):
                if (splitData[0].lower() == byGroup.lower()):
                    titles.append(Encryptor.AESDecrypt(title,
                                                       AESEncryptionKey))
            else:
                titles.append(Encryptor.AESDecrypt(title, AESEncryptionKey))
    return titles
Example #4
0
def CheckTestFile():
    if (not DoesProgramFileExist(testFile, workingPath)):
        #file doesn't exist, cannot perform check
        return False
    else:
        with open(workingPath + testFile) as f:
            checkFound = f.readline()
        passCheck = Encryptor.AESDecrypt(checkFound, Encryptor.GetKey())
        if (passCheck == "PASS"):
            return True
    return False
Example #5
0
def GetPasswordTitle(searchTerm, encryptionKey):
    AESEncryptionKey = Encryptor.BindKey(Encryptor.GetKey(), encryptionKey)
    if (not DoesProgramFileExist(passFile)):
        return None
    with open((GetFileLocation() + passFile), "r") as f:
        encDataSet = f.readline()
    dataSet = Encryptor.DecryptFile(encDataSet, AESEncryptionKey)
    for idx, data in enumerate(dataSet):
        if (data != "" and data[0] != "#"):
            title = SplitString(data, sep2)[1]
            foundTitle = Encryptor.AESDecrypt(title, AESEncryptionKey).lower()
            if (searchTerm.lower() == foundTitle):
                return idx
    return -1
Example #6
0
def ReadSFFPSL():
    try:
        if (not DoesProgramFileExist(exSecFile, securityPath)):
            return False
        with open(securityPath + exSecFile) as f:
            keyFound = f.readline()
        keyFound = Encryptor.AESDecrypt(keyFound, sep2)
        extractKey = ""
        for i in range(len(keyFound)):
            if (i % 3 == 0):
                extractKey += keyFound[i]

        UpdateSecurityKey(extractKey)
        return True
    except:
        return False
Example #7
0
def GetUserAccount(passKey):
    accFile = open((GetFileLocation() + accountFile), "r")
    if (accFile.mode == 'r'):
        encAccString = accFile.read()
        toReturn = ""
        try:
            #Decrypt file and split based on seperator
            accountString = Encryptor.AESDecrypt(encAccString, passKey)
            accFile.close()
            return SplitString(accountString, seperator)
        except:
            #Failed to decrypt
            pass
        accFile.close()
        return None
    accFile.close()
    return None
Example #8
0
def AmmendPasswordFile(passTitle,
                       password,
                       encryptionKey,
                       inputUsername="******",
                       inputExtra="null",
                       inputGroup="null",
                       lineNum=-1):
    AESEncryptionKey = Encryptor.BindKey(Encryptor.GetKey(), encryptionKey)
    #Returns successful runs,
    if (not DoesProgramFileExist(passFile)):
        #Will create the file if it doesn't exist
        toWrite = ["#Locker.psl"]
        encryptedLineWrite = Encryptor.EncryptFile(toWrite, AESEncryptionKey)
        with open((GetFileLocation() + passFile), "w+") as pF:
            pF.write(encryptedLineWrite)

    #Get Current File
    with open((GetFileLocation() + passFile), "r") as f:
        data = f.readline()
    fileContent = Encryptor.DecryptFile(data, AESEncryptionKey)

    #lineNum = -1 denotes a new password to be added
    if (lineNum >= 0 and lineNum < len(fileContent)
            and (password == "" or inputUsername == "" or inputGroup == ""
                 or inputExtra == "")):
        #Check what values = '' and overrite with stored data
        #First seperate fileContent by sep2
        sep2Content = SplitString(fileContent[lineNum], sep2)
        #Now update group values
        if (inputGroup == ""):
            inputGroup = sep2Content[0]
        #Now get user/pass segment
        userPassSeg = Encryptor.AESDecrypt(sep2Content[2],
                                           AESEncryptionKey).split(userpassSep)
        if (password == ""):
            password = userPassSeg[0]
        if (inputUsername == ""):
            inputUsername = userPassSeg[1]
        if (inputExtra == ""):
            inputExtra = userPassSeg[2]
            print(inputExtra)

    lineWrite = inputGroup + sep2 + Encryptor.AESEncrypt(
        passTitle, AESEncryptionKey) + sep2 + Encryptor.AESEncrypt(
            password + userpassSep + inputUsername + userpassSep + inputExtra,
            AESEncryptionKey)

    #Ammend file contents
    if (lineNum == -1):
        fileContent.append(lineWrite)
    elif (lineNum >= 0):
        if (lineNum > len(fileContent)):
            return False
        fileContent[lineNum] = lineWrite
    else:
        raise ValueError("Invalid edit number, use '-1' to add new password")

    #Write back to file
    writeFileString = Encryptor.EncryptFile(fileContent, AESEncryptionKey)
    with open((GetFileLocation() + passFile), "w") as f:
        f.write(writeFileString)

    return True
Example #9
0
 def GetFileEncryptionKey(self):
     return enc.AESDecrypt(self.passw, self.sessionSALT)