Expand description
Asynchronous PSEC implementation.
PSEC (Peer-to-peer Secure Ephemeral Communications) is a simplification/adaptation of TLS 1.3 for P2P networks which provides an encrypted and authenticated secure transport layer for ephemeral communications. PSEC ensures deniability, forward secrecy, future secrecy, and optional plaintext length obfuscation. This crate is an implementation of this protocol built with the tokio framework.
§Usage
Add this in your Cargo.toml
:
[dependencies]
async-psec = "0.4"
And then:
use rand::rngs::OsRng;
use tokio::net::TcpStream;
use async_psec::{Session, Identity, PsecReader, PsecWriter, PsecError};
#[tokio::main]
async fn main() -> Result<(), PsecError> {
let identity = Identity::generate(&mut OsRng); //generate a new PSEC identity
//connect to another PSEC node listening on 10.152.152.10:7530
let stream = TcpStream::connect("10.152.152.10:7530").await.unwrap();
let mut psec_session = Session::from(stream); //wrap the TcpStream into a PSEC session
psec_session.do_handshake(&identity).await?; //perform the PSEC handshake
//encrypt a message, obfuscate its length with padding then send it
psec_session.encrypt_and_send(b"Hello I'm Alice", true).await?;
//receive then decrypt a message
println!("Received: {:?}", psec_session.receive_and_decrypt().await?);
}
§Split Feature
If you want to split the Session
struct in two parts, you must enable the split
feature:
[dependencies]
async-psec = { version = "0.4", feature = ["split"] }
This can be useful if you want to send data from one thread/task and receive from another in parallel.
Structs§
- Session
- A PSEC connection.
- Session
Read Half - The read half of a PSEC session. Obtained with
Session::into_split
. - Session
Write Half - The write half of a PSEC session. Obtained with
Session::into_split
.
Enums§
- Psec
Error - Errors that can be returned by PSEC operations.
Constants§
- PUBLIC_
KEY_ LENGTH - The length of a PSEC public key, in bytes.
Traits§
- Psec
Reader - Read from a PSEC session.
- Psec
Writer - Write to a PSEC session.
Type Aliases§
- Identity
- A PSEC Identity.