Example #1
0
 def run(self):
     try:
         #            Logger.log("Encrypting focus : page = " + str(self.page) + " count = " + str(self.count) + " guid = " + str(int(m.hexdigest(), 16)))
         m = hashlib.md5()
         m.update((self.fileName + ":" + str(self.page) + ":" +
                   str(self.count)).encode('utf-8'))
         getChord = self.chord.locateSuccessor(int(m.hexdigest(), 16), True)
         #Check to make sure the file guid is located in the respective node.
         if getChord.guid == self.chord.guid:
             #                Logger.printLog("Encrypt page = " + str(self.page) + " count = " + str(self.count) + " guid = " + str(int(m.hexdigest(), 16)))
             #No need for chain encryption if count is a total of 1, if it's greater then it'll do a chain encryption
             if self.count == 1:
                 #                   Logger.log("page = " + str(self.page) + " count = initial")
                 RSACipher, cipherText, IV, tag = Encryptor.initialize(
                     self.data)
             else:
                 #                    Logger.log("page = " + str(self.page) + " count =" + str(count))
                 for y in self.chord.keychain:
                     if y["Chord"] == self.prevKey:
                         for x in self.chainEncryption:
                             if x["Set"] == self.count - 1:
                                 RSACipher, cipherText, IV, tag = Encryptor.chainInitialize(
                                     b64decode(x["RSACipher"]),
                                     b64decode(self.data),
                                     b64decode(x["IV"]),
                                     b64decode(x["Tag"]), y["Key"])
             self.chainEncryption.append({
                 'Set': self.count,
                 'RSACipher': RSACipher,
                 'IV': IV,
                 'Tag': tag
             })
             #If the encryption happens the MAX_CHAIN_ENCRPYTION amount of times, then it will be finished, else it will chainEncrpyt again
             if self.count == constant.MAX_CHAIN_ENCRYPTION:
                 tokenHash = hashlib.md5()
                 combo = str(int(m.hexdigest(), 16)) + ":" + str(self.token)
                 tokenHash.update(combo.encode('utf-8'))
                 getChord.createPage(cipherText, int(int(m.hexdigest(),
                                                         16)),
                                     int(tokenHash.hexdigest(), 16),
                                     self.chainEncryption)
             else:
                 getChord.chainEncrypt(self.fileName, cipherText,
                                       self.count + 1, self.chainEncryption,
                                       self.page, self.token,
                                       self.chord._guid)
         else:
             getChord.chainEncrypt(self.fileName, self.data, self.count,
                                   self.chainEncryption, self.page,
                                   self.token, self.prevKey)
     except Exception as e:
         print(str(e))