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 Chacha20poly1305 using the RustCrypto implementation
- Send/receive files through a Portal relay
Example of SPAKE2 key negotiation:
use ;
// receiver
let id = "id".to_string;
let pass ="test".to_string;
let = init;
// sender
let id = "id".to_string;
let pass ="test".to_string;
let = init;
// Both clients should derive the same key
receiver.derive_key.unwrap;
sender.derive_key.unwrap;
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.
Example of Sending a file:
use ;
use TcpStream;
use Write;
let mut client = connect.unwrap;
// Create portal request as the Sender
let id = "id".to_string;
let pass ="test".to_string;
let = init;
// complete key derivation + peer verification
let mut file = portal.load_file.unwrap;
// Encrypt the file and share state
file.encrypt.unwrap;
file.sync_file_state.unwrap;
for data in file.get_chunks
Example of Receiving a file:
use ;
use TcpStream;
use Write;
let mut client = connect.unwrap;
// receiver
let dir = Receiver;
let pass ="test".to_string;
let = init;
// serialize & send request
let request = portal.serialize.unwrap;
client.write_all.unwrap;
// get response
let response = read_response_from.unwrap;
// complete key derivation + peer verification
// create outfile
let fsize = response.get_file_size;
let mut file = portal.create_file.unwrap;
let callback = ;
// Receive until connection is done
let len = file.download_file.unwrap;
assert_eq!;
// Decrypt the file
file.decrypt.unwrap;