[OTR-dev] Sending encrypted messages

Pierre Lebreton dev.amonchakai at gmail.com
Sun Jun 28 10:28:39 EDT 2015


Hello,

I have been working on integrating OTR to my XMPP client for BlackBerry 10.

I managed to get many things work, but I still have some trouble to send
encrypted messages. So I was wondering if someone could help me to locate
what I am missing.

What I am able to do is to:
- initiate the OTR protocol, and got up to the point where "gone_secure" is
called, and I have the fingerprint of the recipient.
- If the other client (Adium) is sending me encrypted messages, I am able
to decrypt them.

But when I try to send messages, "otrl_message_sending" replace my message
by a new OTR request:

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

"?OTRv2?

<b>amonchakai2 at jabber.de</b> has requested an <a href="
https://otr.cypherpunks.ca/">Off-the-Record private conversation</a>.
However, you do not have a plugin to support that.

See <a href="https://otr.cypherpunks.ca/">https://otr.cypherpunks.ca/</a>
for more information."

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

And if I send that, I can see the exchange of keys, and back to square 1.
And if I try to send again my message, otrl_message_sending keep replacing
my message by the initialization request.


For the moment my functions
- myotr_new_fingerprint
- myotr_write_fingerprint
- myotr_gone_secure

Do nothing, and I was wondering if somehow I need to accept fingerprint? In
some example I saw on the web such as there:
https://github.com/monkeyiq/otr/blob/master/main.cpp

They just stop the conversation if the fingerprint is not accepted, so I
assumed that, for now, I did not have to do something particular.

Do I need to do something in particular to acknowledge that the connection
is established, so it can start encrypting when sending messages?


Thanks

Best,
Pierre






I will avoid to put all the code, to make this email readable.

Basically I defined these functions:


//
=====================================================================================================

static OtrlMessageAppOps ui_ops = {
    myotr_policy,
    NULL,
    NULL,
    myotr_inject_message,
    NULL,
    myotr_new_fingerprint,
    myotr_write_fingerprint,
    myotr_gone_secure,
    myotr_gone_insecure,
    NULL,
    NULL,
    NULL,
    NULL,
    NULL,
    NULL,
    NULL,
    NULL,
    NULL
};



the policy is:


static OtrlPolicy myotr_policy(void *opdata, ConnContext *context)
{
    return OTRL_POLICY_ALLOW_V2
        | OTRL_POLICY_REQUIRE_ENCRYPTION;
}


//
=====================================================================================================


void message_received(const QString& ourAccount, const QString& account,
const QString& protocol, const QString& message) {
    uint32_t ignore = 0;
    char *new_message = NULL;
    OtrlTLV *tlvs = NULL;


    ignore = otrl_message_receiving(us, &ui_ops, NULL,
ourAccount.toAscii(), protocol.toAscii(), account.toAscii(),
message.toAscii(), &new_message, &tlvs, NULL, NULL, NULL);

    // if ignore == 1, then it is a core message from OTR. We don't want to
display that.
    if(ignore == 0) {

        if (new_message) {
          QString ourm(new_message);
          otrl_message_free(new_message);

          qDebug() << "encrypted message: " <<  ourm;
        } else {

          qDebug() << "message not encrypted: " <<  message;
        }
    }

    if(tlvs) {
        qDebug() << "there are side info!";
        otrl_tlv_free(tlvs);
    }
}


void send_message (const QString& ourAccount, const QString& account, const
QString& protocol, const QString& message) {
    char *new_message = NULL;
    gcry_error_t err;

    err = otrl_message_sending(us, &ui_ops, NULL, ourAccount.toAscii(),
protocol.toAscii(), account.toAscii(), OTRL_INSTAG_BEST, message.toAscii(),
NULL, &new_message,
            OTRL_FRAGMENT_SEND_SKIP, NULL, NULL, NULL);

    qDebug() << "error code: " << err;

    if (new_message) {
        QString ourm(new_message);
        otrl_message_free(new_message);
        qDebug() << "encrypted message: " <<  ourm;

        XMPP::get()->sendXMPPMessageTo(account, ourm);
    }

    if (err) {
        qDebug() << "plouf!";
    }
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cypherpunks.ca/pipermail/otr-dev/attachments/20150628/1d4fec2f/attachment.html>


More information about the OTR-dev mailing list