Code Monkey home page Code Monkey logo

threema-gateway-rs's Introduction

Rust SDK for Threema Gateway

GitHub CI Crates.io Version Crates.io Downloads

This is a mostly-complete implementation of an asynchronous Threema Gateway client library in Rust. For implementation status, see feature list below.

Docs

Features

Sending

  • Send simple messages
  • Send end-to-end encrypted messages

Encrypting

  • Encrypt raw bytes
  • Encrypt text messages
  • Encrypt image messages
  • Encrypt file messages
  • Encrypt delivery receipt messages

Lookup

  • Look up ID by phone number
  • Look up ID by e-mail
  • Look up ID by phone number hash
  • Look up ID by e-mail hash
  • Look up capabilities by ID
  • Look up public key by ID
  • Look up remaining credits

Receiving

  • Decode incoming request body
  • Verify MAC of incoming message
  • Decrypt incoming message
  • Decode incoming message

Files

  • Upload files
  • Download files

Usage

Take a look at the examples in the examples/ directory to see how they're implemented.

Generate a new keypair:

cargo run --example generate_keypair

Lookup public key:

cargo run --example lookup_pubkey -- <our_id> <secret> <their_id>

Send simple transport-encrypted encrypted message:

cargo run --example send_simple -- <from> id <to-id> <secret> <text>...
cargo run --example send_simple -- <from> email <to-email> <secret> <text>...
cargo run --example send_simple -- <from> phone <to-phone> <secret> <text>...

Send e2e encrypted message:

cargo run --example send_e2e_text -- <from> <to> <secret> <private-key> <text>...

Look up Threema ID by phone:

cargo run --example lookup_id -- by_phone <from> <secret> 41791234567

Look up Threema ID by email hash:

cargo run --example lookup_id -- by_email_hash <from> <secret> 1ea093239cc5f0e1b6ec81b866265b921f26dc4033025410063309f4d1a8ee2c

Decode and decrypt an incoming message payload:

cargo run --example receive -- <our-id> <secret> <private-key> <request-body>

Download a blob:

cargo run --example download_blob -- <our-id> <secret> <private-key> <blob-id>

Cargo Features

This library offers the following optional features:

  • receive: Add support for processing incoming messages. Enabled by default.

Rust Version Requirements (MSRV)

This library generally tracks the latest stable Rust version but tries to guarantee backwards compatibility with older stable versions as much as possible. However, in many cases transitive dependencies make guaranteeing a minimal supported Rust version impossible (see this discussion).

TLS

This library uses rustls with native (system-provided) root certificates to establish a TLS connection.

License

Licensed under either of

Contributing

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

threema-gateway-rs's People

Contributors

dbrgn avatar shorty1o1 avatar threema-danilo avatar threema-donat avatar

Stargazers

 avatar  avatar  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

threema-gateway-rs's Issues

Support noDeliveryReceipts key

The send_e2e now supports the optional noDeliveryReceipts parameter. If set to 1, the recipient is requested not to send automated delivery receipts for this message. Older app versions may ignore this flag.

Api object

It would probably make sense to put the API secret and โ€“ in the case of e2e messages โ€“ the private key into a Api object or similar. Then we don't have to pass these values as naked &strs to the sending / decrypting functions.

Async API

Having an async API would be nice.

GatewayError: Do not include endpoint URL

URLs could contain API secrets, so they should not be written to a log.

Steps to reproduce: Validate credentials with an invalid endpoint URL. This will result in a timeout, with the URL contained in the error message. Instead, only include the hostname.

Upgrade reqwest

To 0.11.

Note: Potentially make the TLS features configurable.

More type safety

It shouldn't be possible to mix up public and private key, for example.

Fix mime_guess deprecations

warning: use of deprecated item 'mime_guess::guess_mime_type': Use `from_path(path).first_or_octet_stream()` instead
 --> examples/send_e2e_file.rs:8:5
  |
8 | use mime_guess::guess_mime_type;
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: `#[warn(deprecated)]` on by default

warning: use of deprecated item 'mime_guess::guess_mime_type': Use `from_path(path).first_or_octet_stream()` instead
  --> examples/send_e2e_file.rs:95:21
   |
95 |     let mime_type = guess_mime_type(&filepath);
   |                     ^^^^^^^^^^^^^^^

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.