Exemple #1
0
 def handlePreKeyWhisperMessage(self, recipient_id, device_id, key):
     preKeyWhisperMessage = PreKeyWhisperMessage(serialized=key)
     if not preKeyWhisperMessage.getPreKeyId():
         raise Exception("Received PreKeyWhisperMessage without PreKey =>" +
                         recipient_id)
     sessionCipher = self.get_session_cipher(recipient_id, device_id)
     try:
         log.debug(self.account +
                   " => Received PreKeyWhisperMessage from " + recipient_id)
         key = sessionCipher.decryptPkmsg(preKeyWhisperMessage)
         # Publish new bundle after PreKey has been used
         # for building a new Session
         self.plugin.publish_bundle(self.account)
         return key
     except UntrustedIdentityException as e:
         log.info(self.account + " => Received WhisperMessage " +
                  "from Untrusted Fingerprint! => " + e.getName())
Exemple #2
0
 def handle_PreKeyWhisperMessage(self, message):
     """Handle received PreKey message"""
     logger.info('Received PreKeyWhisperMessage from {}, '
                 'decrypting...'.format(message.identity))
     preKeyWhisperMessage = PreKeyWhisperMessage(serialized=message.message)
     sessionCipher = self.getSessionCipher(message.identity)
     plaintext = sessionCipher.decryptPkmsg(preKeyWhisperMessage)
     return plaintext
Exemple #3
0
 def handlePreKeyWhisperMessage(self, recipient_id, device_id, key):
     preKeyWhisperMessage = PreKeyWhisperMessage(serialized=key)
     if not preKeyWhisperMessage.getPreKeyId():
         raise Exception("Received PreKeyWhisperMessage without PreKey =>" +
                         recipient_id)
     sessionCipher = self.get_session_cipher(recipient_id, device_id)
     try:
         log.debug(self.account +
                   " => Received PreKeyWhisperMessage from " +
                   recipient_id)
         key = sessionCipher.decryptPkmsg(preKeyWhisperMessage)
         # Publish new bundle after PreKey has been used
         # for building a new Session
         self.plugin.publish_bundle(self.account)
         return key
     except UntrustedIdentityException as e:
         log.info(self.account + " => Received WhisperMessage " +
                  "from Untrusted Fingerprint! => " + e.getName())
Exemple #4
0
    def _process_pre_key_message(self, jid, device, key):
        self._log.info('Process pre key message from %s', jid)
        pre_key_message = PreKeyWhisperMessage(serialized=key)
        if not pre_key_message.getPreKeyId():
            raise Exception('Received Pre Key Message '
                            'without PreKey => %s' % jid)

        session_cipher = self._get_session_cipher(jid, device)
        key = session_cipher.decryptPkmsg(pre_key_message)

        identity_key = pre_key_message.getIdentityKey()
        trust = self._get_trust_from_identity_key(jid, identity_key)
        fingerprint = get_fingerprint(identity_key)

        self._storage.setIdentityLastSeen(jid, identity_key)

        self.xmpp_con.set_bundle()
        self.add_device(jid, device)
        return key, fingerprint, trust
Exemple #5
0
 def handlePreKeyWhisperMessage(self, node):
     pkMessageProtocolEntity = EncryptedMessageProtocolEntity.fromProtocolTreeNode(node)
     enc = pkMessageProtocolEntity.getEnc(EncProtocolEntity.TYPE_PKMSG)
     preKeyWhisperMessage = PreKeyWhisperMessage(serialized=enc.getData())
     sessionCipher = self.getSessionCipher(pkMessageProtocolEntity.getAuthor(False))
     plaintext = sessionCipher.decryptPkmsg(preKeyWhisperMessage)
     if enc.getVersion() == 2:
         padding = ord(plaintext[-1]) & 0xFF
         self.parseAndHandleMessageProto(pkMessageProtocolEntity, plaintext[:-padding])
     else:
         self.handleConversationMessage(node, plaintext)
Exemple #6
0
    def handlePreKeyWhisperMessage(self, node):
        pkMessageProtocolEntity = EncryptedMessageProtocolEntity.fromProtocolTreeNode(
            node)

        preKeyWhisperMessage = PreKeyWhisperMessage(
            serialized=pkMessageProtocolEntity.getEncData())
        sessionCipher = self.getSessionCipher(
            pkMessageProtocolEntity.getFrom(False))
        plaintext = sessionCipher.decryptPkmsg(preKeyWhisperMessage)

        bodyNode = ProtocolTreeNode("body", data=plaintext)
        node.addChild(bodyNode)
        self.toUpper(node)
Exemple #7
0
 def decrypt_pkmsg(self, senderid, data, unpad):
     logger.debug("decrypt_pkmsg(senderid=%s, data=(omitted), unpad=%s)" % (senderid, unpad))
     pkmsg = PreKeyWhisperMessage(serialized=data)
     try:
         plaintext = self._get_session_cipher(senderid).decryptPkmsg(pkmsg)
         return self._unpad(plaintext) if unpad else plaintext
     except NoSessionException:
         raise exceptions.NoSessionException()
     except InvalidKeyIdException:
         raise exceptions.InvalidKeyIdException()
     except InvalidMessageException:
         raise exceptions.InvalidMessageException()
     except DuplicateMessageException:
         raise exceptions.DuplicateMessageException()
Exemple #8
0
 def handlePreKeyWhisperMessage(self, node):
     pkMessageProtocolEntity = EncryptedMessageProtocolEntity(node)
     enc_ = pkMessageProtocolEntity.getEnc(EncProtocolEntity.TYPE_PKMSG)
     preKeyWhisperMessage = PreKeyWhisperMessage(serialized=enc_.getData())
     sessionCipher = self.getSessionCipher(
         Jid.denormalize(pkMessageProtocolEntity.getAuthor()))
     plaintext = sessionCipher.decryptPkmsg(preKeyWhisperMessage)
     if enc_.getVersion() == 2:
         paddingByte = plaintext[-1] if type(plaintext[-1]) is int else ord(
             plaintext[-1])
         padding = paddingByte & 0xFF
         self.parseAndHandleMessageProto(pkMessageProtocolEntity,
                                         plaintext[:-padding])
     else:
         logger.error("Ignoring message with old version")
Exemple #9
0
    def handlePreKeyWhisperMessage(self, node):
        plaintext = ""
        try:
            pkMessageProtocolEntity = EncryptedMessageProtocolEntity.fromProtocolTreeNode(
                node)
            preKeyWhisperMessage = PreKeyWhisperMessage(
                serialized=pkMessageProtocolEntity.getEncData())
            sessionCipher = self.getSessionCipher(
                pkMessageProtocolEntity.getFrom(False))
            plaintext = sessionCipher.decryptPkmsg(preKeyWhisperMessage)
        except Exception as e:
            print("Message decript error: %s" % (str(e)))

        if pkMessageProtocolEntity.getVersion() == 2:
            plaintext = self.unpadV2Plaintext(plaintext)

        bodyNode = ProtocolTreeNode("body", data=plaintext)
        node.addChild(bodyNode)
        self.toUpper(node)
Exemple #10
0
 def handlePreKeyWhisperMessage(self, recipient_id, device_id, key):
     preKeyWhisperMessage = PreKeyWhisperMessage(serialized=key)
     sessionCipher = self.get_session_cipher(recipient_id, device_id)
     key = sessionCipher.decryptPkmsg(preKeyWhisperMessage)
     log.debug('PreKeyWhisperMessage -> ' + str(key))
     return key
Exemple #11
0
 def _get_identity_key_from_pk_message(key):
     pre_key_message = PreKeyWhisperMessage(serialized=key)
     return pre_key_message.getIdentityKey()