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
            ])
Beispiel #2
0
    def sendKeys(self, fresh=True, countPreKeys=_COUNT_PREKEYS):
        identityKeyPair = KeyHelper.generateIdentityKeyPair(
        ) if fresh else self.store.getIdentityKeyPair()
        registrationId = KeyHelper.generateRegistrationId(
        ) if fresh else self.store.getLocalRegistrationId()
        preKeys = KeyHelper.generatePreKeys(KeyHelper.getRandomSequence(),
                                            countPreKeys)
        signedPreKey = KeyHelper.generateSignedPreKey(
            identityKeyPair, KeyHelper.getRandomSequence(65536))
        preKeysDict = {}
        for preKey in preKeys:
            keyPair = preKey.getKeyPair()
            preKeysDict[self.adjustId(preKey.getId())] = self.adjustArray(
                keyPair.getPublicKey().serialize()[1:])

        signedKeyTuple = (
            self.adjustId(signedPreKey.getId()),
            self.adjustArray(
                signedPreKey.getKeyPair().getPublicKey().serialize()[1:]),
            self.adjustArray(signedPreKey.getSignature()))

        setKeysIq = SetKeysIqProtocolEntity(
            self.adjustArray(identityKeyPair.getPublicKey().serialize()[1:]),
            signedKeyTuple, preKeysDict, Curve.DJB_TYPE,
            self.adjustId(registrationId))

        onResult = lambda _, __: self.persistKeys(
            registrationId, identityKeyPair, preKeys, signedPreKey, fresh)
        self._sendIq(setKeysIq, onResult, self.onSentKeysError)
Beispiel #3
0
    def _generate_axolotl_keys(self):
        identityKeyPair = KeyHelper.generateIdentityKeyPair()
        registrationId = KeyHelper.generateRegistrationId()
        preKeys = KeyHelper.generatePreKeys(KeyHelper.getRandomSequence(),
                                            DEFAULT_PREKEY_AMOUNT)
        self.storeLocalData(registrationId, identityKeyPair)

        for preKey in preKeys:
            self.storePreKey(preKey.getId(), preKey)
Beispiel #4
0
    def _generate_axolotl_keys(self):
        identityKeyPair = KeyHelper.generateIdentityKeyPair()
        registrationId = KeyHelper.generateRegistrationId()
        preKeys = KeyHelper.generatePreKeys(KeyHelper.getRandomSequence(),
                                            DEFAULT_PREKEY_AMOUNT)
        self.storeLocalData(registrationId, identityKeyPair)

        for preKey in preKeys:
            self.storePreKey(preKey.getId(), preKey)
Beispiel #5
0
    def init_store(self):
        """Create new identity key pair and initialize database"""
        logger.info('Creating new identity...')
        identityKeyPair = KeyHelper.generateIdentityKeyPair()
        registrationId = KeyHelper.generateRegistrationId()
        preKeys = KeyHelper.generatePreKeys(KeyHelper.getRandomSequence(), self.COUNT_PREKEYS)
        signedPreKey = KeyHelper.generateSignedPreKey(identityKeyPair,
                                                      KeyHelper.getRandomSequence(65536))

        self.store.storeLocalData(registrationId, identityKeyPair)
        self.store.storeSignedPreKey(signedPreKey.getId(), signedPreKey)

        for preKey in preKeys:
            self.store.storePreKey(preKey.getId(), preKey)
    def __init__(self, dbConn):
        """
        :type dbConn: Connection
        """
        self.dbConn = dbConn
        dbConn.execute("CREATE TABLE IF NOT EXISTS identities (_id INTEGER PRIMARY KEY AUTOINCREMENT,"
                       "recipient_id INTEGER UNIQUE,"
                       "registration_id INTEGER, public_key BLOB, private_key BLOB,"
                       "next_prekey_id INTEGER, timestamp INTEGER);")

        if self.getLocalRegistrationId() is None or self.getIdentityKeyPair() is None:
            identity = KeyHelper.generateIdentityKeyPair()
            registration_id = KeyHelper.generateRegistrationId(True)
            self._storeLocalData(registration_id, identity)
    def _generate_axolotl_keys(self):
        identity_key_pair = KeyHelper.generateIdentityKeyPair()
        registration_id = KeyHelper.getRandomSequence(2147483647)
        pre_keys = KeyHelper.generatePreKeys(
            KeyHelper.getRandomSequence(4294967296), DEFAULT_PREKEY_AMOUNT)
        self.storeLocalData(registration_id, identity_key_pair)

        signed_pre_key = KeyHelper.generateSignedPreKey(
            identity_key_pair, KeyHelper.getRandomSequence(65536))

        self.storeSignedPreKey(signed_pre_key.getId(), signed_pre_key)

        for pre_key in pre_keys:
            self.storePreKey(pre_key.getId(), pre_key)
Beispiel #8
0
    def init_store(self):
        """Create new identity key pair and initialize database"""
        logger.info('Creating new identity...')
        identityKeyPair = KeyHelper.generateIdentityKeyPair()
        registrationId = KeyHelper.generateRegistrationId()
        preKeys = KeyHelper.generatePreKeys(KeyHelper.getRandomSequence(),
                                            self.COUNT_PREKEYS)
        signedPreKey = KeyHelper.generateSignedPreKey(
            identityKeyPair, KeyHelper.getRandomSequence(65536))

        self.store.storeLocalData(registrationId, identityKeyPair)
        self.store.storeSignedPreKey(signedPreKey.getId(), signedPreKey)

        for preKey in preKeys:
            self.store.storePreKey(preKey.getId(), preKey)
    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
            ])
Beispiel #10
0
    def sendKeys(self, fresh = True, countPreKeys = _COUNT_PREKEYS):
        identityKeyPair     = KeyHelper.generateIdentityKeyPair() if fresh else self.store.getIdentityKeyPair()
        registrationId      = KeyHelper.generateRegistrationId() if fresh else self.store.getLocalRegistrationId()
        preKeys             = KeyHelper.generatePreKeys(KeyHelper.getRandomSequence(), countPreKeys)
        signedPreKey        = KeyHelper.generateSignedPreKey(identityKeyPair, KeyHelper.getRandomSequence(65536))
        preKeysDict = {}
        for preKey in preKeys:
            keyPair = preKey.getKeyPair()
            preKeysDict[self.adjustId(preKey.getId())] = self.adjustArray(keyPair.getPublicKey().serialize()[1:])

        signedKeyTuple = (self.adjustId(signedPreKey.getId()),
                          self.adjustArray(signedPreKey.getKeyPair().getPublicKey().serialize()[1:]),
                          self.adjustArray(signedPreKey.getSignature()))

        setKeysIq = SetKeysIqProtocolEntity(self.adjustArray(identityKeyPair.getPublicKey().serialize()[1:]), signedKeyTuple, preKeysDict, Curve.DJB_TYPE, self.adjustId(registrationId))

        onResult = lambda _, __: self.persistKeys(registrationId, identityKeyPair, preKeys, signedPreKey, fresh)
        self._sendIq(setKeysIq, onResult, self.onSentKeysError)
Beispiel #11
0
 def test_gensig(self):
     identityKeyPair = KeyHelper.generateIdentityKeyPair()
     KeyHelper.generateSignedPreKey(identityKeyPair, 0)