python CFFI bindings for the olm cryptographic ratchet library
Project description
python-olm
Python bindings for Olm.
The specification of the Olm cryptographic ratchet which is used for peer to peer sessions of this library can be found here.
The specification of the Megolm cryptographic ratchet which is used for group sessions of this library can be found here.
An example of the implementation of the Olm and Megolm cryptographic protocol can be found in the Matrix protocol for which the implementation guide can be found here.
The full API reference can be found here.
Installation instructions
To install from the source package, you will need:
- cmake (recommended) or GNU make
- a C/C++ compiler
You can then run pip install python-olm
.
This should work in UNIX-like environments, including macOS, and may work in other environments too, but is known to not work yet in Windows.
Accounts
Accounts create and hold the central identity of the Olm protocol, they consist of a fingerprint and identity key pair. They also produce one time keys that are used to start peer to peer encrypted communication channels.
Account Creation
A new account is created with the Account class, it creates a new Olm key pair. The public parts of the key pair are available using the identity_keys property of the class.
>>> alice = Account()
>>> alice.identity_keys
{'curve25519': '2PytGagXercwHjzQETLcMa3JOsaU2qkPIESaqoi59zE',
'ed25519': 'HHpOuFYdHwoa54GxSttz9YmaTmbuVU3js92UTUjYJgM'}
One Time keys
One time keys need to be generated before people can start an encrypted peer to peer channel to an account.
>>> alice.generate_one_time_keys(1)
>>> alice.one_time_keys
{'curve25519': {'AAAAAQ': 'KiHoW6CIy905UC4V1Frmwr3VW8bTWkBL4uWtWFFllxM'}}
After the one time keys are published they should be marked as such so they aren't reused.
>>> alice.mark_keys_as_published()
>>> alice.one_time_keys
{'curve25519': {}}
Pickling
Accounts should be stored for later reuse, storing an account is done with the pickle method while the restoring step is done with the from_pickle class method.
>>> pickle = alice.pickle()
>>> restored = Account.from_pickle(pickle)
Sessions
Sessions are used to create an encrypted peer to peer communication channel between two accounts.
Session Creation
>>> alice = Account()
>>> bob = Account()
>>> bob.generate_one_time_keys(1)
>>> id_key = bob.identity_keys["curve25519"]
>>> one_time = list(bob.one_time_keys["curve25519"].values())[0]
>>> alice_session = OutboundSession(alice, id_key, one_time)
Encryption
After an outbound session is created an encrypted message can be exchanged:
>>> message = alice_session.encrypt("It's a secret to everybody")
>>> message.ciphertext
'AwogkL7RoakT9gnjcZMra+y39WXKRmnxBPEaEp6OSueIA0cSIJxGpBoP8YZ+CGweXQ10LujbXMgK88
xG/JZMQJ5ulK9ZGiC8TYrezNYr3qyIBLlecXr/9wnegvJaSFDmWDVOcf4XfyI/AwogqIZfAklRXGC5b
ZJcZxVxQGgJ8Dz4OQII8k0Dp8msUXwQACIQvagY1dO55Qvnk5PZ2GF+wdKnvj6Zxl2g'
>>> message.message_type
0
After the message is transfered, bob can create an InboundSession to decrypt the message.
>>> bob_session = InboundSession(bob, message)
>>> bob_session.decrypt(message)
"It's a secret to everybody"
Pickling
Sessions like accounts can be stored for later use the API is the same as for accounts.
>>> pickle = session.pickle()
>>> restored = Session.from_pickle(pickle)
Group Sessions
Group Sessions are used to create a one-to-many encrypted communication channel. The group session key needs to be shared with all participants that should be able to decrypt the group messages. Another thing to notice is that, since the group session key is ratcheted every time a message is encrypted, the session key should be shared before any messages are encrypted.
Group Session Creation
Group sessions aren't bound to an account like peer-to-peer sessions so their creation is straightforward.
>>> alice_group = OutboundGroupSession()
>>> bob_inbound_group = InboundGroupSession(alice_group.session_key)
Group Encryption
Group encryption is pretty simple. The important part is to share the session key with all participants over a secure channel (e.g. peer-to-peer Olm sessions).
>>> message = alice_group.encrypt("It's a secret to everybody")
>>> bob_inbound_group.decrypt(message)
("It's a secret to everybody", 0)
Pickling
Pickling works the same way as for peer-to-peer Olm sessions.
>>> pickle = session.pickle()
>>> restored = InboundGroupSession.from_pickle(pickle)
Project details
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 python-olm-3.2.16.tar.gz
.
File metadata
- Download URL: python-olm-3.2.16.tar.gz
- Upload date:
- Size: 2.7 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a1c47fce2505b7a16841e17694cbed4ed484519646ede96ee9e89545a49643c9 |
|
MD5 | 07380893f6111ddd14c3fa08de80d248 |
|
BLAKE2b-256 | b8eb23ca73cbdc8c7466a774e515dfd917d9fbe747c1257059246fdc63093f04 |
File details
Details for the file python_olm-3.2.16-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: python_olm-3.2.16-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 301.0 kB
- Tags: CPython 3.12, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 45e76b3f5060a5cf8451140d6c7e3b438f972ff432b6f39d0ca2c7f2296509bb |
|
MD5 | dd97da430ff2b8d7ab04d6f89b987b5d |
|
BLAKE2b-256 | 39ee1e15304ac67d3a7ebecbcac417d6479abb7186aad73c6a035647938eaa8e |
File details
Details for the file python_olm-3.2.16-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
.
File metadata
- Download URL: python_olm-3.2.16-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 293.7 kB
- Tags: CPython 3.12, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 16bbb209d43d62135450696526ed0a811150e9de9df32ed91542bf9434e79030 |
|
MD5 | d041987ba1af1a3f0fd82081580defd5 |
|
BLAKE2b-256 | 6b56652349f97dc2ce6d1aed43481d179c775f565e68796517836406fb7794c7 |
File details
Details for the file python_olm-3.2.16-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
.
File metadata
- Download URL: python_olm-3.2.16-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
- Upload date:
- Size: 297.0 kB
- Tags: CPython 3.12, manylinux: glibc 2.17+ i686, manylinux: glibc 2.5+ i686
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 10a5e68a2f4b5a2bfa5fdb5dbfa22396a551730df6c4a572235acaa96e997d3f |
|
MD5 | 79dff936649fe63edd9b4667d0c05e67 |
|
BLAKE2b-256 | 7993f6729f10149305262194774d6c8b438c0b084740cf239f48ab97b4df02fa |
File details
Details for the file python_olm-3.2.16-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: python_olm-3.2.16-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 300.8 kB
- Tags: CPython 3.11, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d41ce8cf04bfe0986c802986d04d2808fbb0f8ddd7a5a53c1f2eef7a9db76ae1 |
|
MD5 | 6d8af697424d3b3bc548ee1e292925f0 |
|
BLAKE2b-256 | a850da98e66dee3f0384fa0d350aa3e60865f8febf86e14dae391f89b626c4b7 |
File details
Details for the file python_olm-3.2.16-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
.
File metadata
- Download URL: python_olm-3.2.16-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 293.0 kB
- Tags: CPython 3.11, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7c528a71df69db23ede6651d149c691c569cf852ddd16a28d1d1bdf923ccbfa6 |
|
MD5 | 777c0e76d199d72c18e38160c22f62d0 |
|
BLAKE2b-256 | 6a5c34af434e8397503ded1d5e88d9bfef791cfa650e51aee5bbc74f9fe9595b |
File details
Details for the file python_olm-3.2.16-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
.
File metadata
- Download URL: python_olm-3.2.16-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
- Upload date:
- Size: 296.4 kB
- Tags: CPython 3.11, manylinux: glibc 2.17+ i686, manylinux: glibc 2.5+ i686
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6862318d4970de508db8b84ad432e2f6b29286f91bfc136020cbb2aa2cf726fc |
|
MD5 | b281fc79e47268c32dc3abadc016f059 |
|
BLAKE2b-256 | 6ed9a0294653a8b34470c8a5c5316397bbbbd39f6406aea031eec60c638d3169 |
File details
Details for the file python_olm-3.2.16-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: python_olm-3.2.16-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 300.8 kB
- Tags: CPython 3.10, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2fd199908833349551931686ebdd983fdd9cf01bd2f98fd1991ccf99ed2a7049 |
|
MD5 | a7ddc83a5e33b13008d2a136b318e223 |
|
BLAKE2b-256 | f927bbdfa8f2c146604888ee64bcd945f5c772217d1ab63bdd0ac5aa11908bd8 |
File details
Details for the file python_olm-3.2.16-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
.
File metadata
- Download URL: python_olm-3.2.16-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 293.1 kB
- Tags: CPython 3.10, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c10e94f1369f6ffa3dae2cc8f74757a6c050cefeb4f59ba10f95da0195e88329 |
|
MD5 | 881031b2e01a55b2b6ebfca045ba6989 |
|
BLAKE2b-256 | 9538ac79c3d5b7d1a3c09807b467692b26c61527e4733b6de4db908525b16465 |
File details
Details for the file python_olm-3.2.16-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
.
File metadata
- Download URL: python_olm-3.2.16-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
- Upload date:
- Size: 296.4 kB
- Tags: CPython 3.10, manylinux: glibc 2.17+ i686, manylinux: glibc 2.5+ i686
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 989af27a123ac0cb5c56269097e8ce879185ecc46d0c18b849ded43c8944f423 |
|
MD5 | 8ac4868e5ae5a87dbc77bdf8ec5b5677 |
|
BLAKE2b-256 | cc5797c2b0c8df19136e7ae0ebc3647866cf9b704d54a3d96d65949e250d1204 |
File details
Details for the file python_olm-3.2.16-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: python_olm-3.2.16-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 300.8 kB
- Tags: CPython 3.9, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d697b93b1aae4f425dd3b651f288d1209f2f88d991eed0432a96ba229a50e978 |
|
MD5 | 0a9524565c1c69689c6f235e41e84032 |
|
BLAKE2b-256 | 94a689a17f24b5e41132e8831a827a137b7353ebd4c0a021d5d7b94842765d29 |
File details
Details for the file python_olm-3.2.16-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
.
File metadata
- Download URL: python_olm-3.2.16-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 293.1 kB
- Tags: CPython 3.9, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1488b9d7f08754a9da927f582dbe426542225c9796b3b71a3be241622226d6f4 |
|
MD5 | 733794dd6de9c3381f7176d2a483ac35 |
|
BLAKE2b-256 | 89bbf6648c1f4086dce3a6f1d97a1b14e68cba798151de04f4e6c2a416cc4786 |
File details
Details for the file python_olm-3.2.16-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
.
File metadata
- Download URL: python_olm-3.2.16-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
- Upload date:
- Size: 296.3 kB
- Tags: CPython 3.9, manylinux: glibc 2.17+ i686, manylinux: glibc 2.5+ i686
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6f2215ff1635b6b70dbd0bd8549424cf7bb0179aba72afd23205aae3707a686e |
|
MD5 | b1200d076f6dda933c2d17d51d7e4249 |
|
BLAKE2b-256 | f04fb2ef94cff6c2cb6c1add7758214abe4385915e968eaa535ab3087ab6951f |
File details
Details for the file python_olm-3.2.16-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: python_olm-3.2.16-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 300.9 kB
- Tags: CPython 3.8, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 39ddf368f30979a0bf8bc1a1b6a944d991b759b948c94e9d738e0181cbe22767 |
|
MD5 | 6dd04b4a87b30342d604b920aee92c51 |
|
BLAKE2b-256 | b40e24a20061e68f8c2352125c617bf15d74fb2bac98448229688e8f737985e8 |
File details
Details for the file python_olm-3.2.16-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
.
File metadata
- Download URL: python_olm-3.2.16-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 293.2 kB
- Tags: CPython 3.8, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 04a4da47b90c5b01fba89fffa1710d10fd3a33b6f47e4fe33402325858556b38 |
|
MD5 | 2e7cf462e073a492c55aaa02bfacd9b2 |
|
BLAKE2b-256 | ef071dacebeccac4c3c3081ba1674e3efefb7934f9e03e1127f1810cfa6fe43f |
File details
Details for the file python_olm-3.2.16-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
.
File metadata
- Download URL: python_olm-3.2.16-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
- Upload date:
- Size: 296.5 kB
- Tags: CPython 3.8, manylinux: glibc 2.17+ i686, manylinux: glibc 2.5+ i686
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0558b1cad408eb473a90c0f64f892a8f59797408f3ad256f2ca8ae440ff2002c |
|
MD5 | b6a8317dcef4e996dd6324c765a0089f |
|
BLAKE2b-256 | 54013cfdb8169271a29ef803daf9be0fccb6968e3392c61635725ed6bef3ec3a |
File details
Details for the file python_olm-3.2.16-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: python_olm-3.2.16-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 300.6 kB
- Tags: CPython 3.7m, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 51b7f9f655c1812f7e3a859ca6048ed6870962c913d74ce956feffe49b0d04e2 |
|
MD5 | 44201fbb2d05d05bd47d845dabdfd0c6 |
|
BLAKE2b-256 | cacdedc2cba45655ed34d45c7eed271fa3ed9d9c52f48e8620e43c6d249dac8f |
File details
Details for the file python_olm-3.2.16-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
.
File metadata
- Download URL: python_olm-3.2.16-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 292.8 kB
- Tags: CPython 3.7m, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f42c048b9fc420d638a11f2f08e67745307a576914a4e68ed0ca4554a10487bf |
|
MD5 | 0917b080416638a2d95c09b235e97be9 |
|
BLAKE2b-256 | 44836ea4f148ffd56aeb01c3634541ab0ab6d8652958d45b937a7b8d1ceac6e4 |
File details
Details for the file python_olm-3.2.16-cp37-cp37m-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
.
File metadata
- Download URL: python_olm-3.2.16-cp37-cp37m-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
- Upload date:
- Size: 296.1 kB
- Tags: CPython 3.7m, manylinux: glibc 2.17+ i686, manylinux: glibc 2.5+ i686
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a0a449c16c5f3756b8e1a89763c22391b43ed6da17046df08bb4be7dab609b35 |
|
MD5 | aca9ff8ed470db90e0613a345a0cb6e7 |
|
BLAKE2b-256 | 7f3b7cbb64e3a7936057b9e8ff6822adaaa948c088932a10a7e8c7dc948a29ae |