1 个不稳定版本

0.2.0 2021 年 2 月 14 日

#978密码学

ISC 许可证

50KB
1K SLoC

ssb-box-stream

Build Status

实现 Scuttlebutt握手机制 以及 Box Stream,以在两个 peer 之间建立安全的认证和加密连接。

用法

一个简单的 echo 服务器(见 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?

一个客户端(见 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?;

依赖项

~20MB
~115K SLoC