Esempio n. 1
0
    def handlePlaintextNode(self, node):
        plaintext = node.getChild("body").getData()
        entity = MessageProtocolEntity.fromProtocolTreeNode(node)
        recipient_id = entity.getTo(False)

        if not self.store.containsSession(recipient_id, 1):
            entity = GetKeysIqProtocolEntity([node["to"]])
            if node["to"] not in self.pendingMessages:
                self.pendingMessages[node["to"]] = []
            self.pendingMessages[node["to"]].append(node)

            self._sendIq(entity, self.onGetKeysResult, self.onGetKeysError)
        else:

            sessionCipher = self.getSessionCipher(recipient_id)



            ciphertext = sessionCipher.encrypt(plaintext)
            encEntity = EncryptedMessageProtocolEntity(
                EncryptedMessageProtocolEntity.TYPE_MSG if ciphertext.__class__ == WhisperMessage else EncryptedMessageProtocolEntity.TYPE_PKMSG ,
                                                   "%s/%s" % (CURRENT_ENV.getOSName(), CURRENT_ENV.getVersion()),
                                                   1,
                                                   ciphertext.serialize(),
                                                   MessageProtocolEntity.MESSAGE_TYPE_TEXT,
                                                   _id= node["id"],
                                                   to = node["to"],
                                                   notify = node["notify"],
                                                   timestamp= node["timestamp"],
                                                   participant=node["participant"],
                                                   offline=node["offline"],
                                                   retry=node["retry"]
                                                   )
            self.toLower(encEntity.toProtocolTreeNode())
Esempio n. 2
0
    def handlePlaintextNode(self, node):
        plaintext = node.getChild("body").getData()
        entity = MessageProtocolEntity.fromProtocolTreeNode(node)
        recipient_id = entity.getTo(False)

        if not self.store.containsSession(recipient_id, 1):
            entity = GetKeysIqProtocolEntity([node["to"]])
            if node["to"] not in self.pendingMessages:
                self.pendingMessages[node["to"]] = []
            self.pendingMessages[node["to"]].append(node)

            self._sendIq(
                entity, lambda a, b: self.onGetKeysResult(
                    a, b, self.processPendingMessages), self.onGetKeysError)
        else:

            sessionCipher = self.getSessionCipher(recipient_id)

            if node["to"] in self.v2Jids:
                version = 2
                padded = bytearray()
                padded.append(ord("\n"))
                padded.extend(self.encodeInt7bit(len(plaintext)))
                padded.extend(plaintext)
                padded.append(ord("\x01"))
                plaintext = padded
            else:
                version = 1
            ciphertext = sessionCipher.encrypt(plaintext)
            encEntity = EncryptedMessageProtocolEntity(
                EncryptedMessageProtocolEntity.TYPE_MSG
                if ciphertext.__class__ == WhisperMessage else
                EncryptedMessageProtocolEntity.TYPE_PKMSG,
                version,
                ciphertext.serialize(),
                MessageProtocolEntity.MESSAGE_TYPE_TEXT,
                _id=node["id"],
                to=node["to"],
                notify=node["notify"],
                timestamp=node["timestamp"],
                participant=node["participant"],
                offline=node["offline"],
                retry=node["retry"])
            self.toLower(encEntity.toProtocolTreeNode())
Esempio n. 3
0
    def handlePlaintextNode(self, node):
        plaintext = node.getChild("body").getData()
        entity = MessageProtocolEntity.fromProtocolTreeNode(node)
        recipient_id = entity.getTo(False)

        if not self.store.containsSession(recipient_id, 1):
            entity = GetKeysIqProtocolEntity([node["to"]])
            if node["to"] not in self.pendingMessages:
                self.pendingMessages[node["to"]] = []
            self.pendingMessages[node["to"]].append(node)

            self._sendIq(entity, lambda a, b: self.onGetKeysResult(a, b, self.processPendingMessages),
                         self.onGetKeysError)
        else:

            sessionCipher = self.getSessionCipher(recipient_id)

            if node["to"] in self.v2Jids:
                version = 2
                padded = bytearray()
                padded.append(ord("\n"))
                padded.extend(self.encodeInt7bit(len(plaintext)))
                padded.extend(plaintext)
                padded.append(ord("\x01"))
                plaintext = padded
            else:
                version = 1
            ciphertext = sessionCipher.encrypt(plaintext)
            encEntity = EncryptedMessageProtocolEntity(
                EncryptedMessageProtocolEntity.TYPE_MSG if ciphertext.__class__ == WhisperMessage else EncryptedMessageProtocolEntity.TYPE_PKMSG,
                version,
                ciphertext.serialize(),
                MessageProtocolEntity.MESSAGE_TYPE_TEXT,
                _id=node["id"],
                to=node["to"],
                notify=node["notify"],
                timestamp=node["timestamp"],
                participant=node["participant"],
                offline=node["offline"],
                retry=node["retry"]
            )
            self.toLower(encEntity.toProtocolTreeNode())