Пример #1
0
    def processKeyExchangeMessage(self, message):
        # When sending a message to someone we may end up in this function
        ourBaseKey = ratcheting_session.Curve().generateKeyPair(True)
        ourEphemeralKey = ratcheting_session.Curve().generateKeyPair(True)
        theirBaseKey = message.publicKey
        theirEphemeralKey = theirBaseKey
        theirIdentityKey = message.identityKey
        ourIdentityKey = IdentityKeyUtil().getIdentityKeyPair()

        #if self.sessionRecord.sessionState.needsRefresh: self.sessionRecord.sessionState.archiveCurrentState()
        #else:                                            self.sessionRecord.sessionState.clear()

        ratcheting_session.initializeSession(self.sessionRecord.sessionState,
                                             ourBaseKey, theirBaseKey,
                                             ourEphemeralKey,
                                             theirEphemeralKey, ourIdentityKey,
                                             theirIdentityKey)

        self.sessionRecord.sessionState.setPendingPreKey(
            message.keyId, ourBaseKey.publicKey)
        self.sessionRecord.sessionState.setLocalRegistrationId(123)
        self.sessionRecord.sessionState.setRemoteRegistrationId(
            message.registrationId)

        self.sessionRecord.save()
Пример #2
0
    def processPreKeyExchangeMessage(self, message):
        # When receiving a message from someone we end up here
        preKeyId = message.preKeyId
        theirBaseKey = message.baseKey
        theirEphemeralKey = message.message.senderEphemeral
        theirIdentityKey = message.identityKey

        print("KeyExchangeProcessor: Received pre-key with local key ID: " +
              str(preKeyId))

        #if not PreKeyRecord().hasRecord(preKeyId) and SessionRecord().hasSession(self.recipientDevice):
        #    raise "We've already processed the prekey part, letting bundled message fall through..."

        #if not PreKeyRecord().hasRecord(preKeyId):
        #    print("No such prekey:" + str(preKeyId))
        #    raise "ERROR"

        preKeyRecord = PreKeyRecord(preKeyId)
        ourBaseKey = preKeyRecord.keyPair
        ourEphemeralKey = ourBaseKey
        ourIdentityKey = IdentityKeyUtil().getIdentityKeyPair()
        #simultaneousInitiate = self.sessionRecord.getSessionState().hasPendingPreKey()

        #if not simultaneousInitiate:
        #    self.sessionRecord.clear()
        #else:
        #    self.sessionRecord.archiveCurrentState()

        ratcheting_session.initializeSession(self.sessionRecord.sessionState,
                                             ourBaseKey, theirBaseKey,
                                             ourEphemeralKey,
                                             theirEphemeralKey, ourIdentityKey,
                                             theirIdentityKey)

        self.sessionRecord.sessionState.setLocalRegistrationId(123)
        self.sessionRecord.sessionState.setRemoteRegistrationId(
            message.registrationId)

        #if simultaneousInitiate:
        #    self.sessionRecord.getSessionState().setNeedsRefresh(True)

        self.sessionRecord.save()
Пример #3
0
    def processPreKeyExchangeMessage(self, message):
        # When receiving a message from someone we end up here
        preKeyId = message.preKeyId
        theirBaseKey = message.baseKey
        theirEphemeralKey = message.message.senderEphemeral
        theirIdentityKey = message.identityKey

        print("KeyExchangeProcessor: Received pre-key with local key ID: " + str(preKeyId))

        #if not PreKeyRecord().hasRecord(preKeyId) and SessionRecord().hasSession(self.recipientDevice):
        #    raise "We've already processed the prekey part, letting bundled message fall through..."

        #if not PreKeyRecord().hasRecord(preKeyId):
        #    print("No such prekey:" + str(preKeyId))
        #    raise "ERROR"

        preKeyRecord = PreKeyRecord(preKeyId)
        ourBaseKey = preKeyRecord.keyPair
        ourEphemeralKey = ourBaseKey
        ourIdentityKey = IdentityKeyUtil().getIdentityKeyPair()
        #simultaneousInitiate = self.sessionRecord.getSessionState().hasPendingPreKey()

        #if not simultaneousInitiate:
        #    self.sessionRecord.clear()
        #else:
        #    self.sessionRecord.archiveCurrentState()

        ratcheting_session.initializeSession(self.sessionRecord.sessionState,
                                             ourBaseKey, theirBaseKey,
                                             ourEphemeralKey, theirEphemeralKey,
                                             ourIdentityKey, theirIdentityKey)

        self.sessionRecord.sessionState.setLocalRegistrationId(123)
        self.sessionRecord.sessionState.setRemoteRegistrationId(message.registrationId)

        #if simultaneousInitiate:
        #    self.sessionRecord.getSessionState().setNeedsRefresh(True)

        self.sessionRecord.save()
Пример #4
0
    def processKeyExchangeMessage(self, message):
        # When sending a message to someone we may end up in this function
        ourBaseKey = ratcheting_session.Curve().generateKeyPair(True)
        ourEphemeralKey = ratcheting_session.Curve().generateKeyPair(True)
        theirBaseKey = message.publicKey
        theirEphemeralKey = theirBaseKey
        theirIdentityKey = message.identityKey
        ourIdentityKey = IdentityKeyUtil().getIdentityKeyPair()

        #if self.sessionRecord.sessionState.needsRefresh: self.sessionRecord.sessionState.archiveCurrentState()
        #else:                                            self.sessionRecord.sessionState.clear()

        ratcheting_session.initializeSession(self.sessionRecord.sessionState,
                                     ourBaseKey, theirBaseKey,
                                     ourEphemeralKey, theirEphemeralKey,
                                     ourIdentityKey, theirIdentityKey)

        self.sessionRecord.sessionState.setPendingPreKey(message.keyId, ourBaseKey.publicKey)
        self.sessionRecord.sessionState.setLocalRegistrationId(123)
        self.sessionRecord.sessionState.setRemoteRegistrationId(message.registrationId)

        self.sessionRecord.save()