Example #1
0
def create_ephemeral_channel(msg_id: bytes, ttl: int, ttr: int,
                             addr_from: bytes, kyber_pk: bytes,
                             kyber_sk: bytes, receiver_kyber_pk: bytes,
                             dilithium_pk: bytes, dilithium_sk: bytes,
                             prf512_seed: bytes, data: bytes, nonce: int):
    sender_kyber = Kyber(kyber_pk, kyber_sk)
    sender_kyber.kem_encode(receiver_kyber_pk)
    enc_aes256_symkey = bytes(sender_kyber.getCypherText())
    aes256_symkey = sender_kyber.getMyKey()
    aes = AES(bytes(aes256_symkey))
    sender_dilithium = Dilithium(dilithium_pk, dilithium_sk)

    ephemeral_data = EphemeralChannelPayload.create(addr_from, prf512_seed,
                                                    data)

    ephemeral_data.dilithium_sign(msg_id, ttl, ttr, enc_aes256_symkey, nonce,
                                  sender_dilithium)

    encrypted_ephemeral_message = EncryptedEphemeralMessage()

    encrypted_ephemeral_message._data.msg_id = msg_id
    encrypted_ephemeral_message._data.ttl = ttl
    encrypted_ephemeral_message._data.ttr = ttr
    encrypted_ephemeral_message._data.channel.enc_aes256_symkey = enc_aes256_symkey
    encrypted_ephemeral_message._data.nonce = nonce
    encrypted_ephemeral_message._data.payload = aes.encrypt(
        ephemeral_data.to_json().encode())

    return encrypted_ephemeral_message
Example #2
0
    def handle_ephemeral(self, source, message: qrllegacy_pb2.LegacyMessage):
        """
        Receives Ephemeral Message
        :param source:
        :param message:
        :return:
        """
        try:
            encrypted_ephemeral = EncryptedEphemeralMessage(message.ephData)
        except Exception as e:
            logger.error(
                'ephemeral_message rejected - unable to decode serialised data - closing connection'
            )
            logger.exception(e)
            source.loseConnection()
            return

        if not source.factory.master_mr.isRequested(
                encrypted_ephemeral.get_message_hash(), self):
            return

        if not encrypted_ephemeral.validate():
            return

        source.factory.broadcast_ephemeral_message(
            encrypted_ephemeral)  # FIXME(cyyber) : Fix broken link
Example #3
0
def create_ephemeral_message(ttl: int,
                             ttr: int,
                             addr_from: bytes,
                             kyber_pk: bytes,
                             kyber_sk: bytes,
                             receiver_kyber_pk: bytes,
                             prf512_seed: bytes,
                             seq: int,
                             data: bytes,
                             nonce: int):
    sender_kyber = Kyber(kyber_pk, kyber_sk)
    sender_kyber.kem_encode(receiver_kyber_pk)

    aes256_symkey = sender_kyber.getMyKey()
    aes = AES(aes256_symkey)

    ephemeral_data = EphemeralMessagePayload.create(addr_from, data)

    encrypted_ephemeral_message = EncryptedEphemeralMessage()

    encrypted_ephemeral_message._data.msg_id = RNG.generate(prf512_seed, seq)
    encrypted_ephemeral_message._data.ttl = ttl
    encrypted_ephemeral_message._data.ttr = ttr
    encrypted_ephemeral_message._data.nonce = nonce
    encrypted_ephemeral_message._data.payload = aes.encrypt(ephemeral_data.to_json())

    return encrypted_ephemeral_message
Example #4
0
    def add(self, encrypted_ephemeral):
        self.update()
        target_hash = encrypted_ephemeral.get_message_hash()

        for raw_encrypted_ephemeral in self.encrypted_ephemeral_message_list:
            if EncryptedEphemeralMessage(raw_encrypted_ephemeral).get_message_hash() == target_hash:
                return
        self._data.encrypted_ephemeral_message_list.extend([encrypted_ephemeral.pbdata])
Example #5
0
    def PushEphemeralMessage(self, request: qrl_pb2.PushEphemeralMessageReq,
                             context) -> qrl_pb2.PushTransactionResp:
        logger.debug("[PublicAPI] PushEphemeralMessageReq")
        submitted = False

        if config.user.accept_ephemeral:
            encrypted_ephemeral_message = EncryptedEphemeralMessage(
                request.ephemeral_message)
            submitted = self.qrlnode.broadcast_ephemeral_message(
                encrypted_ephemeral_message)

        answer = qrl_pb2.PushTransactionResp()
        answer.some_response = str(submitted)
        return answer
Example #6
0
    def PushEphemeralMessage(self, request: qrl_pb2.PushEphemeralMessageReq,
                             context) -> qrl_pb2.PushTransactionResp:
        logger.debug("[PublicAPI] PushEphemeralMessageReq")
        submitted = False

        if config.user.accept_ephemeral:
            encrypted_ephemeral_message = EncryptedEphemeralMessage(
                request.ephemeral_message)
            submitted = self.qrlnode.broadcast_ephemeral_message(
                encrypted_ephemeral_message)

        answer = qrl_pb2.PushTransactionResp()
        answer.error_code = qrl_pb2.PushTransactionResp.ERROR
        if submitted:
            answer.error_code = qrl_pb2.PushTransactionResp.SUBMITTED

        return answer