portal-lib
A small Protocol Library for Portal - An encrypted file transfer utility
This crate enables a consumer to:
- Create/serialize/deserialize Portal request/response messages.
- Negoticate a symmetric key with a peer using SPAKE2
- Encrypt files with Chacha20-Poly1305 using either the RustCrypto implementation or Ring's
- Send/receive files through a Portal relay
The library is broken up into two abstractions:
- A higher level API, exposted via the
Portalstruct, to facilitate automating transfers easily - A lower level API, exposed via the
Protocolstruct, if you need access to lower-level facilities
Higher Level API - Example of Sending a file:
use Path;
use Error;
use TcpStream;
use ;
Higher Level API - Example of Receiving a file:
use Path;
use Error;
use TcpStream;
use ;
Lower Level API - Example of SPAKE2 key negotiation:
use ;
// Securely receive/derive your id & password for this session
let channel_id = Stringfrom;
let password = Stringfrom;
// Init a Spake2 context
let = start_symmetric;
// Connect to the relay
let mut stream = connect.unwrap;
// Send the connection message to the relay. If the relay cannot
// match us with a peer this will fail.
let confirm =
connect.unwrap;
// Derive the shared session key
let key = derive_key.unwrap;
// confirm that the peer has the same key
confirm_peer?;
You can use the confirm_peer() method to verify that a remote peer has derived the same key as you, as long as the communication stream implements the std::io::Read and std::io::Write traits.