GithubHelp home page GithubHelp logo

hbruintjes / ceema Goto Github PK

View Code? Open in Web Editor NEW
20.0 4.0 4.0 183 KB

Threema protocol implementation in C++

License: Apache License 2.0

CMake 6.95% C++ 90.53% C 2.52%
protocol threema-protocol threema pidgin purple

ceema's Introduction

Ceema

This is the ceema library, which provides a C++ implementation of the Threema communication protocol (and, in the future, a C interface to it). The aim is to provide a somewhat simple interface to hook the Threema protocol in client applications such as multi-protocol IM clients.

If you are looking for a ready-to-use desktop application, consider openMittsu.

Building

Since this is CMake based, building the library consists of the following steps

git submodule init
git submodule sync
git submodule update --init --recursive
mkdir build && cd build
cmake ../
make

Dependencies

This library requires the following dependencies to be installed (both headers and libraries):

  • curl
  • jsoncpp
  • openssl
  • sodium

Library layout

Under src you will find:

  • client: Structures for dealing with clients/contact. The primary class is Client, and a utility class ContactStore
  • encoding: Some utilities for massaging data (hashing, padding, ...)
  • logging: What it says on the tin
  • protocol: Main protocol handling. Goes from packets, to messages, to payloads
  • socket: Low-level network interface
  • types: Type definitions used throughout the library

Protocol

The protocol is fairly straightforward. First, a client-server handshake is performed to set-up the encryption (using sodium/NaCl). This is handled by the Session class. Next, the client and server will communicate in (encrypted) packets as follows:

  • A (2 byte) length prefix is sent, followed by an encrypted packet
  • A packet consists of a (4 byte) type prefix, followed by an optional payload. There are roughtly 4 types of packets:
    • Session status packets, indicating start (after any pending messages have been sent), or end (server generally ends the session when the client connects using the same credentials form another source). Normally sent by the server only. The end packet contains a UTF-8 encoded string payload
    • Keep-alive/ping packets, containing an arbitrary payload that must be in the reply. Can be sent both by the server and the client
    • Messages (see below), identified by a random ID
    • Acknowledgements, sent by both the server and the client in response to receiving a message, containing the sender and ID of the message being acknowledged. Without an acknowledgement, the server will keep retrying to deliver the message.
  • Messages contain both a sender and recipient, some arbitrary message ID, a timestamp (seconds since epoch), the ID or nickname of the sender and some payload. They are prefixed by a (1 byte) type identifier, which determines the type of payload. The payload is encrypted using the keys of the sender and recipient, after adding padding according to PKCS#7. The following types of messages are known:
    • Client message:
      • Text: Payload is a UTF-8 encoded string.
      • Picture
      • Location: Payload is UTF-8 encoded string with coordinates: Two lines, separated by LF, first in decimal, then minutes
      • Video
      • Audio
      • Poll
    • User status message, either typing, or typing stopped
    • Client message-status message, can be received, seen, agree/disagree
    • Group message:
      • Create
      • Sync
      • Leave
      • Title
      • Text
      • Picture
      • Location
      • Video
      • Audio
      • Poll

Backup string

The Threema client allows for backup of the private key and client ID using a backup string. Its is a base32 encoded string consisting of a salt and the encrypted data. The salt and password generate a hash which can be used to decrypt the data, which will yield the client ID, private key, and 2 bytes of the SHA-256 hash of both which can be used to validate the decryption.

Using the Pidgin Plugin

Importing users and groups

For importing users and groups from a backup, use menu Accounts->Threema->Import from Backup

Adding users and groups manually

Adding users

Users have to be added manually via the Add Buddy menu in Pidgin.

Adding groups

When online with Pidgin while the administrator of a group creates or updates a group, this group is automatically created/updated by the plugin. However, this does not work if you are the administrator since it is not possible to be online with the same account on two devices.

A workaraound for this and in case that you want to add a group that already exists and is not updated by the administrator, you can enter the relevant data in Pidgin's configuration file blist.xml. This file is located at ~/.purple/blist.xml. The syntax for a group entry in the buddy list is the following:

<chat proto='prpl-threepl' account='MACCOUNT'>
  <alias>Alias</alias>
  <component name='id'>GROUP-ID-Hex-16digits</component>
  <component name='owner'>OACCOUNT</component>
  <setting name='name' type='string'>Group Name</setting>
  <setting name='members' type='string'>MEMBER01MEMBER02...MEMBERxx</setting>
</chat>

ceema's People

Contributors

davidfoerster avatar hbruintjes avatar ttlmax avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

ceema's Issues

threepl: Unexpect packet type: 0x209 [sic!]

Starting today I receive the error message in the title when I try to connect to my Threema account via Pidgin (v2.14.10). Pidgin then disables the account. Is that some protocol change that threepl/ceema don’t support (yet)? Note that I had to change the server configuration as per #5.

Is there some further info or logs that you need to debug the issue?

Can’t log in anymore: "Invalid output size / Invalid username, password or backup string"

Since yesterday I can’t log into Threema using Pidgin with threepl any longer. Whenever I try I get a pop-up dialogue:

threema-login-error

  • Window title: Login Error
  • Message title: Invalid output size
  • Message: Invalid username, password or backup string
  • Available buttons: close

Considering that I changed none of my log-in data recently I doubt that that’s the actual issue.

  • Pidgin and libpurple version: 2.14.10
  • ceema/threepl version: 8f2d466

Pidgin’s debug log contains nothing of relevance regarding the log-in process:

(18:25:14) account: Connecting to account XXXXXXXX.
(18:25:14) connection: Connecting. gc = 0x5611e8f83160
(18:25:14) blist: Updating buddy status for XXXXXXXX (Threema)
(18:25:14) blist: Updating buddy status for XXXXXXXX (Threema)
(18:25:14) blist: Updating buddy status for XXXXXXXX (Threema)
(18:25:14) blist: Updating buddy status for XXXXXXXX (Threema)
(18:25:14) blist: Updating buddy status for XXXXXXXX (Threema)
(18:25:14) blist: Updating buddy status for XXXXXXXX (Threema)
(18:25:14) blist: Updating buddy status for XXXXXXXX (Threema)
(18:25:14) blist: Updating buddy status for XXXXXXXX (Threema)
(18:25:14) blist: Updating buddy status for XXXXXXXX (Threema)
(18:25:14) blist: Updating buddy status for XXXXXXXX (Threema)
(18:25:14) pidgin-encryption: Using pre-existing menu icon for conv 0x5611e69a2d90, win 0x5611e89d2a20, item 0x5611e87116f0
(18:25:14) pidgin-libnotify: Conversation Updated (UNSEEN)

Any idea what might be wrong?

Problem with init plugin

First, thanks a lot for writing this plugin!

I'm trying to install it, and the build looks successful (some warnings), but in Pidgin, the "Add Account" dialogue doesn't list anything related to Threema, and the "Debug Window" shows the following upon opening "Tools" > "Plugins" (where the plugin doesn't appear either):

(17:49:13) plugins: probing /home/sabine/.purple/plugins/libceema.so
(17:49:13) plugins: /home/sabine/.purple/plugins/libceema.so is not usable because the 'purple_init_plugin' symbol could not be found.  Does the plugin call the PURPLE_INIT_PLUGIN() macro?

Looks like this refers to this definition:

extern "C" gboolean purple_init_plugin(PurplePlugin *plugin) {

Do you know what could be going on there? Thanks a lot!

OS: Fedora 32, 64-bit
Kernel: 5.7.8-200.fc32.x86_64, gcc version 10.1.1 20200507 (Red Hat 10.1.1-1)
Pidgin version: 2.13.0-18.fc32 (libpurple 2.13.0)

Log-in server (and plug-in) status

Hello, as you may have noticed, the log-in server at g-xx.0.threema.ch disappeared some time last fall. Are there any known alternatives? Or is this library (and purple/Pidgin plug-in) essentially dead without it?

openMittsu is still working, so I’m trying to figure out what's going on.

From reading its source code, it looks like xx of the hostname should be replaced with digits. However, when I try that with a couple of values I only get an error message:

Unable to decrypt HELLO packet

They all point to the same two IP addresses 185.88.236.90 and 185.88.236.110, so I doubt that the specific digits matter.

GPL compatiblity

The libpurple plugin that you've written wouldn't be license-compatible with libpurple as libpurple is GPL and ceema uses OpenSSL which has GPL-incompatible licensing terms.

Can OpenSSL be removed from the project so that it can become GPL-compatible?

libcurl during build missing

During make I get the following error:

make[2]: *** No rule to make target '<parentdir>/ceema/3rdparty/curl/lib/libcurl.so', needed by 'libceema.so.0.0.1'.  Stop.
make[1]: *** [CMakeFiles/Makefile2:118: src/CMakeFiles/ceema.dir/all] Error 2
make: *** [Makefile:136: all] Error 2

I have installed: sudo dnf install libcurl-devel libcurl
I am confused why make needs something from /3rdparty/curl since this directory or submodule does not exist in the repository.

What do I need to make this libcurl.so available?

Sorry to create an issue even though I expect that I need to change something, not ceema. I don't see another way of asking for support.

Btw: to get to this point, the following installations were necessary on Fedora 37:
sudo dnf install openssl-devel libsodium-devel curlpp-devel mbedtls-devel

Threema login information

I've compiled the pidgin plugin and could basically add a Threema account.
But how / what do I need to enter for Username / Password?

Problems with plugin for pidgin

First of all, great project and thanks for providing this.

Unfortunately I have problems running the plugin in pidgin 2.13.0. A connection is established (the connection with openMittsu is interrupted as soon as pidgin connects) but I encounter the following issues:

  • Adding a user is not possible, since the account is not shown in the drop down list for selection the threema account (on Debian 10 with Gnome)
  • Adding a user crashes pidgin (on Ubunut 18.04 LTS with Gnome) but the account is available in the drop down list
  • Sending an message to a new user (user name = threema id?) opens a chat window but any message sent just disappears without being echoed in the chat window
  • Receiving a message does not open a chat window but gives the error message: "Unsupported TLS library used by CURL"

Maybe it is just some sort of mis-configuration, is there any kind of readme or documentation?

Best, Torsten

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.