Rust扩展为信号协议提供Python绑定
signal-protocol的Python项目详细描述
信号协议
实验性的Python绑定到^{signal_protocol
Python模块的Rust扩展。请参见here,了解在Python分配的内存中存储机密的基本限制。⚠️使用风险自负!⚠️ 在
使用
初始设置
fromsignal_protocolimportcurve,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=10pre_key_record=state.PreKeyRecord(pre_key_id,pre_key_pair)store.save_pre_key(pre_key_id,pre_key_record)signed_pre_key_id=33signed_prekey=state.SignedPreKeyRecord(signed_pre_key_id,42,# This is a timestamp since this key should be periodically rotatedsigned_pre_key_pair,signed_pre_key_signature,)store.save_signed_pre_key(signed_pre_key_id,signed_prekey)
向新参与者发送消息
^{pr2}$开发人员入门
您需要在系统上同时安装Rust和python3.7+。要在virtualenv中安装项目,请执行以下操作:
pip install -r requirements.txt
python setup.py develop # This will call out to rustc
然后通过pytest -v tests/
运行测试,以确认所有测试都正常。测试从上游的板条箱移植到Python上。您可以将测试用作如何使用库的参考。在
- 项目
标签: