Pluggable Transports in Rust (PTRS)
PTRS is a library for writing pluggable transports in Rust.
⚠️ 🚧 WARNING This crate is still under construction 🚧 ⚠️
- interface subject to change at any time
- Not production ready
- do not rely on this for any security critical applications
Library Usage
This library (currently) revolves around the abstraction of connections as anything that implement
the traits [tokio::io:AsyncRead] + [tokio::io::AsyncWrite] + Unpin + Send + Sync. This allows
us to define the expected shared behavior of pluggable transports as a transform of these
[Stream]s.
/// Future containing a generic result. We use this for functions that take
/// and/or return futures that will produce Read/Write tunnels once awaited.
pub type FutureResult<T, E> = ;
/// Future containing a generic result, shorthand for ['FutureResult']. We use
/// this for functions that take and/or return futures that will produce
/// Read/Write tunnels once awaited.
pub type F<T, E> = ;
/// Client Transport
/// Server Transport
Integrating ptrs Transports
Given this abstraction integrating transports into async rust applications becomes relatively straightforward, for example, integrating the identity transport (which performs a direct copy with no actual transform) could be done similar to:
/// TODO
Integration on the client side is similarly straightforward.
/// TODO
For more in depth integration exapmples see the binary examples in the
lyrebird crate.
Configuration & State
Transports can be configured using their respective builder interface implementations
which require options(...) and statedir(...) functions. See the
obfs4 transport for and example implementation of the
ptrs interfaces.
Composition
Because the ptrs interface wraps objects implementing connection oriented traits and and returns trait objects implementing the same abstraction is is possible to wrap multiple transports on top of one another. One reason to do this might be to have separate reliability, obfuscation and padding strategies that can be composed interchangeably.
let listener = bind
.await
.unwrap;
let = listener.accept.await.unwrap;
let pb: &BuilderS = &<Passthrough as >server_builder;
let client1 = build;
let conn1 = client1.reveal.await.unwrap;
let client2 = build;
let conn2 = client2.reveal.await.unwrap;
let client3 = build;
let mut sock = client3.reveal.await.unwrap;
let = split;
_ = copy.await;
In the client:
let pb: &BuilderC = &<Passthrough as >client_builder;
let client = build;
let conn_fut1 = client.establish;
let client = build;
let conn_fut2 = client.establish;
let client = build;
let conn_fut3 = client.establish;
let mut conn = conn_fut3.await?;
let msg = b"a man a plan a canal panama";
_ = conn.write.await?;
Implementing a Transport
There are several constructions that can be used to build up a pluggable transport, in part this is because no individual construction has proven demonstrably better than the others.
The obfs4 transport is implemented using the tokio_util::codec model.
Notes / Resources
While this is related to and motivated by the Tor pluggable transport system, the primary concern of this repository is creating a consistent and useful abstraction for building pluggable transports. For more information about Tor related pluggable transports see the following resources.
Open Source License
Dual licensing under both MIT and Apache-2.0 is the currently accepted standard by the Rust language community and has been used for both the compiler and many public libraries since (see Why dual MIT/ASL2license?). In order to match the community standards, ptrs is using the dual MIT+Apache-2.0 license.
Contributing
Contributors, Issues, and Pull Requests are Welcome