コード例 #1
0
    def toProtocolTreeNode(self):
        node = super(ListGroupsResultIqProtocolEntity, self).toProtocolTreeNode()

        groupsNodes = []
        for group in self.groupsList:
            groupNode = ProtocolTreeNode("group", {
                "id":       group.getId(),
                "creator":    group.getCreator(),
                "subject":  group.getSubject(),
                "s_o":      group.getSubjectOwner(),
                "s_t":      str(group.getSubjectTime()),
                "creation": str(group.getCreationTime())
                },
            )
            participants = []
            for jid, _type in group.getParticipants().items():
                pnode = ProtocolTreeNode("participant", {"jid": jid})
                if _type:
                    pnode["type"] = _type
                participants.append(pnode)
            groupNode.addChildren(participants)
            groupsNodes.append(groupNode)

        node.addChild(ProtocolTreeNode("groups", children = groupsNodes))
        return node
コード例 #2
0
    def toProtocolTreeNode(self):
        node = super(CreateGroupsNotificationProtocolEntity,
                     self).toProtocolTreeNode()
        createNode = ProtocolTreeNode("create", {
            "type": self.getCreatetype(),
            "key": self.key
        })
        groupNode = ProtocolTreeNode(
            "group", {
                "subject": self.getSubject(),
                "creation": str(self.getCreationTimestamp()),
                "creator": self.getCreatorJid(),
                "s_t": self.getSubjectTimestamp(),
                "s_o": self.getSubjectOwnerJid(),
                "id": self.getGroupId()
            })

        participants = []
        for jid, _type in self.getParticipants().items():
            pnode = ProtocolTreeNode("participant", {"jid": jid})
            if _type:
                pnode["type"] = _type
            participants.append(pnode)

        groupNode.addChildren(participants)
        createNode.addChild(groupNode)
        node.addChild(createNode)

        return node
コード例 #3
0
ファイル: iq_keys_set.py プロジェクト: 3esmit/yowsup
    def toProtocolTreeNode(self):
        node = super(SetKeysIqProtocolEntity, self).toProtocolTreeNode()
        identityNode = ProtocolTreeNode("identity", data = self.identityKey)

        listNode = ProtocolTreeNode("list")
        keyNodes = []
        for keyId, pk in self.preKeys.items():
            keyNode = ProtocolTreeNode("key")
            keyNode.addChild(ProtocolTreeNode("id", data = keyId))
            keyNode.addChild(ProtocolTreeNode("value", data = pk))
            keyNodes.append(keyNode)

        listNode.addChildren(keyNodes)

        regNode = ProtocolTreeNode("registration", data = self.registration)
        typeNode = ProtocolTreeNode("type", data = chr(self.djbType))
        _id, val, signature = self.signedPreKey
        skeyNode = ProtocolTreeNode("skey", children = [
            ProtocolTreeNode("id", data = _id),
            ProtocolTreeNode("value", data = val),
            ProtocolTreeNode("signature", data = signature)
        ])

        node.addChildren([
            listNode,
            identityNode,
            regNode,
            typeNode,
            skeyNode
        ])

        return node
コード例 #4
0
    def toProtocolTreeNode(self):
        node = super(ListGroupsResultIqProtocolEntity,
                     self).toProtocolTreeNode()

        groupsNodes = []
        for group in self.groupsList:
            groupNode = ProtocolTreeNode(
                "group",
                {
                    "id": group.getId(),
                    "creator": group.getCreator(),
                    "subject": group.getSubject(),
                    "s_o": group.getSubjectOwner(),
                    "s_t": str(group.getSubjectTime()),
                    "creation": str(group.getCreationTime())
                },
            )
            participants = []
            for jid, _type in group.getParticipants().items():
                pnode = ProtocolTreeNode("participant", {"jid": jid})
                if _type:
                    pnode["type"] = _type
                participants.append(pnode)
            groupNode.addChildren(participants)
            groupsNodes.append(groupNode)

        node.addChild(ProtocolTreeNode("groups", children=groupsNodes))
        return node
コード例 #5
0
    def toProtocolTreeNode(self):
        node = super(SetKeysIqProtocolEntity, self).toProtocolTreeNode()
        identityNode = ProtocolTreeNode("identity", data=self.identityKey)

        listNode = ProtocolTreeNode("list")
        keyNodes = []
        for keyId, pk in self.preKeys.items():
            keyNode = ProtocolTreeNode("key")
            keyNode.addChild(ProtocolTreeNode("id", data=keyId))
            keyNode.addChild(ProtocolTreeNode("value", data=pk))
            keyNodes.append(keyNode)

        listNode.addChildren(keyNodes)

        regNode = ProtocolTreeNode("registration", data=self.registration)
        typeNode = ProtocolTreeNode("type", data=chr(self.djbType))
        _id, val, signature = self.signedPreKey
        skeyNode = ProtocolTreeNode("skey",
                                    children=[
                                        ProtocolTreeNode("id", data=_id),
                                        ProtocolTreeNode("value", data=val),
                                        ProtocolTreeNode("signature",
                                                         data=signature)
                                    ])

        node.addChildren([listNode, identityNode, regNode, typeNode, skeyNode])

        return node
コード例 #6
0
 def setUp(self):
     super(BroadcastTextMessageTest, self).setUp()
     self.ProtocolEntity = BroadcastTextMessage
     broadcastNode = ProtocolTreeNode("broadcast")
     jids = ["jid1", "jid2"]
     toNodes = [ProtocolTreeNode("to", {"jid": jid}) for jid in jids]
     broadcastNode.addChildren(toNodes)
     self.node.addChild(broadcastNode)
コード例 #7
0
 def setUp(self):
     super(BroadcastTextMessageTest, self).setUp()
     self.ProtocolEntity = BroadcastTextMessage
     broadcastNode = ProtocolTreeNode("broadcast")
     jids = ["jid1", "jid2"]
     toNodes = [ProtocolTreeNode("to", {"jid" : jid}) for jid in jids]
     broadcastNode.addChildren(toNodes)
     self.node.addChild(broadcastNode)
コード例 #8
0
 def toProtocolTreeNode(self):
     node = super(CreateGroupsIqProtocolEntity, self).toProtocolTreeNode()
     cnode = ProtocolTreeNode("create", {"subject": self.subject})
     participantNodes = [
         ProtocolTreeNode("participant", {"jid": participant}) for participant in self.participantList
     ]
     cnode.addChildren(participantNodes)
     node.addChild(cnode)
     return node
コード例 #9
0
 def toProtocolTreeNode(self):
     node = super(CreateGroupsIqProtocolEntity, self).toProtocolTreeNode()
     cnode = ProtocolTreeNode("create", {"subject": self.subject})
     participantNodes = [
         ProtocolTreeNode("participant", {"jid": participant})
         for participant in self.participantList
     ]
     cnode.addChildren(participantNodes)
     node.addChild(cnode)
     return node
コード例 #10
0
    def toProtocolTreeNode(self):
        node = super().toProtocolTreeNode()
        demoteNode = ProtocolTreeNode("demote", {"subject": self.subject})
        participants = []
        for jid in self.getParticipants():
            pnode = ProtocolTreeNode("participant", {"jid": jid})
            participants.append(pnode)

        demoteNode.addChildren(participants)
        node.addChild(demoteNode)

        return node
コード例 #11
0
    def toProtocolTreeNode(self):
        node = super(AddGroupsNotificationProtocolEntity, self).toProtocolTreeNode()
        addNode = ProtocolTreeNode("add")
        participants = []
        for jid in self.getParticipants():
            pnode = ProtocolTreeNode("participant", {"jid": jid})
            participants.append(pnode)

        addNode.addChildren(participants)
        node.addChild(addNode)

        return node
コード例 #12
0
    def toProtocolTreeNode(self):
        node = super(RemoveGroupsNotificationProtocolEntity, self).toProtocolTreeNode()
        removeNode = ProtocolTreeNode("remove", {"subject": self.subject})
        participants = []
        for jid in self.getParticipants():
            pnode = ProtocolTreeNode("participant", {"jid": jid})
            participants.append(pnode)

        removeNode.addChildren(participants)
        node.addChild(removeNode)

        return node
コード例 #13
0
    def toProtocolTreeNode(self):
        node = super(AddGroupsNotificationProtocolEntity, self).toProtocolTreeNode()
        addNode = ProtocolTreeNode("add")
        participants = []
        for jid in self.getParticipants():
            pnode = ProtocolTreeNode("participant", {"jid": jid})
            participants.append(pnode)

        addNode.addChildren(participants)
        node.addChild(addNode)

        return node
コード例 #14
0
    def toProtocolTreeNode(self):
        node = super(RemoveGroupsNotificationProtocolEntity,
                     self).toProtocolTreeNode()
        removeNode = ProtocolTreeNode("remove", {"subject": self.subject})
        participants = []
        for jid in self.getParticipants():
            pnode = ProtocolTreeNode("participant", {"jid": jid})
            participants.append(pnode)

        removeNode.addChildren(participants)
        node.addChild(removeNode)

        return node
コード例 #15
0
    def toProtocolTreeNode(self):
        node = super(OutgoingReceiptProtocolEntity, self).toProtocolTreeNode()
        if self.read:
            node.setAttribute("type", "read")
        if self.participant:
            node.setAttribute("participant", self.participant)
        if self.callId:
            offer = ProtocolTreeNode("offer", {"call-id": self.callId})
            node.addChild(offer)

        node.setAttribute("to", self.to)

        if len(self.messageIds) > 1:
            listNode = ProtocolTreeNode("list")
            listNode.addChildren([ProtocolTreeNode("item", {"id": mId}) for mId in self.messageIds])
            node.addChild(listNode)

        return node
コード例 #16
0
    def toProtocolTreeNode(self):
        node = super(IncomingReceiptProtocolEntity, self).toProtocolTreeNode()
        node.setAttribute("from", self._from)
        node.setAttribute("t", str(self.timestamp))
        if self.offline is not None:
            node.setAttribute("offline", "1" if self.offline else "0")
        if self.type is not None:
            node.setAttribute("type", self.type)
        if self.participant is not None:
            node.setAttribute("participant", self.participant)

        if self.items is not None:
            inodes = []
            for item in self.items:
                inode = ProtocolTreeNode("item", {"id": item})
                inodes.append(inode)

            lnode = ProtocolTreeNode("list")
            lnode.addChildren(inodes)
            node.addChild(lnode)
        return node
コード例 #17
0
    def toProtocolTreeNode(self):
        node = super(IncomingReceiptProtocolEntity, self).toProtocolTreeNode()
        node.setAttribute("from", self._from)
        node.setAttribute("t", str(self.timestamp))
        if self.offline is not None:
            node.setAttribute("offline", "1" if self.offline else "0")
        if self.type is not None:
            node.setAttribute("type", self.type)
        if self.participant is not None:
            node.setAttribute("participant", self.participant)

        if self.items is not None:
            inodes = []
            for item in self.items:
                inode = ProtocolTreeNode("item", {"id": item})
                inodes.append(inode)

            lnode = ProtocolTreeNode("list")
            lnode.addChildren(inodes)
            node.addChild(lnode)
        return node
コード例 #18
0
    def toProtocolTreeNode(self):
        node = super(ResultGetKeysIqProtocolEntity, self).toProtocolTreeNode()
        listNode = ProtocolTreeNode("list")
        node.addChild(listNode)

        for jid, preKeyBundle in self.preKeyBundleMap.items():
            userNode = ProtocolTreeNode("user", {"jid": jid})
            registrationNode = ProtocolTreeNode("registration", data = self.__class__._intToBytes(preKeyBundle.getRegistrationId()))
            typeNode = ProtocolTreeNode("type", data = self.__class__._intToBytes(Curve.DJB_TYPE))
            identityNode = ProtocolTreeNode("identity", data = preKeyBundle.getIdentityKey().getPublicKey().getPublicKey())

            skeyNode = ProtocolTreeNode("skey")
            skeyNode_idNode = ProtocolTreeNode("id", data=self.__class__._intToBytes(preKeyBundle.getSignedPreKeyId()))
            skeyNode_valueNode = ProtocolTreeNode("value", data=preKeyBundle.getSignedPreKey().getPublicKey())
            skeyNode_signatureNode = ProtocolTreeNode("signature", data=preKeyBundle.getSignedPreKeySignature())
            skeyNode.addChildren([skeyNode_idNode, skeyNode_valueNode, skeyNode_signatureNode])

            preKeyNode = ProtocolTreeNode("key")
            preKeyNode_idNode = ProtocolTreeNode("id", data = self.__class__._intToBytes(preKeyBundle.getPreKeyId()))
            preKeyNode_valueNode = ProtocolTreeNode("value", data= preKeyBundle.getPreKey().getPublicKey())
            preKeyNode.addChildren([preKeyNode_idNode, preKeyNode_valueNode])

            userNode.addChildren([
                registrationNode,
                typeNode,
                identityNode,
                skeyNode,
                preKeyNode
            ])
            listNode.addChild(userNode)

        return node
コード例 #19
0
    def setUp(self):
        super(ResultIqProtocolEntityTest, self).setUp()
        self.ProtocolEntity = ResultGetKeysIqProtocolEntity
        listNode = ProtocolTreeNode("list")
        self.node.addChild(listNode)

        for i in range(0, 1):
            userNode = ProtocolTreeNode(
                "user",
                {"jid": "user_%s@%s" % (i, YowConstants.WHATSAPP_SERVER)})
            listNode.addChild(userNode)
            registrationNode = ProtocolTreeNode(
                "registration",
                data=ResultGetKeysIqProtocolEntity._intToBytes(
                    KeyHelper.generateRegistrationId()))

            typeNode = ProtocolTreeNode(
                "type",
                data=ResultGetKeysIqProtocolEntity._intToBytes(Curve.DJB_TYPE))

            identityKeyPair = KeyHelper.generateIdentityKeyPair()
            identityNode = ProtocolTreeNode("identity",
                                            data=identityKeyPair.getPublicKey(
                                            ).getPublicKey().getPublicKey())

            signedPreKey = KeyHelper.generateSignedPreKey(identityKeyPair, i)

            signedPreKeyNode = ProtocolTreeNode("skey")
            signedPreKeyNode_idNode = ProtocolTreeNode(
                "id",
                data=ResultGetKeysIqProtocolEntity._intToBytes(
                    signedPreKey.getId()))

            signedPreKeyNode_valueNode = ProtocolTreeNode(
                "value",
                data=signedPreKey.getKeyPair().getPublicKey().getPublicKey())

            signedPreKeyNode_sigNode = ProtocolTreeNode(
                "signature", data=signedPreKey.getSignature())

            signedPreKeyNode.addChildren([
                signedPreKeyNode_idNode, signedPreKeyNode_valueNode,
                signedPreKeyNode_sigNode
            ])

            preKey = KeyHelper.generatePreKeys(i * 10, 1)[0]

            preKeyNode = ProtocolTreeNode("key")
            preKeyNode_idNode = ProtocolTreeNode(
                "id",
                data=ResultGetKeysIqProtocolEntity._intToBytes(preKey.getId()))
            preKeyNode_valNode = ProtocolTreeNode(
                "value",
                data=preKey.getKeyPair().getPublicKey().getPublicKey())
            preKeyNode.addChildren([preKeyNode_idNode, preKeyNode_valNode])

            userNode.addChildren([
                registrationNode, typeNode, identityNode, signedPreKeyNode,
                preKeyNode
            ])
コード例 #20
0
    def toProtocolTreeNode(self):
        node = super(ResultGetKeysIqProtocolEntity, self).toProtocolTreeNode()
        listNode = ProtocolTreeNode("list")
        node.addChild(listNode)

        for jid, preKeyBundle in self.preKeyBundleMap.items():
            userNode = ProtocolTreeNode("user", {"jid": jid})
            registrationNode = ProtocolTreeNode("registration", data = self.__class__._intToBytes(preKeyBundle.getRegistrationId()))
            typeNode = ProtocolTreeNode("type", data = self.__class__._intToBytes(Curve.DJB_TYPE))
            identityNode = ProtocolTreeNode("identity", data = preKeyBundle.getIdentityKey().getPublicKey().getPublicKey())

            skeyNode = ProtocolTreeNode("skey")
            skeyNode_idNode = ProtocolTreeNode("id", data=self.__class__._intToBytes(preKeyBundle.getSignedPreKeyId()))
            skeyNode_valueNode = ProtocolTreeNode("value", data=preKeyBundle.getSignedPreKey().getPublicKey())
            skeyNode_signatureNode = ProtocolTreeNode("signature", data=preKeyBundle.getSignedPreKeySignature())
            skeyNode.addChildren([skeyNode_idNode, skeyNode_valueNode, skeyNode_signatureNode])

            preKeyNode = ProtocolTreeNode("key")
            preKeyNode_idNode = ProtocolTreeNode("id", data = self.__class__._intToBytes(preKeyBundle.getPreKeyId()))
            preKeyNode_valueNode = ProtocolTreeNode("value", data= preKeyBundle.getPreKey().getPublicKey())
            preKeyNode.addChildren([preKeyNode_idNode, preKeyNode_valueNode])

            userNode.addChildren([
                registrationNode,
                typeNode,
                identityNode,
                skeyNode,
                preKeyNode
            ])
            listNode.addChild(userNode)

        return node
コード例 #21
0
    def toProtocolTreeNode(self):
        node = super(InfoGroupsResultIqProtocolEntity, self).toProtocolTreeNode()
        groupNode = ProtocolTreeNode("group", {
            "subject": self.getSubject(),
            "creation": str(self.getCreationTimestamp()),
            "creator": self.getCreatorJid(),
            "s_t": self.getSubjectTimestamp(),
            "s_o": self.getSubjectOwnerJid(),
            "id": self.getGroupId()
        })

        participants = []
        for jid, _type in self.getParticipants().items():
            pnode = ProtocolTreeNode("participant", {"jid": jid})
            if _type:
                pnode["type"] = _type
            participants.append(pnode)

        groupNode.addChildren(participants)
        node.addChild(groupNode)

        return node
コード例 #22
0
    def setUp(self):
        super(ResultIqProtocolEntityTest, self).setUp()
        self.ProtocolEntity = ResultGetKeysIqProtocolEntity
        listNode = ProtocolTreeNode("list")
        self.node.addChild(listNode)

        for i in range(0, 1):
            userNode = ProtocolTreeNode("user", {"jid": "user_%s@%s" % (i, YowConstants.WHATSAPP_SERVER)})
            listNode.addChild(userNode)
            registrationNode = ProtocolTreeNode("registration",
                                                data = ResultGetKeysIqProtocolEntity._intToBytes(
                                                    KeyHelper.generateRegistrationId()))

            typeNode = ProtocolTreeNode("type", data = ResultGetKeysIqProtocolEntity._intToBytes(Curve.DJB_TYPE))

            identityKeyPair = KeyHelper.generateIdentityKeyPair()
            identityNode = ProtocolTreeNode("identity", data=identityKeyPair.getPublicKey().getPublicKey().getPublicKey())

            signedPreKey = KeyHelper.generateSignedPreKey(identityKeyPair, i)

            signedPreKeyNode = ProtocolTreeNode("skey")
            signedPreKeyNode_idNode = ProtocolTreeNode("id",
                                                       data = ResultGetKeysIqProtocolEntity._intToBytes(
                                                           signedPreKey.getId()))

            signedPreKeyNode_valueNode = ProtocolTreeNode("value",
                                                          data = signedPreKey.getKeyPair().getPublicKey().getPublicKey())

            signedPreKeyNode_sigNode = ProtocolTreeNode("signature",
                                                        data = signedPreKey.getSignature())

            signedPreKeyNode.addChildren([signedPreKeyNode_idNode, signedPreKeyNode_valueNode, signedPreKeyNode_sigNode])

            preKey = KeyHelper.generatePreKeys(i * 10, 1)[0]

            preKeyNode = ProtocolTreeNode("key")
            preKeyNode_idNode = ProtocolTreeNode("id", data = ResultGetKeysIqProtocolEntity._intToBytes(preKey.getId()))
            preKeyNode_valNode = ProtocolTreeNode("value", data = preKey.getKeyPair().getPublicKey().getPublicKey())
            preKeyNode.addChildren([preKeyNode_idNode, preKeyNode_valNode])

            userNode.addChildren([
                registrationNode,
                typeNode,
                identityNode,
                signedPreKeyNode,
                preKeyNode
            ])