Example #1
0
def getEncryptedMessage(recipient, plaintext):
    session = session_record.SessionRecord(recipient)
    # TODO also check hasSession
    if not session.hasSession(
    ) or session.sessionState.sessionStructure.needsRefresh:

        preKeyList = serverapi.getRecipientsPreKeyList(recipient)

        for preKey in preKeyList.keys:
            #device = PushAddress.create(recipient. number, preKey.deviceid)
            processor = receive_textsecure.KeyExchangeProcessor(recipient)

            # TODO check if the identity key is trusted
            #if processor.isTrusted(preKey):
            processor.processKeyExchangeMessage(preKey)

    cipher = session_cipher.SessionCipher(recipient)
    message = cipher.encrypt(plaintext)
    remoteRegistrationId = cipher.getRemoteRegistrationId()

    PREKEY_TYPE = 3
    WHISPER_TYPE = 2
    IncomingPushMessageSignal = IncomingPushMessageSignal_pb2.IncomingPushMessageSignal(
    )

    if message.type == PREKEY_TYPE:
        return PushBody(IncomingPushMessageSignal.PREKEY_BUNDLE,
                        remoteRegistrationId, message.serialized)
    elif message.type == WHISPER_TYPE:
        return PushBody(IncomingPushMessageSignal.CIPHERTEXT,
                        remoteRegistrationId, message.serialized)
    else:
        raise "Unknown ciphertext type" + str(message.type)
def getEncryptedMessage(recipient, plaintext):
    session = session_record.SessionRecord(recipient)
    # TODO also check hasSession
    if not session.hasSession() or session.sessionState.sessionStructure.needsRefresh:

        preKeyList = serverapi.getRecipientsPreKeyList(recipient)

        for preKey in preKeyList.keys:
            # device = PushAddress.create(recipient. number, preKey.deviceid)
            processor = receive_textsecure.KeyExchangeProcessor(recipient)

            # TODO check if the identity key is trusted
            # if processor.isTrusted(preKey):
            processor.processKeyExchangeMessage(preKey)

    cipher = session_cipher.SessionCipher(recipient)
    message = cipher.encrypt(plaintext)
    remoteRegistrationId = cipher.getRemoteRegistrationId()

    PREKEY_TYPE = 3
    WHISPER_TYPE = 2
    IncomingPushMessageSignal = IncomingPushMessageSignal_pb2.IncomingPushMessageSignal()

    if message.type == PREKEY_TYPE:
        return PushBody(IncomingPushMessageSignal.PREKEY_BUNDLE, remoteRegistrationId, message.serialized)
    elif message.type == WHISPER_TYPE:
        return PushBody(IncomingPushMessageSignal.CIPHERTEXT, remoteRegistrationId, message.serialized)
    else:
        raise "Unknown ciphertext type" + str(message.type)
Example #3
0
    def on_add_button_clicked(self, widget):
        #When Subscribe button is clicked

        phone_entry = self.phone_entry.get_text()
        alias = self.alias_entry.get_text()

        try:
            preKeyList = serverapi.getRecipientsPreKeyList(phone_entry)

        except serverapi.ServerError as e:
            ErrorDialog('Error', str(e))
            return

        phoneNumber = phone_entry
        identityKey = preKeyList.keys[0].identityKey.publicKey
        alias = alias

        import keyutils
        keyutils.RecipientUtil().saveRecipient(phoneNumber, identityKey, alias)

        self.window.destroy()
Example #4
0
    def on_add_button_clicked(self, widget):
        #When Subscribe button is clicked

        phone_entry = self.phone_entry.get_text()
        alias = self.alias_entry.get_text()

        try:
            preKeyList = serverapi.getRecipientsPreKeyList(phone_entry)

        except serverapi.ServerError as e:
            ErrorDialog('Error', str(e))
            return

        phoneNumber = phone_entry
        identityKey = preKeyList.keys[0].identityKey.publicKey
        alias = alias

        import keyutils
        keyutils.RecipientUtil().saveRecipient(phoneNumber, identityKey, alias)

        self.window.destroy()