Esempio n. 1
0
 def fromProtocolTreeNode(node):
     entity = ResultIqProtocolEntity.fromProtocolTreeNode(node)
     entity.__class__ = SuccessLeaveGroupsIqProtocolEntity
     entity.setProps(
         node.getChild("leave").getChild("group").getAttributeValue("id")
     )
     return entity
 def fromProtocolTreeNode(node):
     entity = ResultIqProtocolEntity.fromProtocolTreeNode(node)
     entity.__class__ = ListParticipantsResultIqProtocolEntity
     entity.setParticipants([
         pNode.getAttributeValue("jid") for pNode in node.getAllChildren()
     ])
     return entity
Esempio n. 3
0
    def fromProtocolTreeNode(node):
        entity = ResultIqProtocolEntity.fromProtocolTreeNode(node)
        entity.__class__ = ResultGetKeysIqProtocolEntity
        entity.setPreKeyBundleMap()
        userNodes = node.getChild("list").getAllChildren()
        for userNode in userNodes:
            try:
                preKeyNode = userNode.getChild("key")
                signedPreKeyNode = userNode.getChild("skey")
                registrationId = ResultGetKeysIqProtocolEntity._bytesToInt(userNode.getChild("registration").getData())
                identityKey = IdentityKey(DjbECPublicKey(ResultGetKeysIqProtocolEntity.encStr(userNode.getChild("identity").getData())))

                preKeyId = ResultGetKeysIqProtocolEntity._bytesToInt(preKeyNode.getChild("id").getData())
                preKeyPublic = DjbECPublicKey(ResultGetKeysIqProtocolEntity.encStr(preKeyNode.getChild("value").getData()))

                signedPreKeyId = ResultGetKeysIqProtocolEntity._bytesToInt(signedPreKeyNode.getChild("id").getData())
                signedPreKeySig = ResultGetKeysIqProtocolEntity.encStr(signedPreKeyNode.getChild("signature").getData())
                signedPreKeyPub = DjbECPublicKey(ResultGetKeysIqProtocolEntity.encStr(signedPreKeyNode.getChild("value").getData()))

                preKeyBundle = PreKeyBundle(registrationId, 1, preKeyId, preKeyPublic,
                                            signedPreKeyId, signedPreKeyPub, signedPreKeySig, identityKey)

                entity.setPreKeyBundleFor(userNode["jid"], preKeyBundle)
            except Exception as err:
                print(err)
                continue

        return entity
Esempio n. 4
0
    def fromProtocolTreeNode(node):
        entity = ResultIqProtocolEntity.fromProtocolTreeNode(node)
        entity.__class__ = ResultGetKeysIqProtocolEntity
        entity.setPreKeyBundleMap()
        userNodes = node.getChild("list").getAllChildren()
        for userNode in userNodes:
            preKeyNode = userNode.getChild("key")

            if preKeyNode is None:
                logger = logging.getLogger(__name__)
                logger.warning("Failed to receive preKeyNode for %s"%(userNode.getAttributeValue("jid") if "jid" in userNode.attributes else "unknown"))

                preKeyId = None
                preKeyPublic = None
            else:
                preKeyId = ResultGetKeysIqProtocolEntity._bytesToInt(preKeyNode.getChild("id").getData())
                preKeyPublic = DjbECPublicKey(ResultGetKeysIqProtocolEntity.encStr(preKeyNode.getChild("value").getData()))

            signedPreKeyNode = userNode.getChild("skey")
            registrationId = ResultGetKeysIqProtocolEntity._bytesToInt(userNode.getChild("registration").getData())
            identityKey = IdentityKey(DjbECPublicKey(ResultGetKeysIqProtocolEntity.encStr(userNode.getChild("identity").getData())))

            signedPreKeyId = ResultGetKeysIqProtocolEntity._bytesToInt(signedPreKeyNode.getChild("id").getData())
            signedPreKeySig = ResultGetKeysIqProtocolEntity.encStr(signedPreKeyNode.getChild("signature").getData())
            signedPreKeyPub = DjbECPublicKey(ResultGetKeysIqProtocolEntity.encStr(signedPreKeyNode.getChild("value").getData()))

            preKeyBundle = PreKeyBundle(registrationId, 1, preKeyId, preKeyPublic,
                                        signedPreKeyId, signedPreKeyPub, signedPreKeySig, identityKey)

            entity.setPreKeyBundleFor(userNode["jid"], preKeyBundle)

        return entity
Esempio n. 5
0
    def fromProtocolTreeNode(node):
        entity = ResultIqProtocolEntity.fromProtocolTreeNode(node)
        entity.__class__ = ResultGetKeysIqProtocolEntity
        entity.setPreKeyBundleMap()
        userNodes = node.getChild("list").getAllChildren()
        for userNode in userNodes:
            preKeyNode = userNode.getChild("key")
            signedPreKeyNode = userNode.getChild("skey")
            registrationId = ResultGetKeysIqProtocolEntity._bytesToInt(userNode.getChild("registration").getData())
            identityKey = IdentityKey(DjbECPublicKey(ResultGetKeysIqProtocolEntity.encStr(userNode.getChild("identity").getData())))

            #preKeyId = ResultGetKeysIqProtocolEntity._bytesToInt(preKeyNode.getChild("id").getData())
            #preKeyPublic = DjbECPublicKey(ResultGetKeysIqProtocolEntity.encStr(preKeyNode.getChild("value").getData()))

            try: preKeyId = ResultGetKeysIqProtocolEntity._bytesToInt(preKeyNode.getChild("id").getData())
            except: preKeyId = None; pass
            try: preKeyPublic = DjbECPublicKey(ResultGetKeysIqProtocolEntity.encStr(preKeyNode.getChild("value").getData()))
            except: preKeyPublic = None; pass

            signedPreKeyId = ResultGetKeysIqProtocolEntity._bytesToInt(signedPreKeyNode.getChild("id").getData())
            signedPreKeySig = ResultGetKeysIqProtocolEntity.encStr(signedPreKeyNode.getChild("signature").getData())
            signedPreKeyPub = DjbECPublicKey(ResultGetKeysIqProtocolEntity.encStr(signedPreKeyNode.getChild("value").getData()))

            preKeyBundle = PreKeyBundle(registrationId, 1, preKeyId, preKeyPublic,
                                        signedPreKeyId, signedPreKeyPub, signedPreKeySig, identityKey)

            entity.setPreKeyBundleFor(userNode["jid"], preKeyBundle)

        return entity
Esempio n. 6
0
    def fromProtocolTreeNode(node):
        entity = ResultIqProtocolEntity.fromProtocolTreeNode(node)
        entity.__class__ = ResultGetKeysIqProtocolEntity
        entity.setPreKeyBundleMap()
        userNodes = node.getChild("list").getAllChildren()
        for userNode in userNodes:
            preKeyNode = userNode.getChild("key")

            if (preKeyNode is None):
                logger = logging.getLogger(__name__)
                logger.setLevel(logging.DEBUG)
                # create file handler which logs even debug messages
                fh = logging.FileHandler('/var/log/yowsup_failed_number.log')
                fh.setLevel(logging.DEBUG)
                # create formatter and add it to the handlers
                formatter = logging.Formatter(
                    '%(asctime)s - %(name)s - %(levelname)s - %(message)s')
                fh.setFormatter(formatter)
                # add the handlers to the logger
                logger.addHandler(fh)
                logger.warning("Failed to receive preKeyNode for %s" %
                               (userNode.getAttributeValue("jid") if "jid"
                                in userNode.attributes else "unknown"))

                # it seems, simply using None for IDs breaks sending, but at last allows receiving
                preKeyId = None
                preKeyPublic = None
            else:
                preKeyId = ResultGetKeysIqProtocolEntity._bytesToInt(
                    preKeyNode.getChild("id").getData())
                preKeyPublic = DjbECPublicKey(
                    ResultGetKeysIqProtocolEntity.encStr(
                        preKeyNode.getChild("value").getData()))

            signedPreKeyNode = userNode.getChild("skey")
            registrationId = ResultGetKeysIqProtocolEntity._bytesToInt(
                userNode.getChild("registration").getData())
            identityKey = IdentityKey(
                DjbECPublicKey(
                    ResultGetKeysIqProtocolEntity.encStr(
                        userNode.getChild("identity").getData())))

            signedPreKeyId = ResultGetKeysIqProtocolEntity._bytesToInt(
                signedPreKeyNode.getChild("id").getData())
            signedPreKeySig = ResultGetKeysIqProtocolEntity.encStr(
                signedPreKeyNode.getChild("signature").getData())
            signedPreKeyPub = DjbECPublicKey(
                ResultGetKeysIqProtocolEntity.encStr(
                    signedPreKeyNode.getChild("value").getData()))

            preKeyBundle = PreKeyBundle(registrationId, 1, preKeyId,
                                        preKeyPublic, signedPreKeyId,
                                        signedPreKeyPub, signedPreKeySig,
                                        identityKey)

            entity.setPreKeyBundleFor(userNode["jid"], preKeyBundle)

        return entity
Esempio n. 7
0
 def fromProtocolTreeNode(node):
     entity = ResultIqProtocolEntity.fromProtocolTreeNode(node)
     entity.__class__ = ListGroupsResultIqProtocolEntity
     groups = [
         Group(groupNode["id"], groupNode["owner"], groupNode["subject"], groupNode["s_o"], groupNode["s_t"], groupNode["creation"])
         for groupNode in node.getAllChildren()
     ]
     entity.setProps(groups)
     return entity
 def fromProtocolTreeNode(node):
     entity = ResultIqProtocolEntity.fromProtocolTreeNode(node)
     entity.__class__ = SuccessAddParticipantsIqProtocolEntity
     participantList = []
     for participantNode in node.getAllChildren():
         if participantNode["type"] == "success":
             participantList.append(participantNode["participant"])
     entity.setProps(node.getAttributeValue("from"), participantList)
     return entity
Esempio n. 9
0
 def fromProtocolTreeNode(node):
     entity = ResultIqProtocolEntity.fromProtocolTreeNode(node)
     entity.__class__ = SuccessAddParticipantsIqProtocolEntity
     participantList = []
     for participantNode in node.getAllChildren():
         if participantNode["type"] == "success":
             participantList.append(participantNode["participant"])
     entity.setProps(node.getAttributeValue("from"), participantList)
     return entity
 def fromProtocolTreeNode(node):
     entity= ResultIqProtocolEntity.fromProtocolTreeNode(node)
     entity.__class__ = ResultRequestUploadIqProtocolEntity
     mediaNode = node.getChild("media")
     if mediaNode:
         entity.setUploadProps(mediaNode["url"], mediaNode["ip"], mediaNode["resume"])
     else:
         duplicateNode = node.getChild("duplicate")
         if duplicateNode:
             entity.setUploadProps(duplicateNode["url"], duplicateNode["ip"], duplicate = True)
     return entity
Esempio n. 11
0
 def fromProtocolTreeNode(node):
     entity = ResultIqProtocolEntity.fromProtocolTreeNode(node)
     entity.__class__ = ResultRequestUploadIqProtocolEntity
     mediaNode = node.getChild("media")
     if mediaNode:
         entity.setUploadProps(mediaNode["url"], mediaNode["ip"],
                               mediaNode["resume"])
     else:
         duplicateNode = node.getChild("duplicate")
         if duplicateNode:
             entity.setUploadProps(duplicateNode["url"],
                                   duplicateNode["ip"],
                                   duplicate=True)
     return entity
Esempio n. 12
0
 def onDeletePictureResult(self, resultNode, originalIqRequestEntity):
     self.toUpper(ResultIqProtocolEntity.fromProtocolTreeNode(resultNode))
Esempio n. 13
0
 def fromProtocolTreeNode(node):
     entity = ResultIqProtocolEntity.fromProtocolTreeNode(node)
     entity.__class__ = ListParticipantsResultIqProtocolEntity
     entity.setParticipants([ pNode.getAttributeValue("jid") for pNode in node.getAllChildren() ])
     return entity
Esempio n. 14
0
 def onDeletePictureResult(self, resultNode, originalIqRequestEntity):
     self.toUpper(ResultIqProtocolEntity.fromProtocolTreeNode(resultNode))
Esempio n. 15
0
 def onSetStatusResult(self, resultNode, originIqRequestEntity):
     self.toUpper(ResultIqProtocolEntity.fromProtocolTreeNode(resultNode))
 def fromProtocolTreeNode(node):
     entity = ResultIqProtocolEntity.fromProtocolTreeNode(node)
     entity.__class__ = SuccessCreateGroupsIqProtocolEntity
     entity.setProps(node.getChild("group").getAttributeValue("id"))
     return entity
Esempio n. 17
0
 def onSetStatusResult(self, resultNode, originIqRequestEntity):
     self.toUpper(ResultIqProtocolEntity.fromProtocolTreeNode(resultNode))