P2P-Secure-Conn 🦀
A lightweight, async-first Rust library for establishing Mutual TLS (mTLS) connections. Built on top of tokio-rustls and rustls, it simplifies the process of generating self-signed identities and enforcing strict two-way authentication between peers.
Features
- Mutual Authentication (mTLS): Both the client and the server must present valid certificates to establish a connection.
- Self-Signed Friendly: Built-in utility to generate x509 identities on the fly using
rcgen. - Async Ready: Designed specifically for the
tokioecosystem. - Simple API: Wraps complex
rustlsconfigurations into straightforwardacceptandconnectfunctions.
Usage example (to see a full working example in action check out file-express)
Set up crypto provider
let _ = ring::default_provider().install_default();
Peer A generates identity meaning cert and key, and generate fingerprint
let = generate_identity?;
let hash = get_cert_fingerprint;
Peer B does the same
let = generate_identity?;
let hash = get_cert_fingerprint;
The hash must then be shared between them
Peer A
let listener = bind.await?;
let addr = listener.local_addr?;
let mut secure_conn: SecureConn = accept.await.expect;
Peer B
let mut secure_conn: SecureConn = connect.await?;
SecureConnection is a Tls wrapper
So you can use secure_conn variable like this for example
secure_conn.stream.write_all.await?;
let mut buf = ;
secure_conn.stream.read_exact.await?;
License
This project is licensed under the MIT License, see the LICENSE file for details.