Expand description
Implementation of Scuttlebutt Handshake and Box Stream to establish a secure authenticated and encrypted connection between two peers.
§Usage
A simple echo server (see examples/echo_server.rs)
let server_identity = sodiumoxide::crypto::sign::gen_keypair().unwrap();
let listener = async_std::net::TcpListener::bind("localhost:5555").await?;
let (stream, _) = listener.accept().await?;
let server =
ssb_box_stream::Server::new(&NETWORK_IDENTIFIER, &server_identity.0, &server_identity.1);
let (mut sender, mut receiver, client_key) = server.accept(stream).await?;
println!("Connected to client {:?}", client_key);
while let Some(data) = receiver.try_next().await? {
println!("<- {}", String::from_utf8_lossy(&data));
sender.send(data).await?
}
sender.close().await?A client (see examples/client.rs).
// This needs to match the server identity keypair
let server_identity_pk = sodiumoxide::crypto::sign::gen_keypair().0;
let client_identity = sodiumoxide::crypto::sign::gen_keypair();
let stream = async_std::net::TcpStream::connect("localhost:5555").await?;
let client = ssb_box_stream::Client::new(
&NETWORK_IDENTIFIER,
&server_identity_pk,
&client_identity.0,
&client_identity.1,
);
let (mut sender, _receiver) = client.connect(stream).await?;
sender.send(Vec::from(b"hello world")).await?;Structs§
- BoxStream
Params - A pair of CipherParams, one for receiving and decrypting data, the other for encrypting and sending data.
- Cipher
Params - Parameters for encrypting or decrypting a sequence of packets
- Client
- Parameters to establish a secure connection as a client
- Decrypt
- A Stream of
Vec<u8>that decrypts and authenticates data from the underlyingReader. - Encrypt
- A Sink for
Vec<u8>that encrypts data and sends it to the underlyingWriter - Server
- Parameters to establish a secure connection as a server
Enums§
- Decrypt
Error - Error when decrypting and authenticating data.
- Error
- Errors returned when running the handshake protocol.
Functions§
- box_
stream - Take a duplex stream and create a Sink for sending encrypted data and a Stream for receiving and decrypting data.