Threema is an end-to-end encrypted messenger with support for Android, iOS and desktop. Historically, these three code bases have grown independently of each other. Combined with an increasingly complex protocol, this led to various problems, including hard-to-catch bugs, incompatibilities and slower development.
By developing our own library, we laid the foundation for addressing these problems. In this talk, we’ll show how we model protocol flows as state machines - a decision that yields several benefits, such as easier testing of edge cases, avoiding asynchronous code across FFI boundaries, and enabling the use of native TCP, TLS and WebSocket implementations.