Crates.io | vented |
lib.rs | vented |
version | 0.11.7 |
source | src |
created_at | 2020-11-06 14:08:46.698127 |
updated_at | 2020-11-21 18:39:50.63369 |
description | Event driven encrypted tcp communicaton |
homepage | |
repository | https://github.com/trivernis/vented |
max_upload_size | |
id | 309223 |
size | 84,828 |
Vented is an event based asynchronous TCP server with encryption that uses message pack for payload data.
Vented uses key cryptography to encrypt the connection between the client and the serve. The authenticity of both parties is validated by global public keys that need to be known to both parties beforehand. The encryption itself uses randomly generated keys and a nonce that corresponds to the message number. The crate used for encryption is crypto_box which the XChaCha20Poly1305 encryption. The crate used for the key exchanges is x25519-dalek.
use vented::server::VentedServer;
use vented::server::data::{Node, ServerTimeouts};
use vented::stream::SecretKey;
use rand::thread_rng;
use vented::event::Event;
fn main() {
let global_secret_b = SecretKey::generate(&mut thread_rng());
let nodes = vec![
Node {
id: "B".to_string(),
addresses: vec![],
trusted: true,
public_key: global_secret_b.public_key() // load it from somewhere
},
];
// in a real world example the secret key needs to be loaded from somewhere because connections
// with unknown keys are not accepted.
let global_secret = SecretKey::generate(&mut thread_rng());
let mut server = VentedServer::new("A".to_string(), global_secret, nodes.clone(), ServerTimeouts::default());
server.listen("localhost:20000".to_string());
server.on("pong", |_event| {
Box::pin(async {println!("Pong!");
None
})
});
assert!(async_std::task::block_on(server.emit("B", Event::new("ping".to_string()))).is_err()) // this won't work without a known node B
}
}