Rust extension providing Python bindings to the signal protocol
Project description
signal-protocol
Experimental Python bindings to libsignal-client
Rust signal protocol implementation. This project provides a Rust extension using PyO3 to define a signal_protocol
Python module. See here for a fundamental limitation storing secrets in Python-allocated memory. ⚠️USE AT YOUR OWN RISK!⚠️
Usage
Initial setup
from signal_protocol import curve, identity_key, state, storage
# Each client must generate a long-term identity key pair.
# This should be stored somewhere safe and persistent.
identity_key_pair = identity_key.IdentityKeyPair.generate()
# Clients must generate prekeys. The example here is generating a
# single prekey, but clients will generate many as they are one-time use
# and consumed when a message from a new chat participant is sent. See issue #7.
pre_key_pair = curve.KeyPair.generate()
# Clients must generate a registration_id and store it somewhere safe and persistent.
registration_id = 12 # TODO generate (not yet supported in upstream crate)
# The InMemSignalProtocolStore is a single object which provide the four storage
# interfaces required: IdentityKeyStore (for one's own identity key state and the (public)
# identity keys for other chat participants), PreKeyStore (for one's own prekey state),
# SignedPreKeyStore (for one's own signed prekeys), and SessionStore (for established sessions
# with chat participants).
store = storage.InMemSignalProtocolStore(identity_key_pair, registration_id)
# Clients should also generate a signed prekey.
signed_pre_key_pair = curve.KeyPair.generate()
serialized_signed_pre_pub_key = signed_pre_key_pair.public_key().serialize()
signed_pre_key_signature = store.get_identity_key_pair().private_key().calculate_signature(serialized_signed_pre_pub_key)
# Clients should store their prekeys (both one-time and signed) in the protocol store
# along with IDs that can be used to retrieve them later.
pre_key_id = 10
pre_key_record = state.PreKeyRecord(pre_key_id, pre_key_pair)
store.save_pre_key(pre_key_id, pre_key_record)
signed_pre_key_id = 33
signed_prekey = state.SignedPreKeyRecord(
signed_pre_key_id,
42, # This is a timestamp since this key should be periodically rotated
signed_pre_key_pair,
signed_pre_key_signature,
)
store.save_signed_pre_key(signed_pre_key_id, signed_prekey)
Sending a message to a new participant
from signal_protocol import session, session_cipher
# To create a session, you must fetch a prekey bundle for the recipient from the server
# Here the prekey bundle is `recipient_bundle` for participant `recipient_address`
session.process_prekey_bundle(
recipient_address,
store,
recipient_bundle,
)
# Once the prekey bundle is processed (storing data from the recipient in your local
# protocol store), you can encrypt messages
ciphertext = session_cipher.message_encrypt(store, recipient_address, "hello")
Developer Getting Started
You will need both Rust and Python 3.7+ installed on your system. To install the project in your virtualenv:
pip install -r requirements.txt
python setup.py develop # This will call out to rustc
Then run the tests via pytest -v tests/
to confirm all is working. Tests are ported to Python from the upstream crate. You can use the tests as a reference for how to use the library.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
File details
Details for the file signal-protocol-0.2.1.tar.gz
.
File metadata
- Download URL: signal-protocol-0.2.1.tar.gz
- Upload date:
- Size: 13.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.53.0 CPython/3.7.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4757ff05ca9219323b8abdbbda006468c27906e6cb83691b92be29fb3c95ecf7 |
|
MD5 | f536b76df5ca26f9b9096a5dc59761e4 |
|
BLAKE2b-256 | 153f966089f66098c576f4dec0094898288581f45def0bf7374589ec47d4c9c4 |
File details
Details for the file signal_protocol-0.2.1-cp37-cp37m-manylinux2014_x86_64.whl
.
File metadata
- Download URL: signal_protocol-0.2.1-cp37-cp37m-manylinux2014_x86_64.whl
- Upload date:
- Size: 5.4 MB
- Tags: CPython 3.7m
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.53.0 CPython/3.7.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 39b1805b61677352d75af9e35d6a197a30721fd48bb68df676f86f2d60e8fdaf |
|
MD5 | 58523c3ddc7bed295237dd05fef61708 |
|
BLAKE2b-256 | c1a3dbbb86786e306417e5cf0fb2fa73117ba880b892676e1b9c358fe4c31324 |
File details
Details for the file signal_protocol-0.2.1-cp37-cp37m-macosx_10_14_x86_64.whl
.
File metadata
- Download URL: signal_protocol-0.2.1-cp37-cp37m-macosx_10_14_x86_64.whl
- Upload date:
- Size: 1.3 MB
- Tags: CPython 3.7m, macOS 10.14+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.53.0 CPython/3.7.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6a2e58b5d6912fbaa3491287ce080f43360d1860bd6a968da6cecb780d4580d5 |
|
MD5 | 354e697fb85e317f7549f7ea15550eef |
|
BLAKE2b-256 | 9c913f6323ab63f913c64f9846d49bbeb2d328435741c2de2138441bfb796606 |
File details
Details for the file signal_protocol-0.2.1-cp36-cp36m-manylinux2014_x86_64.whl
.
File metadata
- Download URL: signal_protocol-0.2.1-cp36-cp36m-manylinux2014_x86_64.whl
- Upload date:
- Size: 4.1 MB
- Tags: CPython 3.6m
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.53.0 CPython/3.7.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3e7f3914480d52d0c63621ddf924281412b91f43bd8c3478b5eb99b12f894d94 |
|
MD5 | b425bdc380c9515333469048a05c978e |
|
BLAKE2b-256 | 69636679bbd8b0f94d98360688bbe6d52b0d8369580422d294e37a4e8390a687 |
File details
Details for the file signal_protocol-0.2.1-cp35-cp35m-manylinux2014_x86_64.whl
.
File metadata
- Download URL: signal_protocol-0.2.1-cp35-cp35m-manylinux2014_x86_64.whl
- Upload date:
- Size: 2.7 MB
- Tags: CPython 3.5m
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.53.0 CPython/3.7.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8ada0d8fda9571493d4c5a013b9e9886c1732c71e0fea52b727547c109e55a8e |
|
MD5 | 780dfa947fcb4b4eb9ef92325e30fc47 |
|
BLAKE2b-256 | 60c2c4c87be1a940faff0badf84467b1a368d89521391029a2fae692214d96fe |