|
|
@@ -4,11 +4,14 @@ use crypto_box::{ |
|
|
|
}; |
|
|
|
use std::io::Write; |
|
|
|
use std::net::TcpStream; |
|
|
|
use crate::message::*; |
|
|
|
|
|
|
|
mod message; |
|
|
|
|
|
|
|
fn main() { |
|
|
|
let port: u32 = 7878; // Port Server |
|
|
|
//let stream = TcpStream::connect("172.30.16.1:8080"); |
|
|
|
//let stream = TcpStream::connect("27.0.0.1:8080"); |
|
|
|
// Server Port |
|
|
|
let port: u32 = 7878; |
|
|
|
|
|
|
|
match TcpStream::connect(format!("localhost:{}", port)) { |
|
|
|
Ok(mut stream) => { |
|
|
|
println!("Successfully connected to server"); |
|
|
@@ -49,6 +52,7 @@ fn main() { |
|
|
|
|
|
|
|
// Encrypt the message using the box |
|
|
|
let ciphertext = salsa_box.encrypt(&nonce, &plaintext[..]).expect("Fehler"); |
|
|
|
let message = Message::new(0,0,4, PayloadType::Msg); |
|
|
|
|
|
|
|
println!("Sending {0} as {1:?}", buffer.trim(), plaintext); |
|
|
|
stream.write(buffer.as_bytes()).unwrap(); |
|
|
@@ -82,17 +86,3 @@ fn main() { |
|
|
|
} |
|
|
|
println!("Terminated."); |
|
|
|
} |
|
|
|
|
|
|
|
fn generate_box(partner_public_key: PublicKey) -> (SalsaBox, PublicKey) { |
|
|
|
// Generate a random secret key. |
|
|
|
// NOTE: The secret key bytes can be accessed by calling `secret_key.as_bytes()` |
|
|
|
let own_secret_key = SecretKey::generate(&mut OsRng); |
|
|
|
|
|
|
|
// Get the public key for the secret key we just generated |
|
|
|
let own_public_key = own_secret_key.public_key().clone(); |
|
|
|
|
|
|
|
// Create a `SalsaBox` by performing Diffie-Hellman key agreement between |
|
|
|
// the two keys. |
|
|
|
let salsa_box = SalsaBox::new(&partner_public_key, &own_secret_key); |
|
|
|
(salsa_box, own_public_key) |
|
|
|
} |